Game Development Community

Converting to C++ from Script

by Eric Sapp · in iTorque 2D · 09/19/2009 (2:42 pm) · 1 replies

Hey,

I'm starting to optimize my game and have been doing research on converting math intensive scripts to C++. So my first objective is to convert my watered down gravity script to C++. Basically it's this:

function Object::Gravity( %this )
{

%newVel = %this.getLinearVelocityY() + 9.8;
%this.setLinearVelocityY( %newVel );

if (%this.getVisible() == true)
{
%this.GravityUpdate = %this.schedule( 75 , "Gravity" );
}

}


This is the kind of script that should be converted correct? What's the proper process for converting something like this? Thanks!

-Eric

#1
09/19/2009 (4:45 pm)
> This is the kind of script that should be converted correct?

so this is executing about 13 times per second ? that's not very much, and i'd be surprised if you got much performance boost from converting it to C.

the slowdown with script is in interpreting the script itself, not in the actual math. i would look instead for loops in script or pieces of script which execute very frequently. for example, if you had a loop which iterated over all the objects in the scene checking for what object type they are, that would likely be a slow-down.