WIP comms stuff and trying to make pokemon_rb serializable
This commit is contained in:
parent
0c83161f85
commit
063cb4374a
|
@ -8,7 +8,7 @@
|
|||
"name": "sync: pokeblue",
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"program": "target/debug/examples/sdl2_emulator.exe",
|
||||
"program": "target/debug/ferretro-synced.exe",
|
||||
"args": ["--core", "./data/gambatte_libretro.dll", "--rom", "./data/pokeblue.gb", "--state", "./data/pkblue-route1.sav"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -22,7 +22,7 @@
|
|||
"name": "sync: sonic2",
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"program": "target/debug/examples/sdl2_emulator.exe",
|
||||
"program": "target/debug/ferretro-synced.exe",
|
||||
"args": ["--core", "./data/genesis_plus_gx_libretro.dll", "--rom", "./data/sonic2.bin"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
|
|
@ -151,6 +151,8 @@ dependencies = [
|
|||
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_bytes 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -489,6 +491,27 @@ dependencies = [
|
|||
name = "serde"
|
||||
version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
|
@ -661,6 +684,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d051a07231e303f5f719da78cb6f7394f6d5b54f733aef5b0b447804a83edd7b"
|
||||
"checksum sdl2-sys 0.32.6 (registry+https://github.com/rust-lang/crates.io-index)" = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86"
|
||||
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
|
||||
"checksum serde_bytes 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "325a073952621257820e7a3469f55ba4726d8b28657e7e36653d1c36dc2c84ae"
|
||||
"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
|
||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
"checksum structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "30b3a3e93f5ad553c38b3301c8a0a0cec829a36783f6a0c467fc4bf553a5f5bf"
|
||||
"checksum structopt-derive 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea692d40005b3ceba90a9fe7a78fa8d4b82b0ce627eebbffc329aab850f3410e"
|
||||
|
|
|
@ -14,9 +14,10 @@ libloading = "^0.5"
|
|||
num = "0.2"
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
# example: sdl2_emulator
|
||||
sdl2 = "^0.32"
|
||||
crossbeam-channel = "^0.4"
|
||||
structopt = "^0.3"
|
||||
structopt = "^0.3"
|
||||
serde = { version = "1.0.104", features = ["derive"] }
|
||||
serde_bytes = "0.11"
|
||||
|
||||
[dev-dependencies]
|
|
@ -0,0 +1,37 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::sync::mpsc::{Sender, Receiver};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
pub struct Communication<T> {
|
||||
tx: Sender<T>,
|
||||
rx: Receiver<T>,
|
||||
}
|
||||
|
||||
impl<T> Communication<T> {
|
||||
pub fn new() -> Box<Self> {
|
||||
let (to_thread, from_main): (Sender<T>, Receiver<T>) = mpsc::channel();
|
||||
let (to_main, from_thread): (Sender<T>, Receiver<T>) = mpsc::channel();
|
||||
|
||||
// let child = thread::spawn(move || {
|
||||
// let client = WebsocketClient::<T> {
|
||||
// thread_tx: to_main,
|
||||
// thread_rx: from_main,
|
||||
// };
|
||||
|
||||
// // todo: loop
|
||||
// println!("listener thread finished");
|
||||
// });
|
||||
|
||||
Box::new(Communication {
|
||||
tx: to_thread,
|
||||
rx: from_thread,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct WebsocketClient<T> {
|
||||
thread_tx: Sender<T>,
|
||||
thread_rx: Receiver<T>,
|
||||
}
|
|
@ -1,7 +1,3 @@
|
|||
extern crate crossbeam_channel;
|
||||
extern crate ferretro;
|
||||
extern crate sdl2;
|
||||
|
||||
use ferretro::retro;
|
||||
use ferretro::retro::ffi::{GameGeometry, SystemInfo, SystemAvInfo, MemoryMap};
|
||||
use ferretro::retro::constants::{InputIndex, JoypadButton, AnalogAxis, DeviceType};
|
||||
|
@ -13,13 +9,11 @@ use ferretro_synced::sync::pokemon_rb::SyncedPokemonRedBlue;
|
|||
|
||||
use std::ffi::CStr;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::pin::Pin;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
use sdl2::audio::{AudioCallback, AudioFormat, AudioSpec, AudioSpecDesired, AudioDevice};
|
||||
use sdl2::controller::{GameController, Button, Axis};
|
||||
use sdl2::event::Event;
|
||||
|
@ -27,7 +21,7 @@ use sdl2::keyboard::Keycode;
|
|||
use sdl2::rect::Rect;
|
||||
use sdl2::render::WindowCanvas;
|
||||
|
||||
struct MyEmulator {
|
||||
pub struct MyEmulator {
|
||||
retro: retro::wrapper::LibretroWrapper,
|
||||
core_path: PathBuf,
|
||||
sys_path: Option<PathBuf>,
|
||||
|
@ -497,34 +491,6 @@ impl AudioCallback for MySdlAudio {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn main() -> failure::Fallible<()> {
|
||||
let opt: Opt = Opt::from_args();
|
||||
let mut emu = MyEmulator::new(&opt.core, &opt.system);
|
||||
emu.load_game(&opt.rom);
|
||||
match (&opt.state) {
|
||||
Some(s) => emu.load_state(s),
|
||||
None => ()
|
||||
}
|
||||
emu.run();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opt {
|
||||
/// Core module to use.
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
core: PathBuf,
|
||||
/// ROM to load using the core.
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
rom: PathBuf,
|
||||
/// System directory, often containing BIOS files
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
system: Option<PathBuf>,
|
||||
/// Serialized game state to load
|
||||
#[structopt(long, parse(from_os_str))]
|
||||
state: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn button_map(retro_button: &JoypadButton) -> Option<Button> {
|
||||
match retro_button {
|
||||
|
@ -576,4 +542,4 @@ fn axis_map(index: &InputIndex, axis: &AnalogAxis) -> Axis {
|
|||
(InputIndex::Right, AnalogAxis::X) => Axis::RightX,
|
||||
(InputIndex::Right, AnalogAxis::Y) => Axis::RightY,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
extern crate crossbeam_channel;
|
||||
extern crate ferretro;
|
||||
extern crate sdl2;
|
||||
extern crate serde;
|
||||
extern crate serde_bytes;
|
||||
|
||||
use structopt::StructOpt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
mod emulator;
|
||||
use emulator::MyEmulator;
|
||||
mod comms;
|
||||
use comms::Communication;
|
||||
|
||||
pub fn main() -> failure::Fallible<()> {
|
||||
let opt: Opt = Opt::from_args();
|
||||
let mut emu = MyEmulator::new(&opt.core, &opt.system);
|
||||
emu.load_game(&opt.rom);
|
||||
match (&opt.state) {
|
||||
Some(s) => emu.load_state(s),
|
||||
None => ()
|
||||
}
|
||||
|
||||
//let mut comms = Communication::new::<ferretro_synced::sync::pokemon_rb::Message>();
|
||||
|
||||
emu.run();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opt {
|
||||
/// Core module to use.
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
core: PathBuf,
|
||||
/// ROM to load using the core.
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
rom: PathBuf,
|
||||
/// System directory, often containing BIOS files
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
system: Option<PathBuf>,
|
||||
/// Serialized game state to load
|
||||
#[structopt(long, parse(from_os_str))]
|
||||
state: Option<PathBuf>,
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
use std::default::Default;
|
||||
use std::fmt::Display;
|
||||
use crate::sync::memory_rw::MemoryRw;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use ferretro::retro::wrapper::LibretroWrapper; // want LibretroWrapper.api : LibretroApi.get_memory()
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -9,8 +10,14 @@ pub struct SyncedPokemonRedBlue {
|
|||
battle_context: BattleContext,
|
||||
}
|
||||
|
||||
//#[derive(Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
active_pkmn: Box<[u8]>
|
||||
}
|
||||
|
||||
struct Raw {
|
||||
active_pokemon_raw: [u8; 0x27],
|
||||
|
||||
player_and_party: [u8; 0x19e],
|
||||
pokemon_out: u8,
|
||||
}
|
||||
|
@ -40,6 +47,13 @@ impl SyncedPokemonRedBlue {
|
|||
println!("{}", result);
|
||||
result
|
||||
}
|
||||
|
||||
// pub fn get_message<'a>(&self) -> Message {
|
||||
// Message {
|
||||
// active_pkmn: Box::from(&self.raw.active_pokemon_raw.clone())
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
impl Default for Raw {
|
||||
|
|
Loading…
Reference in New Issue