Game Development Community

TGE/T2D/TSE #defines

by Gary "ChunkyKs" Briggs · in Torque Game Engine · 06/02/2005 (2:34 pm) · 6 replies

Heya,

I'm currently messing about with my ODEScript stuff, and I'm at a point where I'd like conditional compilation based on which Torque flavor it's being compiled with.
For example, this bit would only be compiled with TGE and [I assume] TSE:

ConsoleMethod(tdBody, UpdateShape, void, 2, 2,
	"() "
	"Update the transform and velocity of the associated shape") {
	
	const dReal *p;

	ShapeBase *s;
	s = (ShapeBase *)Sim::findObject(object->shapeid);
	if(NULL == s) return;
	
	p = dBodyGetLinearVel(object->body);
	s->SetVelocity(Point3F(p[0],p[1],p[2]);
	
	p = dBodyGetPosition(object->body);
	s->setPosition(Point3F(p[0],p[1],p[2]);
}

Yes, I know it's not finished.
Gary (-;

#1
06/02/2005 (3:35 pm)
Yea something like a TORQUE_GE, TORQUE_2D, and TORQUE_SE defines set in the preprocessor settings plus a getTorqueVersion() and a getTorqueVersionString() global which returns a number and a pretty formatted string respectively.

I asked for something similar before and didn't get a response. =(
#2
06/02/2005 (3:40 pm)
Good idea. Am bringing this up at next programmer meeting.
#3
06/02/2005 (6:40 pm)
Having thought about this a little, I'd like to respectfully add some requests/thoughts:

1) I'd like to have them all additive. For example, I'd like to do the following:
#ifdef T2D
do_stuff_with_fxSceneObject2D();
#endif

#ifdef TGE
do_stuff_with_shapeBase();
#endif

Explicitly for the case where someone has added T2D to TGE, and I want both.

2) Version number availability, as Tom S asked for. I'd quite like them to be available as #defines, though. Functions are just bonus candy. Major and minor numbers separately available would also be nice:

#ifdef TGE
Con::printf("TGE Features At Least Version %i.%2i", TGE_MAJOR, TGE_MINOR);
#endif

#ifdef T2D
Con::printf("T2D Features At Least Version %i.%2i", T2D_MAJOR, T2D_MINOR);
#endif

for anyone who wants a simpler comparison [eg #if TGE_VERSION >= 1.3], a third define like:
#define TGE_VERSION TGE_MAJOR.TGE_MINOR
would be good.

3) For convenience, a common, distinct, prefix is nice; names like TAP_TGE, TAP_T2D, TAP_TSE are easier to work with than TORQUE_2D, TORQUE_GE, TORQUE_SE [since TORQUE_ is a prefix used for, for eg, TORQUE_DEBUG], or T2D, TGE, and TSE


Of course, as Ben said in IRC, "Why don't we leave [him] alone and let the Torque maintainers work this out among themselves", but I just wanted to add my wishlist :-)

Thanks,
Gary (-;
#4
06/03/2005 (1:21 am)
Why the explosion of symbols? Why not just put the version in the base symbol?

#define TGE 0x103

If you need to break this down:

#define TGE_MAJOR (TGE >> 8)
#define TGE_MINOR (TGE & 0xFF)

You can use macro stringizing to get these into a pretty string.

More useful would be a feature bit vector. As TGE/TSE evolve new bits are added to indicate support for new features. Then you can test for a feature before trying to use it, possibly throwing an #error if your base source is too old or including your own implementation. GG could release the bit names in advance of implementation so we could disable our versions once they make it into the official code. Here's one: GG_FEATURE_THREADSAFE_ALLOC. ;)
#5
06/03/2005 (1:29 pm)
Agreed, I've written some code that could easily work between TSE/TGE with a simple processor define. I just defined it myself for my projects, but it'd be useful for resources and whatnot.
#6
06/03/2005 (1:38 pm)
Well aside from that, and i've mentioned similar issues to Ben before, cosmetic changes to source code should be avoided between TGE and TSE. Like reformatting brackets and spaces in code on TGE and not TSE ensures that my patch will not work across both when otherwise it would just fine.

Maybe one day we'll see a unification of the core parts of the code bases so that this issue goes away. I welcome the Torque Core Platform. =)