EntityList decoding now fully works and tested

This commit is contained in:
mykola2312 2023-09-04 07:38:59 +03:00
parent 5ea616cd44
commit 35ce0e9076
3 changed files with 31 additions and 9 deletions

View file

@ -10,7 +10,7 @@ const NO_FLAGS: u32 = 0;
pub struct Entity {
pub flags: u32,
pub type_idx: usize,
pub esh: ESH,
pub esh: Option<ESH>,
enc_size: usize,
}
@ -26,14 +26,19 @@ impl DecoderCtx<&mut EntityList, &EntityList> for Entity {
Entity {
flags,
type_idx,
esh,
esh: Some(esh),
enc_size,
}
}
EntityEncoding::World => {
let flags = rd.read_u32()?;
let type_idx = rd.read_u16()? as usize;
let esh: ESH = rd.read(0)?;
let esh: Option<ESH> = if type_idx != 0xFFFF {
Some(rd.read(0)?)
} else {
None
};
let enc_size = rd.offset() - offset;
Entity {
flags,
@ -50,12 +55,12 @@ impl DecoderCtx<&mut EntityList, &EntityList> for Entity {
match ctx.get_entity_encoding() {
EntityEncoding::File => {
wd.write(ctx.get_type_name(self.type_idx))?;
wd.write(&self.esh)?;
wd.write(self.esh.as_ref().unwrap())?;
}
EntityEncoding::World => {
wd.write_u32(self.flags)?;
wd.write_u16(self.type_idx as u16)?;
wd.write(&self.esh)?;
wd.write(self.esh.as_ref().unwrap())?;
}
}
Ok(wd.into_raw(0, 0))

View file

@ -91,9 +91,8 @@ impl DecoderCtx<EntityEncoding,EntityEncoding> for EntityList {
let ent_count = rd.read_u16()?;
ent_list.unk1 = rd.read_u32()?;
for i in 1..ent_count {
for _ in 1..ent_count {
let ent: Entity = rd.read_opt(0, &mut ent_list)?;
println!("ok read {}", i);
ent_list.entities.push(ent);
}
@ -131,6 +130,6 @@ impl DecoderCtx<EntityEncoding,EntityEncoding> for EntityList {
}
fn get_enc_size(&self) -> usize {
todo!();
self.enc_size
}
}

View file

@ -31,7 +31,25 @@ impl World {
const WORLD_HDR_LEN: usize = 0x13;
pub fn test(&self) -> Result<()> {
println!("read {} ents", self.ents.entities.len());
for i in 0..self.ents.entities.len() {
let ent = &self.ents.entities[i];
let idx = i+1;
let type_name = match ent.type_idx {
0xFFFF => "<NO ESH>",
_ => self.ents.get_type_name(ent.type_idx).str.as_str()
};
println!("idx {} type {}", idx, type_name);
match ent.esh.as_ref() {
Some(esh) => {
for (name, value) in esh.props.iter() {
println!("\t{} {}", &name, &value);
}
},
None => continue
}
}
Ok(())
}