Questions about scaling -- libgdx

Hey guys,

I’m in the middle of making my game that takes on the general structure of a 2d overhead MMORPG. I am at the point where I need to be coding with larger scale in mind. The thing is, I’m not really sure if what I am doing is considered efficient. Here is where I am at, and here are my questions:

Currently I have a small test environment I made with Tiled. Within the environment I make a player controlled object, and an enemy object that roams randomly while in dosile state, and chases the player if the player approaches within range.

  1. At the moment I have the enemy object constantly calculating the distance between enemy and player. If the player comes within range, the enemy attacks. Is this how a MMORPG is typically built? My concern is that if I have over 5000 enemy’s on one very large instance of a MMORPG map which constantly calculates it’s distance to each player object, won’t that slow down efficiency and put strain on each players computer?

  2. If a player is within the game, is their computer effectively trying to account memory for each monster on the entire map, even if it’s outside of the players visible range?

  3. When generating player and enemy objects with libgdx, I’m simply creating the objects and calling batch.draw on them. Is this an effective way of generating players and monsters?

Best,
Void

I don’t do libgdx so I cant help you with that but:

[quote]My concern is that if I have over 5000 enemy’s on one very large instance of a MMORPG map which constantly calculates it’s distance to each player object, won’t that slow down efficiency and put strain on each players computer?
[/quote]
On client side only do rendering and calculations that are not exploitable by players. All calculations should be handled by the server.
So by letting the server do critical stuff you basically reduce the load on the client’s PC by a large amount.

[quote]2. If a player is within the game, is their computer effectively trying to account memory for each monster on the entire map, even if it’s outside of the players visible range?
[/quote]
Yes if you e.g. have all entities in a collection and you want to check distance between them and your player you indeed have to cycle through the whole list every logic-tick. But you can reduce that load by only rendering what the player can see. In 2D you simply take a rectangle and check if said entities are inside, if not skip them else do stuff to them.

Edit: To further reduce the overhead for entity calculations you can divide your whole map into several regions and restrict your collection of entities to entities only in the region the player is in and then check against the rectangle.

Hope this helps with some of your problems.

Thanks for the great reply! You opened up a few door I never knew I had. Are there any useful sources for games in regards to what should and should not be server side? It’s a very weak point of mine. For example I’m not exactly sure how a mmorpg is actually structured when it comes to packaging it up for individual clients, and how the server communicates with all of those clients. At the moment I’ve only been coding my entire game from a single player aspect, so I figure it’s probably better to refactor my code base early on. Is there a particular pattern that developers follow when it comes to structuring the code for server and client side?

Also your comment on the rectangle is a very interesting thought. In order to reduce server stress do you think it would suffice to first see if the enemy is within the players visibility rectangle, and if it is, then to keep updating the distance between player and enemy?

I’ve never made a multiplayer game so I cant help you with that.
All I know about multiplayer is that you should use the server for calculations and the client should only do the rendering and when you plan to do a game that can be played both in singleplayer and multiplayer you should setup a local server (like minecraft does it these days).
I usually try to get my hands on some books about the topic I need help with and read them.

About the rectangle:
Let’s say you have an EntityHandler that has a List CURRENT_ENTITIES.
All entities have to be in that List.

The following example is taken from my current game’s collision detection. I modified the code a bit so you can see what I mean:
Inside my GameLoop class is a method that gets executed 60 times per second:


@Override
public void handle(long now)
{
    ...
    checkAsteroids();
    ...
    renderAsteroids();
    ...
}


private void checkAsteroids()
{
     for(Asteroid asteroid : main.getAsteroidHandler().getCURRENT_ASTEROIDS())
     {
         if(asteroid.getImageView().getBoundsInParent().intersects(screenRectangle.getBoundsInParent()))
         {
             //screenRectangle is a rectangle with your screens dimension.
             //The rectangle moves when the player moves.
             
             main.getAsteroidHandler.getASTEROIDS_ON_SCREEN().add(asteroid);
             //You now have every entity (in this case an asteroid) inside a collection (List<>) that can be seen by the user.
         }
     }
}

private void renderAsteroids()
{
    for(Asteroid asteroid : main.getAsteroidHandler().getASTEROIDS_ON_SCREEN())
    {
        asteroid.render();
    }
}

Usually (at least for fast-action games that demand low latency) both the client and server run the simulation, with the server providing verification and any necessary correction in player positions etc. if clients are getting out of sync. The correction is what’s happening when you see ‘rubber banding’ in games.

Thanks Nox – you verified exactly what I was thinking. That will definitely help optimize the overall process!

Burnt – If we assume that both the client and server run the simulation, wouldn’t that slow down the client significantly? Especially if our goal is to reduce the load from the player, and do any large calculations on the server?

Well if you don’t have to run something on the client, then don’t, but in some cases you want to, such as games with real time feedback from other players, in that case the game potentially plays very poorly in less than perfect network conditions. (e.g. what would happen if a FPS game only relied on the server for player and bullet positions? It would totally break in the face of even slight lag without client-side prediction)

Some reading: http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/
The rest of his articles are worth reading as well.

Thanks for the advice, I’m looking forward towards reading that link at work xD