Kinda OT - Loading terrain in to a physics engine.

EagleEye

19-01-2006 21:16:08

I'm making a client/server based game, where the client will be using the PLSM2 for terrain loading. All game movements will be handled by the server, where the client sends a movement request to the server, the server does collision detection, etc, and updates the client on the positions of objects. This means there is no physics on the client itself. The main reason for this is that in multiplayer games, it's bad to trust the client with anything. Plus, the independant objects (the objects in the game world other than the character) will be controlled by the server. If I had the physics on the client, there would be many clients all trying to figure out the collisions of all of the objects... so which client would I trust to be right?

In any case, that's the model I'm going for.

The problem is, on the server, I don't really want to load a scene graph or run the Ogre engine.

I'm curious if it is possible to load an entire terrain (not paged, because all of it would have to be in memory at all times to do collision detection for the entire game world) in to the physics engine without having a scene graph.

The PLSM2 uses the Terrain scene manager as a base, which would enable me to load that entire terrain at once instead of it being paged. I'd simply take the pre-split terrain and use that on the server, and use the split terrain information on the client.

But how to accomplish it, I have no idea... Any suggestions?

Falagard

19-01-2006 21:40:02

Depends on the physics engine and how you integrate the terrain with it, even on the client side.

Basically though, you're going to need to be able to either load the terrain data into the physics engine's custom data structures, or implement your own collision detection with the terrain without actually using the PagingLandscapeSceneManager.

I'd just pull the relevant code out of the PLM2 manager for loading terrain from data files (such as .raw or .bmp or whatever for heightmaps).

If you're using ODE and the terrain callback collision system, all it needs is a function callback for getting a height at a certain x,z position on the terrain.

Clay

tuan kuranes

20-01-2006 05:57:40

some already did it and add a PagingLandScapeTexture_None class handling a texture mode called "None" that help doing that. use that and loadnow getoption and all map will be loaded on the server. (no need for camera, no need for a window)

on wiki, there's a newton plsm2 howto.

Falagard

20-01-2006 05:58:47

Sweet, I didn't know that :-)

EagleEye

20-01-2006 06:30:54

some already did it and add a PagingLandScapeTexture_None class handling a texture mode called "None" that help doing that. use that and loadnow getoption and all map will be loaded on the server. (no need for camera, no need for a window)

on wiki, there's a newton plsm2 howto.


So I don't even need an ogre scene manager to accomplish this? Just the PLSM dll? I suppose I should go check out the wiki. :) If the PLSM will load the entire map file, then I don't have to worry about it using the Terrain Scene manager... :)

tuan kuranes

20-01-2006 06:32:15

you still need Ogre, but you don't need to start rendering.

EagleEye

20-01-2006 09:09:45

Okay. That sounds reasonable.

EagleEye

20-01-2006 19:36:48

Do you have a link to the appropriate wiki page for this?

Edit: Nevermind, I found the NEWTON howto... I thought there was something more. :)

EagleEye

20-01-2006 22:26:20

Could you tell me about this "loadnow" and "getoption" thing?

DrPain

21-01-2006 01:39:55

Here's how I load it in my server:

global->sceneMgr = (PagingLandScapeSceneManager *)global->root->getSceneManager(ST_EXTERIOR_REAL_FAR);
hardwareBufferManager = new Ogre::DefaultHardwareBufferManager();
global->sceneMgr->setWorldGeometry("paginglandscape2.cfg");
global->sceneMgr->setOption("LoadNow", NULL);

EagleEye

21-01-2006 07:50:24

Here's how I load it in my server:

global->sceneMgr = (PagingLandScapeSceneManager *)global->root->getSceneManager(ST_EXTERIOR_REAL_FAR);
hardwareBufferManager = new Ogre::DefaultHardwareBufferManager();
global->sceneMgr->setWorldGeometry("paginglandscape2.cfg");
global->sceneMgr->setOption("LoadNow", NULL);


Ahh, I was thinking it was a config file option. Thanks.

EagleEye

25-01-2006 19:09:44

I'm getting errors about the resources loading and such... I don't NEED to load resources because I'm not using any textures or anything. I seem to remember having the impresion that you didn't have to load the actual textures, and that you could just load the heightmaps or something.

Is there an option to do that?

Edited to add: I guess I do need the resource locations to find the heightmaps... I'm working on using code instead of resources.cfg... it seems to be working for that.

