mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 11:47:46 +00:00
Add explicit calculate_stack_size function and test it
This commit is contained in:
parent
1902dadbec
commit
835b48ff5b
1 changed files with 51 additions and 1 deletions
52
src/model.rs
52
src/model.rs
|
@ -664,7 +664,7 @@ impl MDL {
|
|||
|
||||
// update lod values
|
||||
// TODO: From Xande, need to be cleaned up :)
|
||||
self.file_header.stack_size = self.file_header.vertex_declaration_count as u32 * 136;
|
||||
self.file_header.stack_size = self.file_header.calculate_stack_size();
|
||||
self.file_header.runtime_size =
|
||||
2 //StringCount
|
||||
+ 2 // Unknown
|
||||
|
@ -882,3 +882,53 @@ impl MDL {
|
|||
Some(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
impl ModelFileHeader {
|
||||
pub fn calculate_stack_size(&self) -> u32 {
|
||||
// TODO: where does this magical 136 constant come from?
|
||||
self.vertex_declaration_count as u32 * 136
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Cursor;
|
||||
use crate::model::{MDL, ModelFileHeader};
|
||||
|
||||
#[test]
|
||||
fn test_stack_size() {
|
||||
let example_header = ModelFileHeader {
|
||||
version: 0,
|
||||
stack_size: 0,
|
||||
runtime_size: 0,
|
||||
vertex_declaration_count: 6,
|
||||
material_count: 0,
|
||||
vertex_offsets: [0; 3],
|
||||
index_offsets: [0; 3],
|
||||
vertex_buffer_size: [0; 3],
|
||||
index_buffer_size: [0; 3],
|
||||
lod_count: 0,
|
||||
index_buffer_streaming_enabled: false,
|
||||
has_edge_geometry: false,
|
||||
};
|
||||
|
||||
assert_eq!(816, example_header.calculate_stack_size());
|
||||
|
||||
let example_header2 = ModelFileHeader {
|
||||
version: 0,
|
||||
stack_size: 0,
|
||||
runtime_size: 0,
|
||||
vertex_declaration_count: 2,
|
||||
material_count: 0,
|
||||
vertex_offsets: [0; 3],
|
||||
index_offsets: [0; 3],
|
||||
vertex_buffer_size: [0; 3],
|
||||
index_buffer_size: [0; 3],
|
||||
lod_count: 0,
|
||||
index_buffer_streaming_enabled: false,
|
||||
has_edge_geometry: false,
|
||||
};
|
||||
|
||||
assert_eq!(272, example_header2.calculate_stack_size());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue