I developed multiplayer games before, but now I wanted to create MMORPG Architecture for training / challenge purposes. I want to go as far as modeling hundreds (or a couple of thousand) simultaneous players on the same server.
So far so good, except that right now I ran into a problem to find a good way to update all game objects on the server as often and as quickly as possible.
By the objects of the game, I mean all the players, Mobs, Bullets.
The problem is that all players, Mobs, Bullets are stored in collections on server memory for faster processing and repeat all of them to check for collisions, update health, move updates, etc ... too long.
Suppose I have 1000 players and there are 10,000 mobs all over the world, and all players and creatures are responsible for creating 5 other game objects (no more no less), such as bullets.
This will give (1000 + 10000) * 5 = 55000 game objects in the collection.
Iterating over all objects, updating them, perform forever (a couple of minutes) on a dual-core HT i5 with 4-gigabyte RAM. It is not right.
When repeating the code, the code looks like this (pseudo):
for(int i = 0; i < gameobjects.Count; i++) { for(int j = 0; j < gameobjects.Count; j++) { // logic to verify if gameobjects[i] is in range of // gameobjects[j] } }
As an optimization, I think about sharing my game objects in different zones and collections, but this will not solve the problem when I need to update all objects several times per second.
How can I switch to updating all game objects on the server side? I did a hard search to find interesting game design templates, but so far no results. :(
Thanks in advance!