I've been trying to develop a 2D MMORPG (like tibia ) using Java. The server of my game loads all the map and store all the objects (tiles, itens, player, monster) in memory. But when I try to load a map very big, it consume all the memory of my computer , the question is: what is the best way to load a big map and handle with the objects?

One tip - don't make objects for each tile, use arrays of primitives + objects for special properties of tiles (if any) instead. If your world will expand or/and take very big amounts of RAM, consider storing it in chunks and load them when someone is close to them or you must update something.

When you have an MMO, why do you send the complete Map to each client?

Only send each client the dynamic objects (changed delta data) in the clients relevant "area".

Static Leveldata, like hills, trees etc (everything that cant change) should be locally in the clients resources at the start.

If you need to change the map, offer patches or a downloader to the clients.These changes can remain on a standard file-webserver.

---

if you meant, that you server-side map, (needed for the gamelogic) is too big,then you made a structural error on how much data your serverside map actually needs.It (the mapdata representing the world) only needs relevant data for collision detection, events and dynamic objects. This should be quite compact inthe size of this should be only few megabytes when you handle your data efficiently.

When you have an MMO, why do you send the complete Map to each client?

Only send each client the dynamic objects (changed delta data) in the clients relevant "area".

Static Leveldata, like hills, trees etc (everything that cant change) should be locally in the clients resources at the start.

If you need to change the map, offer pathces or an downloader to the clients.These changes can remain on a standard file-webserver.

---

if you meant, that you server-side map, (needed for the gamelogic) is too big,then you made a structural error on how much data your serverside map actually needs.It (the mapdata representing the world) only needs relevant data for collision detection, events and dynamic objects. This should be quite compact inthe size of this should be only few megabytes when you handle your data efficiently.

Damocles, I'm sending to client only the relevant part of the map, only what the player can see. The problem maybe is the structure of my object on the server-side. Follow the structure of them:

1 2 3 4

publicclassMapaextendsAbstractMap { //AbstractMap there are only methods

privatefinalPositionposition;privateItemground;privatefinalMapamapa; //there is only one instance of Mapa on serverprivateList<Item> itens = newLinkedList<Item>();privateList<Creature> creatures = newLinkedList<Creature>(); //I'm not loading creatures in the map load...}

Yeah, in this case you might want to find a new way to represent a map. You are creating about 5 new objects per tile. Eventually, you'll run out of room.

For large maps use primitives like int or byte. They are easier to store and you can fit a lot more without crashing. It really helps to separate the items from the map. Any object on the tile should probably be stored in a (item, x position, y position) to help reduce space. The smaller the better when it comes to any large map.

Yeah, in this case you might want to find a new way to represent a map. You are creating about 5 new objects per tile. Eventually, you'll run out of room.

For large maps use primitives like int or byte. They are easier to store and you can fit a lot more without crashing. It really helps to separate the items from the map. Any object on the tile should probably be stored in a (item, x position, y position) to help reduce space. The smaller the better when it comes to any large map.

Not only that, he also has 2 collections per tile.

Why do you have two objects (ground and itens) regarding items?Does that Creature collection includes players?

You could also try mapping the game objects (like items, players and monsters) to the Map itselt, not the Tile

All of the above is correct, and I also recommend looking into a static tile system so you only create one instance of a tile, and draw it in multiple places. And really ask yourself, does the tile need to know its position? I've never created a tile system where the tile knows its position in the world, and it works out pretty well because all you need is a array of the tiles, and then a way to get a tile out of the array. That's instantly much less memory used, and you conserve the intended functuality!

Edit: I just noticed you're storing your map in each tile. Why do this? If you need the world, just pass it in when you need it. Storing the map just seems wasteful!

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org