osmarjunior
Junior Newbie
|
 |
«
Posted
2013-11-26 15:55:33 » |
|
Hi people, 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? Thanks. p.s: sorry my english
|
|
|
|
Seiya02
|
 |
«
Reply #1 - Posted
2013-11-26 16:14:08 » |
|
On Server start: load nothing, Just when there's some clients connecting load the area arround them. Basically working like a Chunk system i guess
|
|
|
|
Danny02
|
 |
«
Reply #2 - Posted
2013-11-26 17:12:51 » |
|
In my opinion you did something horrible wrong, because I can't imagine a game world which would consume too much memory on the server (did you try to extend the Java heap?)
|
|
|
|
Games published by our own members! Check 'em out!
|
|
osmarjunior
Junior Newbie
|
 |
«
Reply #3 - Posted
2013-11-26 18:56:21 » |
|
The map I'm trying to load is the global Tibia map, so it is very big! Maybe the problem is the structure of my objects.  Is there any best practices to struct this kind of objects?
|
|
|
|
Danny02
|
 |
«
Reply #4 - Posted
2013-11-26 19:49:07 » |
|
I don't know how big this map is, but most of the time the final data-structure isn't the problem. It may be that your parser creates too many temporary object which let the JVM explode.
Anyway, did you try to just extend the Java heap size?(add -Xmx1024m as a start parameter to Java to set the heap to 1GB)
|
|
|
|
osmarjunior
Junior Newbie
|
 |
«
Reply #5 - Posted
2013-11-27 10:54:50 » |
|
Yes Danny02, I setted -Xmx3048m -XX:MaxPermSize=2048m and it consumes all the memory. The map has thereabout 13437971 tiles, with at least one item (the ground), it's a lot of objects  kkk
|
|
|
|
Danny02
|
 |
«
Reply #6 - Posted
2013-11-27 15:31:22 » |
|
Then pls show us some code. What are your data-structures and how do you load the map, because when we say you just need one id + type per tile you should only need around 200mb
|
|
|
|
Mac70
|
 |
«
Reply #7 - Posted
2013-11-27 15:40:59 » |
|
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.
|
|
|
|
Damocles
|
 |
«
Reply #8 - Posted
2013-11-27 16:08:10 » |
|
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 in the size of this should be only few megabytes when you handle your data efficiently.
|
|
|
|
osmarjunior
Junior Newbie
|
 |
«
Reply #9 - Posted
2013-11-27 18:47:19 » |
|
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 in the 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
| public class Mapa extends AbstractMap {
protected HashMap<Position, Tile> tiles = new HashMap<Position, Tile>(); } |
1 2 3 4 5 6 7 8
| public class Tile {
private final Position position; private Item ground; private final Mapa mapa; private List<Item> itens = new LinkedList<Item>(); private List<Creature> creatures = new LinkedList<Creature>(); } |
1 2 3 4 5 6
| public class Position { private int x; private int y; private int z; } |
1 2 3 4
| public class Item {
private ItemType itemType; } |
1 2 3 4 5 6 7 8 9 10 11
| public class ItemType {
protected Group group; protected EnumSet<ItemAttribute> attributes; protected int serverId; protected int clientId; protected String article; protected String name; protected String pluralName;
} |
|
|
|
|
Games published by our own members! Check 'em out!
|
|
osmarjunior
Junior Newbie
|
 |
«
Reply #10 - Posted
2013-11-28 19:03:52 » |
|
May someone help me? 
|
|
|
|
ctomni231
|
 |
«
Reply #11 - Posted
2013-12-05 11:57:13 » |
|
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.
|
|
|
|
Rorkien
|
 |
«
Reply #12 - Posted
2013-12-05 12:08:27 » |
|
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
|
|
|
|
Opiop
|
 |
«
Reply #13 - Posted
2013-12-05 20:14:38 » |
|
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!
|
|
|
|
Genius Coder
|
 |
«
Reply #14 - Posted
2014-01-21 22:26:28 » |
|
A strategy I have used before is only Loading the tiles within your clients player position and that usually works quite well as it won't load other clients tiles and will run very smoothly
|
I love making games...
|
|
|
|