feed position history into model inputs

This commit is contained in:
2026-03-27 14:50:08 -07:00
parent 9ad8a70ad0
commit a05113baa5

View File

@@ -13,7 +13,8 @@ use strafesnet_graphics::setup;
use strafesnet_roblox_bot_file::v0;
const SIZE: glam::UVec2 = glam::uvec2(64, 36);
const INPUT: usize = (SIZE.x * SIZE.y) as usize;
const POSITION_HISTORY: usize = 4;
const INPUT: usize = (SIZE.x * SIZE.y) as usize + POSITION_HISTORY * 3;
const HIDDEN: [usize; 2] = [INPUT >> 3, INPUT >> 7];
// MoveForward
// MoveLeft
@@ -75,6 +76,7 @@ struct GraphicsState {
graphics_texture_view: wgpu::TextureView,
output_staging_buffer: wgpu::Buffer,
texture_data: Vec<u8>,
position_history: Vec<glam::Vec3>,
}
impl GraphicsState {
fn new(map: &strafesnet_common::map::CompleteMap) -> Self {
@@ -126,6 +128,7 @@ impl GraphicsState {
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
mapped_at_creation: false,
});
let position_history = Vec::with_capacity(POSITION_HISTORY);
Self {
device,
queue,
@@ -133,9 +136,31 @@ impl GraphicsState {
graphics_texture_view,
output_staging_buffer,
texture_data,
position_history,
}
}
fn generate_inputs(&mut self, pos: glam::Vec3, angles: glam::Vec2, inputs: &mut Vec<f32>) {
// write position history to model inputs
if !self.position_history.is_empty() {
let camera = strafesnet_graphics::graphics::view_inv(pos, angles).inverse();
for &pos in self.position_history.iter().rev() {
let relative_pos = camera.transform_vector3(pos);
inputs.extend_from_slice(&relative_pos.to_array());
}
}
// fill remaining history with zeroes
for _ in self.position_history.len()..POSITION_HISTORY {
inputs.extend_from_slice(&[0.0, 0.0, 0.0]);
}
// track position history
if self.position_history.len() < POSITION_HISTORY {
self.position_history.push(pos);
} else {
self.position_history.rotate_left(1);
*self.position_history.last_mut().unwrap() = pos;
}
let mut encoder = self
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {