Game Development Community

Working on Terrain Manager class...

by Bryan Turner · in Torque Game Engine · 04/04/2002 (9:56 am) · 239 replies

SORRY FOLKS!

Looks like the GORPE updates have fallen off the shelf. I do not have a copy of the most recent TM project, but you are welcome to download my old versions here (pre-Torque 1.2):

www.fractalsacpe.org/TorqueTerrain
www.fractalsacpe.org/TorqueTerrainManager.zip

------------------------------------------------------

Hello again.

I got to working on a Terrain Manager class after digging through the terrain rendering code, and it's coming along nicely.

Basically I took Mark F's suggestions and created a TerrainManager class which is the single point of interface for all terrain functions. Moved the relevent structures to it (Material, BlockSize/Mask/Shift, etc). And stubbed the rest of the functions to point to a TerrainBlock. It hit a lot of files to compile/link, but it's working :)

Now I'm getting to the part where I don't understand..

- Should the TerrainBlock remain a SceneObject? I don't think so, since the TerrainManager should be the only thing in the scene.. But taking this step makes the terrain engine *very* unhappy. I'd like some sort of reassurance that this is the right direction.

- How do I specify a vector of data in the mission file datablocks for things like textures, height map files, etc? Basically I want a datablock for TerrainManager which may contain many TerrainBlock datablocks (which contain resource lists for terrain files, textures, etc..).

Some general terrain engine questions:
- What is a 'square' in the terrain engine, and why does *everyone* need it?

- What is a 'grid block' in the terrain engine? How does it differ from a 'square'?

- What is an MPM (material properties map), and why is it passed around with no encapsulation?

Thanks!
--Bryan
#81
06/25/2002 (8:03 am)
Daniel, you are able to save the terrains now?
So everything is working smoothly, even editor-wise?
Would be awesome, I was always holding back putting all these code changes in - but now I would go ahead and do it! :-))
#82
07/03/2002 (4:57 am)
Marco,

Sorry, I've gotten sucked into real life again. Hopefully I'll have some time over the long weekend to put out build 6.

Currently, I can get the terrains to save, but when loading back in, they crash Torque. I believe this is an error in my scripting. Daniel has sent me some updated information which sounds like it will fix the problem.

Also, I've extended the TerrainManager layer to cover the rest of the terrain functions, (mostly editor stuff) which was not abstracted in the previous code. This completes the API for TerrainManager. The remaining issues for full-integration are:

- Paiting the terrain (how to determine which terrain is being painted).

- Finding a Modulus operation which works with negative numbers (ie: -1 mod 8 == 7). Currently this is causing the editor to be extremely slow at editing across landscape borders which include negative tiles.

- Validating the other editor functions work correctly (they should, but I haven't tested them all).

--Bryan
#83
07/04/2002 (7:26 am)
Hey Bryan!

Sounds great. I'll look forward to that. Would be great. But don't forget the real life out there 8)
#84
07/11/2002 (3:25 pm)
> Finding a Modulus operation which works with negative
> numbers (ie: -1 mod 8 == 7). Currently this is causing the
> editor to be extremely slow at editing across landscape
> borders which include negative tiles.

I believe the general way to handle negativity in the moduland is:

- Replace the moduland with its absolute value.

- Do the modulo operation to get the answer A.

- If the original moduland was negative, then replace A with modulus - A.

So in this case, replace -1 with its absolute value, which gives you 1 % 8 = 1; since the original moduland was negative, the real answer is 8 - 1 = 7.

Similarly, if you wanted to find -26 % 8, you would first find 26 % 8 = 2, then do 8 - 2 = 6.

If your modulus is a variable, probably that's what you'll need to do.

---

Now, if your modulus is always going to be a fixed value that is known to you, there's a slightly faster way; if the moduland is negative, then add the largest positive multiple of the modulus to the moduland before doing the operation. So if you were using signed 32-bit numbers and your modulus is always going to be 8, then you can add the constant 268435456 to any negative moduland before doing the operation.

So, -1 % 8 = -1 + 268435456 % 8 = 268435455 % 8 = 7

There's a "hole" in that approach if you have a negative moduland way down near the bottom of the range (the obvious example is -268435457), but presumably if you're dealing in TGE terrain coordinates that won't happen. :-)

Actually, if your modulus is fixed AND your moduland is always going to be within a certain known range, which is significantly smaller than the overall range of the integer type, then it's possible that you can skip the if-check for the negativity of the moduland and just always add a certain multiple of the modulus to the moduland before doing the operation. You need a multiple of the modulus that will a) always have a positive result when added to any negative moduland b) never cause an overflow when added to a positive moduland.
#85
07/17/2002 (5:11 pm)
Joel,

Well, that's what I tried (the first one) and it didn't seem to work. Take the case of -8:

invert: -(-8) = 8
modulus: 8 mod 8 = 0
reverse: 8-0 = 8
results in: -8 mod 8 = 8

Which cannot be correct since the output of a modulus operation should be 0..(mod-1). In this case, 8 is an illegal value.

I like the second approach though, might just add MAX_INT/2 to everything and be done with it. :)

--Bryan
#86
07/17/2002 (8:51 pm)
Ok, I figgured I've procrastinated long enough. Finally got around to putting in Daniel's save code, and merging with the latest head.

