Compare commits

...

10 Commits
master ... bot

Author SHA1 Message Date
4e1ed43161 read bot debug function 2024-08-05 18:42:52 -07:00
00ac7960e0 please don't fill my hard drive 2024-08-05 17:32:03 -07:00
f2e9f81fe4 special place for debug bots 2024-08-05 17:27:17 -07:00
bfcf973524 rethink physics instructions 2024-08-05 17:26:46 -07:00
97da935d9d drop droppable instructions 2024-08-05 13:34:30 -07:00
68ccee81b1 newtypes 2024-08-05 13:34:11 -07:00
2c000cca67 prototype 2024-08-02 13:44:47 -07:00
cd65db0008 newtypes 2024-08-02 13:44:41 -07:00
91b90675c4 prototype 2024-08-02 12:11:23 -07:00
8911968a7c rand dep 2024-08-02 12:11:17 -07:00
9 changed files with 327 additions and 2 deletions

96
Cargo.lock generated
View File

@ -44,12 +44,35 @@ version = "1.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "either" name = "either"
version = "1.13.0" version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]] [[package]]
name = "glam" name = "glam"
version = "0.28.0" version = "0.28.0"
@ -67,12 +90,27 @@ dependencies = [
"syn 2.0.72", "syn 2.0.72",
] ]
[[package]]
name = "libc"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "3.5.0" version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "ppv-lite86"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee4364d9f3b902ef14fab8a1ddffb783a1cb6b4bba3bfc1fa3922732c7de97f"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.86" version = "1.0.86"
@ -91,6 +129,36 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "strafesnet_common" name = "strafesnet_common"
version = "0.2.0" version = "0.2.0"
@ -108,6 +176,7 @@ version = "0.1.1"
dependencies = [ dependencies = [
"binrw", "binrw",
"id", "id",
"rand",
"strafesnet_common", "strafesnet_common",
] ]
@ -138,3 +207,30 @@ name = "unicode-ident"
version = "1.0.12" version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zerocopy"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.72",
]

View File

@ -8,4 +8,5 @@ edition = "2021"
[dependencies] [dependencies]
binrw = "0.14.0" binrw = "0.14.0"
id = { version = "0.1.0", registry = "strafesnet" } id = { version = "0.1.0", registry = "strafesnet" }
rand = "0.8.5"
strafesnet_common = { version = "0.2.0", registry = "strafesnet" } strafesnet_common = { version = "0.2.0", registry = "strafesnet" }

View File

