This commit is contained in:
2026-03-26 13:13:15 -07:00
parent 293daf3ab2
commit 9c455141cf
3 changed files with 30 additions and 1 deletions

1
Cargo.lock generated
View File

@@ -5451,6 +5451,7 @@ name = "strafe-ai"
version = "0.1.0"
dependencies = [
"burn",
"png",
"pollster",
"strafesnet_common",
"strafesnet_graphics",

View File

@@ -14,3 +14,4 @@ strafesnet_roblox_bot_file = { version = "0.9.4", registry = "strafesnet" }
strafesnet_roblox_bot_player = { version = "=0.6.2-depth", registry = "strafesnet" }
strafesnet_snf = { version = "0.4.0", registry = "strafesnet" }
pollster = "0.4.0"
png = "0.18.1"

View File

@@ -11,6 +11,24 @@ const LIMITS: wgpu::Limits = wgpu::Limits::defaults();
use strafesnet_graphics::setup;
use strafesnet_roblox_bot_file::v0;
pub fn output_image_native(image_data: &[u8], texture_dims: (usize, usize), path: String) {
use std::io::Write;
let mut png_data = Vec::<u8>::with_capacity(image_data.len());
let mut encoder = png::Encoder::new(
std::io::Cursor::new(&mut png_data),
texture_dims.0 as u32,
texture_dims.1 as u32,
);
encoder.set_color(png::ColorType::Rgba);
let mut png_writer = encoder.write_header().unwrap();
png_writer.write_image_data(image_data).unwrap();
png_writer.finish().unwrap();
let mut file = std::fs::File::create(&path).unwrap();
file.write_all(&png_data).unwrap();
}
const SIZE_X: usize = 64;
const SIZE_Y: usize = 36;
const INPUT: usize = SIZE_X * SIZE_Y;
@@ -164,7 +182,7 @@ fn training() {
let mut last_mx = first.event.mouse_pos.x;
let mut last_my = first.event.mouse_pos.y;
for input_event in it {
for (i, input_event) in it.enumerate() {
let mouse_dx = input_event.event.mouse_pos.x - last_mx;
let mouse_dy = input_event.event.mouse_pos.y - last_my;
last_mx = input_event.event.mouse_pos.x;
@@ -288,6 +306,8 @@ fn training() {
}
output_staging_buffer.unmap();
println!("{texture_data:?}");
// discombolulate stride
for y in 0..size.y {
inputs.extend(
@@ -298,6 +318,13 @@ fn training() {
)
}
// write a png
output_image_native(
&inputs[i * input_size..(i + 1) * input_size],
(SIZE_X, SIZE_Y),
format!("depth_images/{i}.png").into(),
);
texture_data.clear();
}