s3k: sync position and some animations

This commit is contained in:
Vivian Lim 2020-03-26 02:43:36 -07:00
parent e6814926d1
commit f887af7e73
1 changed files with 28 additions and 19 deletions

View File

@ -25,8 +25,8 @@ pub struct SyncedSonic3AndKnuckles {
#[derive(Serialize, Deserialize)]
pub struct Sonic3AndKnucklesMessage {
sonic_pos: SparseVector<u8>,
ctrl1_held_press: [u8; 2],
ctrl1_held_press_logical: [u8; 2],
//ctrl1_held_press: [u8; 2],
//ctrl1_held_press_logical: [u8; 2],
}
impl TryFrom<&mut Sonic3AndKnucklesMemoryHandles> for Sonic3AndKnucklesMessage {
@ -37,8 +37,8 @@ impl TryFrom<&mut Sonic3AndKnucklesMemoryHandles> for Sonic3AndKnucklesMessage {
Ok(Sonic3AndKnucklesMessage {
sonic_pos: src.sonic_data.get_tracked_data_if_changed()?,
ctrl1_held_press: global_game_state.ctrl1_held_press.copy_from_memory()?,
ctrl1_held_press_logical: global_game_state.ctrl1_held_press_logical.copy_from_memory()?,
//ctrl1_held_press: global_game_state.ctrl1_held_press.copy_from_memory()?,
//ctrl1_held_press_logical: global_game_state.ctrl1_held_press_logical.copy_from_memory()?,
})
}
}
@ -117,16 +117,15 @@ impl SyncableGame for SyncedSonic3AndKnuckles {
//println!("sonic data: {:?}", self.memory_handles.sonic_data.handle.slice);
//let mut global_game_state = self.memory_handles.global_game_state.get()?;
println!("flag {:X?}", self.memory_handles.arbitrary_ram.subslice(MemorySpan::ByAddress(0xf600..0xf609))?);
/*
let mut global_game_state = self.memory_handles.global_game_state.get()?;
//println!("flag {:X?}", self.memory_handles.arbitrary_ram.subslice(MemorySpan::ByAddress(0xf600..0xf609))?);
global_game_state.tails_control_counter.write_back([0x77, 0x77])?; // force CPU tails to never take over
global_game_state.tails_respawn_counter.write_back([0x00, 0x00])?; // force tails to never helicopter-respawn
if (global_game_state.lives_counter[1] < 0x45) {
global_game_state.lives_counter.write_back([0x00, 0x45]); // fix lives count
global_game_state.hud_redraw.write_back([0x01, 0x01, 0x01, 0x01]); // force hud to redraw
}
*/
/*
@ -137,8 +136,10 @@ impl SyncableGame for SyncedSonic3AndKnuckles {
}
fn send_state_messages(&mut self) -> Result<(), failure::Error>{
match self.memory_handles.global_game_state.get()?.game_mode {
GameMode::Level => {
let state = self.memory_handles.global_game_state.get()?;
match state.game_mode {
//GameMode::Level => {
GameMode::SegaScreen => {
let message: Sonic3AndKnucklesMessage = (&mut self.memory_handles).try_into()?;
if message.sonic_pos.num_chunks > 0{
self.comms.send(message)
@ -165,14 +166,21 @@ impl Sonic3AndKnucklesMemoryHandles {
Ok(Sonic3AndKnucklesMemoryHandles {
sonic_data: TrackedMemorySlice::create(
MemorySliceHandle::create(0xb000, 0x4A, 0, memory_map)?,
vec![MemorySpan::ByAddress(0xb008..0xb018),
MemorySpan::ByAddress(0xb022..0xb023),
MemorySpan::ByAddress(0xb028..0xb036),
MemorySpan::ByAddress(0xb038..0xb040),
MemorySpan::ByAddress(0xb038..0xb040),
vec![
MemorySpan::ByAddress(0xb004..0xb006), // Render flags + routine
MemorySpan::ByAddress(0xb010..0xb01e), // position and velocity
MemorySpan::ByAddress(0xb020..0xb022), // which animation. don't copy b021 so that the game will start playing the new animation if it differs
MemorySpan::ByAddress(0xb026..0xb028), // angles
/*MemorySpan::ByAddress(0xb025..0xb026), // character ability tracker*/
MemorySpan::ByAddress(0xb02a..0xb02c), // status bitfield 2
MemorySpan::ByAddress(0xb02d..0xb02e), // air
MemorySpan::ByAddress(0xb02f..0xb030), // double jump flag
//MemorySpan::ByAddress(0xb038..0xb039), // character id
MemorySpan::ByAddress(0xb03d..0xb03e), // charging spindash
MemorySpan::ByAddress(0xb040..0xb041), // jumping
])?,
//MemorySpan::ByAddress(0xb028..0xb03d)])?,
tails_data: MemorySliceHandle::create(0xb040, 0x4A, 0, memory_map)?,
tails_data: MemorySliceHandle::create(0xb04A, 0x4A, 0, memory_map)?,
global_game_state: GlobalGameHandle::create(memory_map)?,
arbitrary_ram: MemorySliceHandle::create(0xf600, 0x900, 0, memory_map)?,
})
@ -190,7 +198,8 @@ impl SyncedSonic3AndKnuckles {
fn handle_message(&mut self, msg: Sonic3AndKnucklesMessage) -> Result<(), failure::Error> {
let mut global_game_state =self.memory_handles.global_game_state.get()?;
match global_game_state.game_mode {
GameMode::Level => {
GameMode::SegaScreen => {
//GameMode::Level => {
/*
const SKIP_INDICES: [usize; 5]= [0x01, 0x20, 0x21, 0x3e, 0x3f];
match msg.sonic_pos {
@ -203,8 +212,8 @@ impl SyncedSonic3AndKnuckles {
*/
msg.sonic_pos.write_into(self.memory_handles.tails_data.slice);
global_game_state.ctrl2_held_press.write_back(msg.ctrl1_held_press)?;
global_game_state.ctrl2_held_press_logical.write_back(msg.ctrl1_held_press_logical)?;
//global_game_state.ctrl2_held_press.write_back(msg.ctrl1_held_press)?;
//global_game_state.ctrl2_held_press_logical.write_back(msg.ctrl1_held_press_logical)?;
Ok(())
}