Previous Blog Next Blog
Prev/Next Blog
by date

My Programming Cheatsheet

My Programming Cheatsheet
Name:James Ford
Date Posted:Jul 28, 2008
Rating:4.8 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for James Ford

Blog post
//---------------------------
// Programming Notes
//---------------------------

These are my "programming notes", a txt tile I keep on my desktop for things I looked up one to many times and decided to write down.


const F32*
means the F32 is const, you can't change its value but you can change the pointer
const *F32
means the pointer is const, you cannot change the pointer, but you can change the F32


Rotate vector by an angle ( in 3D this is rotating around the z axis )
x' = cos(theta)*x - sin(theta)*y
y' = sin(theta)*x + cos(theta)*y


EndMission / EndGame script function flowchart
loadmission() -> endmission()
destroyserver() -> endmission()
endMission() -> onmissionended() -> endgame() -> resetmission()
GameConnection::onDeath() -> cycleGame() -> onCycleExec() -> endgame()


How to get a sequence name by its index.
const char* seqName = mShape->getName( thread->sequence->nameIndex );


How to set a conditional breakpoint using string comparisions.
if ( dStrcmp( seqName, "chew" ) == 0 )
{
int t = 0; // set breakpoint here
}


This is how you get a nodes name:
S32 nodeNameIdx = mShapeInstance->getShape()->nodes[cast.node].nameIndex;
const UTF8 *nodeName = mShapeInstance->getShape()->getName( nodeNameIdx );


To regenerate intellisense:
Close VStudio, delete .ncb and .suo files in the solution folder, reopen and build project.


description of Player::getTransform MatrixF columns
column0 = rightvec
column1 = forwardVec
column2 = upVec
column3 = position


Calculate Size of a Terrain Block
squaresize x texelsPerMeter = terrain length ( or width )


UP is POSITIVE Z
Higher objects have a more POSITIVE z position


qSort itemA - itemB is ASCENDING - lowest val is element0
itemB - itemA is DESCENDING - highest val is element0


To post a url link with and give it a different visible name.
{url=VisibleName}www.url.com{/url}
But use square brackets.


PI = 180 Degrees

sin(x) = len(opposite) / (len(hypotenuse)

cos(x) = len(adjacent) / len(hypotenuse)

tan(x) = len(opposite) / len(adjacent)

Recent Blog Posts
List:09/28/08 - Behavior Trees in TGB Experiment
07/28/08 - My Programming Cheatsheet
05/24/08 - Be the Dinosaur - AI Postmortem
09/07/07 - TGB 1.5.1 Tutorial Pack In Development

Submit ResourceSubmit your own resources!

Peter Simard   (Jul 28, 2008 at 19:06 GMT)
Bookmarked!

Brian Richardson   (Jul 28, 2008 at 22:43 GMT)   Resource Rating: 5
That conditional breakpoint note is good beyond string conditions. Sometimes using the debugger's conditional breakpoints is too slow, just doing a manual one in code like that works better.

Danni   (Jul 29, 2008 at 01:20 GMT)   Resource Rating: 5
Or! Conditional breakpoint;

if ( dStrcmp( seqName, "chew" ) == 0 )
__asm int 03h;


Nice post :D

Orion Elenzil   (Jul 29, 2008 at 05:28 GMT)
i do the exact same thing for conditional breakpoints,
but just to help me remember to remove it later, i usually name the variable "breakable" instead of "t".

Tony Richards   (Jul 29, 2008 at 12:18 GMT)
Nice tips, but you got one of the const examples incorrect.

Quote:


const *F32
means the pointer is const, you cannot change the pointer, but you can change the F32



The correct way to declare a pointer that is const but the value to which it points is not const:

F32 * const


The rule of thumb is the const modifier modifies that which precedes it, and if there's nothing modifiable that precedes it then it modifies that which follows it.

You really should always follow the rule of thumb without the exceptions and always make the const modifier modify that which precedes it. Of course, old habits die hard and I don't always do it the right way either. :-P


// the method is const
int Foo::method() const;

// The method returns a const int, but the method is not const.
const int Foo::method();

// The method returns a pointer to a const char
const char* Foo::method();

// And this is the preferred method, for consistency reasons
// The method returns a pointer to a const char
char const * Foo::method();

// This method returns a const pointer to a non-const char
char * const Foo::method();

// This method returns a const pointer to a const char
const char * const Foo::method();

// And this is the preferred method, for consistency reasons
// This method returns a const pointer to a const char
char const * const Foo::method();



@Danni - Sorry, I have to disagree with your suggestion... cute trick, but it's a really bad idea.

Why? Eventually you will forget to remove the offending line... and what's worse is if you remember to remove it but you're having a bad day and you do something like this:


if ( dStrcmp( seqName, "chew" ) == 0 )
// __asm int 03h;


Oops!

The example given is definitely a lot better.

if ( dStrcmp( seqName, "chew" ) == 0 )
{
int t = 0; // set breakpoint here
}


The breakpoint doesn't exist except in the debugger, and if you forget to remove it then no harm done. The only thing that might happen is you degrade the performance.

Danni   (Jul 30, 2008 at 23:51 GMT)   Resource Rating: 5
Hmm, you never had a breakpoint not fire when clearly the code executed? Not sure why but I occasionaly see it with templates.

I would also rather have it break something noticable than forget it is there. :)

You must be a member and be logged in to either append comments or rate this resource.