Links are at the top of the page. This build includes a working mission directory ready for editing and saving.

Let me know if anyone has problems with this build.

--Bryan
#87
07/17/2002 (9:05 pm)
Bryan, there seems to be a problem with the download:
Quote:
Forbidden
You don't have permission to access /TorqueTerrainManager.zip on this server.
#88
07/18/2002 (11:06 am)
*ditto*
#89
07/18/2002 (3:11 pm)
Fixed. Forgot about those file permissions. :)

Have at it.
--Bryan

Doh.. DNS issues now. If www.fractalscape.org does not work for you, use this instead:

fractalscape.dyndns.org
#90
09/16/2002 (7:02 pm)
Bryan,

If you like, I'll be more than happy to post the zip to www.battlebazaar.com and/or lain.battlebazaar.com. They don't move around (although Lain is currently down while I get LockedArea and Teamz up and running).

AMEN to this feature, by the way. This was on my "list of things I really need but don't have time to tackle yet."

I want to look at this in detail to see if it can be made to do the following:

ABCDE
FGHIJ
KLMNO
PQRST

When a user enters H, they can see into C, but probably can't see into R yet.

When the user enters H, you could unload PQRST, and replace them with whatever is north of ABCDE.

In this way, you could support an arbitrarily large map. This is precisely what games that have huge land bases and no "pause to zone" do -- for example Asheron's Call or Ultima Online.

I don't know how doable this is with your code (because I've not looked at it yet), but I would think that this code wouldn't care if you did it this way (it deosn't know nor care that PQRST changed for its logic).

The trick would be getting the loads to occur fast enough to do them in the background.
#91
09/24/2002 (11:35 am)
How's it coming along Bryan?
#92
09/26/2002 (3:36 pm)
Has anyone else had problems with shadows not being drawn on the terrain after making these changes? Neither static or dynamic (ie, the player's) shadows draw on my terrain. In fact, it seems that the terrain isn't even getting lit at all. When I re-light the terrain the scene I get an error that the terrain didn't pass validation, I don't have the exact message tho as I'm at work right now.

I tracked the error all the way down the lighting pipeline a few weeks ago, but I've been too busy to look at it in a while. Just wondering if others have had the same problem or not.
#93
10/04/2002 (1:14 am)
Jep, same problem here with Torque_1_1_2. I'm on it...
#94
10/10/2002 (6:09 pm)
Hey all,

It's been awhile since I've posted, sorry about that. The TerrainManager was basically finished as of the last release, so I've put it asside to work on other projects. If you have problems with the code, try merging with the latest release instead of just replacing the files.

The lighting should be working, unless the engine has changed since my code was written.

Dave,

That is exactly what TerrainManager was designed for. While you'll still have to implement the loading/management of the terrain tiles, the TerrainManager abstracts the interface to the rest of the engine so that all it sees is a single terrain object.

If there are any questions/problems, and especially if there are bug fixes, I'm happy to include them in the source archive. I hope this project will get absorbed into the main codebase once enough people have need of it.

--Bryan
bryan.turner@pobox.com
#95
10/28/2002 (6:43 am)
The link is broken or the server is down.
Maybe, you could post TorqueTerrainManager.zip as a resource?

:)
-Bendik
#96
10/28/2002 (9:04 am)
Well, until the server is up again, you can get the latest release on our website, too: tork.zenkel.com/downloads/torque/TorqueTerrainManager.zip
#97
11/03/2002 (11:48 pm)
Has anyone done any work on this? This is exactly what ive been looking for but I cant get it to complie with the latest build.

I get all kinds of errors here are a few random examples.

f:\TGE-BigTerrain\torque\engine\sim\netGhost.cc(44): error C2660: 'ConsoleObject::getClassId' : function does not take 0 parameters

f:\TGE-BigTerrain\torque\engine\game\vehicles\vehicle.cc(1407): error C2039: 'setCompressionPoint' : is not a member of 'GameConnection'

f:\TGE-BigTerrain\torque\engine\game\player.cc(3287): error C2039: 'setCompressionPoint' : is not a member of 'GameConnection'

f:\TGE-BigTerrain\torque\lib\dtsSDK\DTSShape.cpp(131): error C2660: 'std::vector >::assign' : function does not take 1 parameters

I would REALLY like to see this. Could someone please let me know what the latest is on this.

Loonatik
#98
11/04/2002 (12:17 pm)
Bump
#99
11/04/2002 (11:55 pm)
It seems like you have not updated all the files..(guesses)

I ran it, and it worked fine with T 1.1.2...

...it was a bit buggy as I was working on terrain.
(You can't do terrain manipulations with it)
-Has a Modest crashrate. So I removed it, and am now in a waiting position for someone to streamline the code.

If noone does this, I might do it once I'm done with my forest code.

:)
#100
11/05/2002 (7:11 am)
I had problems with re-lighting the terrain. When I lowered the ambient lighting by a lot and re-lit the scene, the terrain wasn't darkened accordingly. I didn't merge the code with the Torque engine; I just copied the files over the existing ones, so that may have screwed things up.

Also, there were some occasions where I couldn't drop the player using F8 in certain places.