Fix encoding, test with patched retroarch
This commit is contained in:
@@ -423,7 +423,6 @@ pub fn decode<R: std::io::BufRead>(rply: &mut R) -> Result<ReplayDecoder<'_, R>>
|
|||||||
pub struct ReplayEncoder<'a, W: std::io::Write + std::io::Seek> {
|
pub struct ReplayEncoder<'a, W: std::io::Write + std::io::Seek> {
|
||||||
rply: &'a mut W,
|
rply: &'a mut W,
|
||||||
pub header: Header,
|
pub header: Header,
|
||||||
// pub initial_state: Vec<u8>,
|
|
||||||
pub frame_number: u64,
|
pub frame_number: u64,
|
||||||
last_pos: u64,
|
last_pos: u64,
|
||||||
ss_state: statestream::Ctx,
|
ss_state: statestream::Ctx,
|
||||||
@@ -572,8 +571,6 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn encode_initial_checkpoint(&mut self, checkpoint: &[u8]) -> Result<()> {
|
fn encode_initial_checkpoint(&mut self, checkpoint: &[u8]) -> Result<()> {
|
||||||
// let initial = std::mem::take(&mut self.initial_state);
|
|
||||||
let old_pos = self.rply.stream_position()?;
|
|
||||||
self.rply
|
self.rply
|
||||||
.seek(std::io::SeekFrom::Start(HEADERV2_LEN_BYTES as u64))?;
|
.seek(std::io::SeekFrom::Start(HEADERV2_LEN_BYTES as u64))?;
|
||||||
self.encode_checkpoint(checkpoint, 0)?;
|
self.encode_checkpoint(checkpoint, 0)?;
|
||||||
@@ -581,12 +578,9 @@ impl<'w, W: std::io::Write + std::io::Seek> ReplayEncoder<'w, W> {
|
|||||||
self.header.set_initial_state_size(
|
self.header.set_initial_state_size(
|
||||||
u32::try_from(encoded_size).map_err(ReplayError::CheckpointTooBig)?,
|
u32::try_from(encoded_size).map_err(ReplayError::CheckpointTooBig)?,
|
||||||
);
|
);
|
||||||
// self.initial_state = initial;
|
|
||||||
// dbg!("initial state size", self.header.initial_state_size());
|
|
||||||
// Have to rewrite header to account for initial state size
|
// Have to rewrite header to account for initial state size
|
||||||
self.write_header()?;
|
self.write_header()?;
|
||||||
self.last_pos = self.rply.stream_position()?;
|
self.last_pos = self.rply.stream_position()?;
|
||||||
self.rply.seek(std::io::SeekFrom::Start(old_pos))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -278,6 +278,7 @@ impl<'w, 'c, W: std::io::Write> Encoder<'w, 'c, W> {
|
|||||||
};
|
};
|
||||||
superblock_contents[block_i] = found_block.index;
|
superblock_contents[block_i] = found_block.index;
|
||||||
if found_block.is_new {
|
if found_block.is_new {
|
||||||
|
let block_out_bytes = self.ctx.block_index.get(found_block.index);
|
||||||
bytes_out += rmp_size(r::write_uint(
|
bytes_out += rmp_size(r::write_uint(
|
||||||
self.writer,
|
self.writer,
|
||||||
u64::from(u8::from(SSToken::NewBlock)),
|
u64::from(u8::from(SSToken::NewBlock)),
|
||||||
@@ -285,8 +286,8 @@ impl<'w, 'c, W: std::io::Write> Encoder<'w, 'c, W> {
|
|||||||
bytes_out +=
|
bytes_out +=
|
||||||
rmp_size(r::write_uint(self.writer, u64::from(found_block.index))?);
|
rmp_size(r::write_uint(self.writer, u64::from(found_block.index))?);
|
||||||
bytes_out += rmp_size(r::write_bin_len(self.writer, self.ctx.block_size)?);
|
bytes_out += rmp_size(r::write_bin_len(self.writer, self.ctx.block_size)?);
|
||||||
self.writer.write_all(block_bytes)?;
|
self.writer.write_all(block_out_bytes)?;
|
||||||
bytes_out += block_bytes.len();
|
bytes_out += block_out_bytes.len();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let found_superblock = self
|
let found_superblock = self
|
||||||
|
|||||||
Reference in New Issue
Block a user