strafe-client/src/main.rs

155 lines
5.3 KiB
Rust
Raw Normal View History

2023-10-06 03:32:25 +00:00
mod bvh;
2023-10-06 03:32:02 +00:00
mod aabb;
mod luau;
2023-09-22 22:21:13 +00:00
mod model;
mod setup;
mod window;
2023-10-04 22:58:02 +00:00
mod worker;
mod zeroes;
mod integer;
2023-10-04 22:58:02 +00:00
mod physics;
mod graphics;
2023-10-10 00:09:24 +00:00
mod settings;
2023-09-23 02:41:27 +00:00
mod primitives;
2023-09-22 22:19:44 +00:00
mod instruction;
2024-01-18 21:05:26 +00:00
mod load_bsp;
2023-09-22 22:19:44 +00:00
mod load_roblox;
2023-11-30 09:51:17 +00:00
mod face_crawler;
mod compat_worker;
2023-11-30 09:51:17 +00:00
mod model_physics;
mod model_graphics;
mod physics_worker;
mod graphics_worker;
fn load_file(path: std::path::PathBuf)->Option<model::IndexedModelInstances>{
println!("Loading file: {:?}", &path);
//oh boy! let's load the map!
if let Ok(file)=std::fs::File::open(path){
let mut input = std::io::BufReader::new(file);
let mut first_8=[0u8;8];
//.rbxm roblox binary = "<roblox!"
//.rbxmx roblox xml = "<roblox "
//.bsp = "VBSP"
//.vmf =
//.snf = "SNMF"
//.snf = "SNBF"
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){
match &first_8[0..4]{
b"<rob"=>{
match match &first_8[4..8]{
b"lox!"=>rbx_binary::from_reader(input).map_err(|e|format!("{:?}",e)),
b"lox "=>rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()).map_err(|e|format!("{:?}",e)),
other=>Err(format!("Unknown Roblox file type {:?}",other)),
}{
Ok(dom)=>Some(load_roblox::generate_indexed_models(dom)),
Err(e)=>{
println!("Error loading roblox file:{:?}",e);
2023-10-02 22:27:41 +00:00
None
},
}
},
2024-01-18 21:05:26 +00:00
b"VBSP"=>load_bsp::generate_indexed_models(&mut input).ok(),
//b"SNFM"=>Some(sniffer::generate_indexed_models(input)),
//b"SNFB"=>Some(sniffer::load_bot(input)),
other=>{
println!("loser file {:?}",other);
None
},
2023-10-02 00:18:29 +00:00
}
}else{
println!("Failed to read first 8 bytes and seek back to beginning of file.");
None
2023-10-02 00:18:29 +00:00
}
}else{
println!("Could not open file");
None
}
}
pub fn default_models()->model::IndexedModelInstances{
let mut indexed_models = Vec::new();
indexed_models.push(primitives::unit_sphere());
indexed_models.push(primitives::unit_cylinder());
indexed_models.push(primitives::unit_cube());
println!("models.len = {:?}", indexed_models.len());
//quad monkeys
indexed_models[0].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_translation(glam::vec3(10.,5.,10.))).unwrap(),
..Default::default()
});
indexed_models[0].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_translation(glam::vec3(20.,5.,10.))).unwrap(),
color:glam::vec4(1.0,0.0,0.0,1.0),
..Default::default()
});
indexed_models[0].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_translation(glam::vec3(10.,5.,20.))).unwrap(),
color:glam::vec4(0.0,1.0,0.0,1.0),
..Default::default()
});
indexed_models[0].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_translation(glam::vec3(20.,5.,20.))).unwrap(),
color:glam::vec4(0.0,0.0,1.0,1.0),
..Default::default()
});
//decorative monkey
indexed_models[0].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_translation(glam::vec3(15.,10.,15.))).unwrap(),
color:glam::vec4(0.5,0.5,0.5,0.5),
attributes:model::CollisionAttributes::Decoration,
..Default::default()
});
//teapot
indexed_models[1].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_scale_rotation_translation(glam::vec3(0.5, 1.0, 0.2),glam::quat(-0.22248298016985793,-0.839457167990537,-0.05603504040830783,-0.49261857546227916),glam::vec3(-10.,7.,10.))).unwrap(),
..Default::default()
});
//ground
indexed_models[2].instances.push(model::ModelInstance{
transform:integer::Planar64Affine3::try_from(glam::Affine3A::from_translation(glam::vec3(0.,0.,0.))*glam::Affine3A::from_scale(glam::vec3(160.0, 1.0, 160.0))).unwrap(),
..Default::default()
});
model::IndexedModelInstances{
textures:Vec::new(),
models:indexed_models,
spawn_point:integer::Planar64Vec3::Y*50,
modes:Vec::new(),
}
}
fn main(){
let strafelua_vm = luau::new_state(true).expect("Failed to load strafe lua");
// luau/tests/Vector.lua
strafelua_vm.load(r#"
local v2 = Vector2.new(1, 3)
local v3 = Vector3.new(-10, 30, 50)
local v4 = Vector4.new(50, 30, 10, -1000)
local function InspectVectorTable(Vector: {[string]: number})
local aye: {string} = {"{"}
for k,v in Vector do
table.insert(aye, `{tostring(k)}={tostring(v)}`)
end
table.insert(aye, "}")
return table.concat(aye, " ")
end
print("----StrafeLua----")
print(_VERSION)
print("Vector2=",InspectVectorTable(v2))
print("Vector3=",InspectVectorTable(v3))
print("Vector4=",InspectVectorTable(v4))
print("Vector2.ZERO=",InspectVectorTable(Vector2.ZERO))
print("Vector2.ONE=",InspectVectorTable(Vector2.ONE))
print("Vector2.NEG_ZERO=",InspectVectorTable(Vector2.NEG_ZERO))
print("Vector2.NEG_ONE=",InspectVectorTable(Vector2.NEG_ONE))
print("Vector2.NEG_X=",InspectVectorTable(Vector2.NEG_X))
print("Vector2.NEG_Y=",InspectVectorTable(Vector2.NEG_Y))
print("-----------------")
"#).exec().expect("Lua syntax error!");
//Lua syntax error!: SyntaxError { message: "[string \"src/main.rs:122:18\"]:7: Expected ')' (to close '(' at column 7), got ','", incomplete_input: false }
//we got our first lua syntax error, todo: make an error handler in luau.rs
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
2023-08-30 01:20:58 +00:00
}