Game Development Community

dev|Pro Game Development Curriculum

Porting to iTorque2D from TGB (C++)

by Pedro Vicente · 04/20/2011 (1:32 pm) · 0 comments

Hello everyone

This is a resource where I posted some issues found while porting the Game of Life Tutorial (a C++ TGB 1.7.5 application) to iTorque2D. The port was pretty much straightforward, except for the items below. For all of them workarounds or fixes are shown.
ITEM 1: Using STL, a change in source is needed
ITEM 3: an assertion in the engine while trying to define several font sizes
ITEM 4: mouse events disabled when using onLevelLoaded

TDN Tutorial:
tdn.garagegames.com/wiki/TGB/Tutorials/The_Game_of_Life

The Game of Life Tutorial Help in the forums
www.garagegames.com/community/forums/viewthread/125451

Thread in the forums for issues that were found and not solved
EDIT: Currently all issues were solved
www.garagegames.com/community/forums/viewthread/125582

ITEM 1: Using the C++ Standard Template Library (STL)

Both the Torque Memory Manager and STL redefine operator new, so when trying to use both, you will get a linking error.

FIX: The fix is simple and the Torque developers already did almost for you. Just uncomment the lines in WinMemory.cc regarding enabling the Torque Memory Manager
//Uncomment the ifdef and endif lines for it to work, and define TORQUE_DISABLE_MEMORY_MANAGER
#ifndef TORQUE_DISABLE_MEMORY_MANAGER
#ifdef new
#undef new
#endif
//--------------------------------------
void* FN_CDECL operator new(dsize_t, void* ptr)
{
   return (ptr);
}
#endif

ITEM 2: Message Con::Evaluate() failed

When calling a ConsoleMethod in my app that is trigered by a keyboard ActionMap, in iTorque2D , this message is printed
Con::Evaluate() failed

This seems to be a false error message. It originates from CodeBlock::compileExec in codeBlock.cc (TGB 1.7.5 does not include the print message call)
if(!statementList)
   {
	   Con::errorf( "Con::Evaluate(%s) failed", string );
      delete this;
      return "";
   }


ITEM 3: use of several font sizes in t2dTextObject


When using the function below to create a t2dTextObject object, iTorque2D asserts with the error

Couldn't not create character data for Times New Roman Bold_193
Fatal: (enginesourcedglbitmappng.cc @ 54) PNG read catastrophic error!

function Game::MakeTextObject( %this, %text )
{
    %obj = new t2dTextObject() 
    { 
        scenegraph      = %this;
        text            = "";
        textAlign       = "Center";
        font            = "Times New Roman Bold";
        fontSizes       = "193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208";
        hideOverflow    = false;
        autoSize        = true;
        Visible         = true;
    };

    %obj.setBlendColor( 0.0, 1.0, 0.0, 1.0 );
    %obj.setSize( 3 );
    %obj.setLayer( 1 );
    %obj.text = %text;
    return %obj;
}

SOLUTION: change the fontSizes to

fontSizes       = "208";

ITEM 4. mouse events disabled when onLevelLoaded is defined


The mouse cursor disappears and the application does not respond to any mouse events when adding a onLevelLoaded function (class is a t2dSceneGraph instance)

function CaTutorialPart2::onLevelLoaded( %this, %scenegraph )
{
}

FIX: Do not use onLevelLoaded
NOTE: system is Windows