fix angry ghost being visually weird, cull more dead entitiys from enemy sync

This commit is contained in:
bgkillas 2024-10-13 19:52:47 -04:00
parent 8ae4052480
commit 2810aa9c1c
5 changed files with 34 additions and 16 deletions

View file

@ -1,21 +1,37 @@
dofile_once("data/scripts/lib/utilities.lua")
local function get_herd_id( entity_id )
local genome = EntityGetFirstComponentIncludingDisabled(entity_id, "GenomeDataComponent")
local herd = ComponentGetValue2(genome, "herd_id")
return herd
end
local function shoot_projectile( who_shot, entity_file, x, y, vel_x, vel_y, send_message )
local entity_id = EntityLoad( entity_file, x, y )
local herd_id = get_herd_id( who_shot )
if( send_message == nil ) then send_message = true end
GameShootProjectile( who_shot, x, y, x+vel_x, y+vel_y, entity_id, send_message )
edit_component( entity_id, "ProjectileComponent", function(comp,vars)
vars.mWhoShot = who_shot
vars.mShooterHerdId = herd_id
end)
edit_component( entity_id, "VelocityComponent", function(comp,vars)
ComponentSetValueVector2( comp, "mVelocity", vel_x, vel_y )
end)
return entity_id
end
function wand_fired( wand_id )
local projectile_velocity = 600
local entity_id = GetUpdatedEntityID()
local children = EntityGetAllChildren( entity_id )
local ghost_ids = {}
local root = EntityGetRootEntity(entity_id)
local shooter
if EntityHasTag(root, "ew_peer") and not EntityHasTag(root, "ew_notplayer") then
shooter = EntityGetWithTag("player_unit")[1]
if EntityHasTag(shooter, "ew_notplayer") then
shooter = root
end
else
shooter = root
end
local shooter = EntityGetRootEntity(entity_id)
if ( children ~= nil ) then
for i,v in ipairs( children ) do

View file

@ -183,6 +183,7 @@ end)
-- Load an entity that doesn't get saved.
function util.load_ephemerial(path, x, y)
local entity = EntityCreateNew()
EntityAddTag(entity, "ew_synced_entity")
EntitySetTransform(entity, x, y)
local ent_2 = EntityLoad(path, x, y)
EntityAddChild(entity, ent_2)

View file

@ -339,6 +339,11 @@ function enemy_sync.client_cleanup()
ctx.entity_by_remote_id[remote_id] = nil
end
end
for _, ent in ipairs(EntityGetWithTag("ew_synced_entity") or {}) do
if #(EntityGetAllChildren(ent) or {}) == 0 then
EntityKill(ent)
end
end
end
function enemy_sync.on_world_update_host()

View file

@ -24,7 +24,7 @@ local iter_slow = 0
local iter_slow_2 = 0
local function do_benchmark()
--[[local function do_benchmark()
local world_ffi = require("noitapatcher.nsew.world_ffi")
local grid_world = world_ffi.get_grid_world()
local chunk_map = grid_world.vtable.get_chunk_map(grid_world)
@ -37,7 +37,7 @@ local function do_benchmark()
local end_time = GameGetRealWorldTimeSinceStarted()
local elapsed = (end_time - start) * 1000 * 1000 * 1000 / (iters * 128 * 128)
print("Benchmark:", elapsed, "ns/pixel")
end
end]]
function world_sync.on_world_initialized()
local c = 0

View file

@ -130,10 +130,6 @@ local function load_extra_modules()
end
end
local function is_suitable_target(entity)
return EntityGetIsAlive(entity) and not EntityHasTag(entity,"ew_notplayer")
end
function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message,
unknown1, multicast_index, unknown3)
ctx.hook.on_projectile_fired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message, unknown1, multicast_index, unknown3)