Enums in game script?
by Shawn LeBlanc · in Torque Game Builder · 03/11/2007 (9:31 pm) · 22 replies
Hello,
I was wondering if there's any way in script to create C/C++ style enumerations, like:
enum
{
STATE_IDLE,
STATE_MOVING,
STATE_SEARCHING,
STATE_DEAD
} eState;
Right now, a temporary method I'm using is to use functions, like:
function StateIdle() {return 0;}
function StateMoving() {return 1;};
function StateSearching() {return 2;};
function StateDead() {return 3;}
It's not quite perfect, but it does avoid using magic numbers everywhere in my code.
Thanks!
Shawn
I was wondering if there's any way in script to create C/C++ style enumerations, like:
enum
{
STATE_IDLE,
STATE_MOVING,
STATE_SEARCHING,
STATE_DEAD
} eState;
Right now, a temporary method I'm using is to use functions, like:
function StateIdle() {return 0;}
function StateMoving() {return 1;};
function StateSearching() {return 2;};
function StateDead() {return 3;}
It's not quite perfect, but it does avoid using magic numbers everywhere in my code.
Thanks!
Shawn
#22
After reading a good portion of her comments on the matter, I'm all for keeping TGB games as tight as possible ... if you can shave a CPU cycle here, and a memory byte there ... it'll all eventually add up into Framerates ...
Some other tricks, from Amanda's posts, were not switching between image formats (mixing JPG and PNG files, for example) and not switching between solid and transparent files (even if the image should be solid, toss a single transparent pixel so its treated as a transparent image) -- these things allowed games to function properly, and even (from my understanding) helped with performance in the end ...
Lots of odd things here and there make a difference, it's a matter of finding them ... and recording them ...
And, as always, a lot of performance tuning just comes from knowing certain things up front ... it's extremely hard to write your game without thinking about performance and then later tweak it for performance ... not fun at all ...
Best to just do things right, the first time around ... unless your a super-coder ... at which point, you either always do things right the first time, or your able to redo them so quickly, doing them wrong the first time around doesn't bother you ;)
03/14/2007 (12:43 pm)
@Dennis, an asinine amount of global vars, will effect performance ... granted, depending on system specs, and what not, you may not be able to notice the hit ... some of Amanda's posts (Amaranthia) refer specifically to tuning TGB games for low-end systems as she has a fairly decent test market to work with due to her success ... and she found that a large number of casual gamers, even in her test base, were using low-end systems that had severely reduced system specs ranging from Low-memory (128 or below), Old or Poorly Implemented "on-board" Video Cards (Intel boards on Corporate workstations, for example), and less-then-new CPUs ... After reading a good portion of her comments on the matter, I'm all for keeping TGB games as tight as possible ... if you can shave a CPU cycle here, and a memory byte there ... it'll all eventually add up into Framerates ...
Some other tricks, from Amanda's posts, were not switching between image formats (mixing JPG and PNG files, for example) and not switching between solid and transparent files (even if the image should be solid, toss a single transparent pixel so its treated as a transparent image) -- these things allowed games to function properly, and even (from my understanding) helped with performance in the end ...
Lots of odd things here and there make a difference, it's a matter of finding them ... and recording them ...
And, as always, a lot of performance tuning just comes from knowing certain things up front ... it's extremely hard to write your game without thinking about performance and then later tweak it for performance ... not fun at all ...
Best to just do things right, the first time around ... unless your a super-coder ... at which point, you either always do things right the first time, or your able to redo them so quickly, doing them wrong the first time around doesn't bother you ;)
Torque Owner Dennis Harrington