Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Loading a large map in server  (Read 8198 times)
0 Members and 1 Guest are viewing this topic.
Offline osmarjunior

Junior Newbie





« Posted 2013-11-26 15:55:33 »

Hi people,

I've been trying to develop a 2D MMORPG (like tibia Tongue) 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 Sad, the question is: what is the best way to load a big map and handle with the objects?

Thanks.

p.s: sorry my english
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« 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
Offline 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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.  Clueless Is there any best practices to struct this kind of objects?
Offline 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)
Offline 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 Lips Sealed kkk
Offline 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
Offline 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.

Check out my Devblog! Smiley
Offline 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.

Offline 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 { //AbstractMap there are only methods

         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; //there is only one instance of Mapa on server
   private List<Item> itens = new LinkedList<Item>();
   private List<Creature> creatures = new LinkedList<Creature>(); //I'm not loading creatures in the map load...
}


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; //it's an Enum
    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!
Legends of Yore - The Casual Retro Roguelike
Offline osmarjunior

Junior Newbie





« Reply #10 - Posted 2013-11-28 19:03:52 »

May someone help me?  Huh
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« 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.

Offline 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
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« 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!

Offline Genius Coder

Junior Devvie


Medals: 1
Exp: 4 years



« 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...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!