[SpiderMonkey] How can I send and sync a Terrain from the Server to the Clients?


How can I send and synchronize a Terrain (TerraMonkey) from the Server to the Clients?
If I send a serialized Object of the Terrain with an AbstractMessage, it will be make a high network load, or?

Is there a reason that you don’t just bundle the Terrain with the clients when you build them? Since it’s not dynamic terrain this is probably the easiest way.

Otherwise you will have to extract the relevant data (height maps, alpha maps, whatever) and send those. Yes, they will be sizeable. You could compress them somehow.

None of this is SpiderMonkey specific, really. You’d have this issue with any networking API you used.

1 Like

Thank you for your answer!
The Terrain is dynamic and will be also changed by the clients, for example the player can sink and lift the terrain, the clients must send this changes to the server.
The other problem is, that the terrain is endless and will be automatically generated and extended by the server, if this is neccessary.
How can I get the HeightMap and the Alphamap from a terrain object?
Is there a specific method?

I’ve never used JME terrain so I wouldn’t know. But you could try looking at the Javadoc and see if anything jumps out.

You will have your work cut out for you, though.

Im still scratching my head on the alpha but the height map part is easier. The simple answer is you don’t send the height map. If you are using spidermonkey then you could just send the whole TerrainQuad object over reliable and set the material on the other end.

The heightmap is only used to set data in the TerrainQuad you can instance the TerrainQuad without it to get a blank map, or feed it an array of floats to get a custom map without the heightmap.

Assuming your sending messages in a non-serialized manner, then you could composed a message made of the various points on the TerrainQuad using getHeight(Vector2f) on the TerrainQuad. Send to the client, either composing a new quad from a float array or unlock and existing quad (setLock(false)) and set the height points (setHeight(Vector2f, float))

Im assuming but havent tested out yet that I can make a small image and pass said image to the client as my alpha map. Stretching the small image to produce a low detail alpha map on larger world tiles.

Oh on the point of network load, most of the stuff a terrainquad points to are memory references that would have no meaning on the other end. Like Materials, Nodes, etc. The map itself could probley be calculated like this.

(size * size) * (float size) = bytes

bytes/1024 = kilobytes of traffic

height map of 32x32 that would be

32x32x4=4096 bytes

4096/1024 = 4kb of data

Really old modems 12kb/s both ways
Modems push 56kb/s both ways
ADSL 56k-256kb up / 512+ down
( your client would be be concerned about down, server up )
Cable 1024kb+ both ways atleast

So depending on size it wouldnt be a problem considering it only gets sent either one time, or peroidicly as people move around the map or change zones.

When terrain height is modified you can send those same parameters over to the server. They will bundle up nicely.
Terrain.adjustHeight() http://hub.jmonkeyengine.org/javadoc/com/jme3/terrain/geomipmap/TerrainQuad.html#adjustHeight(java.util.List,%20java.util.List)

Thank you for your answer.
Do I must lock the terrain after the change?

API notes say you only need to unlock for editing, and that locking improves performance.

I assume you do not need to lock it, and it may not be locked when you instance it.