Simulating a large number of game entities
So here is my current situation. In my zombie game, I want many many many zombies (or other game entities, human AI, etc) - 1000's. At the moment I can probably have near to a 1000 in the player's immediate area, and it runs smoothly (provided that they aren't mixed too equally. Say half zombies/ half humans - that doesn't run too smoothly as there is too much interaction). So I am happy with that. Now, however, I want to go a step further.
The world is rather large and I want these entities to be all over. This is the case at the moment, but as I said previously, only entities local (in a screen or two's range) of the player is processed - the others just stand there and do nothing until the player comes close enough. This causes some issues. One would be that zombies spawn in great numbers at midnight, and during the day their numbers should die down (at the moment this is a "natural process" of their health just ticking down during the day). However, the far away zombies are not processed so when you enter a new area you may be surprised to find up to 5000 zombies. This is both impossible to play :P and laggy. (I knew this would be the case at the time of implementing it like this).
So, I wanted to implement a sort of global processing queue to process the far away entities, based on some priority system. Thinking back, this is probably still a bad idea. The world should easily contain up to 50 000 entities in this scenario, and without testing, I am guessing that the global processor would just be too inefficient (it would maybe only be able to process 500 or so entities per frame). The idea was to have it run a simulation of the other entities as closely as possible, and this would surely break that rule.
I realize that however, that the point is not to be "accurate", but to be fun, and perhaps too fool the player as far as possible. Key entities (such as an AI-survivor side-kick type character), may be simulated in a very "fake" way. Certain random events can occur (such as "DIE"), and the only place zombie entities should be spawned is in the local area around the player.
Does this last idea sound better than the first? Sorry for the horribly long post, I just thought it would be interesting to hear how other games/devs do it or would do it. There's certainly enough talent and experience lying around here :P
The world is rather large and I want these entities to be all over. This is the case at the moment, but as I said previously, only entities local (in a screen or two's range) of the player is processed - the others just stand there and do nothing until the player comes close enough. This causes some issues. One would be that zombies spawn in great numbers at midnight, and during the day their numbers should die down (at the moment this is a "natural process" of their health just ticking down during the day). However, the far away zombies are not processed so when you enter a new area you may be surprised to find up to 5000 zombies. This is both impossible to play :P and laggy. (I knew this would be the case at the time of implementing it like this).
So, I wanted to implement a sort of global processing queue to process the far away entities, based on some priority system. Thinking back, this is probably still a bad idea. The world should easily contain up to 50 000 entities in this scenario, and without testing, I am guessing that the global processor would just be too inefficient (it would maybe only be able to process 500 or so entities per frame). The idea was to have it run a simulation of the other entities as closely as possible, and this would surely break that rule.
I realize that however, that the point is not to be "accurate", but to be fun, and perhaps too fool the player as far as possible. Key entities (such as an AI-survivor side-kick type character), may be simulated in a very "fake" way. Certain random events can occur (such as "DIE"), and the only place zombie entities should be spawned is in the local area around the player.
Does this last idea sound better than the first? Sorry for the horribly long post, I just thought it would be interesting to hear how other games/devs do it or would do it. There's certainly enough talent and experience lying around here :P
Thanked by 1hermantulleken
Comments
Similar to the graph theory stuff, I guess, but you could group the zombies in such a way that you're running the sim in increasing detail the closer you are to a zombie/group of zombies. Zombies far away would be simulated together. (i.e., run a sim once, and all the other zombies are given the same properties. They don't even need to exist; when the player comes close enough, out of view the rest of the zombies get spawned.)
Also, your zombies can be nothing but nulls/points in space until further properties are needed. So you're not rendering them, and you're not simulating any properties that you don't need, until you're close enough for them to matter.
Thanks a lot :D
So split up your world as @Elyaradine suggested and rather than bothering actually spawning and destroying them, run a simple calculation when the player enters an area. For example, if say a given number of zombies should spawn every night and a random percentage within a range of them should survive in the day, then when your player enters an area after a certain number of days you can just do something like:
You could maybe keep areas adjacent to where your player is now actually updating "properly" in that they do a minor update on zombies in them, so if a player moves back and forth between two areas he doesn't catch on to the random spawning, but only needing to do that on the few areas he can move to directly will already drop your calcs drastically.
I confess I'm no expert I'm just throwing myself mentally into your world. Hope it helps
However, I have decided that the interaction itself is not so important anymore, and I can just throw random events (sorta like pulling a random card from a deck), and have that happen to the survivor. I might random a number each frame, and based on that number I may kill the survivor, etc. As long as it is off screen, and far away enough from the player, it will not truly make a difference to the player if the event actually played out or not.
P. S. Why is a random card never a joker. I remember in stats when they they taught probability a deck always has 52 cards but I know it has an additional 2 jokers. I asked the lecturer why not use the full 54 card deck with the argument that cutting the 2cards out makes it the subset. Answer is always we don't use jokers. Whatever
Goodluck with your game man
Thanks, I will post an early prototype soon!
Looling forward to it
This ensures that the player will never see areas that aren't being processed. However, funny things may still happen with the AI that are off-screen. If an AI entity leaves the processable area, he will essentially freeze. This could cause some entities to pile up at the edges, or frozen entities could be attacked without having the ability to retaliate or escape (if the attacker stays in the processable region).
Is this something that you guys think I should even consider? Maybe this behaviour won't really be noticed. But I could perhaps restructure the way I process my entities, and maintain a single list of active entities (and then just keep them below a specified limit to prevent lag).
Any thoughts?
Basically anything outside the 3x3 player world essentially doesn't exist(from a player's perspective). So my suggestion is to keep a list of the number of entites you want the player to experience in his 3x3 tile world. Then as soon as an entity "falls" off of this 3x3 world you move it to somewhere inside the 3x3 world instead of destroying it and recreating another one later. This results in no entities around the map to process and an ever growing entity population in the player's proximity, simulating a growing entity population on the entire map.
I could always extend this in interesting way that may allow special entities to leave the area (and be processed by semi-randomly triggered events instead of "accurate" simulation). By special entities I mean important AI such as a boss zombie or important survivor AI.