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
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
#62
I've been collecting bugs for the past few days and plan to fix them soon (hopefully this weekend). This should include:
- Save/Load
- CRC errors
- Crash when not enough/too many TerrainBlocks
--Bryan
05/30/2002 (1:05 pm)
Marco,I've been collecting bugs for the past few days and plan to fix them soon (hopefully this weekend). This should include:
- Save/Load
- CRC errors
- Crash when not enough/too many TerrainBlocks
--Bryan
#63
edito. But then i can't reload it. Well, i hope you've got more luck on this than me.
Happy coding.
05/31/2002 (12:58 am)
Oh, ok. That's great. Because my code doesn't work. I don't know why. I can save my changes i made throug the edito. But then i can't reload it. Well, i hope you've got more luck on this than me.
Happy coding.
#64
I'm confused! How do I save the terrain files? I see functions for save/load of the terrain data files, but I can't find a 'save' option in the editor. Does 'save mission' also save the terrain? There appears to be a console command for saving terrain files also, but I don't know if this is the 'normal' way to save them.
Status:
- Fixed the crash for wrong number of terrains.
- Fixed the CRC issues (returns 0 for now).
- Studied the terrain painting issues. Shouldn't be hard to fix, just need to figgure out which terrain is being edited at the moment.
Thanks,
--Bryan
05/31/2002 (9:19 pm)
Help!I'm confused! How do I save the terrain files? I see functions for save/load of the terrain data files, but I can't find a 'save' option in the editor. Does 'save mission' also save the terrain? There appears to be a console command for saving terrain files also, but I don't know if this is the 'normal' way to save them.
Status:
- Fixed the crash for wrong number of terrains.
- Fixed the CRC issues (returns 0 for now).
- Studied the terrain painting issues. Shouldn't be hard to fix, just need to figgure out which terrain is being edited at the moment.
Thanks,
--Bryan
#65
Terrain.save(%filename);
To save multiple terrains, it might look in this way.
Same for the mission:
greetings
Daniel
06/01/2002 (8:54 am)
There is only one way to save a terrain file:Terrain.save(%filename);
To save multiple terrains, it might look in this way.
%group = nameToID(MissionGroup);
if(%group !=-1)
{
%count =%group.getCount() -1;
for(%i= 0; % <=%count; %i++)
{
%obj= %group.getObject(%i);
if(!strICmp(%obj.getClassName, "TerrainBlock"))
%obj.save(%obj.terrainFile);
}
}
// else no terrain to saveSame for the mission:
MissionGroup.save(%filename);
greetings
Daniel
#66
06/01/2002 (1:54 pm)
Bryan, yes, "Save mission" in the editor should save the terrain file, too! And you can export it as a *.png, too... maybe this code has to be adjusted, too then... cause now you have to decide *which* terrain to export...
#67
06/05/2002 (8:16 pm)
Bryan, have you tested this as a dedicated server ? or at least as a hosted multiplayer server ?
#68
Unfortunately not. I only have one machine, so unless someone knows how to run a server and a client on the same machine, I'm kinda stuck.
But this will change next month after I get a new machine. I'll be able to run a server off one and a client off the other.
Has anyone been able to test it server/client?
--Bryan
06/07/2002 (11:33 am)
Ken,Unfortunately not. I only have one machine, so unless someone knows how to run a server and a client on the same machine, I'm kinda stuck.
But this will change next month after I get a new machine. I'll be able to run a server off one and a client off the other.
Has anyone been able to test it server/client?
--Bryan
#69
06/07/2002 (11:44 am)
I'll test it in dedicated mode tonight or this weekend.
#70
06/07/2002 (11:53 am)
Unless I'm missing something obvious you can run a dedicated server and client on the same machine. Just run them as two separate tasks. It works fine for me under Win98.
#71
Then I updated to the latest head, and it blew up again. The new problem is that I can do multiple terrains 'across' but only one row 'down'. I'm guessing that I screwed up the merge somehow. It's gonna be a nightmare trying to track down the error; we're releasing a new BETA this weekend with our new databse interface to our shiny new mySQL database Authentication and Persistence Server, so I'll have to put this on hold until the dust settles from that ...
06/07/2002 (10:33 pm)
The reason I asked is because although it worked fine in singleplayer mode, or as host of a multiplayer (with no remotes), it worked fine. Then I fired it up in dedicated mode on our server, and Kablooie. I made a quick fix by using your global in a tactical location, and it worked again.Then I updated to the latest head, and it blew up again. The new problem is that I can do multiple terrains 'across' but only one row 'down'. I'm guessing that I screwed up the merge somehow. It's gonna be a nightmare trying to track down the error; we're releasing a new BETA this weekend with our new databse interface to our shiny new mySQL database Authentication and Persistence Server, so I'll have to put this on hold until the dust settles from that ...
#72
This is the EditorSaveMission() function you need to save all terrains.
Some information:
- Group with TerrainBlocks has to be called 'Terrain'
- TerrainManager has to be called 'TerrainMgr'
- TerrainManager must have a field 'detailTexture', so every TerrainBlock gets the same detailTexture when being saved.
- Mission is saved as $missionDir/%missionname/mission.mis
- Terrains are saved as $terrainDir/%missionname/terrain@ %terrCount @.ter
%missionname is 'MissionInfo.name', so you have to rename the mission to save it in another directory.
- TerrainBlock.preserveFile will not let the editor save the terrain file, even when being modified.
- TerrainBlock.lockFile will not let the editor change the terrainfile's location, even when you change the mission name.
You will need this function, too:
greetings
Daniel
06/08/2002 (9:57 am)
Ok, now we added the TerrainManager, too. Now I could have a look myself.This is the EditorSaveMission() function you need to save all terrains.
Some information:
- Group with TerrainBlocks has to be called 'Terrain'
- TerrainManager has to be called 'TerrainMgr'
- TerrainManager must have a field 'detailTexture', so every TerrainBlock gets the same detailTexture when being saved.
- Mission is saved as $missionDir/%missionname/mission.mis
- Terrains are saved as $terrainDir/%missionname/terrain@ %terrCount @.ter
%missionname is 'MissionInfo.name', so you have to rename the mission to save it in another directory.
- TerrainBlock.preserveFile will not let the editor save the terrain file, even when being modified.
- TerrainBlock.lockFile will not let the editor change the terrainfile's location, even when you change the mission name.
You will need this function, too:
function oneWord(%text)
{
return strReplace(%text, " ", "_");
}function EditorSaveMission()
{
%missionname= oneWord(MissionInfo.name);
%missionfile= $missionDir @"/"@ %missionname @"/mission.mis";
// first check for dirty and read-only files:
if((EWorldEditor.isDirty || ETerrainEditor.isMissionDirty) && !isWriteableFileName(%missionfile))
{
MessageBoxOK("Error", "Mission file \""@ %missionfile @ "\" is read-only.");
return false;
}
%group = nameToID(Terrain);
%terrCount= 0;
%count =%group.getCount() -1;
for(%i= 0; %i <=%count; %i++)
{
%obj= %group.getObject(%i);
if(!strICmp(%obj.getClassName(), "TerrainBlock"))
{
// OK this is a terrain, we can now go on.
// Are we allowed to modify this terrain?
if(!%obj.preserveFile)
{
// Are we allowed to change the terrain file's location?
if(!%obj.lockFile)
{
// Generate filename
%terrainfile= $terrainDir @"/"@ %missionname @"/terrain"@ %terrCount @".ter";
%terrCount++;
%obj.terrainFile= %terrainfile;
// Check detail map
if(strICmp(%obj.detailTexture, TerrainMgr.detailTexture))
{
%obj.detailTexture= TerrainMgr.detailTexture;
ETerrainEditor.isDirty= true;
}
}
else %terrainfile= expandFilename(%obj.terrainFile);
// File is now set. Let us save.
// is the file read-only?
if(ETerrainEditor.isDirty && !isWriteableFileName(%terrainfile))
{
MessageBoxOK("Error", "Terrain file \""@ %terrainfile @ "\" is read-only.");
return false;
}
// Save
if(ETerrainEditor.isDirty || !isFile(%terrainfile))
%obj.save(%terrainfile);
}
// /OK this is a terrain, we can now go on.
}
}
// Save the mission at last
if(EWorldEditor.isDirty || ETerrainEditor.isMissionDirty || !isFile(%missionfile))
MissionGroup.save(%missionfile);
EWorldEditor.isDirty = false;
ETerrainEditor.isDirty = false;
ETerrainEditor.isMissionDirty = false;
return true;
}greetings
Daniel
#73
Excellent! I'll get this merged in with my other fixes and with the newest HEAD. Hopefully I can get build 6 out tonight.
Ken,
Where exactly did you need to put another reference to the global? I'll put that in too.
Thanks everyone, this project is getting a lot of good support.
--Bryan
06/10/2002 (2:33 pm)
Daniel,Excellent! I'll get this merged in with my other fixes and with the newest HEAD. Hopefully I can get build 6 out tonight.
Ken,
Where exactly did you need to put another reference to the global? I'll put that in too.
Thanks everyone, this project is getting a lot of good support.
--Bryan
#74
I'm having some trouble getting the *.cs code to integrate. Here's what I'm seeing:
- My '$terrainDir' is null
- My '$missionDir' is null
- When saving "/Stronghold/terrain0.ter" it is always "read-only" because the pathname begins with a '/' (a side effect of the isWriteableFileName function)
- If I hack it up a bit, the files are saved as:
torque\example\Stronghold\terrain0.ter
I doubt this is the correct location for them.. I would expect them to be:
torque\example\rw\data\missions\Stronghold\terrain0.ter
- Once the files are saved (as above), the file size is incorrect. The normally 384K file is about 80-100K. If I move the file back to the mission directory and load it in a mission, it crashes Torque.
So...
How do I:
- Get the files to save in the correct spot.
- Get them to save with the correct size.
- Load them back once they're in a sub-directory.
Thanks!
--Bryan
06/10/2002 (7:22 pm)
Daniel,I'm having some trouble getting the *.cs code to integrate. Here's what I'm seeing:
- My '$terrainDir' is null
- My '$missionDir' is null
- When saving "/Stronghold/terrain0.ter" it is always "read-only" because the pathname begins with a '/' (a side effect of the isWriteableFileName function)
- If I hack it up a bit, the files are saved as:
torque\example\Stronghold\terrain0.ter
I doubt this is the correct location for them.. I would expect them to be:
torque\example\rw\data\missions\Stronghold\terrain0.ter
- Once the files are saved (as above), the file size is incorrect. The normally 384K file is about 80-100K. If I move the file back to the mission directory and load it in a mission, it crashes Torque.
So...
How do I:
- Get the files to save in the correct spot.
- Get them to save with the correct size.
- Load them back once they're in a sub-directory.
Thanks!
--Bryan
#75
Example
$terrainDir= "fps/data/terrains";
$missionDir= "fps/data/missions";
Or
$terrainDir= "fps/data/maps";
$terrainDir= "fps/data/maps";
I have no problem. Fix both variables and look if it works now.
Have you set the detail texture of your terrain manager?
This is how it has to be:
greetings
Daniel
06/11/2002 (2:34 am)
You have to set $terrainDir and $missionDir.Example
$terrainDir= "fps/data/terrains";
$missionDir= "fps/data/missions";
Or
$terrainDir= "fps/data/maps";
$terrainDir= "fps/data/maps";
I have no problem. Fix both variables and look if it works now.
Have you set the detail texture of your terrain manager?
This is how it has to be:
new TerrainManager(TerrainMgr) {
rotation = "1 0 0 0";
scale = "1 1 1";
numBlocksWide = "2";
numBlocksHigh = "1";
squareSize = "8";
detailTexture = "~/data/world/detail/detail01.png";
};
new SimGroup(Terrain) {
new TerrainBlock() {
detailTexture = "~/data/world/detail/detail01.png";
terrainFile = "./terrain0.ter";
locked = "true";
lockFile = "false";
preserveFile = "false";
};
new TerrainBlock() {
detailTexture = "~/data/world/detail/detail01.png";
terrainFile = "./terrain1.ter";
locked = "true";
lockFile = "false";
preserveFile = "false";
};
};greetings
Daniel
#76
I have implemented this new code about saving terrain into my project. it works, but just for the mis file.
I doesn't look like he saves the terrain. I don't know what i'm doing wrong. I can't find a failure in the code
i propably made. So, can anyone help me?
Thanks
06/12/2002 (10:46 pm)
HI AllI have implemented this new code about saving terrain into my project. it works, but just for the mis file.
I doesn't look like he saves the terrain. I don't know what i'm doing wrong. I can't find a failure in the code
i propably made. So, can anyone help me?
Thanks
#77
Does your code save the edited terrains now? My code don't want to. I made the changes
fi developer said. And it seems to work, i don't get an error. But it doesn't save the terrain. It doesn't even
tuch the terrainfiles. Maybe you can upload the code with these changes?
That's absolutly strange. I don't know where to search anymore.
06/23/2002 (11:16 pm)
Bryan:Does your code save the edited terrains now? My code don't want to. I made the changes
fi developer said. And it seems to work, i don't get an error. But it doesn't save the terrain. It doesn't even
tuch the terrainfiles. Maybe you can upload the code with these changes?
That's absolutly strange. I don't know where to search anymore.
#78
06/23/2002 (11:38 pm)
Sorry for the obvious question, but have you checked to make sure the files aren't set as read only?
#79
Make sure it is true after you have modified the terrain.
greetings
Daniel
06/24/2002 (8:34 am)
Are you sure your TerrainManager did not break ETerrainEditor.isDirty ??Make sure it is true after you have modified the terrain.
greetings
Daniel
#80
Much thanks again.
06/25/2002 (7:56 am)
Thank you guys, I will double check that. There has to be a error somewhere in there. I will find it :)Much thanks again.
Torque 3D Owner Marco Meier
Slickware Games
Something new about the save/load function? I've tryied to do it myself. Well it saved, but till now, i can't
open it again. This sucks. Bryan, you've made any progress?