@ -1,4 +1,7 @@
use binrw::{BinReaderExt, binrw}; use std::io::Seek;
use binrw::{binrw,BinReaderExt,BinWriterExt};
use crate::newtypes::instruction::TimedPhysicsInstruction;
#[derive(Debug)] #[derive(Debug)]
pub enum Error{ pub enum Error{
@ -8,6 +11,46 @@ pub enum Error{
File(crate::file::Error), File(crate::file::Error),
} }
pub struct BotDebug{
name:String,
file:std::fs::File,
}
impl BotDebug{
pub fn new()->std::io::Result<Self>{
let rng:u128=rand::random();
let name=format!("debug_bots/{rng:x}");
Ok(Self{
file:std::fs::File::create(name.as_str())?,
name,
})
}
pub fn delete(self)->std::io::Result<()>{
std::mem::drop(self.file);
std::fs::remove_file(self.name)
}
pub fn push(&mut self,ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<(),binrw::Error>{
let ret=match TryInto::<TimedPhysicsInstruction>::try_into(ins){
Ok(ins)=>self.file.write_le(&ins),
Err(crate::newtypes::physics::PhysicsInputInstructionError::DropInstruction)=>Ok(()),
};
//check if too much data has written to be reasonable
//avoid filling my hard drive on an infinite loop basically
if self.file.stream_position().is_ok_and(|pos|50*1024*1024<pos){
panic!();
}
ret
}
}
pub fn read_bot_debug(mut reader:impl BinReaderExt)->Result<Vec<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>>,binrw::Error>{
let mut instructions=Vec::new();
while let Ok(ins)=reader.read_le::<TimedPhysicsInstruction>(){
instructions.push(ins.try_into().unwrap());
}
Ok(instructions)
}
/* block types /* block types
BLOCK_BOT_HEADER: BLOCK_BOT_HEADER:

View File

@ -1,7 +1,10 @@
mod common; mod common;
pub mod aabb; pub mod aabb;
pub mod model; pub mod model;
pub mod mouse;
pub mod integer; pub mod integer;
pub mod physics;
pub mod instruction;
pub mod gameplay_modes; pub mod gameplay_modes;
pub mod gameplay_style; pub mod gameplay_style;
pub mod gameplay_attributes; pub mod gameplay_attributes;

View File

@ -1,10 +1,13 @@
use super::common::flag; use super::common::flag;
pub type ModeId=u32;
pub type StageId=u32;
#[binrw::binrw] #[binrw::binrw]
#[brw(little)] #[brw(little)]
pub struct StageElement{ pub struct StageElement{
pub header:u8, pub header:u8,
pub stage_id:u32, pub stage_id:StageId,
#[br(if(header&Self::JUMP_LIMIT!=0))] #[br(if(header&Self::JUMP_LIMIT!=0))]
pub jump_limit:Option<u8>, pub jump_limit:Option<u8>,
} }

View File

@ -0,0 +1,27 @@
use super::integer::Time;
#[binrw::binrw]
#[brw(little)]
pub struct TimedPhysicsInstruction{
pub time:Time,
pub instruction:super::physics::PhysicsInputInstruction,
}
impl TryInto<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
type Error=super::integer::RatioError;
fn try_into(self)->Result<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,Self::Error>{
Ok(strafesnet_common::instruction::TimedInstruction{
time:strafesnet_common::integer::Time::raw(self.time),
instruction:self.instruction.try_into()?,
})
}
}
impl TryFrom<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
type Error=super::physics::PhysicsInputInstructionError;
fn try_from(value:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<Self,Self::Error>{
Ok(Self{
time:value.time.get(),
instruction:value.instruction.try_into()?,
})
}
}

View File

@ -38,6 +38,23 @@ pub struct Ratio64Vec2{
pub x:Ratio64, pub x:Ratio64,
pub y:Ratio64, pub y:Ratio64,
} }
impl TryInto<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
type Error=RatioError;
fn try_into(self)->Result<strafesnet_common::integer::Ratio64Vec2,Self::Error>{
Ok(strafesnet_common::integer::Ratio64Vec2{
x:self.x.try_into()?,
y:self.y.try_into()?,
})
}
}
impl From<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
fn from(value:strafesnet_common::integer::Ratio64Vec2)->Self{
Self{
x:value.x.into(),
y:value.y.into(),
}
}
}
pub type Angle32=i32; pub type Angle32=i32;
pub type Planar64=i64; pub type Planar64=i64;

37
src/newtypes/mouse.rs Normal file
View File

@ -0,0 +1,37 @@
use super::integer::Time;
#[binrw::binrw]
#[brw(little)]
pub enum EncodedMouseDelta{
//X did not move Y has 1 byte, time has 2 bytes
X0Y1T2{
y:i8,
t:u16,
},
X1Y1T2
}
///TODO: delta delta encoding lol
#[binrw::binrw]
#[brw(little)]
pub struct MouseState{
pub pos:[i32;2],
pub time:Time,
}
impl Into<strafesnet_common::mouse::MouseState> for MouseState{
fn into(self)->strafesnet_common::mouse::MouseState{
strafesnet_common::mouse::MouseState{
pos:self.pos.into(),
time:strafesnet_common::integer::Time::raw(self.time),
}
}
}
impl From<strafesnet_common::mouse::MouseState> for MouseState{
fn from(value:strafesnet_common::mouse::MouseState)->Self{
Self{
pos:value.pos.to_array(),
time:value.time.get(),
}
}
}

98
src/newtypes/physics.rs Normal file
View File

@ -0,0 +1,98 @@
use super::common::Boolio;
#[binrw::binrw]
#[brw(little)]
pub enum PhysicsInputInstruction{
#[brw(magic=0u8)]
ReplaceMouse(super::mouse::MouseState,super::mouse::MouseState),
#[brw(magic=1u8)]
SetNextMouse(super::mouse::MouseState),
#[brw(magic=2u8)]
SetMoveRight(Boolio),
#[brw(magic=3u8)]
SetMoveUp(Boolio),
#[brw(magic=4u8)]
SetMoveBack(Boolio),
#[brw(magic=5u8)]
SetMoveLeft(Boolio),
#[brw(magic=6u8)]
SetMoveDown(Boolio),
#[brw(magic=7u8)]
SetMoveForward(Boolio),
#[brw(magic=8u8)]
SetJump(Boolio),
#[brw(magic=9u8)]
SetZoom(Boolio),
#[brw(magic=10u8)]
Reset,
#[brw(magic=11u8)]
Restart,
#[brw(magic=12u8)]
Spawn(super::gameplay_modes::ModeId,super::gameplay_modes::StageId),
#[brw(magic=13u8)]
PracticeFly,
#[brw(magic=14u8)]
SetSensitivity(super::integer::Ratio64Vec2),
}
#[derive(Debug)]
pub enum PhysicsInputInstructionError{
/// This is an instruction that can be dropped when serializing
DropInstruction,
}
impl std::fmt::Display for PhysicsInputInstructionError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for PhysicsInputInstructionError{}
impl TryInto<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
type Error=super::integer::RatioError;
fn try_into(self)->Result<strafesnet_common::physics::Instruction,Self::Error>{
Ok(match self{
PhysicsInputInstruction::ReplaceMouse(m0,m1)=>strafesnet_common::physics::Instruction::ReplaceMouse(m0.into(),m1.into()),
PhysicsInputInstruction::SetNextMouse(m)=>strafesnet_common::physics::Instruction::SetNextMouse(m.into()),
PhysicsInputInstruction::SetMoveRight(state)=>strafesnet_common::physics::Instruction::SetMoveRight(state.into()),
PhysicsInputInstruction::SetMoveUp(state)=>strafesnet_common::physics::Instruction::SetMoveUp(state.into()),
PhysicsInputInstruction::SetMoveBack(state)=>strafesnet_common::physics::Instruction::SetMoveBack(state.into()),
PhysicsInputInstruction::SetMoveLeft(state)=>strafesnet_common::physics::Instruction::SetMoveLeft(state.into()),
PhysicsInputInstruction::SetMoveDown(state)=>strafesnet_common::physics::Instruction::SetMoveDown(state.into()),
PhysicsInputInstruction::SetMoveForward(state)=>strafesnet_common::physics::Instruction::SetMoveForward(state.into()),
PhysicsInputInstruction::SetJump(state)=>strafesnet_common::physics::Instruction::SetJump(state.into()),
PhysicsInputInstruction::SetZoom(state)=>strafesnet_common::physics::Instruction::SetZoom(state.into()),
PhysicsInputInstruction::Reset=>strafesnet_common::physics::Instruction::Reset,
PhysicsInputInstruction::Restart=>strafesnet_common::physics::Instruction::Restart,
PhysicsInputInstruction::Spawn(mode_id,stage_id)=>strafesnet_common::physics::Instruction::Spawn(
strafesnet_common::gameplay_modes::ModeId::new(mode_id),
strafesnet_common::gameplay_modes::StageId::new(stage_id),
),
PhysicsInputInstruction::PracticeFly=>strafesnet_common::physics::Instruction::PracticeFly,
PhysicsInputInstruction::SetSensitivity(sensitivity)=>strafesnet_common::physics::Instruction::SetSensitivity(sensitivity.try_into()?),
})
}
}
impl TryFrom<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
type Error=PhysicsInputInstructionError;
fn try_from(value:strafesnet_common::physics::Instruction)->Result<Self,Self::Error>{
match value{
strafesnet_common::physics::Instruction::ReplaceMouse(m0,m1)=>Ok(PhysicsInputInstruction::ReplaceMouse(m0.into(),m1.into())),
strafesnet_common::physics::Instruction::SetNextMouse(m)=>Ok(PhysicsInputInstruction::SetNextMouse(m.into())),
strafesnet_common::physics::Instruction::SetMoveRight(state)=>Ok(PhysicsInputInstruction::SetMoveRight(state.into())),
strafesnet_common::physics::Instruction::SetMoveUp(state)=>Ok(PhysicsInputInstruction::SetMoveUp(state.into())),
strafesnet_common::physics::Instruction::SetMoveBack(state)=>Ok(PhysicsInputInstruction::SetMoveBack(state.into())),
strafesnet_common::physics::Instruction::SetMoveLeft(state)=>Ok(PhysicsInputInstruction::SetMoveLeft(state.into())),
strafesnet_common::physics::Instruction::SetMoveDown(state)=>Ok(PhysicsInputInstruction::SetMoveDown(state.into())),
strafesnet_common::physics::Instruction::SetMoveForward(state)=>Ok(PhysicsInputInstruction::SetMoveForward(state.into())),
strafesnet_common::physics::Instruction::SetJump(state)=>Ok(PhysicsInputInstruction::SetJump(state.into())),
strafesnet_common::physics::Instruction::SetZoom(state)=>Ok(PhysicsInputInstruction::SetZoom(state.into())),
strafesnet_common::physics::Instruction::Reset=>Ok(PhysicsInputInstruction::Reset),
strafesnet_common::physics::Instruction::Restart=>Ok(PhysicsInputInstruction::Restart),
strafesnet_common::physics::Instruction::Spawn(mode_id,stage_id)=>Ok(PhysicsInputInstruction::Spawn(
mode_id.get(),
stage_id.get(),
)),
strafesnet_common::physics::Instruction::PracticeFly=>Ok(PhysicsInputInstruction::PracticeFly),
strafesnet_common::physics::Instruction::SetSensitivity(sensitivity)=>Ok(PhysicsInputInstruction::SetSensitivity(sensitivity.into())),
strafesnet_common::physics::Instruction::Idle=>Err(PhysicsInputInstructionError::DropInstruction),
}
}
}