Skip to content
Snippets Groups Projects
Commit e825ec04 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

Merge branch 'joamag/ws-rename' into 'master'

Rename `_ws` suffixed method to `_wa` to make them compliant with WebAssembly naming

Closes #39

See merge request !42
parents 0ab347b9 62268feb
No related branches found
No related tags found
1 merge request!42Rename `_ws` suffixed method to `_wa` to make them compliant with WebAssembly naming
Pipeline #3995 passed
...@@ -442,7 +442,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -442,7 +442,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
// inference logic to try to infer the best mode from the // inference logic to try to infer the best mode from the
// GBC header in the cartridge data // GBC header in the cartridge data
if (this.autoMode) { if (this.autoMode) {
this.gameBoy.infer_mode_ws(romData); this.gameBoy.infer_mode_wa(romData);
} }
// resets the Game Boy engine to restore it into // resets the Game Boy engine to restore it into
...@@ -452,12 +452,12 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -452,12 +452,12 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
// loads the ROM file into the system and retrieves // loads the ROM file into the system and retrieves
// the cartridge instance associated with it // the cartridge instance associated with it
const cartridge = this.gameBoy.load_rom_ws(romData); const cartridge = this.gameBoy.load_rom_wa(romData);
// loads the callbacks so that the Typescript code // loads the callbacks so that the Typescript code
// gets notified about the various events triggered // gets notified about the various events triggered
// in the WASM side // in the WASM side
this.gameBoy.load_callbacks_ws(); this.gameBoy.load_callbacks_wa();
// in case there's a serial device involved tries to load // in case there's a serial device involved tries to load
// it and initialize for the current Game Boy machine // it and initialize for the current Game Boy machine
...@@ -691,7 +691,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -691,7 +691,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
get wasmEngine(): string | null { get wasmEngine(): string | null {
if (!this.gameBoy) return null; if (!this.gameBoy) return null;
return this.gameBoy.wasm_engine_ws() ?? null; return this.gameBoy.wasm_engine_wa() ?? null;
} }
get framerate(): number { get framerate(): number {
...@@ -804,22 +804,22 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -804,22 +804,22 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
serializeState(): Uint8Array { serializeState(): Uint8Array {
if (!this.gameBoy) throw new Error("Unable to serialize state"); if (!this.gameBoy) throw new Error("Unable to serialize state");
return StateManager.save_ws(this.gameBoy, SaveStateFormat.Bos); return StateManager.save_wa(this.gameBoy, SaveStateFormat.Bos);
} }
unserializeState(data: Uint8Array) { unserializeState(data: Uint8Array) {
if (!this.gameBoy) throw new Error("Unable to unserialize state"); if (!this.gameBoy) throw new Error("Unable to unserialize state");
StateManager.load_ws(data, this.gameBoy, SaveStateFormat.Bos); StateManager.load_wa(data, this.gameBoy, SaveStateFormat.Bos);
} }
buildState(index: number, data: Uint8Array): SaveState { buildState(index: number, data: Uint8Array): SaveState {
const state = StateManager.read_bos_ws(data); const state = StateManager.read_bos_wa(data);
return { return {
index: index, index: index,
timestamp: Number(state.timestamp_ws()), timestamp: Number(state.timestamp_wa()),
agent: state.agent_ws(), agent: state.agent_wa(),
model: state.model_ws(), model: state.model_wa(),
thumbnail: state.image_eager_ws() thumbnail: state.image_eager_wa()
}; };
} }
...@@ -904,17 +904,17 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -904,17 +904,17 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
} }
loadNullDevice(set = true) { loadNullDevice(set = true) {
this.gameBoy?.load_null_ws(); this.gameBoy?.load_null_wa();
if (set) this.serialDevice = SerialDevice.Null; if (set) this.serialDevice = SerialDevice.Null;
} }
loadLoggerDevice(set = true) { loadLoggerDevice(set = true) {
this.gameBoy?.load_logger_ws(); this.gameBoy?.load_logger_wa();
if (set) this.serialDevice = SerialDevice.Logger; if (set) this.serialDevice = SerialDevice.Logger;
} }
loadPrinterDevice(set = true) { loadPrinterDevice(set = true) {
this.gameBoy?.load_printer_ws(); this.gameBoy?.load_printer_wa();
if (set) this.serialDevice = SerialDevice.Printer; if (set) this.serialDevice = SerialDevice.Printer;
} }
...@@ -967,7 +967,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -967,7 +967,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
private updatePalette() { private updatePalette() {
const palette = PALETTES[this.paletteIndex]; const palette = PALETTES[this.paletteIndex];
this.gameBoy?.set_palette_colors_ws(palette.colors); this.gameBoy?.set_palette_colors_wa(palette.colors);
this.storeSettings(); this.storeSettings();
} }
...@@ -1066,7 +1066,7 @@ const wasm = async (setHook = true) => { ...@@ -1066,7 +1066,7 @@ const wasm = async (setHook = true) => {
// wrap the call around try/catch // wrap the call around try/catch
if (setHook) { if (setHook) {
try { try {
GameBoy.set_panic_hook_ws(); GameBoy.set_panic_hook_wa();
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
......
...@@ -1168,7 +1168,7 @@ impl GameBoy { ...@@ -1168,7 +1168,7 @@ impl GameBoy {
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
impl GameBoy { impl GameBoy {
pub fn set_panic_hook_ws() { pub fn set_panic_hook_wa() {
let prev = take_hook(); let prev = take_hook();
set_hook(Box::new(move |info| { set_hook(Box::new(move |info| {
hook_impl(info); hook_impl(info);
...@@ -1176,7 +1176,7 @@ impl GameBoy { ...@@ -1176,7 +1176,7 @@ impl GameBoy {
})); }));
} }
pub fn load_rom_ws(&mut self, data: &[u8]) -> Cartridge { pub fn load_rom_wa(&mut self, data: &[u8]) -> Cartridge {
let rom = self.load_rom(data, None); let rom = self.load_rom(data, None);
rom.set_rumble_cb(|active| { rom.set_rumble_cb(|active| {
rumble_callback(active); rumble_callback(active);
...@@ -1184,18 +1184,18 @@ impl GameBoy { ...@@ -1184,18 +1184,18 @@ impl GameBoy {
rom.clone() rom.clone()
} }
pub fn load_callbacks_ws(&mut self) { pub fn load_callbacks_wa(&mut self) {
self.set_speed_callback(|speed| { self.set_speed_callback(|speed| {
speed_callback(speed); speed_callback(speed);
}); });
} }
pub fn load_null_ws(&mut self) { pub fn load_null_wa(&mut self) {
let null = Box::<NullDevice>::default(); let null = Box::<NullDevice>::default();
self.attach_serial(null); self.attach_serial(null);
} }
pub fn load_logger_ws(&mut self) { pub fn load_logger_wa(&mut self) {
let mut logger = Box::<StdoutDevice>::default(); let mut logger = Box::<StdoutDevice>::default();
logger.set_callback(|data| { logger.set_callback(|data| {
logger_callback(data.to_vec()); logger_callback(data.to_vec());
...@@ -1203,7 +1203,7 @@ impl GameBoy { ...@@ -1203,7 +1203,7 @@ impl GameBoy {
self.attach_serial(logger); self.attach_serial(logger);
} }
pub fn load_printer_ws(&mut self) { pub fn load_printer_wa(&mut self) {
let mut printer = Box::<PrinterDevice>::default(); let mut printer = Box::<PrinterDevice>::default();
printer.set_callback(|image_buffer| { printer.set_callback(|image_buffer| {
printer_callback(image_buffer.to_vec()); printer_callback(image_buffer.to_vec());
...@@ -1213,12 +1213,12 @@ impl GameBoy { ...@@ -1213,12 +1213,12 @@ impl GameBoy {
/// Updates the emulation mode using the cartridge /// Updates the emulation mode using the cartridge
/// of the provided data to obtain the CGB flag value. /// of the provided data to obtain the CGB flag value.
pub fn infer_mode_ws(&mut self, data: &[u8]) { pub fn infer_mode_wa(&mut self, data: &[u8]) {
let mode = Cartridge::from_data(data).gb_mode(); let mode = Cartridge::from_data(data).gb_mode();
self.set_mode(mode); self.set_mode(mode);
} }
pub fn set_palette_colors_ws(&mut self, value: Vec<JsValue>) { pub fn set_palette_colors_wa(&mut self, value: Vec<JsValue>) {
let palette: Palette = value let palette: Palette = value
.into_iter() .into_iter()
.map(|v| Self::js_to_pixel(&v)) .map(|v| Self::js_to_pixel(&v))
...@@ -1228,7 +1228,7 @@ impl GameBoy { ...@@ -1228,7 +1228,7 @@ impl GameBoy {
self.ppu().set_palette_colors(&palette); self.ppu().set_palette_colors(&palette);
} }
pub fn wasm_engine_ws(&self) -> Option<String> { pub fn wasm_engine_wa(&self) -> Option<String> {
let dependencies = dependencies_map(); let dependencies = dependencies_map();
if !dependencies.contains_key("wasm-bindgen") { if !dependencies.contains_key("wasm-bindgen") {
return None; return None;
......
...@@ -165,19 +165,19 @@ impl BosState { ...@@ -165,19 +165,19 @@ impl BosState {
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
impl BosState { impl BosState {
pub fn timestamp_ws(&self) -> Result<u64, String> { pub fn timestamp_wa(&self) -> Result<u64, String> {
Self::timestamp(self).map_err(|e| e.to_string()) Self::timestamp(self).map_err(|e| e.to_string())
} }
pub fn agent_ws(&self) -> Result<String, String> { pub fn agent_wa(&self) -> Result<String, String> {
Self::agent(self).map_err(|e| e.to_string()) Self::agent(self).map_err(|e| e.to_string())
} }
pub fn model_ws(&self) -> Result<String, String> { pub fn model_wa(&self) -> Result<String, String> {
Self::model(self).map_err(|e| e.to_string()) Self::model(self).map_err(|e| e.to_string())
} }
pub fn image_eager_ws(&self) -> Result<Vec<u8>, String> { pub fn image_eager_wa(&self) -> Result<Vec<u8>, String> {
Self::image_eager(self).map_err(|e| e.to_string()) Self::image_eager(self).map_err(|e| e.to_string())
} }
} }
...@@ -1584,11 +1584,11 @@ impl StateManager { ...@@ -1584,11 +1584,11 @@ impl StateManager {
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
impl StateManager { impl StateManager {
pub fn save_ws(gb: &mut GameBoy, format: Option<SaveStateFormat>) -> Result<Vec<u8>, String> { pub fn save_wa(gb: &mut GameBoy, format: Option<SaveStateFormat>) -> Result<Vec<u8>, String> {
Self::save(gb, format).map_err(|e| e.to_string()) Self::save(gb, format).map_err(|e| e.to_string())
} }
pub fn load_ws( pub fn load_wa(
data: &[u8], data: &[u8],
gb: &mut GameBoy, gb: &mut GameBoy,
format: Option<SaveStateFormat>, format: Option<SaveStateFormat>,
...@@ -1596,15 +1596,15 @@ impl StateManager { ...@@ -1596,15 +1596,15 @@ impl StateManager {
Self::load(data, gb, format).map_err(|e| e.to_string()) Self::load(data, gb, format).map_err(|e| e.to_string())
} }
pub fn read_bos_ws(data: &[u8]) -> Result<BosState, String> { pub fn read_bos_wa(data: &[u8]) -> Result<BosState, String> {
Self::read_bos(data).map_err(|e| e.to_string()) Self::read_bos(data).map_err(|e| e.to_string())
} }
pub fn read_bess_ws(data: &[u8]) -> Result<BessState, String> { pub fn read_bess_wa(data: &[u8]) -> Result<BessState, String> {
Self::read_bess(data).map_err(|e| e.to_string()) Self::read_bess(data).map_err(|e| e.to_string())
} }
pub fn thumbnail_ws(data: &[u8], format: Option<SaveStateFormat>) -> Result<Vec<u8>, String> { pub fn thumbnail_wa(data: &[u8], format: Option<SaveStateFormat>) -> Result<Vec<u8>, String> {
Self::thumbnail(data, format).map_err(|e| e.to_string()) Self::thumbnail(data, format).map_err(|e| e.to_string())
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment