Game Development Community

1.5: WaterBlock placement bug if terrain.squareSize > 8

by Fyodor -bank- Osokin · in Torque Game Engine · 11/09/2006 (6:45 pm) · 9 replies

I'm in TGE 1.5, and since waterBlock is different from 1.4.x this is only about 1.5.

If you want to use a terrain with square size > 8, you could have problems.
I was trying to find out where/what is exactly, but can't get into the full logic in code.
So, the description:
I've made simple mission with squareSize of terrain = 16
Placed waterBlock for a full-size (pos= -2048 -2048, size= 4096 4096) so it covers everything by water. All looks fine. Save. in .mis there is correct values.
Now let's restart the mission. If now we go into debugger we will see that void WaterBlock::UpdateFluidRegion( void ) function called few times with different (!!) values. So, passed mTerrainHalfSize from the first call is incorrect and our P.x / P.y is set at the end at -1024 -1024 instead of -2048 -2048.
The P.x and P.y is being updated on mFluid.SetInfo() call, where our variables are changed (X0, Y0 inside).

So, upon restart we have our waterBlock moved from the original location.
And, here comes another bug. If we look to the big water that all around, and our "main" block disappears from our view, the whole water also disappears.
more info in next thread

#1
11/10/2006 (11:27 am)
I have noticed the mysteriously disappearing water blocks as well in 1.5.

I am wondering if there is any comment from Garage Games on this.
#2
02/16/2007 (2:15 pm)
Okay. this is about the water "placement" being reset.
I've found that it's because the UpdateFluidRegion(); is called from the beggining of bool WaterBlock::onAdd(), so, this time the parameters are "default" for terrain and water is reset.

The bool WaterBlock::onSceneAdd( SceneGraph* pGraph ) (where the terrain attributes are gathered and set to waterBlock) is called AFTER the first call of UpdateFluidRegion.

So, as far as I understand the whole structure with waterBlock, the first call to UpdateFluidRegion is done just to be sure that all parameters are set, in case of terrain is not found (addToScene/onSceneAdd call from onAdd).

Not sure if it cause anything, but for me the easest (and safest?) method will be to have a bool waterBlock.initialized variable. So, right after addToScene(); call I do the check, if it's not been set (which means no terrain in mission) I'm going to call the UpdateFluidRegion();

Will play with it now and post results here.

@Robert: only the "copies" (tiles) of waterblocks are disappearing. the original "tile" is always rendered.
And yeah, there is also a bug when the setting "tiled" on waterblock is not working, but that's complitely another story.
#3
02/16/2007 (2:54 pm)
Okay. tested in local and multiplayer - all seems to be working as expected.
the fix:
in engine/terrain/waterBlock.h file

after U32 mTerrainSquareSize; line, INSERT:
bool                isFluidUpdated;         ///< to check if UpdateFluidRegion needs to be called

in engine/terrain/waterBlock.cc file:

in WaterBlock::WaterBlock(), at any place (I put it at the end), add:
isFluidUpdated = false;

in void WaterBlock::UpdateFluidRegion( void ), at the end of function add:
isFluidUpdated = true;

at the beginning of bool WaterBlock::onAdd() function REMOVE (or just comment out) the following:
if( !isClientObject() )
   {
       // Make sure that the Fluid has had a chance to tweak the values.
       UpdateFluidRegion();
   }
at the end of same function ADD:
if( !isClientObject() && !isFluidUpdated )
    {
        // Make sure that the Fluid has had a chance to tweak the values.
        UpdateFluidRegion();
    }

Do rebuild your project and the water placement should work as expected. If any bugs found - please post here.
#4
02/18/2007 (12:10 pm)
Thanks bank! Does this fix also work when squareSize <= 8? That seemed to work before.

Can a few people verify this fixed the issue for them? If so I'll check the changes into head.
#5
02/18/2007 (2:26 pm)
John, yes, it works with <=8.
Actually, this fix makes water to work with any size of terrain.
#6
04/04/2007 (2:34 pm)
This is going into 1.51 head right?
#7
04/09/2007 (4:40 pm)
No, it's not in 1.5.1
#9
08/04/2007 (11:02 am)
Update: There are some minor issues when using for gameplay more than one (main) tile of terrain and waterblocks. E.g. we have terrain with squareSize of 4, but we use 9 tiles (1 main + 1 by every side/corner).

If you need to behave it as it should (replicators placing objects correctly) be sure on mission editor, on the list your WaterBlock objects need to be BEFORE the TerrainBlock. Actualy, I would recommend you to move your terrainBlock to the end of object list.
The server sends objects to client from "last to first", so if client receives waterBlock packets before terrainBlock, you can see your fx*replicators spawn items at wrong position.

P.S. May be it will be nice to modify terrain code, so it will call (upon create) all existing waterBlocks to update their values.