diff --git a/ewext/src/addr_grabber.rs b/ewext/src/addr_grabber.rs index 01552dad..91d13859 100644 --- a/ewext/src/addr_grabber.rs +++ b/ewext/src/addr_grabber.rs @@ -44,8 +44,8 @@ unsafe impl Send for Grabbed {} pub(crate) struct GrabbedGlobals { // These 3 actually point to a pointer. - pub(crate) game_global: *mut usize, - pub(crate) world_state_entity: *mut usize, + pub(crate) _game_global: *mut usize, + pub(crate) _world_state_entity: *mut usize, pub(crate) entity_manager: *const *mut EntityManager, } @@ -93,8 +93,8 @@ pub(crate) fn grab_addrs(lua: LuaState) { GRABBED .set(Grabbed { globals: GrabbedGlobals { - game_global, - world_state_entity, + _game_global: game_global, + _world_state_entity: world_state_entity, entity_manager, }, fns: GrabbedFns { get_entity }, diff --git a/ewext/src/lib.rs b/ewext/src/lib.rs index 60599a91..4f073d3f 100644 --- a/ewext/src/lib.rs +++ b/ewext/src/lib.rs @@ -30,15 +30,9 @@ thread_local! { }); } -struct SavedWorldState { - game_global: usize, - world_state_entity: usize, -} - #[derive(Default)] struct ExtState { particle_world_state: Option, - saved_world_state: Option, } fn init_particle_world_state(lua: LuaState) -> c_int { @@ -76,40 +70,6 @@ fn encode_area(lua: LuaState) -> c_int { 1 } -unsafe fn save_world_state() { - let game_global = grabbed_globals().game_global.read(); - let world_state_entity = grabbed_globals().world_state_entity.read(); - STATE.with(|state| { - let mut state = state.borrow_mut(); - state.saved_world_state = Some(SavedWorldState { - game_global, - world_state_entity, - }) - }); -} - -unsafe fn load_world_state() { - println!("Loading world state"); - STATE.with(|state| { - let state = state.borrow_mut(); - let saved_ws = state.saved_world_state.as_ref().unwrap(); - grabbed_globals().game_global.write(saved_ws.game_global); - grabbed_globals() - .world_state_entity - .write(saved_ws.world_state_entity); - }); -} - -unsafe extern "C" fn save_world_state_lua(_lua: *mut lua_State) -> i32 { - save_world_state(); - 0 -} - -unsafe extern "C" fn load_world_state_lua(_lua: *mut lua_State) -> i32 { - load_world_state(); - 0 -} - fn make_ephemerial(lua: LuaState) -> c_int { unsafe { let entity_id = lua.to_integer(1) as u32; @@ -150,10 +110,6 @@ pub unsafe extern "C" fn luaopen_ewext0(lua: *mut lua_State) -> c_int { add_lua_fn!(init_particle_world_state); add_lua_fn!(encode_area); - LUA.lua_pushcclosure(lua, Some(load_world_state_lua), 0); - LUA.lua_setfield(lua, -2, c"load_world_state".as_ptr()); - LUA.lua_pushcclosure(lua, Some(save_world_state_lua), 0); - LUA.lua_setfield(lua, -2, c"save_world_state".as_ptr()); add_lua_fn!(make_ephemerial); add_lua_fn!(on_world_initialized); } diff --git a/quant.ew/files/system/ewext_init/ewext_init.lua b/quant.ew/files/system/ewext_init/ewext_init.lua index baee5f75..d2528eb4 100644 --- a/quant.ew/files/system/ewext_init/ewext_init.lua +++ b/quant.ew/files/system/ewext_init/ewext_init.lua @@ -10,7 +10,6 @@ local module = {} function module.on_world_initialized() initial_world_state_entity = GameGetWorldStateEntity() ewext.on_world_initialized() - ewext.save_world_state() local grid_world = world_ffi.get_grid_world() local chunk_map = grid_world.vtable.get_chunk_map(grid_world) grid_world = tonumber(ffi.cast("intptr_t", grid_world)) @@ -38,8 +37,6 @@ end function module.on_world_update() if GameGetWorldStateEntity() ~= initial_world_state_entity then - -- -- EntityKill(GameGetWorldStateEntity()) - -- ewext.load_world_state() oh_another_world_state(GameGetWorldStateEntity()) initial_world_state_entity = GameGetWorldStateEntity() end