Compare commits
20 Commits
file-forma
...
debug
| Author | SHA1 | Date | |
|---|---|---|---|
| c7999d08af | |||
| e0725cba8a | |||
| 5ec99a75dc | |||
| 943d78a9fb | |||
| b6fede20bf | |||
| 020eae4781 | |||
| 5d25400942 | |||
| a00b6a63c9 | |||
| 931cef52b1 | |||
| 3e8c5167dc | |||
| 2262c6feac | |||
| fa7e7d58bf | |||
| 0705e879db | |||
| d3e114c7b6 | |||
| e1cdddc892 | |||
| 4abeefa7e8 | |||
| 47aef14ff3 | |||
| 3434cd394a | |||
| b6935b4f5f | |||
| f0035bcee9 |
@@ -1,5 +1,6 @@
|
|||||||
use binrw::{BinReaderExt, binrw};
|
use binrw::{BinReaderExt, binrw};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
InvalidHeader,
|
InvalidHeader,
|
||||||
InvalidSegment(binrw::Error),
|
InvalidSegment(binrw::Error),
|
||||||
@@ -64,7 +65,7 @@ mod simulation{
|
|||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
#[derive(Clone,Copy,id::Id)]
|
#[derive(Clone,Copy,Debug,id::Id)]
|
||||||
pub struct SegmentId(u32);
|
pub struct SegmentId(u32);
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use binrw::BinReaderExt;
|
use binrw::BinReaderExt;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
InvalidHeader,
|
InvalidHeader,
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/file.rs
29
src/file.rs
@@ -2,12 +2,19 @@
|
|||||||
|
|
||||||
use binrw::{binrw, BinReaderExt, io::TakeSeekExt};
|
use binrw::{binrw, BinReaderExt, io::TakeSeekExt};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
InvalidHeader(binrw::Error),
|
InvalidHeader(binrw::Error),
|
||||||
UnexpectedEOF,
|
UnexpectedEOF,
|
||||||
InvalidBlockId(BlockId),
|
InvalidBlockId(BlockId),
|
||||||
Seek(std::io::Error),
|
Seek(std::io::Error),
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for Error{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for Error{}
|
||||||
|
|
||||||
/* spec
|
/* spec
|
||||||
|
|
||||||
@@ -40,7 +47,7 @@ for block_id in 1..num_blocks{
|
|||||||
*/
|
*/
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
#[derive(Clone,Copy)]
|
#[derive(Clone,Copy,Debug)]
|
||||||
pub(crate) enum FourCC{
|
pub(crate) enum FourCC{
|
||||||
#[brw(magic=b"SNFM")]
|
#[brw(magic=b"SNFM")]
|
||||||
Map,
|
Map,
|
||||||
@@ -51,24 +58,25 @@ pub(crate) enum FourCC{
|
|||||||
}
|
}
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
struct Header{
|
#[derive(Debug)]
|
||||||
|
pub struct Header{
|
||||||
/// Type of file
|
/// Type of file
|
||||||
fourcc:FourCC,
|
pub fourcc:FourCC,
|
||||||
/// Type version
|
/// File format version
|
||||||
version:u32,
|
pub version:u32,
|
||||||
/// Minimum data required to know the location of all streamable resources for this specific file
|
/// Minimum data required to know the location of all streamable resources for this specific file
|
||||||
priming:u64,
|
pub priming:u64,
|
||||||
/// uuid for this file
|
/// uuid for this file
|
||||||
resource:u128,
|
pub resource:u128,
|
||||||
//don't need try_calc: the struct will force field initialization anyways and it can be calculated there
|
//don't need try_calc: the struct will force field initialization anyways and it can be calculated there
|
||||||
block_count:u32,
|
pub block_count:u32,
|
||||||
#[br(count=block_count+1)]
|
#[br(count=block_count+1)]
|
||||||
block_location:Vec<u64>,
|
pub block_location:Vec<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,Ord,PartialEq,PartialOrd)]
|
||||||
pub struct BlockId(u32);
|
pub struct BlockId(u32);
|
||||||
|
|
||||||
pub(crate) struct File<R:BinReaderExt>{
|
pub(crate) struct File<R:BinReaderExt>{
|
||||||
@@ -93,6 +101,7 @@ impl<R:BinReaderExt> File<R>{
|
|||||||
}
|
}
|
||||||
let block_start=self.header.block_location[block_id.get() as usize];
|
let block_start=self.header.block_location[block_id.get() as usize];
|
||||||
let block_end=self.header.block_location[block_id.get() as usize+1];
|
let block_end=self.header.block_location[block_id.get() as usize+1];
|
||||||
|
//println!("reading from {} to {}",block_start,block_end);
|
||||||
self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(Error::Seek)?;
|
self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(Error::Seek)?;
|
||||||
Ok(self.as_mut().take_seek(block_end-block_start))
|
Ok(self.as_mut().take_seek(block_end-block_start))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pub mod map;
|
|||||||
pub mod bot;
|
pub mod bot;
|
||||||
pub mod demo;
|
pub mod demo;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
UnexpectedFourCC,
|
UnexpectedFourCC,
|
||||||
Header(file::Error),
|
Header(file::Error),
|
||||||
@@ -14,6 +15,12 @@ pub enum Error{
|
|||||||
Bot(bot::Error),
|
Bot(bot::Error),
|
||||||
Demo(demo::Error),
|
Demo(demo::Error),
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for Error{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for Error{}
|
||||||
|
|
||||||
pub enum SNF<R:BinReaderExt>{
|
pub enum SNF<R:BinReaderExt>{
|
||||||
Map(map::StreamableMap<R>),
|
Map(map::StreamableMap<R>),
|
||||||
|
|||||||
384
src/map.rs
384
src/map.rs
@@ -3,21 +3,29 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::newtypes;
|
use crate::newtypes;
|
||||||
use crate::file::BlockId;
|
use crate::file::BlockId;
|
||||||
use binrw::{binrw,BinReaderExt};
|
use binrw::{binrw,BinReaderExt,BinWriterExt};
|
||||||
use strafesnet_common::model;
|
use strafesnet_common::model;
|
||||||
use strafesnet_common::aabb::Aabb;
|
use strafesnet_common::aabb::Aabb;
|
||||||
use strafesnet_common::bvh::BvhNode;
|
use strafesnet_common::bvh::BvhNode;
|
||||||
use strafesnet_common::gameplay_modes;
|
use strafesnet_common::gameplay_modes;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
InvalidHeader(binrw::Error),
|
InvalidHeader(binrw::Error),
|
||||||
InvalidBlockId(BlockId),
|
InvalidBlockId(BlockId),
|
||||||
InvalidMeshId(model::MeshId),
|
InvalidMeshId(model::MeshId),
|
||||||
|
InvalidModelId(model::ModelId),
|
||||||
InvalidTextureId(model::TextureId),
|
InvalidTextureId(model::TextureId),
|
||||||
InvalidData(binrw::Error),
|
InvalidData(binrw::Error),
|
||||||
IO(std::io::Error),
|
IO(std::io::Error),
|
||||||
File(crate::file::Error),
|
File(crate::file::Error),
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for Error{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for Error{}
|
||||||
|
|
||||||
/* block types
|
/* block types
|
||||||
|
|
||||||
@@ -135,21 +143,18 @@ struct ResourceExternalHeader{
|
|||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
struct MapHeader{
|
struct MapHeader{
|
||||||
num_nodes:u32,
|
|
||||||
num_spacial_blocks:u32,
|
num_spacial_blocks:u32,
|
||||||
num_resource_blocks:u32,
|
num_resource_blocks:u32,
|
||||||
num_resources_external:u32,
|
//num_resources_external:u32,
|
||||||
num_modes:u32,
|
num_modes:u32,
|
||||||
num_attributes:u32,
|
num_attributes:u32,
|
||||||
num_render_configs:u32,
|
num_render_configs:u32,
|
||||||
#[br(count=num_nodes)]
|
|
||||||
nodes:Vec<u32>,
|
|
||||||
#[br(count=num_spacial_blocks)]
|
#[br(count=num_spacial_blocks)]
|
||||||
spacial_blocks:Vec<SpacialBlockHeader>,
|
spacial_blocks:Vec<SpacialBlockHeader>,
|
||||||
#[br(count=num_resource_blocks)]
|
#[br(count=num_resource_blocks)]
|
||||||
resource_blocks:Vec<ResourceBlockHeader>,
|
resource_blocks:Vec<ResourceBlockHeader>,
|
||||||
#[br(count=num_resources_external)]
|
//#[br(count=num_resources_external)]
|
||||||
external_resources:Vec<ResourceExternalHeader>,
|
//external_resources:Vec<ResourceExternalHeader>,
|
||||||
#[br(count=num_modes)]
|
#[br(count=num_modes)]
|
||||||
modes:Vec<newtypes::gameplay_modes::Mode>,
|
modes:Vec<newtypes::gameplay_modes::Mode>,
|
||||||
#[br(count=num_attributes)]
|
#[br(count=num_attributes)]
|
||||||
@@ -158,24 +163,134 @@ struct MapHeader{
|
|||||||
render_configs:Vec<newtypes::model::RenderConfig>,
|
render_configs:Vec<newtypes::model::RenderConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_vec<'a,R:BinReaderExt,T:binrw::BinRead>(len:usize,input:&mut R)->Result<Vec<T>,binrw::Error>
|
||||||
|
where
|
||||||
|
<T as binrw::BinRead>::Args<'a>: Default
|
||||||
|
{
|
||||||
|
let mut vec=Vec::with_capacity(len);
|
||||||
|
for _ in 0..len{
|
||||||
|
vec.push(input.read_le()?);
|
||||||
|
}
|
||||||
|
Ok(vec)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_stage<R:BinReaderExt>(input:&mut R)->Result<newtypes::gameplay_modes::Stage,binrw::Error>{
|
||||||
|
let spawn=input.read_le()?;
|
||||||
|
let ordered_checkpoints_count=input.read_le()?;
|
||||||
|
let unordered_checkpoints_count=input.read_le()?;
|
||||||
|
//println!("ordered_checkpoints_count={ordered_checkpoints_count}");
|
||||||
|
//println!("unordered_checkpoints_count={unordered_checkpoints_count}");
|
||||||
|
let ordered_checkpoints=read_vec(ordered_checkpoints_count as usize,input)?;
|
||||||
|
let unordered_checkpoints=read_vec(unordered_checkpoints_count as usize,input)?;
|
||||||
|
Ok(newtypes::gameplay_modes::Stage{
|
||||||
|
spawn,
|
||||||
|
ordered_checkpoints_count,
|
||||||
|
unordered_checkpoints_count,
|
||||||
|
ordered_checkpoints,
|
||||||
|
unordered_checkpoints,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_stages<R:BinReaderExt>(len:usize,input:&mut R)->Result<Vec<newtypes::gameplay_modes::Stage>,binrw::Error>{
|
||||||
|
let mut vec=Vec::with_capacity(len);
|
||||||
|
for _ in 0..len{
|
||||||
|
vec.push(read_stage(input)?);
|
||||||
|
}
|
||||||
|
Ok(vec)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_mode<R:BinReaderExt>(input:&mut R)->Result<newtypes::gameplay_modes::Mode,binrw::Error>{
|
||||||
|
//println!("read_mode pos={}",input.stream_position().unwrap());
|
||||||
|
let header:newtypes::gameplay_modes::ModeHeader=input.read_le()?;
|
||||||
|
//println!("mode.header pos={}",input.stream_position().unwrap());
|
||||||
|
let style=input.read_le()?;
|
||||||
|
//println!("mode.style pos={}",input.stream_position().unwrap());
|
||||||
|
let start=input.read_le()?;
|
||||||
|
//println!("mode.start pos={}",input.stream_position().unwrap());
|
||||||
|
let zones=read_vec(header.zones as usize,input)?;
|
||||||
|
//println!("mode.zones pos={}",input.stream_position().unwrap());
|
||||||
|
let stages=read_stages(header.stages as usize,input)?;
|
||||||
|
//println!("mode.stages pos={}",input.stream_position().unwrap());
|
||||||
|
let elements=read_vec(header.elements as usize,input)?;
|
||||||
|
Ok(newtypes::gameplay_modes::Mode{
|
||||||
|
header,
|
||||||
|
style,
|
||||||
|
start,
|
||||||
|
zones,
|
||||||
|
stages,
|
||||||
|
elements,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_modes<R:BinReaderExt>(len:usize,input:&mut R)->Result<Vec<newtypes::gameplay_modes::Mode>,binrw::Error>{
|
||||||
|
let mut vec=Vec::with_capacity(len);
|
||||||
|
for _ in 0..len{
|
||||||
|
vec.push(read_mode(input)?);
|
||||||
|
}
|
||||||
|
Ok(vec)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_map_header<R:BinReaderExt>(input:&mut R)->Result<MapHeader,binrw::Error>{
|
||||||
|
let p=input.stream_position().unwrap();
|
||||||
|
println!("read_map_header pos={}",p);
|
||||||
|
let num_spacial_blocks:u32=input.read_le()?;
|
||||||
|
println!("map_header.num_spacial_blocks pos={}",input.stream_position().unwrap()-p);
|
||||||
|
let num_resource_blocks:u32=input.read_le()?;
|
||||||
|
println!("map_header.num_resource_blocks pos={}",input.stream_position().unwrap()-p);
|
||||||
|
//let num_resources_external:u32=input.read_le()?;
|
||||||
|
let num_modes:u32=input.read_le()?;
|
||||||
|
println!("map_header.num_modes pos={}",input.stream_position().unwrap()-p);
|
||||||
|
let num_attributes:u32=input.read_le()?;
|
||||||
|
println!("map_header.num_attributes pos={}",input.stream_position().unwrap()-p);
|
||||||
|
let num_render_configs:u32=input.read_le()?;
|
||||||
|
println!("map_header.num_render_configs pos={}",input.stream_position().unwrap()-p);
|
||||||
|
let spacial_blocks:Vec<SpacialBlockHeader>=read_vec(num_spacial_blocks as usize,input)?;
|
||||||
|
println!("map_header.spacial_blocks pos={}",input.stream_position().unwrap()-p);
|
||||||
|
let resource_blocks:Vec<ResourceBlockHeader>=read_vec(num_resource_blocks as usize,input)?;
|
||||||
|
println!("map_header.resource_blocks pos={}",input.stream_position().unwrap()-p);
|
||||||
|
//let external_resources:Vec<ResourceExternalHeader>=read_vec(num_resources_external as usize,input)?;
|
||||||
|
let modes:Vec<newtypes::gameplay_modes::Mode>=read_modes(num_modes as usize,input)?;
|
||||||
|
println!("map_header.modes pos={}",input.stream_position().unwrap()-p);
|
||||||
|
let attributes:Vec<newtypes::gameplay_attributes::CollisionAttributes>=read_vec(num_attributes as usize,input)?;
|
||||||
|
println!("map_header.attributes pos={} len={}",input.stream_position().unwrap()-p,num_attributes);
|
||||||
|
let render_configs:Vec<newtypes::model::RenderConfig>=read_vec(num_render_configs as usize,input)?;
|
||||||
|
println!("map_header.render_configs pos={} len={}",input.stream_position().unwrap()-p,num_render_configs);
|
||||||
|
Ok(MapHeader{
|
||||||
|
num_spacial_blocks,
|
||||||
|
num_resource_blocks,
|
||||||
|
//num_resources_external,
|
||||||
|
num_modes,
|
||||||
|
num_attributes,
|
||||||
|
num_render_configs,
|
||||||
|
spacial_blocks,
|
||||||
|
resource_blocks,
|
||||||
|
//external_resources,
|
||||||
|
modes,
|
||||||
|
attributes,
|
||||||
|
render_configs,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
struct Region{
|
struct Region{
|
||||||
//consider including a bvh in the region instead of needing to rebalance the physics bvh on the fly
|
//consider including a bvh in the region instead of needing to rebalance the physics bvh on the fly
|
||||||
model_count:u32,
|
model_count:u32,
|
||||||
#[br(count=model_count)]
|
#[br(count=model_count)]
|
||||||
models:Vec<newtypes::model::Model>,
|
models:Vec<(u32,newtypes::model::Model)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
//code deduplication reused in into_complete_map
|
//code deduplication reused in into_complete_map
|
||||||
fn read_region<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<model::Model>,Error>{
|
fn read_region<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||||
//load region from disk
|
//load region from disk
|
||||||
//parse the models and determine what resources need to be loaded
|
//parse the models and determine what resources need to be loaded
|
||||||
//load resources into self.resources
|
//load resources into self.resources
|
||||||
//return Region
|
//return Region
|
||||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||||
let region:Region=block.read_le().map_err(Error::InvalidData)?;
|
let region:Region=block.read_le().map_err(Error::InvalidData)?;
|
||||||
Ok(region.models.into_iter().map(Into::into).collect())
|
Ok(region.models.into_iter().map(|(model_id,model)|
|
||||||
|
(model::ModelId::new(model_id),model.into())
|
||||||
|
).collect())
|
||||||
}
|
}
|
||||||
fn read_mesh<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<model::Mesh,Error>{
|
fn read_mesh<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<model::Mesh,Error>{
|
||||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||||
@@ -206,7 +321,12 @@ pub struct StreamableMap<R:BinReaderExt>{
|
|||||||
impl<R:BinReaderExt> StreamableMap<R>{
|
impl<R:BinReaderExt> StreamableMap<R>{
|
||||||
pub(crate) fn new(mut file:crate::file::File<R>)->Result<Self,Error>{
|
pub(crate) fn new(mut file:crate::file::File<R>)->Result<Self,Error>{
|
||||||
//assume the file seek is in the right place to start reading a map header
|
//assume the file seek is in the right place to start reading a map header
|
||||||
let header:MapHeader=file.as_mut().read_le().map_err(Error::InvalidHeader)?;
|
let mut f=file.as_mut();
|
||||||
|
//let mut f=file.block_reader(BlockId::new(0)).map_err(Error::File)?;
|
||||||
|
println!("file header end position={}",f.stream_position().unwrap());
|
||||||
|
//let header:MapHeader=f.read_le().map_err(Error::InvalidHeader)?;
|
||||||
|
let header=read_map_header(&mut f).map_err(Error::InvalidHeader)?;
|
||||||
|
println!("map header end position={}",f.stream_position().unwrap());
|
||||||
let modes=header.modes.into_iter().map(Into::into).collect();
|
let modes=header.modes.into_iter().map(Into::into).collect();
|
||||||
let attributes=header.attributes.into_iter().map(Into::into).collect();
|
let attributes=header.attributes.into_iter().map(Into::into).collect();
|
||||||
let render_configs=header.render_configs.into_iter().map(Into::into).collect();
|
let render_configs=header.render_configs.into_iter().map(Into::into).collect();
|
||||||
@@ -244,10 +364,10 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
|||||||
}
|
}
|
||||||
pub fn get_intersecting_region_block_ids(&self,aabb:&Aabb)->Vec<BlockId>{
|
pub fn get_intersecting_region_block_ids(&self,aabb:&Aabb)->Vec<BlockId>{
|
||||||
let mut block_ids=Vec::new();
|
let mut block_ids=Vec::new();
|
||||||
self.bvh.the_tester(aabb,&mut |block_id|block_ids.push(block_id));
|
self.bvh.the_tester(aabb,&mut |&block_id|block_ids.push(block_id));
|
||||||
block_ids
|
block_ids
|
||||||
}
|
}
|
||||||
pub fn load_region(&mut self,block_id:BlockId)->Result<Vec<model::Model>,Error>{
|
pub fn load_region(&mut self,block_id:BlockId)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||||
read_region(&mut self.file,block_id)
|
read_region(&mut self.file,block_id)
|
||||||
}
|
}
|
||||||
pub fn load_mesh(&mut self,mesh_id:model::MeshId)->Result<model::Mesh,Error>{
|
pub fn load_mesh(&mut self,mesh_id:model::MeshId)->Result<model::Mesh,Error>{
|
||||||
@@ -259,20 +379,33 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
|||||||
read_texture(&mut self.file,block_id)
|
read_texture(&mut self.file,block_id)
|
||||||
}
|
}
|
||||||
pub fn into_complete_map(mut self)->Result<strafesnet_common::map::CompleteMap,Error>{
|
pub fn into_complete_map(mut self)->Result<strafesnet_common::map::CompleteMap,Error>{
|
||||||
//load all meshes
|
|
||||||
let meshes=self.resource_blocks.meshes.into_values().map(|block_id|
|
|
||||||
read_mesh(&mut self.file,block_id)
|
|
||||||
).collect::<Result<Vec<_>,_>>()?;
|
|
||||||
//load all textures
|
|
||||||
let textures=self.resource_blocks.textures.into_values().map(|block_id|
|
|
||||||
read_texture(&mut self.file,block_id)
|
|
||||||
).collect::<Result<Vec<_>,_>>()?;
|
|
||||||
let mut block_ids=Vec::new();
|
let mut block_ids=Vec::new();
|
||||||
self.bvh.into_visitor(&mut |block_id|block_ids.push(block_id));
|
self.bvh.into_visitor(&mut |block_id|block_ids.push(block_id));
|
||||||
|
//count on reading the file in sequential order being fastest
|
||||||
|
block_ids.sort_unstable();
|
||||||
//load all regions
|
//load all regions
|
||||||
let mut models=Vec::new();
|
let mut model_pairs=HashMap::new();
|
||||||
for block_id in block_ids{
|
for block_id in block_ids{
|
||||||
models.append(&mut read_region(&mut self.file,block_id)?);
|
model_pairs.extend(read_region(&mut self.file,block_id)?);
|
||||||
|
}
|
||||||
|
let mut models=Vec::with_capacity(model_pairs.len());
|
||||||
|
for model_id in 0..model_pairs.len() as u32{
|
||||||
|
let model_id=model::ModelId::new(model_id);
|
||||||
|
models.push(model_pairs.remove(&model_id).ok_or(Error::InvalidModelId(model_id))?);
|
||||||
|
}
|
||||||
|
//load all meshes
|
||||||
|
let mut meshes=Vec::with_capacity(self.resource_blocks.meshes.len());
|
||||||
|
for mesh_id in 0..self.resource_blocks.meshes.len() as u32{
|
||||||
|
let mesh_id=model::MeshId::new(mesh_id);
|
||||||
|
let block_id=self.resource_blocks.meshes[&mesh_id];
|
||||||
|
meshes.push(read_mesh(&mut self.file,block_id)?);
|
||||||
|
};
|
||||||
|
//load all textures
|
||||||
|
let mut textures=Vec::with_capacity(self.resource_blocks.textures.len());
|
||||||
|
for texture_id in 0..self.resource_blocks.textures.len() as u32{
|
||||||
|
let texture_id=model::TextureId::new(texture_id);
|
||||||
|
let block_id=self.resource_blocks.textures[&texture_id];
|
||||||
|
textures.push(read_texture(&mut self.file,block_id)?);
|
||||||
}
|
}
|
||||||
Ok(strafesnet_common::map::CompleteMap{
|
Ok(strafesnet_common::map::CompleteMap{
|
||||||
modes:self.modes,
|
modes:self.modes,
|
||||||
@@ -284,3 +417,208 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use binrw::BinWrite;
|
||||||
|
|
||||||
|
fn write_mode<W:std::io::Seek+std::io::Write>(mode:&newtypes::gameplay_modes::Mode,output:&mut W)->Result<(),binrw::Error>{
|
||||||
|
//println!("write_mode pos={}",output.stream_position().unwrap());
|
||||||
|
mode.header.write_le(output)?;
|
||||||
|
//println!("mode.header pos={}",output.stream_position().unwrap());
|
||||||
|
mode.style.write_le(output)?;
|
||||||
|
//println!("mode.style pos={}",output.stream_position().unwrap());
|
||||||
|
mode.start.write_le(output)?;
|
||||||
|
//println!("mode.start pos={}",output.stream_position().unwrap());
|
||||||
|
mode.zones.write_le(output)?;
|
||||||
|
//println!("mode.zones pos={}",output.stream_position().unwrap());
|
||||||
|
mode.stages.write_le(output)?;
|
||||||
|
//println!("mode.stages pos={}",output.stream_position().unwrap());
|
||||||
|
mode.elements.write_le(output)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_modes<W:std::io::Seek+std::io::Write>(modes:&Vec<newtypes::gameplay_modes::Mode>,output:&mut W)->Result<(),binrw::Error>{
|
||||||
|
for mode in modes{
|
||||||
|
write_mode(mode,output)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_map_header<W:std::io::Seek+std::io::Write>(map_header:&MapHeader,output:&mut W)->Result<(),binrw::Error>{
|
||||||
|
println!("write_map_header pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.num_spacial_blocks.write_le(output)?;
|
||||||
|
println!("map_header.num_spacial_blocks pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.num_resource_blocks.write_le(output)?;
|
||||||
|
println!("map_header.num_resource_blocks pos={}",output.stream_position().unwrap());
|
||||||
|
//map_header.num_resources_external.write_le(output)?;
|
||||||
|
map_header.num_modes.write_le(output)?;
|
||||||
|
println!("map_header.num_modes pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.num_attributes.write_le(output)?;
|
||||||
|
println!("map_header.num_attributes pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.num_render_configs.write_le(output)?;
|
||||||
|
println!("map_header.num_render_configs pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.spacial_blocks.write_le(output)?;
|
||||||
|
println!("map_header.spacial_blocks pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.resource_blocks.write_le(output)?;
|
||||||
|
println!("map_header.resource_blocks pos={}",output.stream_position().unwrap());
|
||||||
|
//map_header.external_resources.write_le(output)?;
|
||||||
|
write_modes(&map_header.modes,output)?;
|
||||||
|
println!("map_header.modes pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.attributes.write_le(output)?;
|
||||||
|
println!("map_header.attributes pos={}",output.stream_position().unwrap());
|
||||||
|
map_header.render_configs.write_le(output)?;
|
||||||
|
println!("map_header.render_configs pos={}",output.stream_position().unwrap());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
const BVH_NODE_MAX_WEIGHT:usize=64*1024;//64 kB
|
||||||
|
fn collect_spacial_blocks(
|
||||||
|
block_location:&mut Vec<u64>,
|
||||||
|
block_headers:&mut Vec<SpacialBlockHeader>,
|
||||||
|
sequential_block_data:&mut std::io::Cursor<&mut Vec<u8>>,
|
||||||
|
bvh_node:strafesnet_common::bvh::BvhWeightNode<usize,(model::ModelId,newtypes::model::Model)>
|
||||||
|
)->Result<(),Error>{
|
||||||
|
//inspect the node weights top-down.
|
||||||
|
//When a node weighs less than the limit,
|
||||||
|
//serialize its entire contents into a region block
|
||||||
|
if *bvh_node.weight()<BVH_NODE_MAX_WEIGHT{
|
||||||
|
let mut models=Vec::new();
|
||||||
|
let mut model_count=0;
|
||||||
|
let extents=bvh_node.aabb().clone().into();
|
||||||
|
bvh_node.into_visitor(&mut |(model_id,model)|{
|
||||||
|
model_count+=1;
|
||||||
|
models.push((model_id.get(),model));
|
||||||
|
});
|
||||||
|
let id=BlockId::new(block_headers.len() as u32+1);
|
||||||
|
block_headers.push(SpacialBlockHeader{
|
||||||
|
id,
|
||||||
|
extents,
|
||||||
|
});
|
||||||
|
let region=Region{
|
||||||
|
model_count,
|
||||||
|
models,
|
||||||
|
};
|
||||||
|
binrw::BinWrite::write_le(®ion,sequential_block_data).map_err(Error::InvalidData)?;
|
||||||
|
block_location.push(sequential_block_data.position());
|
||||||
|
}else{
|
||||||
|
match bvh_node.into_content(){
|
||||||
|
strafesnet_common::bvh::RecursiveContent::Branch(bvh_node_list)=>{
|
||||||
|
for bvh_node in bvh_node_list{
|
||||||
|
collect_spacial_blocks(block_location,block_headers,sequential_block_data,bvh_node)?;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
strafesnet_common::bvh::RecursiveContent::Leaf(_)=>panic!(),//bvh branches are 20 leaves minimum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO: Optionally provide a bot that describes the path through the map
|
||||||
|
/// otherwise sort by distance to start zone
|
||||||
|
pub fn write_map<W:BinWriterExt>(mut writer:W,map:strafesnet_common::map::CompleteMap)->Result<(),Error>{
|
||||||
|
//serialize models and make a bvh that knows the file size of the branch
|
||||||
|
let boxen=map.models.into_iter().enumerate().map(|(model_id,model)|{
|
||||||
|
//grow your own aabb
|
||||||
|
let mesh=map.meshes.get(model.mesh.get() as usize).ok_or(Error::InvalidMeshId(model.mesh))?;
|
||||||
|
let mut aabb=strafesnet_common::aabb::Aabb::default();
|
||||||
|
for &pos in &mesh.unique_pos{
|
||||||
|
aabb.grow(model.transform.transform_point3(pos));
|
||||||
|
}
|
||||||
|
Ok(((model::ModelId::new(model_id as u32),model.into()),aabb))
|
||||||
|
}).collect::<Result<Vec<_>,_>>()?;
|
||||||
|
let bvh=strafesnet_common::bvh::generate_bvh(boxen).weigh_contents(&|_|std::mem::size_of::<newtypes::model::Model>());
|
||||||
|
//build blocks
|
||||||
|
//block location is initialized with two values
|
||||||
|
//the first value represents the location of the first byte after the file header
|
||||||
|
//the second value represents the first byte of the second data block
|
||||||
|
//the first data block is always the map header, so the difference is the map header size.
|
||||||
|
//this information is filled in later after the sizes are known.
|
||||||
|
let mut block_location=vec![0,0];//for file header
|
||||||
|
let mut spacial_blocks=Vec::new();//for map header
|
||||||
|
let mut sequential_block_data=Vec::new();
|
||||||
|
let mut cursor_to_data=std::io::Cursor::new(&mut sequential_block_data);
|
||||||
|
collect_spacial_blocks(&mut block_location,&mut spacial_blocks,&mut cursor_to_data,bvh)?;
|
||||||
|
let mut block_count=spacial_blocks.len() as u32+1;//continue block id
|
||||||
|
println!("spacial_blocks={}",block_count);
|
||||||
|
let mut resource_blocks=Vec::new();//for map header
|
||||||
|
//meshes
|
||||||
|
for mesh in map.meshes.into_iter(){
|
||||||
|
resource_blocks.push(ResourceBlockHeader{
|
||||||
|
resource:ResourceType::Mesh,
|
||||||
|
id:BlockId::new(block_count),
|
||||||
|
});
|
||||||
|
block_count+=1;
|
||||||
|
let serializable_mesh:newtypes::model::Mesh=mesh.into();
|
||||||
|
binrw::BinWrite::write_le(&serializable_mesh,&mut cursor_to_data).map_err(Error::InvalidData)?;
|
||||||
|
block_location.push(cursor_to_data.position());
|
||||||
|
}
|
||||||
|
let aaa=block_count;
|
||||||
|
println!("mesh_blocks={}",block_count-(spacial_blocks.len() as u32));
|
||||||
|
//textures
|
||||||
|
for mut texture in map.textures.into_iter(){
|
||||||
|
resource_blocks.push(ResourceBlockHeader{
|
||||||
|
resource:ResourceType::Texture,
|
||||||
|
id:BlockId::new(block_count),
|
||||||
|
});
|
||||||
|
block_count+=1;
|
||||||
|
sequential_block_data.append(&mut texture);
|
||||||
|
block_location.push(sequential_block_data.len() as u64);
|
||||||
|
}
|
||||||
|
println!("texture_blocks={}",block_count-aaa);
|
||||||
|
//build header
|
||||||
|
let map_header=MapHeader{
|
||||||
|
num_spacial_blocks:spacial_blocks.len() as u32,
|
||||||
|
num_resource_blocks:resource_blocks.len() as u32,
|
||||||
|
//num_resources_external:0,
|
||||||
|
num_modes:map.modes.modes.len() as u32,
|
||||||
|
num_attributes:map.attributes.len() as u32,
|
||||||
|
num_render_configs:map.render_configs.len() as u32,
|
||||||
|
spacial_blocks,
|
||||||
|
resource_blocks,
|
||||||
|
//external_resources:Vec::new(),
|
||||||
|
modes:map.modes.modes.into_iter().map(Into::into).collect(),
|
||||||
|
attributes:map.attributes.into_iter().map(Into::into).collect(),
|
||||||
|
render_configs:map.render_configs.into_iter().map(Into::into).collect(),
|
||||||
|
};
|
||||||
|
let mut file_header=crate::file::Header{
|
||||||
|
fourcc:crate::file::FourCC::Map,
|
||||||
|
version:0,
|
||||||
|
priming:0,
|
||||||
|
resource:0,
|
||||||
|
block_count,
|
||||||
|
block_location,
|
||||||
|
};
|
||||||
|
//probe header length
|
||||||
|
let mut file_header_data=Vec::new();
|
||||||
|
binrw::BinWrite::write_le(&file_header,&mut std::io::Cursor::new(&mut file_header_data)).map_err(Error::InvalidData)?;
|
||||||
|
let mut map_header_data=Vec::new();
|
||||||
|
write_map_header(&map_header,&mut std::io::Cursor::new(&mut map_header_data)).map_err(Error::InvalidData)?;
|
||||||
|
|
||||||
|
//update file header according to probe data
|
||||||
|
let mut offset=file_header_data.len() as u64;
|
||||||
|
file_header.priming=offset;
|
||||||
|
file_header.block_location[0]=offset;
|
||||||
|
offset+=map_header_data.len() as u64;
|
||||||
|
for position in &mut file_header.block_location[1..]{
|
||||||
|
*position+=offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
println!("block_count={}",file_header.block_count);
|
||||||
|
println!("block_locations[0..10]={:?}",&file_header.block_location[0..10]);
|
||||||
|
println!("file header len={}",file_header_data.len());
|
||||||
|
println!("map header len={}",map_header_data.len());
|
||||||
|
println!("num_spacial_blocks={}",map_header.num_spacial_blocks);
|
||||||
|
println!("num_resource_blocks={}",map_header.num_resource_blocks);
|
||||||
|
//println!("num_resources_external={}",map_header.num_resources_external);
|
||||||
|
println!("num_modes={}",map_header.num_modes);
|
||||||
|
println!("num_attributes={}",map_header.num_attributes);
|
||||||
|
println!("num_render_configs={}",map_header.num_render_configs);
|
||||||
|
|
||||||
|
//write (updated) file header
|
||||||
|
writer.write_le(&file_header).map_err(Error::InvalidData)?;
|
||||||
|
//write map header
|
||||||
|
writer.write(&map_header_data).map_err(Error::IO)?;
|
||||||
|
//write blocks
|
||||||
|
writer.write(&sequential_block_data).map_err(Error::IO)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,3 +13,11 @@ impl Into<strafesnet_common::aabb::Aabb> for Aabb{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::aabb::Aabb> for Aabb{
|
||||||
|
fn from(value:strafesnet_common::aabb::Aabb)->Self{
|
||||||
|
Self{
|
||||||
|
max:value.max().get().to_array(),
|
||||||
|
min:value.min().get().to_array(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,44 @@
|
|||||||
use super::integer::{Time,Planar64,Planar64Vec3};
|
use super::integer::{Time,Planar64,Planar64Vec3};
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little,repr=u8)]
|
||||||
|
pub enum Boolio{
|
||||||
|
True,
|
||||||
|
False
|
||||||
|
}
|
||||||
|
impl Into<bool> for Boolio{
|
||||||
|
fn into(self)->bool{
|
||||||
|
match self{
|
||||||
|
Boolio::True=>true,
|
||||||
|
Boolio::False=>false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<bool> for Boolio{
|
||||||
|
fn from(value:bool)->Self{
|
||||||
|
match value{
|
||||||
|
true=>Boolio::True,
|
||||||
|
false=>Boolio::False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct ContactingLadder{
|
pub struct ContactingLadder{
|
||||||
pub sticky:Option<()>,
|
pub sticky:Boolio,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::ContactingLadder> for ContactingLadder{
|
impl Into<strafesnet_common::gameplay_attributes::ContactingLadder> for ContactingLadder{
|
||||||
fn into(self)->strafesnet_common::gameplay_attributes::ContactingLadder{
|
fn into(self)->strafesnet_common::gameplay_attributes::ContactingLadder{
|
||||||
strafesnet_common::gameplay_attributes::ContactingLadder{
|
strafesnet_common::gameplay_attributes::ContactingLadder{
|
||||||
sticky:self.sticky.is_some(),
|
sticky:self.sticky.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::ContactingLadder> for ContactingLadder{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::ContactingLadder)->Self{
|
||||||
|
Self{
|
||||||
|
sticky:value.sticky.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,10 +46,15 @@ impl Into<strafesnet_common::gameplay_attributes::ContactingLadder> for Contacti
|
|||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub enum ContactingBehaviour{
|
pub enum ContactingBehaviour{
|
||||||
|
#[brw(magic=0u8)]
|
||||||
Surf,
|
Surf,
|
||||||
|
#[brw(magic=1u8)]
|
||||||
Ladder(ContactingLadder),
|
Ladder(ContactingLadder),
|
||||||
|
#[brw(magic=2u8)]
|
||||||
NoJump,
|
NoJump,
|
||||||
|
#[brw(magic=3u8)]
|
||||||
Cling,
|
Cling,
|
||||||
|
#[brw(magic=4u8)]
|
||||||
Elastic(u32),
|
Elastic(u32),
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::ContactingBehaviour> for ContactingBehaviour{
|
impl Into<strafesnet_common::gameplay_attributes::ContactingBehaviour> for ContactingBehaviour{
|
||||||
@@ -40,6 +75,24 @@ impl Into<strafesnet_common::gameplay_attributes::ContactingBehaviour> for Conta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::ContactingBehaviour> for ContactingBehaviour{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::ContactingBehaviour)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_attributes::ContactingBehaviour::Surf=>
|
||||||
|
ContactingBehaviour::Surf,
|
||||||
|
strafesnet_common::gameplay_attributes::ContactingBehaviour::Ladder(contacting_ladder)=>
|
||||||
|
ContactingBehaviour::Ladder(
|
||||||
|
contacting_ladder.into()
|
||||||
|
),
|
||||||
|
strafesnet_common::gameplay_attributes::ContactingBehaviour::NoJump=>
|
||||||
|
ContactingBehaviour::NoJump,
|
||||||
|
strafesnet_common::gameplay_attributes::ContactingBehaviour::Cling=>
|
||||||
|
ContactingBehaviour::Cling,
|
||||||
|
strafesnet_common::gameplay_attributes::ContactingBehaviour::Elastic(elasticity)=>
|
||||||
|
ContactingBehaviour::Elastic(elasticity),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -57,6 +110,15 @@ impl Into<strafesnet_common::gameplay_attributes::IntersectingWater> for Interse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::IntersectingWater> for IntersectingWater{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::IntersectingWater)->Self{
|
||||||
|
Self{
|
||||||
|
viscosity:value.viscosity.get(),
|
||||||
|
density:value.density.get(),
|
||||||
|
velocity:value.velocity.get().to_array(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -70,11 +132,20 @@ impl Into<strafesnet_common::gameplay_attributes::Accelerator> for Accelerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::Accelerator> for Accelerator{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::Accelerator)->Self{
|
||||||
|
Self{
|
||||||
|
acceleration:value.acceleration.get().to_array(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub enum Booster{
|
pub enum Booster{
|
||||||
|
#[brw(magic=0u8)]
|
||||||
Velocity(Planar64Vec3),
|
Velocity(Planar64Vec3),
|
||||||
|
#[brw(magic=1u8)]
|
||||||
Energy{direction:Planar64Vec3,energy:Planar64},
|
Energy{direction:Planar64Vec3,energy:Planar64},
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
||||||
@@ -92,6 +163,19 @@ impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::Booster)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_attributes::Booster::Velocity(velocity)=>
|
||||||
|
Booster::Velocity(velocity.get().to_array()),
|
||||||
|
strafesnet_common::gameplay_attributes::Booster::Energy{direction,energy}=>
|
||||||
|
Booster::Energy{
|
||||||
|
direction:direction.get().to_array(),
|
||||||
|
energy:energy.get(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little,repr=u8)]
|
#[brw(little,repr=u8)]
|
||||||
@@ -109,22 +193,38 @@ impl Into<strafesnet_common::gameplay_attributes::TrajectoryChoice> for Trajecto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::TrajectoryChoice> for TrajectoryChoice{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::TrajectoryChoice)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_attributes::TrajectoryChoice::HighArcLongDuration=>
|
||||||
|
TrajectoryChoice::HighArcLongDuration,
|
||||||
|
strafesnet_common::gameplay_attributes::TrajectoryChoice::LowArcShortDuration=>
|
||||||
|
TrajectoryChoice::LowArcShortDuration,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub enum SetTrajectory{
|
pub enum SetTrajectory{
|
||||||
|
#[brw(magic=0u8)]
|
||||||
AirTime(Time),
|
AirTime(Time),
|
||||||
|
#[brw(magic=1u8)]
|
||||||
Height(Planar64),
|
Height(Planar64),
|
||||||
|
#[brw(magic=2u8)]
|
||||||
DotVelocity{direction:Planar64Vec3,dot:Planar64},
|
DotVelocity{direction:Planar64Vec3,dot:Planar64},
|
||||||
|
#[brw(magic=3u8)]
|
||||||
TargetPointTime{
|
TargetPointTime{
|
||||||
target_point:Planar64Vec3,
|
target_point:Planar64Vec3,
|
||||||
time:Time,
|
time:Time,
|
||||||
},
|
},
|
||||||
|
#[brw(magic=4u8)]
|
||||||
TargetPointSpeed{
|
TargetPointSpeed{
|
||||||
target_point:Planar64Vec3,
|
target_point:Planar64Vec3,
|
||||||
speed:Planar64,
|
speed:Planar64,
|
||||||
trajectory_choice:TrajectoryChoice,
|
trajectory_choice:TrajectoryChoice,
|
||||||
},
|
},
|
||||||
|
#[brw(magic=5u8)]
|
||||||
Velocity(Planar64Vec3),
|
Velocity(Planar64Vec3),
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::SetTrajectory> for SetTrajectory{
|
impl Into<strafesnet_common::gameplay_attributes::SetTrajectory> for SetTrajectory{
|
||||||
@@ -161,6 +261,40 @@ impl Into<strafesnet_common::gameplay_attributes::SetTrajectory> for SetTrajecto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::SetTrajectory> for SetTrajectory{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::SetTrajectory)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_attributes::SetTrajectory::AirTime(time)=>
|
||||||
|
SetTrajectory::AirTime(
|
||||||
|
time.get()
|
||||||
|
),
|
||||||
|
strafesnet_common::gameplay_attributes::SetTrajectory::Height(height)=>
|
||||||
|
SetTrajectory::Height(
|
||||||
|
height.get()
|
||||||
|
),
|
||||||
|
strafesnet_common::gameplay_attributes::SetTrajectory::DotVelocity{direction,dot}=>
|
||||||
|
SetTrajectory::DotVelocity{
|
||||||
|
direction:direction.get().to_array(),
|
||||||
|
dot:dot.get(),
|
||||||
|
},
|
||||||
|
strafesnet_common::gameplay_attributes::SetTrajectory::TargetPointTime{target_point,time}=>
|
||||||
|
SetTrajectory::TargetPointTime{
|
||||||
|
target_point:target_point.get().to_array(),
|
||||||
|
time:time.get(),
|
||||||
|
},
|
||||||
|
strafesnet_common::gameplay_attributes::SetTrajectory::TargetPointSpeed{target_point,speed,trajectory_choice}=>
|
||||||
|
SetTrajectory::TargetPointSpeed{
|
||||||
|
target_point:target_point.get().to_array(),
|
||||||
|
speed:speed.get(),
|
||||||
|
trajectory_choice:trajectory_choice.into(),
|
||||||
|
},
|
||||||
|
strafesnet_common::gameplay_attributes::SetTrajectory::Velocity(velocity)=>
|
||||||
|
SetTrajectory::Velocity(
|
||||||
|
velocity.get().to_array()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -174,22 +308,58 @@ impl Into<strafesnet_common::gameplay_attributes::Wormhole> for Wormhole{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::Wormhole> for Wormhole{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::Wormhole)->Self{
|
||||||
|
Self{
|
||||||
|
destination_model:value.destination_model.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub struct GeneralAttributesHeader{
|
||||||
|
pub booster:u8,
|
||||||
|
pub trajectory:u8,
|
||||||
|
pub wormhole:u8,
|
||||||
|
pub accelerator:u8,
|
||||||
|
}
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct GeneralAttributes{
|
pub struct GeneralAttributes{
|
||||||
pub booster:Option<Booster>,
|
pub header:GeneralAttributesHeader,
|
||||||
pub trajectory:Option<SetTrajectory>,
|
#[br(count=header.booster)]
|
||||||
pub wormhole:Option<Wormhole>,
|
pub booster:Vec<Booster>,
|
||||||
pub accelerator:Option<Accelerator>,
|
#[br(count=header.trajectory)]
|
||||||
|
pub trajectory:Vec<SetTrajectory>,
|
||||||
|
#[br(count=header.wormhole)]
|
||||||
|
pub wormhole:Vec<Wormhole>,
|
||||||
|
#[br(count=header.accelerator)]
|
||||||
|
pub accelerator:Vec<Accelerator>,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
|
impl Into<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
|
||||||
fn into(self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
|
fn into(mut self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
|
||||||
strafesnet_common::gameplay_attributes::GeneralAttributes{
|
strafesnet_common::gameplay_attributes::GeneralAttributes{
|
||||||
booster:self.booster.map(Into::into),
|
booster:self.booster.pop().map(Into::into),
|
||||||
trajectory:self.trajectory.map(Into::into),
|
trajectory:self.trajectory.pop().map(Into::into),
|
||||||
wormhole:self.wormhole.map(Into::into),
|
wormhole:self.wormhole.pop().map(Into::into),
|
||||||
accelerator:self.accelerator.map(Into::into),
|
accelerator:self.accelerator.pop().map(Into::into),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::GeneralAttributes)->Self{
|
||||||
|
Self{
|
||||||
|
header:GeneralAttributesHeader{
|
||||||
|
booster:value.booster.is_some() as u8,
|
||||||
|
trajectory:value.trajectory.is_some() as u8,
|
||||||
|
wormhole:value.wormhole.is_some() as u8,
|
||||||
|
accelerator:value.accelerator.is_some() as u8,
|
||||||
|
},
|
||||||
|
booster:super::gameplay_style::stupid(value.booster.map(Into::into)),
|
||||||
|
trajectory:super::gameplay_style::stupid(value.trajectory.map(Into::into)),
|
||||||
|
wormhole:super::gameplay_style::stupid(value.wormhole.map(Into::into)),
|
||||||
|
accelerator:super::gameplay_style::stupid(value.accelerator.map(Into::into)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,12 +367,22 @@ impl Into<strafesnet_common::gameplay_attributes::GeneralAttributes> for General
|
|||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct ContactingAttributes{
|
pub struct ContactingAttributes{
|
||||||
pub contact_behaviour:Option<ContactingBehaviour>,
|
pub contact_behaviour_enabled:u8,
|
||||||
|
#[br(count=contact_behaviour_enabled)]
|
||||||
|
pub contact_behaviour:Vec<ContactingBehaviour>,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
|
impl Into<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
|
||||||
fn into(self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
|
fn into(mut self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
|
||||||
strafesnet_common::gameplay_attributes::ContactingAttributes{
|
strafesnet_common::gameplay_attributes::ContactingAttributes{
|
||||||
contact_behaviour:self.contact_behaviour.map(Into::into),
|
contact_behaviour:self.contact_behaviour.pop().map(Into::into),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::ContactingAttributes)->Self{
|
||||||
|
Self{
|
||||||
|
contact_behaviour_enabled:value.contact_behaviour.is_some() as u8,
|
||||||
|
contact_behaviour:super::gameplay_style::stupid(value.contact_behaviour.map(Into::into)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,23 +390,37 @@ impl Into<strafesnet_common::gameplay_attributes::ContactingAttributes> for Cont
|
|||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct IntersectingAttributes{
|
pub struct IntersectingAttributes{
|
||||||
pub water:Option<IntersectingWater>,
|
pub water_enabled:u8,
|
||||||
|
#[br(count=water_enabled)]
|
||||||
|
pub water:Vec<IntersectingWater>,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
|
impl Into<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
|
||||||
fn into(self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
fn into(mut self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
||||||
strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
||||||
water:self.water.map(Into::into),
|
water:self.water.pop().map(Into::into),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::IntersectingAttributes)->Self{
|
||||||
|
Self{
|
||||||
|
water_enabled:value.water.is_some() as u8,
|
||||||
|
water:super::gameplay_style::stupid(value.water.map(Into::into)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub enum CollisionAttributes{
|
pub enum CollisionAttributes{
|
||||||
|
#[brw(magic=0u8)]
|
||||||
Decoration,
|
Decoration,
|
||||||
|
#[brw(magic=1u8)]
|
||||||
Contact{
|
Contact{
|
||||||
contacting:ContactingAttributes,
|
contacting:ContactingAttributes,
|
||||||
general:GeneralAttributes,
|
general:GeneralAttributes,
|
||||||
},
|
},
|
||||||
|
#[brw(magic=2u8)]
|
||||||
Intersect{
|
Intersect{
|
||||||
intersecting:IntersectingAttributes,
|
intersecting:IntersectingAttributes,
|
||||||
general:GeneralAttributes,
|
general:GeneralAttributes,
|
||||||
@@ -244,3 +438,15 @@ impl Into<strafesnet_common::gameplay_attributes::CollisionAttributes> for Colli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_attributes::CollisionAttributes> for CollisionAttributes{
|
||||||
|
fn from(value:strafesnet_common::gameplay_attributes::CollisionAttributes)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_attributes::CollisionAttributes::Decoration=>
|
||||||
|
CollisionAttributes::Decoration,
|
||||||
|
strafesnet_common::gameplay_attributes::CollisionAttributes::Contact{contacting,general}=>
|
||||||
|
CollisionAttributes::Contact{contacting:contacting.into(),general:general.into()},
|
||||||
|
strafesnet_common::gameplay_attributes::CollisionAttributes::Intersect{intersecting,general}=>
|
||||||
|
CollisionAttributes::Intersect{intersecting:intersecting.into(),general:general.into()},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,25 +22,50 @@ impl Into<strafesnet_common::gameplay_modes::StageElementBehaviour> for StageEle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_modes::StageElementBehaviour> for StageElementBehaviour{
|
||||||
|
fn from(value:strafesnet_common::gameplay_modes::StageElementBehaviour)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_modes::StageElementBehaviour::SpawnAt=>StageElementBehaviour::SpawnAt,
|
||||||
|
strafesnet_common::gameplay_modes::StageElementBehaviour::Trigger=>StageElementBehaviour::Trigger,
|
||||||
|
strafesnet_common::gameplay_modes::StageElementBehaviour::Teleport=>StageElementBehaviour::Teleport,
|
||||||
|
strafesnet_common::gameplay_modes::StageElementBehaviour::Platform=>StageElementBehaviour::Platform,
|
||||||
|
strafesnet_common::gameplay_modes::StageElementBehaviour::Check=>StageElementBehaviour::Check,
|
||||||
|
strafesnet_common::gameplay_modes::StageElementBehaviour::Checkpoint=>StageElementBehaviour::Checkpoint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct StageElement{
|
pub struct StageElement{
|
||||||
pub stage_id:u32,//which stage spawn to send to
|
pub stage_id:u32,//which stage spawn to send to
|
||||||
pub behaviour:StageElementBehaviour,
|
pub behaviour:StageElementBehaviour,
|
||||||
pub jump_limit:Option<u8>,
|
pub jump_limit_enabled:u8,
|
||||||
pub force:Option<()>,//allow setting to lower spawn id i.e. 7->3
|
#[br(count=jump_limit_enabled)]
|
||||||
|
pub jump_limit:Vec<u8>,
|
||||||
|
pub force:super::gameplay_attributes::Boolio,//allow setting to lower spawn id i.e. 7->3
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_modes::StageElement> for StageElement{
|
impl Into<strafesnet_common::gameplay_modes::StageElement> for StageElement{
|
||||||
fn into(self)->strafesnet_common::gameplay_modes::StageElement{
|
fn into(mut self)->strafesnet_common::gameplay_modes::StageElement{
|
||||||
strafesnet_common::gameplay_modes::StageElement::new(
|
strafesnet_common::gameplay_modes::StageElement::new(
|
||||||
strafesnet_common::gameplay_modes::StageId::new(self.stage_id),
|
strafesnet_common::gameplay_modes::StageId::new(self.stage_id),
|
||||||
self.force.is_some(),
|
self.force.into(),
|
||||||
self.behaviour.into(),
|
self.behaviour.into(),
|
||||||
self.jump_limit,
|
self.jump_limit.pop(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_modes::StageElement> for StageElement{
|
||||||
|
fn from(value:strafesnet_common::gameplay_modes::StageElement)->Self{
|
||||||
|
Self{
|
||||||
|
stage_id:value.stage_id().get(),
|
||||||
|
behaviour:value.behaviour().into(),
|
||||||
|
jump_limit_enabled:value.jump_limit().is_some() as u8,
|
||||||
|
jump_limit:super::gameplay_style::stupid(value.jump_limit()),
|
||||||
|
force:value.force().into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -71,9 +96,29 @@ impl Into<strafesnet_common::gameplay_modes::Stage> for Stage{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_modes::Stage> for Stage{
|
||||||
|
fn from(value:strafesnet_common::gameplay_modes::Stage)->Self{
|
||||||
|
let spawn=value.spawn().get();
|
||||||
|
let ordered_checkpoints_count=value.ordered_checkpoints_count();
|
||||||
|
let unordered_checkpoints_count=value.unordered_checkpoints_count();
|
||||||
|
let (ordered_checkpoints,unordered_checkpoints)=value.into_inner();
|
||||||
|
Self{
|
||||||
|
spawn,
|
||||||
|
ordered_checkpoints_count,
|
||||||
|
unordered_checkpoints_count,
|
||||||
|
ordered_checkpoints:ordered_checkpoints.into_iter()
|
||||||
|
.map(|(checkpoint_id,model_id)|(checkpoint_id.get(),model_id.get()))
|
||||||
|
.collect(),
|
||||||
|
unordered_checkpoints:unordered_checkpoints.into_iter()
|
||||||
|
.map(|model_id|model_id.get())
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little,repr=u8)]
|
#[brw(little,repr=u32)]
|
||||||
|
#[repr(u32)]
|
||||||
pub enum Zone{
|
pub enum Zone{
|
||||||
Start,
|
Start,
|
||||||
Finish,
|
Finish,
|
||||||
@@ -88,9 +133,19 @@ impl Into<strafesnet_common::gameplay_modes::Zone> for Zone{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_modes::Zone> for Zone{
|
||||||
|
fn from(value:strafesnet_common::gameplay_modes::Zone)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_modes::Zone::Start=>Zone::Start,
|
||||||
|
strafesnet_common::gameplay_modes::Zone::Finish=>Zone::Finish,
|
||||||
|
strafesnet_common::gameplay_modes::Zone::Anticheat=>Zone::Anticheat,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ModeHeader{
|
pub struct ModeHeader{
|
||||||
pub zones:u32,
|
pub zones:u32,
|
||||||
pub stages:u32,
|
pub stages:u32,
|
||||||
@@ -124,3 +179,26 @@ impl Into<strafesnet_common::gameplay_modes::Mode> for Mode{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_modes::Mode> for Mode{
|
||||||
|
fn from(value:strafesnet_common::gameplay_modes::Mode)->Self{
|
||||||
|
let (style,start,zones,stages,elements)=value.into_inner();
|
||||||
|
Self{
|
||||||
|
header:ModeHeader{
|
||||||
|
zones:zones.len() as u32,
|
||||||
|
stages:stages.len() as u32,
|
||||||
|
elements:elements.len() as u32,
|
||||||
|
},
|
||||||
|
style:style.into(),
|
||||||
|
start:start.get(),
|
||||||
|
zones:zones.into_iter()
|
||||||
|
.map(|(model_id,zone)|(model_id.get(),zone.into()))
|
||||||
|
.collect(),
|
||||||
|
stages:stages.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect(),
|
||||||
|
elements:elements.into_iter()
|
||||||
|
.map(|(model_id,stage_element)|(model_id.get(),stage_element.into()))
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,34 +2,52 @@ use super::integer::{Time,Ratio64,Planar64,Planar64Vec3};
|
|||||||
|
|
||||||
pub type Controls=u32;
|
pub type Controls=u32;
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub struct StyleModifiersHeader{
|
||||||
|
pub strafe:u8,
|
||||||
|
pub rocket:u8,
|
||||||
|
pub jump:u8,
|
||||||
|
pub walk:u8,
|
||||||
|
pub ladder:u8,
|
||||||
|
pub swim:u8,
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct StyleModifiers{
|
pub struct StyleModifiers{
|
||||||
|
pub header:StyleModifiersHeader,
|
||||||
pub controls_mask:Controls,
|
pub controls_mask:Controls,
|
||||||
pub controls_mask_state:Controls,
|
pub controls_mask_state:Controls,
|
||||||
pub strafe:Option<StrafeSettings>,
|
#[br(count=header.strafe)]
|
||||||
pub rocket:Option<PropulsionSettings>,
|
pub strafe:Vec<StrafeSettings>,
|
||||||
pub jump:Option<JumpSettings>,
|
#[br(count=header.rocket)]
|
||||||
pub walk:Option<WalkSettings>,
|
pub rocket:Vec<PropulsionSettings>,
|
||||||
pub ladder:Option<LadderSettings>,
|
#[br(count=header.jump)]
|
||||||
pub swim:Option<PropulsionSettings>,
|
pub jump:Vec<JumpSettings>,
|
||||||
|
#[br(count=header.walk)]
|
||||||
|
pub walk:Vec<WalkSettings>,
|
||||||
|
#[br(count=header.ladder)]
|
||||||
|
pub ladder:Vec<LadderSettings>,
|
||||||
|
#[br(count=header.swim)]
|
||||||
|
pub swim:Vec<PropulsionSettings>,
|
||||||
pub gravity:Planar64Vec3,
|
pub gravity:Planar64Vec3,
|
||||||
pub hitbox:Hitbox,
|
pub hitbox:Hitbox,
|
||||||
pub camera_offset:Planar64Vec3,
|
pub camera_offset:Planar64Vec3,
|
||||||
pub mass:Planar64,
|
pub mass:Planar64,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||||
fn into(self)->strafesnet_common::gameplay_style::StyleModifiers{
|
fn into(mut self)->strafesnet_common::gameplay_style::StyleModifiers{
|
||||||
strafesnet_common::gameplay_style::StyleModifiers{
|
strafesnet_common::gameplay_style::StyleModifiers{
|
||||||
//TODO: fail gracefully in binrw instead of panicing here
|
//TODO: fail gracefully in binrw instead of panicing here
|
||||||
controls_mask:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).unwrap(),
|
controls_mask:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).unwrap(),
|
||||||
controls_mask_state:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask_state).unwrap(),
|
controls_mask_state:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask_state).unwrap(),
|
||||||
strafe:self.strafe.map(Into::into),
|
strafe:self.strafe.pop().map(Into::into),
|
||||||
rocket:self.rocket.map(Into::into),
|
rocket:self.rocket.pop().map(Into::into),
|
||||||
jump:self.jump.map(Into::into),
|
jump:self.jump.pop().map(Into::into),
|
||||||
walk:self.walk.map(Into::into),
|
walk:self.walk.pop().map(Into::into),
|
||||||
ladder:self.ladder.map(Into::into),
|
ladder:self.ladder.pop().map(Into::into),
|
||||||
swim:self.swim.map(Into::into),
|
swim:self.swim.pop().map(Into::into),
|
||||||
gravity:strafesnet_common::integer::Planar64Vec3::raw_array(self.gravity),
|
gravity:strafesnet_common::integer::Planar64Vec3::raw_array(self.gravity),
|
||||||
hitbox:self.hitbox.into(),
|
hitbox:self.hitbox.into(),
|
||||||
camera_offset:strafesnet_common::integer::Planar64Vec3::raw_array(self.camera_offset),
|
camera_offset:strafesnet_common::integer::Planar64Vec3::raw_array(self.camera_offset),
|
||||||
@@ -37,6 +55,38 @@ impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub(crate) fn stupid<T>(o:Option<T>)->Vec<T>{
|
||||||
|
match o{
|
||||||
|
Some(v)=>vec![v],
|
||||||
|
None=>Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::StyleModifiers)->Self{
|
||||||
|
Self{
|
||||||
|
header:StyleModifiersHeader{
|
||||||
|
strafe:value.strafe.is_some() as u8,
|
||||||
|
rocket:value.rocket.is_some() as u8,
|
||||||
|
jump:value.jump.is_some() as u8,
|
||||||
|
walk:value.walk.is_some() as u8,
|
||||||
|
ladder:value.ladder.is_some() as u8,
|
||||||
|
swim:value.swim.is_some() as u8,
|
||||||
|
},
|
||||||
|
controls_mask:value.controls_mask.bits(),
|
||||||
|
controls_mask_state:value.controls_mask_state.bits(),
|
||||||
|
strafe:stupid(value.strafe.map(Into::into)),
|
||||||
|
rocket:stupid(value.rocket.map(Into::into)),
|
||||||
|
jump:stupid(value.jump.map(Into::into)),
|
||||||
|
walk:stupid(value.walk.map(Into::into)),
|
||||||
|
ladder:stupid(value.ladder.map(Into::into)),
|
||||||
|
swim:stupid(value.swim.map(Into::into)),
|
||||||
|
gravity:value.gravity.get().to_array(),
|
||||||
|
hitbox:value.hitbox.into(),
|
||||||
|
camera_offset:value.camera_offset.get().to_array(),
|
||||||
|
mass:value.mass.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little,repr=u8)]
|
#[brw(little,repr=u8)]
|
||||||
@@ -54,6 +104,15 @@ impl Into<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::JumpCalculation)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_style::JumpCalculation::Capped=>JumpCalculation::Capped,
|
||||||
|
strafesnet_common::gameplay_style::JumpCalculation::Energy=>JumpCalculation::Energy,
|
||||||
|
strafesnet_common::gameplay_style::JumpCalculation::Linear=>JumpCalculation::Linear,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -73,6 +132,16 @@ impl Into<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::JumpImpulse)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_style::JumpImpulse::FromTime(time)=>JumpImpulse::FromTime(time.get()),
|
||||||
|
strafesnet_common::gameplay_style::JumpImpulse::FromHeight(height)=>JumpImpulse::FromHeight(height.get()),
|
||||||
|
strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(deltav)=>JumpImpulse::FromDeltaV(deltav.get()),
|
||||||
|
strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(energy)=>JumpImpulse::FromEnergy(energy.get()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -90,25 +159,48 @@ impl Into<strafesnet_common::gameplay_style::ControlsActivation> for ControlsAct
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::ControlsActivation)->Self{
|
||||||
|
Self{
|
||||||
|
controls_mask:value.controls_mask().bits(),
|
||||||
|
controls_intersects:value.controls_intersects().bits(),
|
||||||
|
controls_contains:value.controls_contains().bits(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct StrafeSettings{
|
pub struct StrafeSettings{
|
||||||
enable:ControlsActivation,
|
enable:ControlsActivation,
|
||||||
mv:Planar64,
|
mv:Planar64,
|
||||||
air_accel_limit:Option<Planar64>,
|
air_accel_limit_enabled:u8,
|
||||||
|
#[br(count=air_accel_limit_enabled)]
|
||||||
|
air_accel_limit:Vec<Planar64>,
|
||||||
tick_rate:Ratio64,
|
tick_rate:Ratio64,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
||||||
fn into(self)->strafesnet_common::gameplay_style::StrafeSettings{
|
fn into(mut self)->strafesnet_common::gameplay_style::StrafeSettings{
|
||||||
strafesnet_common::gameplay_style::StrafeSettings::new(
|
strafesnet_common::gameplay_style::StrafeSettings::new(
|
||||||
self.enable.into(),
|
self.enable.into(),
|
||||||
strafesnet_common::integer::Planar64::raw(self.mv),
|
strafesnet_common::integer::Planar64::raw(self.mv),
|
||||||
self.air_accel_limit.map(strafesnet_common::integer::Planar64::raw),
|
self.air_accel_limit.pop().map(strafesnet_common::integer::Planar64::raw),
|
||||||
self.tick_rate.into(),
|
self.tick_rate.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::StrafeSettings)->Self{
|
||||||
|
let (enable,mv,air_accel_limit,tick_rate)=value.into_inner();
|
||||||
|
Self{
|
||||||
|
enable:enable.into(),
|
||||||
|
mv:mv.get(),
|
||||||
|
air_accel_limit_enabled:air_accel_limit.is_some() as u8,
|
||||||
|
air_accel_limit:stupid(air_accel_limit.map(|a|a.get())),
|
||||||
|
tick_rate:tick_rate.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -122,6 +214,13 @@ impl Into<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionS
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::PropulsionSettings)->Self{
|
||||||
|
Self{
|
||||||
|
magnitude:value.magnitude().get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -137,6 +236,15 @@ impl Into<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::JumpSettings)->Self{
|
||||||
|
let (impulse,calculation)=value.into_inner();
|
||||||
|
Self{
|
||||||
|
impulse:impulse.into(),
|
||||||
|
calculation:calculation.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -152,6 +260,14 @@ impl Into<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateS
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::AccelerateSettings)->Self{
|
||||||
|
Self{
|
||||||
|
accel:value.accel().get(),
|
||||||
|
topspeed:value.topspeed().get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -171,6 +287,17 @@ impl Into<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::WalkSettings)->Self{
|
||||||
|
let (accelerate,static_friction,kinetic_friction,surf_dot)=value.into_inner();
|
||||||
|
Self{
|
||||||
|
accelerate:accelerate.into(),
|
||||||
|
static_friction:static_friction.get(),
|
||||||
|
kinetic_friction:kinetic_friction.get(),
|
||||||
|
surf_dot:surf_dot.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -186,6 +313,15 @@ impl Into<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::LadderSettings)->Self{
|
||||||
|
let (accelerate,dot)=value.into_inner();
|
||||||
|
Self{
|
||||||
|
accelerate:accelerate.into(),
|
||||||
|
dot:dot.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little,repr=u8)]
|
#[brw(little,repr=u8)]
|
||||||
@@ -201,6 +337,14 @@ impl Into<strafesnet_common::gameplay_style::HitboxMesh> for HitboxMesh{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::HitboxMesh> for HitboxMesh{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::HitboxMesh)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::gameplay_style::HitboxMesh::Box=>HitboxMesh::Box,
|
||||||
|
strafesnet_common::gameplay_style::HitboxMesh::Cylinder=>HitboxMesh::Cylinder,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -216,3 +360,11 @@ impl Into<strafesnet_common::gameplay_style::Hitbox> for Hitbox{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::gameplay_style::Hitbox> for Hitbox{
|
||||||
|
fn from(value:strafesnet_common::gameplay_style::Hitbox)->Self{
|
||||||
|
Self{
|
||||||
|
halfsize:value.halfsize.get().to_array(),
|
||||||
|
mesh:value.mesh.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ impl Into<strafesnet_common::integer::Ratio64> for Ratio64{
|
|||||||
strafesnet_common::integer::Ratio64::new(self.num,self.den).unwrap()
|
strafesnet_common::integer::Ratio64::new(self.num,self.den).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::integer::Ratio64> for Ratio64{
|
||||||
|
fn from(value:strafesnet_common::integer::Ratio64)->Self{
|
||||||
|
Self{
|
||||||
|
num:value.num(),
|
||||||
|
den:value.den(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use strafesnet_common::model::PolygonIter;
|
||||||
|
|
||||||
use super::integer::{Planar64Vec3,Planar64Affine3};
|
use super::integer::{Planar64Vec3,Planar64Affine3};
|
||||||
|
|
||||||
pub type TextureCoordinate=[f32;2];
|
pub type TextureCoordinate=[f32;2];
|
||||||
@@ -11,6 +13,16 @@ pub struct IndexedVertex{
|
|||||||
pub normal:u32,
|
pub normal:u32,
|
||||||
pub color:u32,
|
pub color:u32,
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::model::IndexedVertex> for IndexedVertex{
|
||||||
|
fn from(value:strafesnet_common::model::IndexedVertex)->Self{
|
||||||
|
Self{
|
||||||
|
pos:value.pos.get(),
|
||||||
|
tex:value.tex.get(),
|
||||||
|
normal:value.normal.get(),
|
||||||
|
color:value.color.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -26,15 +38,44 @@ pub struct PolygonGroup{
|
|||||||
#[br(count=count)]
|
#[br(count=count)]
|
||||||
pub polys:Vec<Polygon>,
|
pub polys:Vec<Polygon>,
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::model::PolygonGroup> for PolygonGroup{
|
||||||
|
fn from(value:strafesnet_common::model::PolygonGroup)->Self{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::model::PolygonGroup::PolygonList(polygon_list)=>{
|
||||||
|
let polys:Vec<Polygon>=polygon_list.polys().map(|poly|{
|
||||||
|
let vertices:Vec<u32>=poly.iter().map(|vert|vert.get()).collect();
|
||||||
|
Polygon{
|
||||||
|
count:vertices.len() as u32,
|
||||||
|
vertices,
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
Self{
|
||||||
|
count:polys.len() as u32,
|
||||||
|
polys,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct RenderConfig{
|
pub struct RenderConfig{
|
||||||
pub texture:Option<u32>,
|
pub texture_enabled:u8,
|
||||||
|
#[br(count=texture_enabled)]
|
||||||
|
pub texture:Vec<u32>,
|
||||||
}
|
}
|
||||||
impl Into<strafesnet_common::model::RenderConfig> for RenderConfig{
|
impl Into<strafesnet_common::model::RenderConfig> for RenderConfig{
|
||||||
fn into(self)->strafesnet_common::model::RenderConfig{
|
fn into(mut self)->strafesnet_common::model::RenderConfig{
|
||||||
strafesnet_common::model::RenderConfig{
|
strafesnet_common::model::RenderConfig{
|
||||||
texture:self.texture.map(strafesnet_common::model::TextureId::new),
|
texture:self.texture.pop().map(strafesnet_common::model::TextureId::new),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::model::RenderConfig> for RenderConfig{
|
||||||
|
fn from(value:strafesnet_common::model::RenderConfig)->Self{
|
||||||
|
Self{
|
||||||
|
texture_enabled:value.texture.is_some() as u8,
|
||||||
|
texture:super::gameplay_style::stupid(value.texture.map(|texture_id|texture_id.get())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,6 +87,15 @@ pub struct IndexedGraphicsGroup{
|
|||||||
#[br(count=count)]
|
#[br(count=count)]
|
||||||
pub groups:Vec<u32>,
|
pub groups:Vec<u32>,
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::model::IndexedGraphicsGroup> for IndexedGraphicsGroup{
|
||||||
|
fn from(value:strafesnet_common::model::IndexedGraphicsGroup)->Self{
|
||||||
|
Self{
|
||||||
|
count:value.groups.len() as u32,
|
||||||
|
render:value.render.get(),
|
||||||
|
groups:value.groups.into_iter().map(|group_id|group_id.get()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
pub struct IndexedPhysicsGroup{
|
pub struct IndexedPhysicsGroup{
|
||||||
@@ -53,6 +103,14 @@ pub struct IndexedPhysicsGroup{
|
|||||||
#[br(count=count)]
|
#[br(count=count)]
|
||||||
pub groups:Vec<u32>,
|
pub groups:Vec<u32>,
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::model::IndexedPhysicsGroup> for IndexedPhysicsGroup{
|
||||||
|
fn from(value:strafesnet_common::model::IndexedPhysicsGroup)->Self{
|
||||||
|
Self{
|
||||||
|
count:value.groups.len() as u32,
|
||||||
|
groups:value.groups.into_iter().map(|group_id|group_id.get()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -123,6 +181,46 @@ impl Into<strafesnet_common::model::Mesh> for Mesh{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::model::Mesh> for Mesh{
|
||||||
|
fn from(value:strafesnet_common::model::Mesh)->Self{
|
||||||
|
Self{
|
||||||
|
header:MeshHeader{
|
||||||
|
unique_pos:value.unique_pos.len() as u32,
|
||||||
|
unique_normal:value.unique_normal.len() as u32,
|
||||||
|
unique_tex:value.unique_tex.len() as u32,
|
||||||
|
unique_color:value.unique_color.len() as u32,
|
||||||
|
unique_vertices:value.unique_vertices.len() as u32,
|
||||||
|
polygon_groups:value.polygon_groups.len() as u32,
|
||||||
|
graphics_groups:value.graphics_groups.len() as u32,
|
||||||
|
physics_groups:value.physics_groups.len() as u32,
|
||||||
|
},
|
||||||
|
unique_pos:value.unique_pos.into_iter()
|
||||||
|
.map(|pos|pos.get().to_array())
|
||||||
|
.collect(),
|
||||||
|
unique_normal:value.unique_normal.into_iter()
|
||||||
|
.map(|normal|normal.get().to_array())
|
||||||
|
.collect(),
|
||||||
|
unique_tex:value.unique_tex.into_iter()
|
||||||
|
.map(|tex|tex.to_array())
|
||||||
|
.collect(),
|
||||||
|
unique_color:value.unique_color.into_iter()
|
||||||
|
.map(|color|color.to_array())
|
||||||
|
.collect(),
|
||||||
|
unique_vertices:value.unique_vertices.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect(),
|
||||||
|
polygon_groups:value.polygon_groups.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect(),
|
||||||
|
graphics_groups:value.graphics_groups.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect(),
|
||||||
|
physics_groups:value.physics_groups.into_iter()
|
||||||
|
.map(Into::into)
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binrw::binrw]
|
#[binrw::binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
@@ -150,3 +248,24 @@ impl Into<strafesnet_common::model::Model> for Model{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<strafesnet_common::model::Model> for Model{
|
||||||
|
fn from(value:strafesnet_common::model::Model)->Self{
|
||||||
|
let (
|
||||||
|
[_0,_1,_2],
|
||||||
|
[_3,_4,_5],
|
||||||
|
[_6,_7,_8],
|
||||||
|
[_9,_a,_b]
|
||||||
|
)=(
|
||||||
|
value.transform.matrix3.x_axis.get().to_array(),
|
||||||
|
value.transform.matrix3.y_axis.get().to_array(),
|
||||||
|
value.transform.matrix3.z_axis.get().to_array(),
|
||||||
|
value.transform.translation.get().to_array()
|
||||||
|
);
|
||||||
|
Self{
|
||||||
|
mesh:value.mesh.get(),
|
||||||
|
attributes:value.attributes.get(),
|
||||||
|
color:value.color.to_array(),
|
||||||
|
transform:[_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user