Better coding and why
by David Dougher · in Torque Game Engine Advanced · 06/05/2004 (12:15 pm) · 6 replies
At one time I saw parts of the torque engine coded like this...
ConsoleMethod( WaterBlock, toggleWireFrame, void, 2, 2, "()")
{
WaterBlock* pWaterBlock = static_cast(object);
if( pWaterBlock )
{
pWaterBlock->mFluid.m_ShowWire = !(pWaterBlock->mFluid.m_ShowWire);
if( pWaterBlock->mFluid.m_ShowWire )
Con::printf( "WaterBlock wire frame ENABLED" );
else
Con::printf( "WaterBlock wire frame DISABLED" );
}
}
Then it was later changed to to...
ConsoleMethod( WaterBlock, toggleWireFrame, void, 2, 2, "()")
{
if( object )
{
object->mFluid.m_ShowWire = !(object->mFluid.m_ShowWire);
if( object->mFluid.m_ShowWire )
Con::printf( "WaterBlock wire frame ENABLED" );
else
Con::printf( "WaterBlock wire frame DISABLED" );
}
}
Now I see it reappear again in TSE. Is there any advantage/disadvantage to either method? It seems like the latter would be more efficient, but perhpas the compiler just throws away the cast as unnecessary?
ConsoleMethod( WaterBlock, toggleWireFrame, void, 2, 2, "()")
{
WaterBlock* pWaterBlock = static_cast
if( pWaterBlock )
{
pWaterBlock->mFluid.m_ShowWire = !(pWaterBlock->mFluid.m_ShowWire);
if( pWaterBlock->mFluid.m_ShowWire )
Con::printf( "WaterBlock wire frame ENABLED" );
else
Con::printf( "WaterBlock wire frame DISABLED" );
}
}
Then it was later changed to to...
ConsoleMethod( WaterBlock, toggleWireFrame, void, 2, 2, "()")
{
if( object )
{
object->mFluid.m_ShowWire = !(object->mFluid.m_ShowWire);
if( object->mFluid.m_ShowWire )
Con::printf( "WaterBlock wire frame ENABLED" );
else
Con::printf( "WaterBlock wire frame DISABLED" );
}
}
Now I see it reappear again in TSE. Is there any advantage/disadvantage to either method? It seems like the latter would be more efficient, but perhpas the compiler just throws away the cast as unnecessary?
About the author
Owner - Pariah Games, Adjunct Professor - Bristol Community College, Mentor - Game Design - Met School Newport, Mentor - Game Design - Met School Providence
#2
It would be really cool to set up a new framework and then have various features implemented by different community members. Ie. a ps 1.1 implementation that uses just cubemap reflection, one that uses real reflection, various wave type implementations, ps 2.0 and 3.0 versions, etc.
I'll probably do it this way anyhow, checking in the various bits that work as I get them done.
Water is going to have some really tricky cases though like using a 'real' reflection on water that has a significant amplitude (causing it to index out of the frame buffer). And then getting that working properly with objects that are half submerged. Ughh.
06/05/2004 (11:00 pm)
The current water block is going to get tossed and re-written. I'm toying with the idea of specing out exactly what we need and giving you heavyweights a shot at implementing it. It would be really cool to set up a new framework and then have various features implemented by different community members. Ie. a ps 1.1 implementation that uses just cubemap reflection, one that uses real reflection, various wave type implementations, ps 2.0 and 3.0 versions, etc.
I'll probably do it this way anyhow, checking in the various bits that work as I get them done.
Water is going to have some really tricky cases though like using a 'real' reflection on water that has a significant amplitude (causing it to index out of the frame buffer). And then getting that working properly with objects that are half submerged. Ughh.
#3
Sent Tim G. a patch file today that should bring you guys up to date with most of the changes (that still apply) since the branch you took to start TSE. Used some nice file comparison tools I have here and it was good exercise to get an idea of where you guys "pulled and plugged" to get TSE working and still keep most of the engine intact. Nice job on preserving most of the header files intact.
Should work on a copy of the current HEAD and I included some extra material in the letter and in the patch file itself.
06/06/2004 (4:09 am)
Ben and Brian,Sent Tim G. a patch file today that should bring you guys up to date with most of the changes (that still apply) since the branch you took to start TSE. Used some nice file comparison tools I have here and it was good exercise to get an idea of where you guys "pulled and plugged" to get TSE working and still keep most of the engine intact. Nice job on preserving most of the header files intact.
Should work on a copy of the current HEAD and I included some extra material in the letter and in the patch file itself.
#4
Thanks for the patch, though! :)
06/06/2004 (12:12 pm)
For TSE patches, Brian and I are better targets than Tim.Thanks for the patch, though! :)
#5
06/07/2004 (3:55 am)
Sounds good to me - and I will do that in the future. However, when I went to the patch site it said that all "general" patches should be e-mailed to Tim.
#6
06/07/2004 (8:11 am)
Tim is the normal patch guy, so I totally understand the confusion. Don't worry about it.
Associate Kyle Carter
The latter method is more correct, since object is already cast to the correct value.
Good eye.