Skip to content

Commit

Permalink
wip: change debug levels, add chunk type debug text
Browse files Browse the repository at this point in the history
  • Loading branch information
berkus committed Mar 31, 2024
1 parent 032b336 commit be3bca7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn setup_cars(
});

let shapes = models.into_iter().map(|m| {
debug!("{:?}", m);
trace!("{:?}", m);
meshes.add(m.bevy_mesh())
});

Expand Down
2 changes: 1 addition & 1 deletion src/support/brender/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Material {
match mat {
Err(_) => break, // @fixme allow only Eof here
Ok(mat) => {
debug!(".. Loaded {}", mat.material.identifier);
trace!(".. Loaded {}", mat.material.identifier);
materials.push(mat)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/support/brender/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Model {
match m {
Err(_) => break, // fixme: allow only Eof here
Ok(m) => {
debug!(".. Loaded {}", m.name);
trace!(".. Loaded {}", m.name);
models.push(m)
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/support/brender/pixelmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use {
crate::support,
byteorder::ReadBytesExt,
culpa::{throw, throws},
log::debug,
log::trace,
std::io::prelude::BufRead,
support::brender::resource::file_type,
};
Expand Down Expand Up @@ -61,9 +61,15 @@ impl FromStream for PixelMap {
pixelmap.origin_x = origin_x;
pixelmap.origin_y = origin_y;

debug!(
trace!(
"Pixelmap {} (type {}, row_bytes {}, {}x{} origin {}x{})",
identifier, r#type, row_bytes, width, height, origin_x, origin_y
identifier,
r#type,
row_bytes,
width,
height,
origin_x,
origin_y
);
}
Chunk::Pixels(PixelsChunk {
Expand All @@ -75,9 +81,10 @@ impl FromStream for PixelMap {
pixelmap.unit_bytes = unit_bytes;
pixelmap.data = data;

debug!(
trace!(
"Pixelmap data in {} units, {} bytes each",
units, unit_bytes
units,
unit_bytes
);
}
Chunk::AddMap() => {}
Expand Down
62 changes: 59 additions & 3 deletions src/support/brender/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,60 @@ pub trait FromStreamExt {
) -> Result<Self::Output, Error>;
}

struct ChunkType(u32);

impl std::fmt::Display for ChunkType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self.0 {
chunk::END => "END",
chunk::PIXELMAP => "PIXELMAP",
chunk::MATERIAL => "MATERIAL",
chunk::ANIM => "ANIM",
chunk::ANIM_TRANSFORM => "ANIM_TRANSFORM",
chunk::ANIM_RATE => "ANIM_RATE",
chunk::FILE_INFO => "FILE_INFO",
chunk::PIVOT => "PIVOT",
chunk::MATERIAL_INDEX => "MATERIAL_INDEX",
chunk::VERTICES => "VERTICES",
chunk::VERTEX_UV => "VERTEX_UV",
chunk::FACE_MATERIAL => "FACE_MATERIAL",
chunk::COLOUR_MAP_REF => "COLOUR_MAP_REF",
chunk::INDEX_BLEND_REF => "INDEX_BLEND_REF",
chunk::INDEX_SHADE_REF => "INDEX_SHADE_REF",
chunk::SCREENDOOR_REF => "SCREENDOOR_REF",
chunk::PIXELS => "PIXELS",
chunk::ADD_MAP => "ADD_MAP",
chunk::ACTOR => "ACTOR",
chunk::ACTOR_MODEL => "ACTOR_MODEL",
chunk::ACTOR_TRANSFORM => "ACTOR_TRANSFORM",
chunk::ACTOR_MATERIAL => "ACTOR_MATERIAL",
chunk::ACTOR_LIGHT => "ACTOR_LIGHT",
chunk::ACTOR_CAMERA => "ACTOR_CAMERA",
chunk::ACTOR_BOUNDS => "ACTOR_BOUNDS",
chunk::ACTOR_ADD_CHILD => "ACTOR_ADD_CHILD",
chunk::TRANSFORM_MATRIX34 => "TRANSFORM_MATRIX34",
chunk::TRANSFORM_MATRIX34_LP => "TRANSFORM_MATRIX34_LP",
chunk::TRANSFORM_QUAT => "TRANSFORM_QUAT",
chunk::TRANSFORM_EULER => "TRANSFORM_EULER",
chunk::TRANSFORM_LOOK_UP => "TRANSFORM_LOOK_UP",
chunk::TRANSFORM_TRANSLATION => "TRANSFORM_TRANSLATION",
chunk::TRANSFORM_IDENTITY => "TRANSFORM_IDENTITY",
chunk::BOUNDS => "BOUNDS",
chunk::LIGHT => "LIGHT",
chunk::CAMERA => "CAMERA",
chunk::FACES => "FACES",
chunk::MODEL => "MODEL",
chunk::ACTOR_CLIP_PLANE => "ACTOR_CLIP_PLANE",
chunk::PLANE => "PLANE",
_ => "UNKNOWN",
}
)
}
}

//------------------------------------------------------------------
/// A binary resource file consisting of chunks with specific size.
/// Reading from such file yields array of chunk results, some of
Expand All @@ -50,9 +104,11 @@ impl FromStream for ChunkHeader {
fn from_stream<R: ReadBytesExt>(source: &mut R) -> Self::Output {
let chunk_type = source.read_u32::<BigEndian>()?;
let size = source.read_u32::<BigEndian>()?;
debug!(
"Loaded chunk type {chunk_type}/0x{:x} size {}",
chunk_type, size
trace!(
"Loaded chunk type {chunk_type}/0x{:x} {} size {}",
chunk_type,
ChunkType(chunk_type),
size
);
Self::Output { chunk_type, size }
}
Expand Down
12 changes: 6 additions & 6 deletions src/support/render_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ pub struct RenderManager {
program: Program,
}

fn debug_tree(name: &String, actor_name: &String, stack: &[Matrix4<f32>]) {
debug!("{} for {}: stack depth {}", name, actor_name, stack.len());
for x in stack.iter().rev() {
debug!(".. {:?}", x);
}
}
// fn debug_tree(name: &String, actor_name: &String, stack: &[Matrix4<f32>]) {
// debug!("{} for {}: stack depth {}", name, actor_name, stack.len());
// for x in stack.iter().rev() {
// debug!(".. {:?}", x);
// }
// }

// Load VertexBuffer
// Load IndexBuffers for each material
Expand Down

0 comments on commit be3bca7

Please sign in to comment.