Skip to content

Commit

Permalink
"entity remove" fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evolutionleo committed Oct 7, 2024
1 parent 76738ef commit 4eaf6cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Client/Client.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Client/objects/oEntityManager/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ base_update = -1
next_update = -1
third_update = -1

entities_to_remove = {}

interpolateEntity = function(t, t1, inst, t2, s2, t3, s3) {
var var_names = variable_struct_get_names(inst.__interpolation)
for(var i = 0; i < array_length(var_names); i++) {
Expand Down
21 changes: 13 additions & 8 deletions Client/objects/oEntityManager/Step_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,36 @@ for(i = 0; i < l; i++) {
var idx2 = next_e_idx[$ uuid]
var idx3 = third_e_idx[$ uuid]

var will_exist = !is_undefined(idx2)
var will_exist = !is_undefined(idx2) and is_undefined(entities_to_remove[$ uuid])

// don't create entities 1 frame before they are gone
if (!existed and !will_exist) {
continue
}

var inst = find_or_create(uuid, type, , props)

// if it was just created - it's remote
if (!existed) {
inst.remote = true
inst.x = entity.x
inst.y = entity.y
props.remote = true
}

if (uuid == global.player_uuid) {
inst.remote = false
props.remote = false
}

var inst = find_or_create(uuid, type, , props)

if (entities_to_remove[$ uuid]) {
instance_destroy(inst)
continue
}

// the reason I'm not using a with() statement here is because for some reason it is not equivallent to this, and produces weird errors (due to this being called in an Async event)
inst.image_xscale = entity.xs
inst.image_yscale = entity.ys
inst.x = entity.x
inst.y = entity.y
inst.image_angle = entity.a
inst.a = entity.a // set for interpolation

inst.state = state

Expand Down
6 changes: 3 additions & 3 deletions Client/scripts/entityHandlers/entityHandlers.gml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// a list of entities
addHandler("entities", function(data) {
//if (use_timestamps(data)) return;

// don't spawn in entities if we're not playing (e.x in menus)
if (!global.playing) {
Expand Down Expand Up @@ -44,12 +43,13 @@ addHandler("entity remove", function(data) {
if (use_timestamps(data))
return;

trace("entity remove: %", data.id)

var uuid = data.id
var obj = asset_get_index(data.obj)
var inst = find_by_uuid(uuid, obj)

if (instance_exists(oEntityManager))
oEntityManager.entities_to_remove[$ uuid] = true

if (instance_exists(inst))
instance_destroy(inst)
})

0 comments on commit 4eaf6cd

Please sign in to comment.