That Megaterrain edge bug from forever ago... Wasn't there a fix for it? Or am I crazy?
by Mitovo · in Torque Game Engine Advanced · 10/04/2012 (8:06 pm) · 13 replies
There was a bug with the megaterrain in TGEA where you'd get those "walls" along the last row/column of vertices if the corresponding terrain on the other side of the map was set at a higher elevation. Likewise, it would drop if the other side was lower, but wouldn't likely be as much of an eyesore. It was apparently a left-over bit from the tiling terrain code.
There were several threads I found about the topic and I saw several references to a fix that was released for it, but in all my searching I have never been able to find that fix. Was that fix ever posted anywhere? I'd like to give it a shot as I'd really still like to use TGEA for a personal project of mine, but that terrain bug is really making it a headache for me.
While I'm on the topic, there's another odd thing with Megaterrains in that when I'm sculpting the landscape across terrain blocks, it seems to stop at the border of the current terrain block, and doesn't "blend" over into the next one. The end result being that the terrain blocks don't line up and, with all the editing and tweaking I try to do, I can't get them to ever line up again. Is there a way to remedy or otherwise deal with that?
I know T3D is the latest and greatest, and it's now under MIT license and all. I just can't quite "click" with it. TGE and of course TGEA has always just clicked with me better, only held back by the strange quirks and glitches, such a the above-mentioned terrain issues. I still am convinced that with the right art assets, TGEA can look great, and it has great performance which is a bonus.
So yeah... I'd like to try and find hat fix for the terrain and apply it if at all possible. I'll even delve into those dark scary waters that is installing an IDE, editing the source file(s) and compiling it to get it work.
Thank you kindly.
There were several threads I found about the topic and I saw several references to a fix that was released for it, but in all my searching I have never been able to find that fix. Was that fix ever posted anywhere? I'd like to give it a shot as I'd really still like to use TGEA for a personal project of mine, but that terrain bug is really making it a headache for me.
While I'm on the topic, there's another odd thing with Megaterrains in that when I'm sculpting the landscape across terrain blocks, it seems to stop at the border of the current terrain block, and doesn't "blend" over into the next one. The end result being that the terrain blocks don't line up and, with all the editing and tweaking I try to do, I can't get them to ever line up again. Is there a way to remedy or otherwise deal with that?
I know T3D is the latest and greatest, and it's now under MIT license and all. I just can't quite "click" with it. TGE and of course TGEA has always just clicked with me better, only held back by the strange quirks and glitches, such a the above-mentioned terrain issues. I still am convinced that with the right art assets, TGEA can look great, and it has great performance which is a bonus.
So yeah... I'd like to try and find hat fix for the terrain and apply it if at all possible. I'll even delve into those dark scary waters that is installing an IDE, editing the source file(s) and compiling it to get it work.
Thank you kindly.
About the author
#2
WARNING: This isn't stock TGEA, so you don't have the ISSINGLEPLAYER preference to avoid a painting bug crash the edge fix causes. My work was only multiplayer, so the only time I used SP mode was for editing. My solution to the paint crash bug was to test for SP mode and skip the fix. I don't have a suggestion on how to do the same in stock TGEA, maybe some other preference is available.
...
On the subject of terrains that become unglued from each other, when that happens the megaterrain is broken.
When a megaterrain is created, each terrain is given data that links it to the neighboring terrains. Renaming terrains is one way I know of that the link becomes broken. Once broken, the terrains can no longer be edited as a single megaterrain.
Another way I know of to break a megaterrain is to edit the shape of a terrain individually, save it, and then try to reload it as part of a megaterrain. It is possible to paint individually, I do this often.
...
Hope this helps.
10/07/2012 (9:28 am)
Here's what I have for the terrain edge walls. I never saw any published fix for this.WARNING: This isn't stock TGEA, so you don't have the ISSINGLEPLAYER preference to avoid a painting bug crash the edge fix causes. My work was only multiplayer, so the only time I used SP mode was for editing. My solution to the paint crash bug was to test for SP mode and skip the fix. I don't have a suggestion on how to do the same in stock TGEA, maybe some other preference is available.
in terrData.cpp
U16 TerrainFile::getHeight(U32 x, U32 y, bool tiling)
{
if ((x == TerrainBlock::BlockSize) && mEdgeTerrainFiles[0] != NULL)
return mEdgeTerrainFiles[0]->getHeight(0,y);
if ((y == TerrainBlock::BlockSize) && mEdgeTerrainFiles[1] != NULL)
return mEdgeTerrainFiles[1]->getHeight(x,0);
//KENHACK if at the edge and NOT linked to another terrain
//KENHACK BUGFIX don't flatten if single player to avoid editor crash painting.
if ((x == TerrainBlock::BlockSize) && (!Con::getBoolVariable("$Py::ISSINGLEPLAYER")))
return 0;
if ((y == TerrainBlock::BlockSize) && (!Con::getBoolVariable("$Py::ISSINGLEPLAYER")))
return 0;
return mHeightMap[(x & TerrainBlock::BlockMask) + ((y & TerrainBlock::BlockMask) << TerrainBlock::BlockShift)];
}...
On the subject of terrains that become unglued from each other, when that happens the megaterrain is broken.
When a megaterrain is created, each terrain is given data that links it to the neighboring terrains. Renaming terrains is one way I know of that the link becomes broken. Once broken, the terrains can no longer be edited as a single megaterrain.
Another way I know of to break a megaterrain is to edit the shape of a terrain individually, save it, and then try to reload it as part of a megaterrain. It is possible to paint individually, I do this often.
...
Hope this helps.
#3
Thank you for posting that!
So, if I understand correctly (bear in mind, I'm a non-programmer, so this is all new and unfamiliar territory for me, but I'm willing to learn as much as I can), I need to locate the terrData.cpp file, add that, or replace the existing 20 lines with it, and then recompile?
My intention is to have a game that's multiplayer, so the ISSINGLEPLAYER bit you talk about shouldn't be an issue - at least assuming I understand what that all means.
What would the process be for using your fix? Loading one version of TGEA with your fix for editing, and then loading another for playtesting/publishing? If I understand correctly, I would edit it in the single-player mode (TGEA's default mode, if I'm not mistaken), and then run it in Multiplayer mode?
Also, is that dependent on any specific version of TGEA, or will it work with any of them?
Thanks again for your help!
10/07/2012 (8:42 pm)
Hi there, Ken.Thank you for posting that!
So, if I understand correctly (bear in mind, I'm a non-programmer, so this is all new and unfamiliar territory for me, but I'm willing to learn as much as I can), I need to locate the terrData.cpp file, add that, or replace the existing 20 lines with it, and then recompile?
My intention is to have a game that's multiplayer, so the ISSINGLEPLAYER bit you talk about shouldn't be an issue - at least assuming I understand what that all means.
What would the process be for using your fix? Loading one version of TGEA with your fix for editing, and then loading another for playtesting/publishing? If I understand correctly, I would edit it in the single-player mode (TGEA's default mode, if I'm not mistaken), and then run it in Multiplayer mode?
Also, is that dependent on any specific version of TGEA, or will it work with any of them?
Thanks again for your help!
#4
In the above, click "view plain" and a pop-up version will come up without any formatting.
Start notepad from windows. Copy and paste the code from the popup into notepad, close and save. Suggested: TGEAwallfix01.txt
Open the TGEAwallfix01.txt with notepad.
Find this part:
&& (!Con::getBoolVariable("$Py::ISSINGLEPLAYER"))
and remove it. It is in there twice, remove both.
Save as TGEAwallfix02.txt and close it.
...
Assuming you have a compiler and your preferred version of TGEA (mine happens to be 1.7.1) but this section of the code should be identical or very close in anything up to and including 1.8.2.
If you haven't already, do a "Build Solution" and make sure your code compiles correctly and the game runs.
In the compiler, do CTRL-F which opens search, set search type to "Full Solution", make sure case sensitive is off, then search for
U16 TerrainFile::getHeight(
That should find the function you need to modify. It must be in the file terrData.cpp or it's not the right one.
Here's a step by step:
From notepad, open the TGEAwallfix02.txt
Compare the code in notepad to the function in the compiler. A perfect fit will be the //KENHACK lines and 4 lines following that (not counting empties) will be new, but everything else matches.
Copy and paste those lines into the source, save, "Build Solution", and test.
That should make the walls go away.
Problem is, when you go to paint, it will (might) crash.
Easiest solution is to comment out what you added, rebuild, paint, then when done painting, put the code back in, build, and the fix will be back in place.
...
Shout if I missed any questions. Glad to help out. I spent a ton of time working with TGEA inside of the Torque MMO Kit, so I have some knowledge in a few areas, but very little about stock Torque itself.
10/08/2012 (3:16 pm)
Good to hear back from you.In the above, click "view plain" and a pop-up version will come up without any formatting.
Start notepad from windows. Copy and paste the code from the popup into notepad, close and save. Suggested: TGEAwallfix01.txt
Open the TGEAwallfix01.txt with notepad.
Find this part:
&& (!Con::getBoolVariable("$Py::ISSINGLEPLAYER"))
and remove it. It is in there twice, remove both.
Save as TGEAwallfix02.txt and close it.
...
Assuming you have a compiler and your preferred version of TGEA (mine happens to be 1.7.1) but this section of the code should be identical or very close in anything up to and including 1.8.2.
If you haven't already, do a "Build Solution" and make sure your code compiles correctly and the game runs.
In the compiler, do CTRL-F which opens search, set search type to "Full Solution", make sure case sensitive is off, then search for
U16 TerrainFile::getHeight(
That should find the function you need to modify. It must be in the file terrData.cpp or it's not the right one.
Here's a step by step:
From notepad, open the TGEAwallfix02.txt
Compare the code in notepad to the function in the compiler. A perfect fit will be the //KENHACK lines and 4 lines following that (not counting empties) will be new, but everything else matches.
Copy and paste those lines into the source, save, "Build Solution", and test.
That should make the walls go away.
Problem is, when you go to paint, it will (might) crash.
Easiest solution is to comment out what you added, rebuild, paint, then when done painting, put the code back in, build, and the fix will be back in place.
...
Shout if I missed any questions. Glad to help out. I spent a ton of time working with TGEA inside of the Torque MMO Kit, so I have some knowledge in a few areas, but very little about stock Torque itself.
#5
if ((x == TerrainBlock::BlockSize))
return 0;
The outer loop is stepping through a 256 x 256 terrain heightmap. When x is at the edge of a block but not linked to another terrain, return 0 as the elevation rather than wrap around, get the wrong height and end up with a wall going up at the edge. The 0 elevation is the lowest possible, so the wall goes down and doesn't get noticed.
10/08/2012 (3:22 pm)
Oh, here's how it works:if ((x == TerrainBlock::BlockSize))
return 0;
The outer loop is stepping through a 256 x 256 terrain heightmap. When x is at the edge of a block but not linked to another terrain, return 0 as the elevation rather than wrap around, get the wrong height and end up with a wall going up at the edge. The 0 elevation is the lowest possible, so the wall goes down and doesn't get noticed.
#6
Thanks for all the info and help! Can't say that all makes sense to me just yet, but I imagine as I mess around with it, it'll start to come together. At least that's the plan.
I did get the engine to compile using MS Visual Studio 2008 Express (C++ version). So that's cool. Now I just need to find and figure out the edits you've recommended.
Will let ya know how it turns out one way or another.
Thanks again!
Edit: Was going to separate my project from the main TGEA folder tree, but apparently that won't work :-/. No biggie, since it seems to be its own isolated project anyway.
10/08/2012 (4:53 pm)
Hey there, Ken.Thanks for all the info and help! Can't say that all makes sense to me just yet, but I imagine as I mess around with it, it'll start to come together. At least that's the plan.
I did get the engine to compile using MS Visual Studio 2008 Express (C++ version). So that's cool. Now I just need to find and figure out the edits you've recommended.
Will let ya know how it turns out one way or another.
Thanks again!
Edit: Was going to separate my project from the main TGEA folder tree, but apparently that won't work :-/. No biggie, since it seems to be its own isolated project anyway.
#7
It doesn't have any of the other info you provided, including the hack. It's just those couple lines.
Is that only 'cause it's a "clean" file, and perhaps you're thinking of it as it was after you added your modification to it? Or is there other stuff that should be there?
To make sure I'm looking at the right section, the section right below it starts with:
10/08/2012 (5:32 pm)
Hm, okay so this is what I found in terrData.cppU16 TerrainBlock::getHeight(U32 x, U32 y) const
{
return mFile->getHeight( x, y );
}It doesn't have any of the other info you provided, including the hack. It's just those couple lines.
Is that only 'cause it's a "clean" file, and perhaps you're thinking of it as it was after you added your modification to it? Or is there other stuff that should be there?
To make sure I'm looking at the right section, the section right below it starts with:
Point2I TerrainBlock::getGridPos( const Point3F& worldPos )
#8
Try putting the 4 lines above the return mFile-> line. If it compiles it might work correctly.
10/08/2012 (8:08 pm)
That looks right. I'm guessing this is newer than 1.7.1. They made a bunch of changes in 1.8.n versions. Can I ask what version so I can check the source?Try putting the 4 lines above the return mFile-> line. If it compiles it might work correctly.
#9
Which 4 lines am I copying? The KenHack ones, or the ones before that?
I went ahead and tried both, and neither seem to be working. It won't compile. Unless I'm somehow doing something wrong somewhere - which wouldn't be at all surprising :)
10/09/2012 (5:03 am)
I'm using 1.8.2.Which 4 lines am I copying? The KenHack ones, or the ones before that?
I went ahead and tried both, and neither seem to be working. It won't compile. Unless I'm somehow doing something wrong somewhere - which wouldn't be at all surprising :)
#10
I'm doing a stock 182 build with this patch. Will confirm it compiles and behaves as it should.
edit: confirmed. Compiled clean, no wall at edge.
10/09/2012 (12:34 pm)
Found it. They moved the code to an inline. That means we have to move the patch there also.I'm doing a stock 182 build with this patch. Will confirm it compiles and behaves as it should.
in terrData.h
inline U16 getHeight(U32 x, U32 y) const
{
if ((x == TerrainBlock::BlockSize) && mEdgeTerrainFiles[0] != NULL)
return mEdgeTerrainFiles[0]->getHeight(0,y);
if ((y == TerrainBlock::BlockSize) && mEdgeTerrainFiles[1] != NULL)
return mEdgeTerrainFiles[1]->getHeight(x,0);
//PATCH forces height to zero at terrain edge to avoid walls.
if (x == TerrainBlock::BlockSize)
return 0;
if (y == TerrainBlock::BlockSize)
return 0;
//END PATCH
return mHeightMap[(x & TerrainBlock::BlockMask) + ((y & TerrainBlock::BlockMask) << TerrainBlock::BlockShift)];
}edit: confirmed. Compiled clean, no wall at edge.
#11
I created a new terrain, edited along the edges and, sure enough, the opposite edge was messed up. Uncommented your patch, recompiled, and it's fine. Re-applied the comments, re-compiled, and the walls are back. Very interesting.
Better yet, I tried editing it in the patched version and it was fine. Even editing along the modified edges. No crashing. The parts I edited were fine, except for that last row of vertices, which stayed at 0. Maybe it's just really intermittent?
I also see what you do, and I guess it's only along those two edges that the problem occurs? Interesting. I never noticed that before. I was too busy trying to deal with it lol.
So thank you much! Very very cool fix, and now I can actually move on and start doing some serious editing!
10/09/2012 (4:03 pm)
And we have a winner!I created a new terrain, edited along the edges and, sure enough, the opposite edge was messed up. Uncommented your patch, recompiled, and it's fine. Re-applied the comments, re-compiled, and the walls are back. Very interesting.
Better yet, I tried editing it in the patched version and it was fine. Even editing along the modified edges. No crashing. The parts I edited were fine, except for that last row of vertices, which stayed at 0. Maybe it's just really intermittent?
I also see what you do, and I guess it's only along those two edges that the problem occurs? Interesting. I never noticed that before. I was too busy trying to deal with it lol.
So thank you much! Very very cool fix, and now I can actually move on and start doing some serious editing!
#12
I'm programming now to the end of November to get a working alpha of my project (sort of a multiplayer Morrowind). Shout if I can be of help.
10/09/2012 (4:12 pm)
Outstanding. Have fun!I'm programming now to the end of November to get a working alpha of my project (sort of a multiplayer Morrowind). Shout if I can be of help.
#13
Thanks again!
10/09/2012 (5:20 pm)
Oooh... Multiplayer Morrowind. That sounds very intriguing. Especially since I just started playing that again with the Overhaul 3 installed. It looks like a completely new game.Thanks again!
Torque Owner Mitovo