From 2adc80ed63654d397f288ee0433e2e38fbc755cd Mon Sep 17 00:00:00 2001 From: bgkillas Date: Thu, 14 Nov 2024 08:46:31 -0500 Subject: [PATCH] make some things nicer --- quant.ew/files/core/player_fns.lua | 8 ++------ quant.ew/files/core/util.lua | 10 +++++++--- quant.ew/files/system/enemy_sync.lua | 18 +++++++++++------- .../files/system/ewext_init/ewext_init.lua | 4 +--- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/quant.ew/files/core/player_fns.lua b/quant.ew/files/core/player_fns.lua index 5e8a0322..ec665aed 100644 --- a/quant.ew/files/core/player_fns.lua +++ b/quant.ew/files/core/player_fns.lua @@ -491,9 +491,7 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata) end print("Spawning player for "..peer_id) local new = EntityLoad("mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_base.xml", x, y) - if new ~= nil then - ewext.make_ephemerial(new) - end + util.make_ephemerial(new) local inv_full = EntityCreateNew("inventory_full") EntityAddChild(new, inv_full) LoadGameEffectEntityTo(new, "mods/quant.ew/files/system/spectate/no_tinker.xml") @@ -542,9 +540,7 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata) end function player_fns.replace_player_entity(new_entity, player_data) - if new_entity ~= nil then - ewext.make_ephemerial(new_entity) - end + util.make_ephemerial(new_entity) if new_entity ~= nil then local old_entity = player_data.entity player_data.entity = new_entity diff --git a/quant.ew/files/core/util.lua b/quant.ew/files/core/util.lua index 7d23273c..3e74432b 100644 --- a/quant.ew/files/core/util.lua +++ b/quant.ew/files/core/util.lua @@ -181,6 +181,12 @@ util.load_ents_tags = util.cached_fn(function(path) return tags end) +function util.make_ephemerial(ent) + if ent ~= nil and EntityGetIsAlive(ent) then + ewext.make_ephemerial(ent) + end +end + -- Load an entity that doesn't get saved. function util.load_ephemerial(path, x, y) --local entity = EntityCreateNew() @@ -188,9 +194,7 @@ function util.load_ephemerial(path, x, y) --EntitySetTransform(entity, x, y) local ent_2 = EntityLoad(path, x, y) --EntityAddChild(entity, ent_2) - if ent_2 ~= nil then - ewext.make_ephemerial(ent_2) - end + util.make_ephemerial(ent_2) return ent_2 end diff --git a/quant.ew/files/system/enemy_sync.lua b/quant.ew/files/system/enemy_sync.lua index 0e2bc524..804e0866 100644 --- a/quant.ew/files/system/enemy_sync.lua +++ b/quant.ew/files/system/enemy_sync.lua @@ -167,7 +167,11 @@ local function get_sync_entities(return_all) table_extend(entities, EntityGetWithTag("perk_fungus_tiny")) table_extend(entities, EntityGetWithTag("helpless_animal")) table_extend_filtered(entities, EntityGetWithTag("prop_physics"), function (ent) - return constants.phys_sync_allowed[EntityGetFilename(ent)] + local f = EntityGetFilename(ent) + if f ~= nil then + return constants.phys_sync_allowed[f] + end + return true end) local entities2 = {} @@ -400,8 +404,8 @@ function enemy_sync.client_cleanup() --print("Despawning unreplicated "..enemy_id.." "..filename) kill(enemy_id) elseif not spawned_by_us[enemy_id] then - local filename = EntityGetFilename(enemy_id) - print("Despawning persisted "..enemy_id.." "..filename) + --local filename = EntityGetFilename(enemy_id) + print("Despawning persisted "..enemy_id)--.." "..filename) kill(enemy_id) end end @@ -482,7 +486,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull) local animation = enemy_info_raw[8] local has_died = filename == nil - local frame = GameGetFrameNum() + local frame_now = GameGetFrameNum() --[[if confirmed_kills[remote_enemy_id] then goto continue @@ -493,7 +497,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull) end if ctx.entity_by_remote_id[remote_enemy_id] == nil then - if filename == nil then + if filename == nil or filename == "" or not ModDoesFileExist(filename) then goto continue end times_spawned_last_minute[remote_enemy_id] = (times_spawned_last_minute[remote_enemy_id] or 0) + 1 @@ -529,7 +533,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull) EntityRemoveComponent(enemy_id, ai_component) end end - ctx.entity_by_remote_id[remote_enemy_id] = {id = enemy_id, frame = frame} + ctx.entity_by_remote_id[remote_enemy_id] = {id = enemy_id, frame = frame_now} for _, phys_component in ipairs(EntityGetComponent(enemy_id, "PhysicsBody2Component") or {}) do if phys_component ~= nil and phys_component ~= 0 then @@ -555,7 +559,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull) end local enemy_data_new = ctx.entity_by_remote_id[remote_enemy_id] - enemy_data_new.frame = frame + enemy_data_new.frame = frame_now local enemy_id = enemy_data_new.id for i, phys_component in ipairs(EntityGetComponent(enemy_id, "PhysicsBodyComponent") or {}) do diff --git a/quant.ew/files/system/ewext_init/ewext_init.lua b/quant.ew/files/system/ewext_init/ewext_init.lua index d57dd3f9..954cf232 100644 --- a/quant.ew/files/system/ewext_init/ewext_init.lua +++ b/quant.ew/files/system/ewext_init/ewext_init.lua @@ -22,9 +22,7 @@ local function oh_another_world_state(entity) print("Another world state: "..entity) GamePrint("Another World State Entity detected") GamePrint("Do a 'mods > restart with enabled mods' to avoid a crash") - if entity ~= nil then - ewext.make_ephemerial(entity) - end + util.make_ephemerial(entity) end function module.on_local_player_spawn()