Thursday, 3 June 2010

Compiler directives...

Well this may sound strange to some but I have been looking at compiler directives and conditional compiling this week, the main reason for all this is simply to allow for one source compiles on all system much like the excellent language BlitzMax that can do almost everything you can imagine but at the moment is limited to the platforms its on (this is changing and I salute Mark for a great effort at tackling the mobile market).

One way I have been successful is like this:

#if defined( __APPLE__ )

//Apple platform defines

#if TARGET_OS_IPHONE

#define TargetPlatform "IPhone"

#elif TARGET_IPHONE_SIMULATOR

#define TargetPlatform "IPhone Simulator"

#elif TARGET_OS_EMBEDDED

#define TargetPlatform "Embedded OS"

#endif

#else

//everything else

#if defined( __WINDOWS__ )

#define TargetPlatform "Windows"

#elif defined( __LINUX__ )

#define TargetPlatform "Linux"

#endif

#endif


#if defined( __APPLE__ )

//Apple stuff here

#else

//Objective C stuffs for apps that dont have the stuff

struct CGRect {

CGPoint origin;

CGSize size;

};

typedef struct CGRect CGRect;


struct CGPoint {

CGFloat x;

CGFloat y;

};

typedef struct CGPoint CGPoint;


struct CGSize {

CGFloat width;

CGFloat height;

};

typedef struct CGSize CGSize;


typedef float CGFloat; // 32-bit

typedef double CGFloat; // 64-bit

#endif


Well as you can see its quite simple I would have done the sys/sysctl.h route but it seems not all C++ compilers accept that file which is 'very' tricky indeed. Without that header you can call sysctlbyname to get system information this I can work around with conditional compiling which im working towards now :).


I have also been adding to JJ Jumper this week too and I will be adding more graphics and code to it over the coming week too the main reason is its another Jewel in the Graveyard Dogs crown. I have been looking at getting the 3d stuff there too BUT I also want the porting done as much as possible too this will take second place to getting the games we have planned out there so it will be coming but will take time to do.


More soon...

No comments:

Post a Comment

blogdigger