My big question is how do I tell it to just load the heightmaps, and not the textures? Simply make the textures not available?

Falagard

25-01-2006 19:15:58

Depends what resources its trying to load. Report the errors here.
But Tuan did mention TextureMode=None in the landscape config file.

EagleEye

25-01-2006 19:36:34

Depends what resources its trying to load. Report the errors here.
But Tuan did mention TextureMode=None in the landscape config file.


So that would be in that ps_height_1k.cfg file, right?

Not the base paginglandscape2.cfg file...

tuan kuranes

26-01-2006 07:53:48

yes, in that ps_height_1k.cfg.

EagleEye

26-01-2006 08:27:59

I'm getting an error now when I do SetWorldGeometry...

My .cfg file that I'm referencing is like this:


DefaultMap=puget_sound

puget_sound=ps_height_1k
#grand_canyon=gcanyon_height_4k2k
#terragen_generated=terragen16bits
#European_Alpes=Alpes

# resource group name where to find map definition
GroupName=PLSM2


Nothing new there.

My ps_height_1k is:

### WARNING
## read Data2dLoader.txt, Mapsplitterreadme.txt
## in ogreaddons paginglandscape root folder before anything here.
##
# resource group name
GroupName=PLSM2


##
##

################## HeightMap OPTIONS.


#
# Before using the paginglandscape2 plugins,
# you'll have to split your big heightmap file into pages.
# Use the Mapsplitter tool for that

# Base file name for the landscape heightfield data
# The file name MUST be LandScapeFileName.x.z.LandScapeExtension (ex: landscape.0.0.png)
# and MUST be squared.
LandScapeFileName=ps_height_1k
LandScapeExtension=png


# Height and Width of the landscape in number of pages
Width=4
Height=4

#
# Size of the Heightfiled in pixels (must be (power of 2) + 1)
PageSize=257
#
# Size of the Heightfiled in pixels
TileSize=65
#
## so if map is 2048x1024, with pagesize=257 and TileSize=64
# it gives 32 pages (8 pages width, 4 pages width), each 16 tiles so it's 512 tiles on the whole map.

#
# Especialized 2D data loader.
# Currently the only available loaders are 'HeightField', 'HeightFieldTC' and 'SplineField'.
#

# 8bits, grayscale images. (png, jpg, etc) or 16 bits (raw)
Data2DFormat=HeightField
# 32bits, RGBA images. (png, jpg, etc) RGB is normal information, in alpha we store heightmap
#Data2DFormat=HeightFieldN

#
# The HeightField TC is a compresed format and need to know the value range from where the
# heightfield file was compressed
MaxValue=3000
MinValue=0
# # 8bits, grayscale images. (png, jpg, etc) or 16 bits (raw)
#Data2DFormat=HeightFieldTC
# 32bits, RGBA images. (png, jpg, etc) RGB is normal information, in alpha we store heightmap
#Data2DFormat=HeightFieldNTC

#experimental spline terrain
#Data2DFormat=SplineField


#
# Scale values
# Beware that scaling is pagesize and heighmap definition range indepedant.
ScaleX=90000
ScaleY=30000
ScaleZ=90000

# if Deformation is no use for you, you can gain fps by saying no here.
Deformable=no
# experimental VRAM saves. need instant base texture and vertex shader support
# "vertex displacment mapping"
VertexCompression=yes

# Use vertex program to morph LODs, if available
VertexProgramMorph=no
# The proportional distance range at which the LOD morph starts to take effect
# This is as a proportion of the distance between the current LODs effective range,
# and the effective range of the next lower LOD
LODMorphStart=0.2
# The maximum error allowed when determining which LOD to use
MaxPixelError=15

################## LIGHTING OPTIONS.
# For lighting
# For better looking deformed texture (instantbase)
# for shader (needed to get slope)
VertexNormals=yes


