mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-23 21:17:45 +00:00
Simplify heap writing
This is because it's slowly turning into a general byte heap, for deferred writing. I haven't checked yet, but most likely they do not throw everything (ob ref lists, strings, etc) into one giant heap but do it in a specific order.
This commit is contained in:
parent
f501576bfa
commit
7fdf3cfbff
1 changed files with 6 additions and 14 deletions
|
@ -86,7 +86,7 @@ pub struct HeapString {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StringHeap {
|
pub struct StringHeap {
|
||||||
pub pos: u64,
|
pub pos: u64,
|
||||||
pub strings: Vec<HeapString>,
|
pub bytes: Vec<u8>,
|
||||||
pub free_pos: u64,
|
pub free_pos: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,15 +94,11 @@ impl StringHeap {
|
||||||
pub fn from(pos: u64) -> Self {
|
pub fn from(pos: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pos,
|
pos,
|
||||||
strings: Vec::new(),
|
bytes: Vec::new(),
|
||||||
free_pos: 0, // unused, so it doesn't matter
|
free_pos: 0, // unused, so it doesn't matter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_string(&mut self, string: &HeapString) {
|
|
||||||
self.strings.push(string.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_free_offset<T>(&mut self, obj: &T) -> i32
|
pub fn get_free_offset<T>(&mut self, obj: &T) -> i32
|
||||||
where
|
where
|
||||||
T: for<'a> BinWrite<Args<'a> = ()> + std::fmt::Debug,
|
T: for<'a> BinWrite<Args<'a> = ()> + std::fmt::Debug,
|
||||||
|
@ -114,6 +110,8 @@ impl StringHeap {
|
||||||
obj.write_le(&mut cursor).unwrap();
|
obj.write_le(&mut cursor).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.bytes.append(&mut buffer);
|
||||||
|
|
||||||
let old_pos = self.free_pos;
|
let old_pos = self.free_pos;
|
||||||
self.free_pos += buffer.len() as u64;
|
self.free_pos += buffer.len() as u64;
|
||||||
|
|
||||||
|
@ -158,10 +156,7 @@ impl BinWrite for StringHeap {
|
||||||
endian: Endian,
|
endian: Endian,
|
||||||
(): Self::Args<'_>,
|
(): Self::Args<'_>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
for string in &self.strings {
|
self.bytes.write_options(writer, endian, ())?;
|
||||||
let bytes = write_string(&string.value);
|
|
||||||
bytes.write_options(writer, endian, ())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -707,15 +702,12 @@ impl LayerGroup {
|
||||||
|
|
||||||
let mut heap = StringHeap {
|
let mut heap = StringHeap {
|
||||||
pos: layer_offset as u64,
|
pos: layer_offset as u64,
|
||||||
strings: Vec::new(),
|
bytes: Vec::new(),
|
||||||
free_pos: layer_offset as u64,
|
free_pos: layer_offset as u64,
|
||||||
};
|
};
|
||||||
|
|
||||||
layer.header.write_le_args(&mut cursor, (&mut heap,)).ok()?;
|
layer.header.write_le_args(&mut cursor, (&mut heap,)).ok()?;
|
||||||
|
|
||||||
// TODO: maybe do this in the binrw definition?
|
|
||||||
heap.add_string(&layer.header.name);
|
|
||||||
|
|
||||||
// write the heap
|
// write the heap
|
||||||
heap.write_le(&mut cursor).ok()?;
|
heap.write_le(&mut cursor).ok()?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue