debug info

This commit is contained in:
Quaternions 2025-02-27 09:45:12 -08:00
parent 8b6f3620f8
commit 364939167c
4 changed files with 85 additions and 23 deletions
engine/session/src
lib
bsp_loader/src
common/src
snf/src/newtypes

@ -211,16 +211,7 @@ impl Session{
self.last_ray_hit=model_id;
if let Some(model_id)=model_id{
if let Some(model)=self.geometry_shared.le_models.get(model_id.get() as usize){
let noice=model.brush_info.flags.iter_names().filter_map(|(name,flags)|{
(flags.bits()!=0).then(||name)
}).collect::<Vec<&str>>().join("|");
println!("brush_info.flags={noice}");
for (i,side) in model.brush_info.sides.iter().enumerate(){
let noice_string=side.iter_names().filter_map(|(name,flags)|{
(flags.bits()!=0).then(||name)
}).collect::<Vec<&str>>().join("|");
println!("brush_info.sides[{i}]={noice_string}");
}
println!("{}",model.debug_info);
}
}
}

@ -43,6 +43,7 @@ fn add_brush<'a>(
origin:vbsp::Vector,
rendercolor:vbsp::Color,
attributes:attr::CollisionAttributesId,
debug_info:model::DebugInfo,
){
let transform=integer::Planar64Affine3::from_translation(
valve_transform(origin.into())
@ -59,7 +60,7 @@ fn add_brush<'a>(
Ok(mesh_id)=>{
let mesh=model::MeshId::new(mesh_id);
world_models.push(
model::Model{mesh,attributes,transform,color,brush_info:model::BrushInfo::BUH}
model::Model{mesh,attributes,transform,color,debug_info}
);
},
Err(e)=>{
@ -70,7 +71,7 @@ fn add_brush<'a>(
_=>{
let mesh=mesh_deferred_loader.acquire_mesh_id(model);
prop_models.push(
model::Model{mesh,attributes,transform,color,brush_info:model::BrushInfo::BUH}
model::Model{mesh,attributes,transform,color,debug_info}
);
}
}
@ -139,7 +140,7 @@ pub fn convert<'a>(
valve_transform(prop.origin.into()),
),
color:glam::Vec4::ONE,
brush_info:model::BrushInfo::BUH,
debug_info:model::DebugInfo::Prop,
}
}).collect();
@ -208,7 +209,7 @@ pub fn convert<'a>(
attributes:ATTRIBUTE_DECORATION,
transform:integer::Planar64Affine3::IDENTITY,
color:glam::Vec4::W,
brush_info:model::BrushInfo::BUH,
debug_info:model::DebugInfo::World,
});
// THE CUBE OF DESTINY
@ -219,6 +220,13 @@ pub fn convert<'a>(
const ENTITY_ATTRIBUTE:gameplay_attributes::CollisionAttributesId=ATTRIBUTE_DECORATION;
const ENTITY_TRIGGER_ATTRIBUTE:gameplay_attributes::CollisionAttributesId=ATTRIBUTE_INTERSECT_DEFAULT;
for raw_ent in &bsp.entities{
let debug_info=match model::EntityInfo::new(raw_ent.properties()){
Ok(entity_info)=>model::DebugInfo::Entity(entity_info),
Err(_)=>{
println!("EntityInfoError");
model::DebugInfo::World
},
};
macro_rules! ent_brush_default{
($entity:ident)=>{
add_brush(mesh_deferred_loader,&mut world_models,&mut prop_models,$entity.model,$entity.origin,$entity.rendercolor,ENTITY_ATTRIBUTE)
@ -459,7 +467,7 @@ pub fn convert<'a>(
integer::vec3::ZERO,
),
color:glam::Vec4::ONE,
brush_info:model::BrushInfo{flags:brush.flags,sides}
debug_info:model::DebugInfo::Brush(model::BrushInfo{flags:brush.flags,sides}),
});
},
Err(e)=>println!("Brush mesh error: {e}"),
@ -475,7 +483,7 @@ pub fn convert<'a>(
attributes:ATTRIBUTE_INTERSECT_DEFAULT,
transform:integer::Planar64Affine3::from_translation(valve_transform(spawn_point.into())),
color:glam::Vec4::W,
brush_info:model::BrushInfo::BUH,
debug_info:model::DebugInfo::World,
});
let first_stage=Stage::empty(model_id);

@ -214,18 +214,81 @@ pub struct Model{
pub attributes:gameplay_attributes::CollisionAttributesId,
pub color:Color4,//transparency is in here
pub transform:Planar64Affine3,
pub brush_info:BrushInfo,
pub debug_info:DebugInfo,
}
#[derive(Debug,Clone)]
pub enum DebugInfo{
World,
Prop,
Brush(BrushInfo),
Entity(EntityInfo),
}
impl std::fmt::Display for DebugInfo{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
match self{
DebugInfo::World=>write!(f,"World"),
DebugInfo::Prop=>write!(f,"Prop"),
DebugInfo::Brush(brush_info)=>brush_info.fmt(f),
DebugInfo::Entity(entity_info)=>entity_info.fmt(f),
}
}
}
#[derive(Debug,Clone)]
pub struct BrushInfo{
pub flags:vbsp::BrushFlags,
pub sides:Vec<vbsp::TextureFlags>,
}
impl BrushInfo{
pub const BUH:Self=BrushInfo{
flags:vbsp::BrushFlags::empty(),
sides:vec![],
};
impl std::fmt::Display for BrushInfo{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
let noice=self.flags.iter_names().filter_map(|(name,flags)|{
(flags.bits()!=0).then(||name)
}).collect::<Vec<&str>>().join("|");
writeln!(f,"brush_info.flags={noice}")?;
for (i,side) in self.sides.iter().enumerate(){
let noice_string=side.iter_names().filter_map(|(name,flags)|{
(flags.bits()!=0).then(||name)
}).collect::<Vec<&str>>().join("|");
writeln!(f,"brush_info.sides[{i}]={noice_string}")?;
}
Ok(())
}
}
#[derive(Debug,Clone)]
pub struct EntityInfo{
pub classname:Box<str>,
pub properties:Vec<(Box<str>,Box<str>)>,
}
pub enum EntityInfoError{
MissingClassname,
}
impl EntityInfo{
pub fn new<'a>(iter:impl IntoIterator<Item=(&'a str,&'a str)>)->Result<Self,EntityInfoError>{
let mut classname:Option<Box<str>>=None;
let mut properties:Vec<(Box<str>,Box<str>)>=Vec::new();
for (name,value) in iter{
match name{
"classname"=>classname=Some(value.into()),
"hammerid"=>(),
_=>properties.push((name.into(),value.into())),
}
}
properties.sort_by(|(n0,_),(n1,_)|n0.cmp(n1));
let Some(classname)=classname else{
return Err(EntityInfoError::MissingClassname);
};
Ok(EntityInfo{classname,properties})
}
}
impl std::fmt::Display for EntityInfo{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
writeln!(f,"struct {}{{",self.classname)?;
for (name,value) in &self.properties{
writeln!(f,"\t{name}:{value},")?;
}
write!(f,"}}")?;
Ok(())
}
}

@ -250,7 +250,7 @@ impl Into<strafesnet_common::model::Model> for Model{
]),
strafesnet_common::integer::vec3::raw_xyz(_9,_a,_b)
),
brush_info:strafesnet_common::model::BrushInfo::BUH,
debug_info:strafesnet_common::model::DebugInfo::World,
}
}
}