d-zone-org / d-zone

An ambient life simulation driven by user activity within a Discord server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing user/actor from world

sparcut opened this issue · comments

I'm trying to reduce the number of sleeper actors, so I'm removing an actor when offline is received for that user.

It's a little hacky, but this is what I've done:

I've added the following line in the else if(data.type == 'presence') statement (Line 176), after the check if user actor exists.

if(data.data.status == 'offline') return users.removeActor(users.actors[data.data.uid]);

It returns as the actor doesn't exist anymore so can't update presence.

Problem is, it doesn't remove the actors from the world, so I went and found where it gets .remove() from ./web/script/engine/entity.js, haven't delved deeper into renderer.js, util.js, etc. to figure out what everything in the remove function does.

Any idea why the actor isn't being removed from the screen?

Otherwise, any advice on building this for a large server? Attempting to get it working on a 5-10k concurrent online and 30k offline, I know ambitious, but I'd like to see if it'll work with only online users since at the moment, it just straight up crashes.

Sorry for making you trudge through my awful code! Thanks for giving it the effort that you did though, that's commendable!

I just pushed a fix which should correct this. I think the problem was that it was trying to remove the entity itself from the z-buffer instead of the entity's sprite.

252954b

I don't have any ideas for other simple ways to reduce actor count, but I can say that when the rewrite has reached parity with the master branch, you should see much better performance even with 45k actors. Beyond that, I also want to have an official and proper implementation of actors entering and leaving the game upon coming online and going offfline.

I just updated the master branch with a new server option to hide offline users. hideOffline: true

I'm closing this since it's fixed on master and the rewrite is going to have it anyway.