6 Commits

Author SHA1 Message Date
7f9a76bd71 pint inputs 2026-03-27 10:02:41 -07:00
757eb2a572 not sigmoid 2026-03-27 09:59:41 -07:00
0828f2ced0 sigmoid 2026-03-27 09:58:21 -07:00
406763b8db png 2026-03-27 09:58:21 -07:00
d069271542 png 2026-03-27 09:58:21 -07:00
93c01910cb include world offset 2026-03-27 09:54:15 -07:00
3 changed files with 39 additions and 2 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,21 @@ 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(&mut png_data, texture_dims.0 as u32, texture_dims.1 as u32);
encoder.set_color(png::ColorType::Grayscale);
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;
@@ -89,6 +104,9 @@ fn training() {
.unwrap();
let timelines =
strafesnet_roblox_bot_file::v0::read_all_to_block(std::io::Cursor::new(bot_file)).unwrap();
let bot = strafesnet_roblox_bot_player::bot::CompleteBot::new(timelines).unwrap();
let world_offset = bot.world_offset();
let timelines = bot.timelines();
// setup graphics
let desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env();
@@ -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;
@@ -235,6 +253,9 @@ fn training() {
fn a(a: v0::Vector3) -> [f32; 2] {
[a.y, a.x]
}
fn sub<T: core::ops::Sub>(lhs: T, rhs: T) -> T::Output {
lhs - rhs
}
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("wgpu encoder"),
@@ -244,7 +265,7 @@ fn training() {
graphics.encode_commands(
&mut encoder,
&graphics_texture_view,
p(output_event.event.position).into(),
sub(p(output_event.event.position).into(), world_offset),
a(output_event.event.angles).into(),
);
@@ -288,6 +309,7 @@ fn training() {
}
output_staging_buffer.unmap();
let inputs_start = inputs.len();
// discombolulate stride
for y in 0..size.y {
inputs.extend(
@@ -297,6 +319,19 @@ fn training() {
.map(|b| f32::from_le_bytes(b.try_into().unwrap())),
)
}
let inputs_end = inputs.len();
println!("inputs = {:?}", &inputs[inputs_start..inputs_end]);
// write a png
output_image_native(
&inputs[i * INPUT..(i + 1) * INPUT]
.iter()
.copied()
.map(|f| (f * 255.0) as u8)
.collect::<Vec<u8>>(),
(SIZE_X, SIZE_Y),
format!("depth_images/{i}.png").into(),
);
texture_data.clear();
}