############### TEXTURING OPTIONS
#
TextureMode=None
################## PERFORMANCES OPTIONS.
#
#
#
# Visible renderables
# This is the number of visible renderables from the current camera position
# to the border of the visible terrain. (The radius of renderables)
VisibleRenderables=80
#
# LOD : LEVEL OF DETAIL
#
# Distance LOD
# This is the number of renderables in the higher LOD.
#
DistanceLOD=5
#
# if not set, it's precomputed to the max possible at this TileSize.
# Must be (2^MaxRendervel < TileSize)
MaxRenderLevel=3
#
#
# FPS Processing limit
# number of renderables loading in a single frame (if needed)
NumRenderablesLoading=50
#
# WINDOWING AROUND CAMERA
#
# Num of adjacent loaded landscape pages.
MaxAdjacentPages=3
#
# Num of adjacent preloaded landscape pages.
# Must be bigger than MaxAdjacentPages + 1, the textures are loaded in a separate thread.
MaxPreloadedPages=4
#
#
# Pages Load Factor
# Pages will be load/unload when they are about PageSize^2 * ChangeFactor
ChangeFactor=1.5
#
#
# Camera Threshold
# If the last camera position minus current camera position is >= CameraTheshold
# then the scene is trasverse to check LOD.
CameraThreshold=5
#
# Memory Pool Initial Usage Values (pre-allocated renderables and tiles.)
# use debug mode to check your needs.
MaxNumRenderables=200
IncrementRenderables=200
MaxNumTiles=200
IncrementTiles=200
# Horizon Visibility computing:
# enable it if your map have moutains, cliff... not if it's mainly plane.
# everything hidden will not be send to GPU saving framerates.
HorizonVisibilityComputing=yes


I'm thinking I probably need to change some stuff in there other than that TextureMode=none

Unfortunately, the error is an assertion that doesn't give me much info... here is exactly what I see:

Assertion failed!

Program: ...mundServer\VermundServer\bin\VermundServer.exe
File: c:\softwaredevelopment\c++\ogres...\ogreha...ger.cpp
Line: 40

Expression: ms_Singleton


The rest is just the instructions on trying to debug, which won't work. :(

EagleEye

26-01-2006 08:33:51

I narrowed down the source file to the OgreHardwareBufferManager.cpp

HardwareBufferManager& HardwareBufferManager::getSingleton(void)
{
assert( ms_Singleton ); return ( *ms_Singleton );
}

:-/

tuan kuranes

26-01-2006 10:11:16

you should at least init Ogre (specially Root object.), but not setup display or launch windows.

EagleEye

26-01-2006 17:09:41

Yeah, I have done that... so I'm not really sure what the problem is.

Private Root As New Root("ogreplugins.cfg", "ogre.cfg", "ogre.log")
Private Scene As SceneManager = Nothing

Sub New()
Try
ResourceGroupManager.getSingleton.createResourceGroup("PLSM2")
ResourceGroupManager.getSingleton.addResourceLocation("media", "FileSystem", "PLSM2", True)

Scene = New SceneManager
Scene = Root.GetSceneManager(SceneType.ExteriorRealFar)
Scene.SetWorldGeometry("paginglandscape2.cfg")
Scene.SetOption("LoadNow", New IntPtr)
Catch ex As Exception
Console.WriteLine("WorldController.new: " & ex.Message)
End Try
End Sub


It's VB, but you should get the idea.

Falagard

26-01-2006 17:57:16

Something must be using the HardwareBufferManager so create it before you do the rest and the singleton will exist.

EagleEye

26-01-2006 19:43:21

I think the problem is I'm not properly initializing root because I'm not using a window object... I think I may set it up fully and just not call StartRendering.

EagleEye

26-01-2006 20:10:10

Okay, I'm having the same problem now with my client app, and it's happened since I set up my server with the network share drive... it seems there's a problem with permissions across the network.

EagleEye

26-01-2006 21:53:00

Turns out the problem was I didn't have a window object being initialized by root.

Private Root As Root
Private Window As RenderWindow
Private Scene As SceneManager = Nothing

Sub New()
Try
Root = New Root("ogreplugins.cfg", "ogre.cfg", "ogre.log")
Root.ShowConfigDialog()
Window = Root.Initialise(True, "Vermund Server")
ResourceGroupManager.getSingleton.createResourceGroup("PLSM2")
ResourceGroupManager.getSingleton.addResourceLocation("media", "FileSystem", "PLSM2", True)
Scene = New SceneManager
Scene = Root.GetSceneManager(SceneType.ExteriorRealFar)
Scene.SetWorldGeometry("paginglandscape2.cfg")
Scene.SetOption("LoadNow", New IntPtr)
Catch ex As Exception
Console.WriteLine("WorldController.new: " & ex.Message)
End Try
End Sub


That works.