Description
Currently, mutating methods on the NativeEngine struct (such as update, process_input, equip_item, and unequip_item in ffi.rs) accept &self (immutable references) despite mutating the state of the underlying C# game core through the FFI boundary.
While this currently works because the simulation loop is single-threaded, it bypasses Rust's aliasing guarantees and presents a concurrency risk if multi-threading is introduced.
Proposed Changes
- Change FFI method signatures in
ffi.rs to take &mut self instead of &self.
- Update callers in
main.rs (e.g. declaring let mut simulation = ... instead of let simulation = ...).
- Update
handle_key_event signature to accept simulation: &mut NativeEngine.
Description
Currently, mutating methods on the
NativeEnginestruct (such asupdate,process_input,equip_item, andunequip_iteminffi.rs) accept&self(immutable references) despite mutating the state of the underlying C# game core through the FFI boundary.While this currently works because the simulation loop is single-threaded, it bypasses Rust's aliasing guarantees and presents a concurrency risk if multi-threading is introduced.
Proposed Changes
ffi.rsto take&mut selfinstead of&self.main.rs(e.g. declaringlet mut simulation = ...instead oflet simulation = ...).handle_key_eventsignature to acceptsimulation: &mut NativeEngine.