Mercurial > projects > chipmunkd
diff trunk/chipmunkd/chipmunk.d @ 13:c03a41d47b60
- finished all constraints properties
- implemented cpAssertWarn the mixin way
author | Extrawurst |
---|---|
date | Fri, 03 Dec 2010 21:38:01 +0100 |
parents | 7ebbd4d05553 |
children | df4ebc8add66 |
line wrap: on
line diff
--- a/trunk/chipmunkd/chipmunk.d Fri Dec 03 01:01:39 2010 +0100 +++ b/trunk/chipmunkd/chipmunk.d Fri Dec 03 21:38:01 2010 +0100 @@ -2,60 +2,47 @@ // written in the D programming language module chipmunkd.chipmunk; -//#ifndef CHIPMUNK_HEADER -//#define CHIPMUNK_HEADER -// -//#ifdef __cplusplus -//extern "C" { -//#endif -// -//void cpMessage(const char *message, const char *condition, const char *file, int line, int isError); -//#ifdef NDEBUG -// #define cpAssertWarn(condition, message) -//#else -// #define cpAssertWarn(condition, message) if(!(condition)) cpMessage(message, #condition, __FILE__, __LINE__, 0) -//#endif + +import std.stdio; +import std.string:format; +import std.conv:to; + +void +cpMessage(string message, string condition, string file, int line, bool isError) +{ + stderr.writeln(.format("%s:%s", isError ? "Aborting due to Chipmunk error" : "Chipmunk warning", message)); + stderr.writeln(.format("\tFailed condition: %s", condition)); + stderr.writeln(.format("\tSource: %s(%s)", file, line)); + + if(isError) {debug{assert(false);}else{asm{int 3;}}} +} debug { - //TODO: - //void cpAssertWarn(bool condition, string message){if(condition) cpMessage(message,condition,__FILE__,__LINE__, 0);} - void cpAssertWarn(bool condition, string message){} + template cpAssertWarn(string _condition, string message,string _f = __FILE__,int _l=__LINE__) + { + enum cpAssertWarn = "if(!("~_condition~"))"~ + "cpMessage(\""~message~"\",\""~_condition~"\",r\""~_f~"\","~to!string(_l)~",false);"; + } } else { - void cpAssertWarn(bool condition, string message){} + template cpAssertWarn(string _condition, string message,string _f = __FILE__,int _l=__LINE__) + { + enum cpAssertWarn = ""; + } } -// +//TODO //#ifdef NDEBUG // #define cpAssert(condition, message) //#else // #define cpAssert(condition, message) if(!(condition)) cpMessage(message, #condition, __FILE__, __LINE__, 1) //#endif // + import chipmunkd.chipmunk_types_h; import core.stdc.stdlib; -// -//#ifndef INFINITY -// #ifdef _MSC_VER -// union MSVC_EVIL_FLOAT_HACK -// { -// unsigned __int8 Bytes[4]; -// float Value; -// }; -// static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}}; -// #define INFINITY (INFINITY_HACK.Value) -// #endif -// -// #ifdef __GNUC__ -// #define INFINITY (__builtin_inf()) -// #endif -// -// #ifndef INFINITY -// #define INFINITY (1e1000) -// #endif -//#endif enum INFINITY = cpFloat.infinity; @@ -92,17 +79,6 @@ enum cpHashValue CP_HASH_COEF = cast(cpHashValue)(3344921057uL); // ulong to uint ?? static cpHashValue CP_HASH_PAIR(T)(T A, T B) {return (cast(cpHashValue)(A)*CP_HASH_COEF ^ cast(cpHashValue)(B)*CP_HASH_COEF);} -void -cpMessage(string message, string condition, string file, int line, int isError) -{ - //TODO: - //fprintf(stderr, (isError ? "Aborting due to Chipmunk error: %s\n" : "Chipmunk warning: %s\n"), message); - //fprintf(stderr, "\tFailed condition: %s\n", condition); - //fprintf(stderr, "\tSource:%s:%d\n", file, line); - - if(isError) abort(); -} - extern const char *cpVersionString; void cpInitChipmunk() { @@ -166,9 +142,3 @@ { return m*(width*width + height*height)/12.0f; } - -//#ifdef __cplusplus -//} -//#endif -// -//#endif