diff --git a/MultiLang/English.cpp b/MultiLang/English.cpp index dd446a3e..4dbe6626 100644 --- a/MultiLang/English.cpp +++ b/MultiLang/English.cpp @@ -209,14 +209,15 @@ static constexpr MultiLang::string debugger_cant_access_appdata = "Couldn't acce static constexpr MultiLang::string debugger_cant_create_folder = "Couldn't create a folder for the preferences!\nThe IDE will use the default values."; static constexpr MultiLang::string debugger_empty_ini = "blitzide.ini is empty!\nDefaults will be set."; static constexpr char credits[] = - "Programming and design: Mark Sibly\r\n" - "Keeping this thing alive: juanjp600, Saalvage, VaneBrain, AestheticalZ and ZiYueCommentary\r\n" - ".INI loading using a modified version of \"IniPP\", originally by Matthias C. M. Troffaes\r\n" - "Documentation: Mark Sibly, Simon Harrison, Paul Gerfen, Shane Monroe and the Blitz Doc Team\r\n" - "Testing and support: James Boyd, Simon Armstrong and the Blitz Dev Team\r\n" - "Image loader courtesy of FreeImage by Floris van den berg\r\n"; +"Programming and design: Mark Sibly\r\n" +"Keeping this thing alive: juanjp600, Saalvage, VaneBrain, AestheticalZ and ZiYueCommentary\r\n" +".INI loading using a modified version of \"IniPP\", originally by Matthias C. M. Troffaes\r\n" +"Documentation: Mark Sibly, Simon Harrison, Paul Gerfen, Shane Monroe and the Blitz Doc Team\r\n" +"Testing and support: James Boyd, Simon Armstrong and the Blitz Dev Team\r\n" +"Image loader courtesy of FreeImage by Floris van den berg\r\n"; static constexpr MultiLang::string title_release = " - Release Version\n\n"; static constexpr MultiLang::string unable_start_program = "Unable to start program! A required module could not be started."; static constexpr MultiLang::string program_ended = "Program has ended."; static constexpr MultiLang::string unknown_exception_thrown = "Unknown/non-standard exception thrown!"; -static constexpr MultiLang::string startup_error = "Startup Error: {0}"; \ No newline at end of file +static constexpr MultiLang::string startup_error = "Startup Error: {0}"; +static constexpr MultiLang::string array_index_out_of_bounds = "Array index out of bounds."; \ No newline at end of file diff --git a/MultiLang/SimplifiedChinese.cpp b/MultiLang/SimplifiedChinese.cpp index 8a59c4be..a90ceea6 100644 --- a/MultiLang/SimplifiedChinese.cpp +++ b/MultiLang/SimplifiedChinese.cpp @@ -221,4 +221,5 @@ static constexpr char credits[] = static constexpr MultiLang::string unable_start_program = "无法启动程序!无法启动所需模块"; static constexpr MultiLang::string program_ended = "程序已结束"; static constexpr MultiLang::string unknown_exception_thrown = "未知/非标准异常抛出!"; -static constexpr MultiLang::string startup_error = "启动错误:{0}"; \ No newline at end of file +static constexpr MultiLang::string startup_error = "启动错误:{0}"; +static constexpr MultiLang::string array_index_out_of_bounds = "数组索引超出范围"; \ No newline at end of file diff --git a/MultiLang/TraditionalChinese.cpp b/MultiLang/TraditionalChinese.cpp index 8b979c60..33bf385d 100644 --- a/MultiLang/TraditionalChinese.cpp +++ b/MultiLang/TraditionalChinese.cpp @@ -218,4 +218,5 @@ static constexpr char credits[] = static constexpr MultiLang::string unable_start_program = "無法啟動程序!無法啟動所需模塊"; static constexpr MultiLang::string program_ended = "程序已結束"; static constexpr MultiLang::string unknown_exception_thrown = "未知/非標準異常拋出!"; -static constexpr MultiLang::string startup_error = "啟動錯誤:{0}"; \ No newline at end of file +static constexpr MultiLang::string startup_error = "啟動錯誤:{0}"; +static constexpr MultiLang::string array_index_out_of_bounds = "數組索引超出範圍"; \ No newline at end of file diff --git a/bbruntime/basic.cpp b/bbruntime/basic.cpp index 87c39068..f2e99a69 100644 --- a/bbruntime/basic.cpp +++ b/bbruntime/basic.cpp @@ -21,6 +21,9 @@ static const int STR_NEW_INC = 512; //current data ptr static BBData* dataPtr; +//why i have to do this??? +static int dummyPtr; + //chunks of mem - WHAT THE FUCK WAS I ON?!?!?!? I dont know, mark //static list memBlks; @@ -60,9 +63,9 @@ static void insertStr(BBStr* str, BBStr* next) { } void* BBStr::operator new(size_t size) { - if(freeStrs.next == &freeStrs) { + if (freeStrs.next == &freeStrs) { BBStr* t = (BBStr*)bbMalloc(sizeof(BBStr) * STR_NEW_INC); - for(int k = 0; k < STR_NEW_INC; ++k) insertStr(t++, &freeStrs); + for (int k = 0; k < STR_NEW_INC; ++k) insertStr(t++, &freeStrs); } BBStr* t = freeStrs.next; removeStr(t); insertStr(t, &usedStrs); @@ -70,7 +73,7 @@ void* BBStr::operator new(size_t size) { } void BBStr::operator delete(void* q) { - if(!q) return; + if (!q) return; BBStr* t = (BBStr*)q; removeStr(t); insertStr(t, &freeStrs); } @@ -161,39 +164,39 @@ void* _bbVecAlloc(BBVecType* type) { } void _bbVecFree(void* vec, BBVecType* type) { - if(type->elementType->type == BBTYPE_STR) { + if (type->elementType->type == BBTYPE_STR) { BBStr** p = (BBStr**)vec; - for(int k = 0; k < type->size; ++p, ++k) { - if(*p) _bbStrRelease(*p); + for (int k = 0; k < type->size; ++p, ++k) { + if (*p) _bbStrRelease(*p); } } - else if(type->elementType->type == BBTYPE_OBJ) { + else if (type->elementType->type == BBTYPE_OBJ) { BBObj** p = (BBObj**)vec; - for(int k = 0; k < type->size; ++p, ++k) { - if(*p) _bbObjRelease(*p); + for (int k = 0; k < type->size; ++p, ++k) { + if (*p) _bbObjRelease(*p); } } bbFree(vec); } -void _bbVecBoundsEx() { - RTEX(MultiLang::array_bounds_ex); +void _bbVecBoundsEx(std::string function) { + ErrorLog(function, MultiLang::array_bounds_ex); } void _bbUndimArray(BBArray* array) { - if(void* t = array->data) { - if(array->elementType == BBTYPE_STR) { + if (void* t = array->data) { + if (array->elementType == BBTYPE_STR) { BBStr** p = (BBStr**)t; int size = array->scales[array->dims - 1]; - for(int k = 0; k < size; ++p, ++k) { - if(*p) _bbStrRelease(*p); + for (int k = 0; k < size; ++p, ++k) { + if (*p) _bbStrRelease(*p); } } - else if(array->elementType == BBTYPE_OBJ) { + else if (array->elementType == BBTYPE_OBJ) { BBObj** p = (BBObj**)t; int size = array->scales[array->dims - 1]; - for(int k = 0; k < size; ++p, ++k) { - if(*p) _bbObjRelease(*p); + for (int k = 0; k < size; ++p, ++k) { + if (*p) _bbObjRelease(*p); } } bbFree(t); @@ -203,8 +206,8 @@ void _bbUndimArray(BBArray* array) { void _bbDimArray(BBArray* array) { int k; - for(k = 0; k < array->dims; ++k) ++array->scales[k]; - for(k = 1; k < array->dims; ++k) { + for (k = 0; k < array->dims; ++k) ++array->scales[k]; + for (k = 1; k < array->dims; ++k) { array->scales[k] *= array->scales[k - 1]; } int size = array->scales[array->dims - 1]; @@ -212,8 +215,8 @@ void _bbDimArray(BBArray* array) { memset(array->data, 0, size * 4); } -void _bbArrayBoundsEx() { - RTEX("Array index out of bounds."); +void _bbArrayBoundsEx(std::string function) { + ErrorLog(function, MultiLang::array_index_out_of_bounds); } static void unlinkObj(BBObj* obj) { @@ -229,10 +232,10 @@ static void insertObj(BBObj* obj, BBObj* next) { } BBObj* _bbObjNew(BBObjType* type) { - if(type->free.next == &type->free) { + if (type->free.next == &type->free) { int obj_size = sizeof(BBObj) + type->fieldCnt * 4; BBObj* o = (BBObj*)bbMalloc(obj_size * OBJ_NEW_INC); - for(int k = 0; k < OBJ_NEW_INC; ++k) { + for (int k = 0; k < OBJ_NEW_INC; ++k) { insertObj(o, &type->free); o = (BBObj*)((char*)o + obj_size); } @@ -242,8 +245,8 @@ BBObj* _bbObjNew(BBObjType* type) { o->type = type; o->ref_cnt = 1; o->fields = (BBField*)(o + 1); - for(int k = 0; k < type->fieldCnt; ++k) { - switch(type->fieldTypes[k]->type) { + for (int k = 0; k < type->fieldCnt; ++k) { + switch (type->fieldTypes[k]->type) { case BBTYPE_VEC: o->fields[k].VEC = _bbVecAlloc((BBVecType*)type->fieldTypes[k]); break; @@ -258,12 +261,12 @@ BBObj* _bbObjNew(BBObjType* type) { } void _bbObjDelete(BBObj* obj) { - if(!obj) return; + if (!obj) return; BBField* fields = obj->fields; - if(!fields) return; + if (!fields) return; BBObjType* type = obj->type; - for(int k = 0; k < type->fieldCnt; ++k) { - switch(type->fieldTypes[k]->type) { + for (int k = 0; k < type->fieldCnt; ++k) { + switch (type->fieldTypes[k]->type) { case BBTYPE_STR: _bbStrRelease(fields[k].STR); break; @@ -276,7 +279,7 @@ void _bbObjDelete(BBObj* obj) { } } std::map::iterator it = object_map.find(obj); - if(it != object_map.end()) { + if (it != object_map.end()) { handle_map.erase(it->second); object_map.erase(it); } @@ -287,9 +290,9 @@ void _bbObjDelete(BBObj* obj) { void _bbObjDeleteEach(BBObjType* type) { BBObj* obj = type->used.next; - while(obj->type) { + while (obj->type) { BBObj* next = obj->next; - if(obj->fields) _bbObjDelete(obj); + if (obj->fields) _bbObjDelete(obj); obj = next; } } @@ -298,35 +301,65 @@ extern void bbDebugLog(BBStr* t); extern void bbStop(); void _bbObjRelease(BBObj* obj) { - if(!obj || --obj->ref_cnt) return; + if (!obj || --obj->ref_cnt) return; unlinkObj(obj); insertObj(obj, &obj->type->free); --unrelObjCnt; } void _bbObjStore(BBObj** var, BBObj* obj) { - if(obj) ++obj->ref_cnt; //do this first incase of self-assignment + if (obj) ++obj->ref_cnt; //do this first incase of self-assignment _bbObjRelease(*var); *var = obj; } +BBObj* _bbObjLoad(void* var) { + BBObj** var1 = (BBObj**)var; + if (var1 && *var1) { + return *var1; + } + return 0; +} + +void* _bbFieldPtrAdd(void* var, int shft) { + //WHAT IS THIS POINTER ARITHMETIC + if ((BBObj*)var) { + char* retVal = (char*)(var); + for (int i = 0; i < shft; i++) { + retVal++; + } + return retVal; + } + ErrorLog("Field reference", MultiLang::null_obj_ex); + dummyPtr = 0; + return &dummyPtr; +} + int _bbObjCompare(BBObj* o1, BBObj* o2) { return (o1 ? o1->fields : 0) != (o2 ? o2->fields : 0); } BBObj* _bbObjNext(BBObj* obj) { + if (!obj) { + ErrorLog("ObjNext", MultiLang::null_obj_ex); + return 0; + } do { obj = obj->next; - if(!obj->type) return 0; - } while(!obj->fields); + if (!obj->type) return 0; + } while (!obj->fields); return obj; } BBObj* _bbObjPrev(BBObj* obj) { + if (!obj) { + ErrorLog("ObjPrev", MultiLang::null_obj_ex); + return 0; + } do { obj = obj->prev; - if(!obj->type) return 0; - } while(!obj->fields); + if (!obj->type) return 0; + } while (!obj->fields); return obj; } @@ -339,13 +372,29 @@ BBObj* _bbObjLast(BBObjType* type) { } void _bbObjInsBefore(BBObj* o1, BBObj* o2) { - if(o1 == o2) return; + if (!o1) { + ErrorLog("ObjInsBefore (o1)", MultiLang::null_obj_ex); + return; + } + if (!o2) { + ErrorLog("ObjInsBefore (o2)", MultiLang::null_obj_ex); + return; + } + if (o1 == o2) return; unlinkObj(o1); insertObj(o1, o2); } void _bbObjInsAfter(BBObj* o1, BBObj* o2) { - if(o1 == o2) return; + if (!o1) { + ErrorLog("ObjInsAfter (o1)", MultiLang::null_obj_ex); + return; + } + if (!o2) { + ErrorLog("ObjInsAfter (o2)", MultiLang::null_obj_ex); + return; + } + if (o1 == o2) return; unlinkObj(o1); insertObj(o1, o2->next); } @@ -371,24 +420,24 @@ int _bbObjEachNext2(BBObj** var) { } BBStr* _bbObjToStr(BBObj* obj) { - if(!obj || !obj->fields) return new BBStr("[NULL]"); + if (!obj || !obj->fields) return new BBStr("[NULL]"); static BBObj* root; static int recurs_cnt; - if(obj == root) return new BBStr("[ROOT]"); - if(recurs_cnt == 8) return new BBStr("...."); + if (obj == root) return new BBStr("[ROOT]"); + if (recurs_cnt == 8) return new BBStr("...."); ++recurs_cnt; BBObj* oldRoot = root; - if(!root) root = obj; + if (!root) root = obj; BBObjType* type = obj->type; BBField* fields = obj->fields; BBStr* s = new BBStr("["), * t; - for(int k = 0; k < type->fieldCnt; ++k) { - if(k) *s += ','; - switch(type->fieldTypes[k]->type) { + for (int k = 0; k < type->fieldCnt; ++k) { + if (k) *s += ','; + switch (type->fieldTypes[k]->type) { case BBTYPE_INT: t = _bbStrFromInt(fields[k].INT); *s += *t; delete t; break; @@ -396,7 +445,7 @@ BBStr* _bbObjToStr(BBObj* obj) { t = _bbStrFromFloat(fields[k].FLT); *s += *t; delete t; break; case BBTYPE_STR: - if(fields[k].STR) *s += '\"' + *fields[k].STR + '\"'; + if (fields[k].STR) *s += '\"' + *fields[k].STR + '\"'; else *s += "\"\""; break; case BBTYPE_OBJ: @@ -413,9 +462,9 @@ BBStr* _bbObjToStr(BBObj* obj) { } int _bbObjToHandle(BBObj* obj) { - if(!obj || !obj->fields) return 0; + if (!obj || !obj->fields) return 0; std::map::const_iterator it = object_map.find(obj); - if(it != object_map.end()) return it->second; + if (it != object_map.end()) return it->second; ++next_handle; object_map[obj] = next_handle; handle_map[next_handle] = obj; @@ -424,13 +473,13 @@ int _bbObjToHandle(BBObj* obj) { BBObj* _bbObjFromHandle(int handle, BBObjType* type) { std::map::const_iterator it = handle_map.find(handle); - if(it == handle_map.end()) return 0; + if (it == handle_map.end()) return 0; BBObj* obj = it->second; return obj->type == type ? obj : 0; } -void _bbNullObjEx() { - RTEX(MultiLang::null_obj_ex); +void _bbNullObjEx(std::string function) { + ErrorLog(function, MultiLang::null_obj_ex); } void _bbRestore(BBData* data) { @@ -438,32 +487,32 @@ void _bbRestore(BBData* data) { } int _bbReadInt() { - switch(dataPtr->fieldType) { - case BBTYPE_END:RTEX(MultiLang::out_of_data); return 0; + switch (dataPtr->fieldType) { + case BBTYPE_END:ErrorLog("ReadInt", MultiLang::out_of_data); return 0; case BBTYPE_INT:return dataPtr++->field.INT; case BBTYPE_FLT:return dataPtr++->field.FLT; case BBTYPE_CSTR:return atoi(dataPtr++->field.CSTR); - default:RTEX(MultiLang::bad_data_type); return 0; + default:ErrorLog("ReadInt", MultiLang::bad_data_type); return 0; } } float _bbReadFloat() { - switch(dataPtr->fieldType) { - case BBTYPE_END:RTEX(MultiLang::out_of_data); return 0; + switch (dataPtr->fieldType) { + case BBTYPE_END:ErrorLog("ReadFloat", MultiLang::out_of_data); return 0; case BBTYPE_INT:return dataPtr++->field.INT; case BBTYPE_FLT:return dataPtr++->field.FLT; case BBTYPE_CSTR:return atof(dataPtr++->field.CSTR); - default:RTEX(MultiLang::bad_data_type); return 0; + default:ErrorLog("ReadFloat", MultiLang::bad_data_type); return 0; } } BBStr* _bbReadStr() { - switch(dataPtr->fieldType) { - case BBTYPE_END:RTEX(MultiLang::out_of_data); return 0; + switch (dataPtr->fieldType) { + case BBTYPE_END:ErrorLog("ReadStr", MultiLang::out_of_data); return 0; case BBTYPE_INT:return new BBStr(itoa(dataPtr++->field.INT)); case BBTYPE_FLT:return new BBStr(ftoa(dataPtr++->field.FLT)); case BBTYPE_CSTR:return new BBStr(dataPtr++->field.CSTR); - default:RTEX(MultiLang::bad_data_type); return 0; + default:ErrorLog("ReadStr", MultiLang::bad_data_type); return 0; } } @@ -496,7 +545,7 @@ bool basic_create() { } bool basic_destroy() { - while(usedStrs.next != &usedStrs) delete usedStrs.next; + while (usedStrs.next != &usedStrs) delete usedStrs.next; handle_map.clear(); object_map.clear(); return true; @@ -530,6 +579,8 @@ void basic_link(void (*rtSym)(const char* sym, void* pc)) { rtSym("_bbObjDeleteEach", _bbObjDeleteEach); rtSym("_bbObjRelease", _bbObjRelease); rtSym("_bbObjStore", _bbObjStore); + rtSym("_bbObjLoad", _bbObjLoad); + rtSym("_bbFieldPtrAdd", _bbFieldPtrAdd); rtSym("_bbObjCompare", _bbObjCompare); rtSym("_bbObjNext", _bbObjNext); rtSym("_bbObjPrev", _bbObjPrev); diff --git a/bbruntime/basic.h b/bbruntime/basic.h index 6db2a4f4..b834e15c 100644 --- a/bbruntime/basic.h +++ b/bbruntime/basic.h @@ -104,11 +104,11 @@ BBStr* _bbStrConst(const char* s); void _bbDimArray(BBArray* array); void _bbUndimArray(BBArray* array); -void _bbArrayBoundsEx(); +void _bbArrayBoundsEx(std::string function); void* _bbVecAlloc(BBVecType* type); void _bbVecFree(void* vec, BBVecType* type); -void _bbVecBoundsEx(); +void _bbVecBoundsEx(std::string function); BBObj* _bbObjNew(BBObjType* t); void _bbObjDelete(BBObj* obj); @@ -127,7 +127,7 @@ int _bbObjCompare(BBObj* o1, BBObj* o2); BBStr* _bbObjToStr(BBObj* obj); int _bbObjToHandle(BBObj* obj); BBObj* _bbObjFromHandle(int handle, BBObjType* type); -void _bbNullObjEx(); +void _bbNullObjEx(std::string function); void _bbRestore(BBData* data); int _bbReadInt(); diff --git a/bbruntime/bbaudio.cpp b/bbruntime/bbaudio.cpp index fc30a061..3a28409c 100644 --- a/bbruntime/bbaudio.cpp +++ b/bbruntime/bbaudio.cpp @@ -4,10 +4,8 @@ gxAudio* gx_audio; -static inline void debugSound(gxSound* s) { - if(debug) { - if(!gx_audio->verifySound(s)) RTEX(MultiLang::sound_not_exist); - } +static inline void debugSound(gxSound* s, std::string function) { + if (!gx_audio->verifySound(s)) ErrorLog(function, MultiLang::sound_not_exist); } static gxSound* loadSound(BBStr* f, bool use_3d) { @@ -25,38 +23,38 @@ gxSound* bbLoadSound(BBStr* f) { } void bbFreeSound(gxSound* sound) { - if(!sound) return; - debugSound(sound); + if (!sound) return; + debugSound(sound, "FreeSound"); gx_audio->freeSound(sound); } void bbLoopSound(gxSound* sound) { - if(!sound) return; - debugSound(sound); + if (!sound) return; + debugSound(sound, "LoopSound"); sound->setLoop(true); } void bbSoundPitch(gxSound* sound, int pitch) { - if(!sound) return; - debugSound(sound); + if (!sound) return; + debugSound(sound, "SoundPitch"); sound->setPitch(pitch); } void bbSoundVolume(gxSound* sound, float volume) { - if(!sound) return; - debugSound(sound); + if (!sound) return; + debugSound(sound, "SoundVolume"); sound->setVolume(volume); } void bbSoundPan(gxSound* sound, float pan) { - if(!sound) return; - debugSound(sound); + if (!sound) return; + debugSound(sound, "SoundPan"); sound->setPan(pan); } gxChannel* bbPlaySound(gxSound* sound) { - if(!sound) return 0; - debugSound(sound); + if (!sound) return 0; + debugSound(sound, "PlaySound"); return sound->play(); } @@ -69,32 +67,32 @@ gxChannel* bbPlayCDTrack(int track, int mode) { } void bbStopChannel(gxChannel* channel) { - if(!channel) return; + if (!channel) return; channel->stop(); } void bbPauseChannel(gxChannel* channel) { - if(!channel) return; + if (!channel) return; channel->setPaused(true); } void bbResumeChannel(gxChannel* channel) { - if(!channel) return; + if (!channel) return; channel->setPaused(false); } void bbChannelPitch(gxChannel* channel, int pitch) { - if(!channel) return; + if (!channel) return; channel->setPitch(pitch); } void bbChannelVolume(gxChannel* channel, float volume) { - if(!channel) return; + if (!channel) return; channel->setVolume(volume); } void bbChannelPan(gxChannel* channel, float pan) { - if(!channel) return; + if (!channel) return; channel->setPan(pan); } @@ -112,7 +110,7 @@ bool audio_create() { } bool audio_destroy() { - if(gx_audio) gx_runtime->closeAudio(gx_audio); + if (gx_audio) gx_runtime->closeAudio(gx_audio); gx_audio = 0; return true; } diff --git a/bbruntime/bbaudio.h b/bbruntime/bbaudio.h index 414ac3d5..ac7b33fc 100644 --- a/bbruntime/bbaudio.h +++ b/bbruntime/bbaudio.h @@ -6,15 +6,15 @@ extern gxAudio* gx_audio; -gxSound* bbLoadSound(BBStr* file); +gxSound* bbLoadSound(BBStr* file); void bbFreeSound(gxSound* sound); -gxChannel* bbPlaySound(gxSound* sound); +gxChannel* bbPlaySound(gxSound* sound); void bbLoopSound(gxSound* sound); void bbSoundPitch(gxSound* sound, int pitch); void bbSoundVolume(gxSound* sound, float volume); void bbSoundPan(gxSound* sound, float pan); -gxChannel* bbPlayMusic(BBStr* s, int mode); -gxChannel* bbPlayCDTrack(int track, int mode); +gxChannel* bbPlayMusic(BBStr* s, int mode); +gxChannel* bbPlayCDTrack(int track, int mode); void bbStopChannel(gxChannel* channel); void bbPauseChannel(gxChannel* channel); void bbResumeChannel(gxChannel* channel); diff --git a/bbruntime/bbbank.cpp b/bbruntime/bbbank.cpp index 345fd724..9a0e29bd 100644 --- a/bbruntime/bbbank.cpp +++ b/bbruntime/bbbank.cpp @@ -34,16 +34,16 @@ struct bbBank { static std::set bank_set; -static inline void debugBank(bbBank* b) { - if(debug) { - if(!bank_set.count(b)) RTEX(MultiLang::bank_not_exist); +static inline void debugBank(bbBank* b, std::string function) { + if (!bank_set.count(b)) { + ErrorLog(function, MultiLang::bank_not_exist); } } -static inline void debugBank(bbBank* b, int offset) { - if(debug) { - debugBank(b); - if (offset >= b->size) RTEX(MultiLang::offset_out_of_range); +static inline void debugBank(bbBank* b, std::string function, int offset) { + debugBank(b, function); + if (offset >= b->size) { + ErrorLog(function, MultiLang::offset_out_of_range); } } @@ -58,84 +58,76 @@ void bbFreeBank(bbBank* b) { } int bbBankSize(bbBank* b) { - debugBank(b); + debugBank(b, "BankSize"); return b->size; } void bbResizeBank(bbBank* b, int size) { - debugBank(b); + debugBank(b, "ResizeBank"); b->resize(size); } void bbCopyBank(bbBank* src, int src_p, bbBank* dest, int dest_p, int count) { - if(debug) { - debugBank(src, src_p + count - 1); - debugBank(dest, dest_p + count - 1); - } + debugBank(src, "CopyBank", src_p + count - 1); + debugBank(dest, "CopyBank", dest_p + count - 1); memmove(dest->data + dest_p, src->data + src_p, count); } int bbPeekByte(bbBank* b, int offset) { - debugBank(b, offset); + debugBank(b, "PeekByte", offset); return *(unsigned char*)(b->data + offset); } int bbPeekShort(bbBank* b, int offset) { - debugBank(b, offset + 1); + debugBank(b, "PeekShort", offset + 1); return *(unsigned short*)(b->data + offset); } int bbPeekInt(bbBank* b, int offset) { - debugBank(b, offset + 3); + debugBank(b, "PeekInt", offset + 3); return *(int*)(b->data + offset); } float bbPeekFloat(bbBank* b, int offset) { - debugBank(b, offset + 3); + debugBank(b, "PeekFloat", offset + 3); return *(float*)(b->data + offset); } void bbPokeByte(bbBank* b, int offset, int value) { - debugBank(b, offset); + debugBank(b, "PokeByte", offset); *(char*)(b->data + offset) = value; } void bbPokeShort(bbBank* b, int offset, int value) { - debugBank(b, offset); + debugBank(b, "PokeShort", offset); *(unsigned short*)(b->data + offset) = value; } void bbPokeInt(bbBank* b, int offset, int value) { - debugBank(b, offset); + debugBank(b, "PokeInt", offset); *(int*)(b->data + offset) = value; } void bbPokeFloat(bbBank* b, int offset, float value) { - debugBank(b, offset); + debugBank(b, "PokeFloat", offset); *(float*)(b->data + offset) = value; } int bbReadBytes(bbBank* b, bbStream* s, int offset, int count) { - if(debug) { - debugBank(b, offset + count - 1); - debugStream(s); - } + debugBank(b, "ReadBytes", offset + count - 1); + debugStream(s, "ReadBytes"); return s->read(b->data + offset, count); } int bbWriteBytes(bbBank* b, bbStream* s, int offset, int count) { - if(debug) { - debugBank(b, offset + count - 1); - debugStream(s); - } + debugBank(b, "WriteBytes", offset + count - 1); + debugStream(s, "WriteBytes"); return s->write(b->data + offset, count); } int bbCallDLL(BBStr* dll, BBStr* fun, bbBank* in, bbBank* out) { - if(debug) { - if(in) debugBank(in); - if(out) debugBank(out); - } + if(in) debugBank(in, "CallDLL"); + if(out) debugBank(out, "CallDLL"); int t = gx_runtime->callDll(*dll, *fun, in ? in->data : 0, in ? in->size : 0, out ? out->data : 0, out ? out->size : 0); diff --git a/bbruntime/bbblitz3d.cpp b/bbruntime/bbblitz3d.cpp index f16ce78b..3be5383f 100644 --- a/bbruntime/bbblitz3d.cpp +++ b/bbruntime/bbblitz3d.cpp @@ -57,122 +57,111 @@ static Loader_B3D loader_b3d; static std::map loader_mat_map; -static inline void debug3d() { - if(debug && !gx_scene) RTEX(MultiLang::graphics_not_set); +static inline void debug3d(std::string function) { + if (!gx_scene) { + ErrorLog(function, MultiLang::graphics_not_set); + } } -static inline void debugTexture(Texture* t) { - if(debug && !texture_set.count(t)) RTEX(MultiLang::texture_not_exist); +static inline void debugTexture(Texture* t, std::string function) { + if (!texture_set.count(t)) { + ErrorLog(function, MultiLang::texture_not_exist); + } } -static inline void debugBrush(Brush* b) { - if(debug && !brush_set.count(b)) RTEX(MultiLang::brush_not_exist); +static inline void debugBrush(Brush* b, std::string function) { + if (!brush_set.count(b)) { + ErrorLog(function, MultiLang::brush_not_exist); + } } -static inline void debugEntity(Entity* e) { - if(debug && !entity_set.count(e)) RTEX(MultiLang::entity_not_exist); +static inline void debugEntity(Entity* e, std::string function) { + if (!entity_set.count(e)) { + ErrorLog(function, MultiLang::entity_not_exist); + } } -static inline void debugParent(Entity* e) { - if(debug) { - debug3d(); - if(e && !entity_set.count(e)) RTEX(MultiLang::parent_entity_not_exist); - } +static inline void debugParent(Entity* e, std::string function) { + debug3d(function); + if (e && !entity_set.count(e)) ErrorLog(function, MultiLang::parent_entity_not_exist); } -static inline void debugMesh(MeshModel* m) { - if(debug) { - debugEntity(m); if(!m->getMeshModel()) RTEX(MultiLang::entity_not_mesh); - } +static inline void debugMesh(MeshModel* m, std::string function) { + debugEntity(m, function); + if (!m->getMeshModel()) ErrorLog(function, MultiLang::entity_not_mesh); } -static inline void debugObject(Object* o) { - if(debug) { - debugEntity(o); if(!o->getObject()) RTEX(MultiLang::entity_not_object); - } +static inline void debugObject(Object* o, std::string function) { + debugEntity(o, function); + if (!o->getObject()) ErrorLog(function, MultiLang::entity_not_object); } -static inline void debugColl(Object* o, int index) { - if(debug) { - debugObject(o); - if(index<1 || index>o->getCollisions().size()) RTEX(MultiLang::collision_out_of_range); - } +static inline void debugColl(Object* o, std::string function, int index) { + debugObject(o, function); + if (index<1 || index>o->getCollisions().size()) ErrorLog(function, MultiLang::collision_out_of_range); } -static inline void debugCamera(Camera* c) { - if(debug) { - debugEntity(c); if(!c->getCamera()) RTEX(MultiLang::entity_not_camera); - } +static inline void debugCamera(Camera* c, std::string function) { + debugEntity(c, function); + if (!c->getCamera()) ErrorLog(function, MultiLang::entity_not_camera); } -static inline void debugLight(Light* l) { - if(debug) { - debugEntity(l); if(!l->getLight()) RTEX(MultiLang::entity_not_light); - } +static inline void debugLight(Light* l, std::string function) { + debugEntity(l, function); + if (!l->getLight()) ErrorLog(function, MultiLang::entity_not_light); } -static inline void debugModel(Model* m) { - if(debug) { - debugEntity(m); if(!m->getModel()) RTEX(MultiLang::entity_not_model); - } +static inline void debugModel(Model* m, std::string function) { + debugEntity(m, function); + if (!m->getModel()) ErrorLog(function, MultiLang::entity_not_model); } -static inline void debugSprite(Sprite* s) { - if(debug) { - debugModel(s); if(!s->getSprite()) RTEX(MultiLang::entity_not_sprite); - } +static inline void debugSprite(Sprite* s, std::string function) { + debugModel(s, function); + if (!s->getSprite()) ErrorLog(function, MultiLang::entity_not_sprite); } -static inline void debugMD2(MD2Model* m) { - if(debug) { - debugModel(m); if(!m->getMD2Model()) RTEX(MultiLang::entity_not_md2_model); - } +static inline void debugMD2(MD2Model* m, std::string function) { + debugModel(m, function); + if (!m->getMD2Model()) ErrorLog(function, MultiLang::entity_not_md2_model); } -static inline void debugBSP(Q3BSPModel* m) { - if(debug) { - debugModel(m); if(!m->getBSPModel()) RTEX(MultiLang::entity_not_bsp_model); - } +static inline void debugBSP(Q3BSPModel* m, std::string function) { + debugModel(m, function); + if (!m->getBSPModel()) ErrorLog(function, MultiLang::entity_not_bsp_model); } -static inline void debugTerrain(Terrain* t) { - if(debug) { - debugModel(t); if(!t->getTerrain()) RTEX(MultiLang::entity_not_terrain); - } +static inline void debugTerrain(Terrain* t, std::string function) { + debugModel(t, function); + if (!t->getTerrain()) ErrorLog(function, MultiLang::entity_not_terrain); } -static inline void debugSegs(int n) { - if(debug) { - debug3d(); - if(n < 3 || n>50) RTEX(MultiLang::illegal_number_segments); - } +static inline void debugSegs(int n, std::string function) { + debug3d(function); + if (n < 3 || n>50) ErrorLog(function, MultiLang::illegal_number_segments); } -static inline void debugVertex(Surface* s, int n) { - if(debug) { - debug3d(); - if(n < 0 || n >= s->numVertices()) RTEX(MultiLang::vertex_out_of_range); - } +static inline void debugVertex(Surface* s, std::string function, int n) { + debug3d(function); + if (n < 0 || n >= s->numVertices()) ErrorLog(function, MultiLang::vertex_out_of_range); } -static inline void debugVertex(Surface* s, int n, int t) { - if(debug) { - debug3d(); - if (n < 0 || n >= s->numVertices()) RTEX(MultiLang::vertex_out_of_range); - if(t < 0 || t>1) RTEX(MultiLang::texture_coordinate_out_of_range); - } +static inline void debugVertex(Surface* s, std::string function, int n, int t) { + debug3d(function); + if (n < 0 || n >= s->numVertices()) ErrorLog(function, MultiLang::vertex_out_of_range); + if (t < 0 || t>1) ErrorLog(function, MultiLang::texture_coordinate_out_of_range); } static Entity* loadEntity(std::string t, int hint) { t = tolower(t); - int n = t.rfind("."); if(n == std::string::npos) return 0; + int n = t.rfind("."); if (n == std::string::npos) return 0; std::string ext = t.substr(n + 1); MeshLoader* l; - if(ext == "x") l = &loader_x; - else if(ext == "3ds") l = &loader_3ds; - else if(ext == "b3d") l = &loader_b3d; + if (ext == "x") l = &loader_x; + else if (ext == "3ds") l = &loader_3ds; + else if (ext == "b3d") l = &loader_b3d; else return 0; const Transform& conv = loader_mat_map[ext]; @@ -184,11 +173,11 @@ static Entity* loadEntity(std::string t, int hint) { } static void collapseMesh(MeshModel* mesh, Entity* e) { - while(e->children()) { + while (e->children()) { collapseMesh(mesh, e->children()); } - if(Model* p = e->getModel()) { - if(MeshModel* t = p->getMeshModel()) { + if (Model* p = e->getModel()) { + if (MeshModel* t = p->getMeshModel()) { t->transform(e->getWorldTform()); mesh->add(*t); } @@ -197,11 +186,11 @@ static void collapseMesh(MeshModel* mesh, Entity* e) { } static void insert(Entity* e) { - if(debug) entity_set.insert(e); + if (debug) entity_set.insert(e); e->setVisible(true); e->setEnabled(true); e->getObject()->reset(); - for(Entity* p = e->children(); p; p = p->successor()) { + for (Entity* p = e->children(); p; p = p->successor()) { insert(p); } } @@ -213,17 +202,17 @@ static Entity* insertEntity(Entity* e, Entity* p) { } static void erase(Entity* e) { - for(Entity* p = e->children(); p; p = p->successor()) { + for (Entity* p = e->children(); p; p = p->successor()) { erase(p); } - if(e->getListener()) listener = 0; - if(debug) entity_set.erase(e); + if (e->getListener()) listener = 0; + if (debug) entity_set.erase(e); } static Entity* findChild(Entity* e, const std::string& t) { - if(e->getName() == t) return e; - for(Entity* p = e->children(); p; p = p->successor()) { - if(Entity* q = findChild(p, t)) return q; + if (e->getName() == t) return e; + for (Entity* p = e->children(); p; p = p->successor()) { + if (Entity* q = findChild(p, t)) return q; } return 0; } @@ -238,60 +227,60 @@ void bbLoaderMatrix(BBStr* ext, float xx, float xy, float xz, float yx, float yy } int bbHWTexUnits() { - debug3d(); + debug3d("HWTexUnits"); return gx_scene->hwTexUnits(); } int bbGfxDriverCaps3D() { - debug3d(); + debug3d("GfxDriverCaps3D"); return gx_scene->gfxDriverCaps3D(); } void bbHWMultiTex(int enable) { - debug3d(); + debug3d("HWMultiTex"); gx_scene->setHWMultiTex(!!enable); } void bbWBuffer(int enable) { - debug3d(); + debug3d("WBuffer"); gx_scene->setWBuffer(!!enable); } void bbDither(int enable) { - debug3d(); + debug3d("Dither"); gx_scene->setDither(!!enable); } void bbAntiAlias(int enable) { - debug3d(); + debug3d("AntiAlias"); gx_scene->setAntialias(!!enable); } void bbWireFrame(int enable) { - debug3d(); + debug3d("WireFrame"); gx_scene->setWireframe(!!enable); } void bbAmbientLight(float r, float g, float b) { - debug3d(); + debug3d("AmbientLight"); Vector t(r * ctof, g * ctof, b * ctof); gx_scene->setAmbient(&(t.x)); } void bbClearCollisions() { - debug3d(); + debug3d("ClearCollisions"); world->clearCollisions(); } void bbCollisions(int src_type, int dest_type, int method, int response) { - debug3d(); + debug3d("Collisions"); world->addCollision(src_type, dest_type, method, response); } static int update_ms; void bbUpdateWorld(float elapsed) { - debug3d(); + debug3d("UpdateWorld"); #ifdef BETA update_ms = gx_runtime->getMilliSecs(); world->update(elapsed); @@ -303,12 +292,12 @@ void bbUpdateWorld(float elapsed) { } void bbCaptureWorld() { - debug3d(); + debug3d("CaptureWorld"); world->capture(); } void bbRenderWorld(float tween) { - debug3d(); + debug3d("RenderWorld"); //Should we remove this stuff? #ifdef BETA @@ -320,17 +309,17 @@ void bbRenderWorld(float tween) { extern int bbKeyHit(int); extern void bbDelay(int); bbDelay(0); - if(bbKeyHit(0x57)) { + if (bbKeyHit(0x57)) { stats_mode = !stats_mode; } - if(bbKeyHit(0x58)) { + if (bbKeyHit(0x58)) { //This stuff is broken. static int n; std::string t = "screenshot" + itoa(++n) + ".bmp"; bbSaveBuffer(bbBackBuffer(), new BBStr(t)); } - if(!stats_mode) return; + if (!stats_mode) return; tris = gx_scene->getTrianglesDrawn() - tris; @@ -369,7 +358,7 @@ float bbStats3D(int n) { int bbRunningUnderWine() { HMODULE ntdllModule = GetModuleHandleW(L"ntdll.dll"); - if(ntdllModule && GetProcAddress(ntdllModule, "wine_get_version")) return true; + if (ntdllModule && GetProcAddress(ntdllModule, "wine_get_version")) return true; return false; } @@ -403,18 +392,18 @@ int bbAvailVirtual() { //Note: modify canvas->backup() to NOT release backup image! Texture* bbLoadTexture(BBStr* file, int flags) { - debug3d(); + debug3d("LoadTexture"); Texture* t = new Texture(*file, flags); delete file; - if(!t->getCanvas(0)) { delete t; return 0; } + if (!t->getCanvas(0)) { delete t; return 0; } texture_set.insert(t); return t; } Texture* bbLoadAnimTexture(BBStr* file, int flags, int w, int h, int first, int cnt) { - debug3d(); + debug3d("LoadAnimTexture"); Texture* t = new Texture(*file, flags, w, h, first, cnt); delete file; - if(!t->getCanvas(0)) { + if (!t->getCanvas(0)) { delete t; return 0; } @@ -423,11 +412,9 @@ Texture* bbLoadAnimTexture(BBStr* file, int flags, int w, int h, int first, int } Texture* bbCreateTexture(int w, int h, int flags, int frames) { - if(debug) { - debug3d(); - if(frames <= 0) { - RTEX(MultiLang::illegal_texture_frames); - } + debug3d("CreateTexture"); + if (frames <= 0) { + ErrorLog("CreateTexture", MultiLang::illegal_texture_frames); } Texture* t = new Texture(w, h, flags, frames); texture_set.insert(t); @@ -435,48 +422,48 @@ Texture* bbCreateTexture(int w, int h, int flags, int frames) { } void bbFreeTexture(Texture* t) { - if(!t) return; - debugTexture(t); - if(texture_set.erase(t)) delete t; + if (!t) return; + debugTexture(t, "FreeTexture"); + if (texture_set.erase(t)) delete t; } void bbTextureBlend(Texture* t, int blend) { - debugTexture(t); + debugTexture(t, "TextureBlend"); t->setBlend(blend); } void bbTextureCoords(Texture* t, int flags) { - debugTexture(t); + debugTexture(t, "TextureCoords"); t->setFlags(flags); } void bbTextureBumpEnvMat(Texture* t, int x, int y, float envmat) { - debugTexture(t); + debugTexture(t, "TextureBumpEnvMat"); t->setBumpEnvMat(x, y, envmat); } void bbTextureBumpEnvScale(Texture* t, float envscale) { - debugTexture(t); + debugTexture(t, "TextureBumpEnvScale"); t->setBumpEnvScale(envscale); } void bbTextureBumpEnvOffset(Texture* t, float envoffset) { - debugTexture(t); + debugTexture(t, "TextureBumpEnvOffset"); t->setBumpEnvOffset(envoffset); } void bbScaleTexture(Texture* t, float u_scale, float v_scale) { - debugTexture(t); + debugTexture(t, "ScaleTexture"); t->setScale(1 / u_scale, 1 / v_scale); } void bbRotateTexture(Texture* t, float angle) { - debugTexture(t); + debugTexture(t, "RotateTexture"); t->setRotation(-angle * dtor); } void bbPositionTexture(Texture* t, float u_pos, float v_pos) { - debugTexture(t); + debugTexture(t, "PositionTexture"); t->setPosition(-u_pos, -v_pos); } @@ -489,51 +476,51 @@ void bbTextureAnisotropic(int level) { } int bbTextureWidth(Texture* t) { - debugTexture(t); + debugTexture(t, "TextureWidth"); return t->getCanvas(0)->getWidth(); } int bbTextureHeight(Texture* t) { - debugTexture(t); + debugTexture(t, "TextureHeight"); return t->getCanvas(0)->getHeight(); } BBStr* bbTextureName(Texture* t) { - debugTexture(t); + debugTexture(t, "TextureName"); CachedTexture* c = t->getCachedTexture(); return c ? new BBStr(c->getName().c_str()) : new BBStr(""); } void bbSetCubeFace(Texture* t, int face) { - debugTexture(t); - if(gxCanvas* c = t->getCanvas(0)) { + debugTexture(t, "SetCubeFace"); + if (gxCanvas* c = t->getCanvas(0)) { c->setCubeFace(face); } } void bbSetCubeMode(Texture* t, int mode) { - debugTexture(t); - if(gxCanvas* c = t->getCanvas(0)) { + debugTexture(t, "SetCubeMode"); + if (gxCanvas* c = t->getCanvas(0)) { c->setCubeMode(mode); } } gxCanvas* bbTextureBuffer(Texture* t, int frame) { //v1.04 - debugTexture(t); - if(gxCanvas* c = t->getCanvas(frame)) { - if(c->getDepth()) return c; + debugTexture(t, "TextureBuffer"); + if (gxCanvas* c = t->getCanvas(frame)) { + if (c->getDepth()) return c; } return 0; } void bbClearTextureFilters() { - debug3d(); + debug3d("ClearTextureFilters"); Texture::clearFilters(); } void bbTextureFilter(BBStr* t, int flags) { - debug3d(); + debug3d("TextureFilter"); Texture::addFilter(*t, flags); delete t; } @@ -542,7 +529,7 @@ void bbTextureFilter(BBStr* t, int flags) { // BRUSH COMMANDS // //////////////////// Brush* bbCreateBrush(float r, float g, float b) { - debug3d(); + debug3d("CreateBrush"); Brush* br = new Brush(); br->setColor(Vector(r * ctof, g * ctof, b * ctof)); brush_set.insert(br); @@ -550,56 +537,56 @@ Brush* bbCreateBrush(float r, float g, float b) { } Brush* bbLoadBrush(BBStr* file, int flags, float u_scale, float v_scale) { - debug3d(); + debug3d("LoadBrush"); Texture t(*file, flags); - delete file; if(!t.getCanvas(0)) return 0; - if(u_scale != 1 || v_scale != 1) t.setScale(1 / u_scale, 1 / v_scale); + delete file; if (!t.getCanvas(0)) return 0; + if (u_scale != 1 || v_scale != 1) t.setScale(1 / u_scale, 1 / v_scale); Brush* br = bbCreateBrush(255, 255, 255); br->setTexture(0, t, 0); return br; } void bbFreeBrush(Brush* b) { - if(!b) return; - debugBrush(b); - if(brush_set.erase(b)) delete b; + if (!b) return; + debugBrush(b, "FreeBrush"); + if (brush_set.erase(b)) delete b; } void bbBrushColor(Brush* br, float r, float g, float b) { - debugBrush(br); + debugBrush(br, "BrushColor"); br->setColor(Vector(r * ctof, g * ctof, b * ctof)); } void bbBrushAlpha(Brush* b, float alpha) { - debugBrush(b); + debugBrush(b, "BrushAlpha"); b->setAlpha(alpha); } void bbBrushShininess(Brush* b, float n) { - debugBrush(b); + debugBrush(b, "BrushShininess"); b->setShininess(n); } void bbBrushTexture(Brush* b, Texture* t, int frame, int index) { - debugBrush(b); - debugTexture(t); + debugBrush(b, "BrushTexture"); + debugTexture(t, "BrushTexture"); b->setTexture(index, *t, frame); } Texture* bbGetBrushTexture(Brush* b, int index) { - debugBrush(b); + debugBrush(b, "GetBrushTexture"); Texture* tex = new Texture(b->getTexture(index)); texture_set.insert(tex); return tex; } void bbBrushBlend(Brush* b, int blend) { - debugBrush(b); + debugBrush(b, "BrushBlend"); b->setBlend(blend); } void bbBrushFX(Brush* b, int fx) { - debugBrush(b); + debugBrush(b, "BrushFX"); b->setFX(fx); } @@ -607,61 +594,64 @@ void bbBrushFX(Brush* b, int fx) { // MESH COMMANDS // /////////////////// Entity* bbCreateMesh(Entity* p) { - debugParent(p); + debugParent(p, "CreateMesh"); MeshModel* m = new MeshModel(); return insertEntity(m, p); } Entity* bbLoadMesh(BBStr* f, Entity* p) { - debugParent(p); + debugParent(p, "LoadMesh"); Entity* e = loadEntity(f->c_str(), MeshLoader::HINT_COLLAPSE); delete f; - if(!e) return 0; + if (!e) return 0; MeshModel* m = new MeshModel(); collapseMesh(m, e); return insertEntity(m, p); } Entity* bbLoadAnimMesh(BBStr* f, Entity* p) { - debugParent(p); + debugParent(p, "LoadAnimMesh"); Entity* e = loadEntity(f->c_str(), 0); delete f; - if(!e) return 0; - if(Animator* anim = e->getObject()->getAnimator()) { + if (!e) return 0; + if (Animator* anim = e->getObject()->getAnimator()) { anim->animate(1, 0, 0, 0); } return insertEntity(e, p); } Entity* bbCreateCube(Entity* p) { - debugParent(p); + debugParent(p, "CreateCube"); Entity* e = MeshUtil::createCube(Brush()); return insertEntity(e, p); } Entity* bbCreateSphere(int segs, Entity* p) { - if(debug) { debugParent(p); if(segs < 2 || segs>100) RTEX("Illegal number of segments!"); } + debugParent(p, "CreateSphere"); + if (segs < 2 || segs > 100) ErrorLog("CreateSphere", MultiLang::illegal_number_segments); Entity* e = MeshUtil::createSphere(Brush(), segs); return insertEntity(e, p); } Entity* bbCreateCylinder(int segs, int solid, Entity* p) { - if(debug) { debugParent(p); if(segs < 3 || segs>100) RTEX("Illegal number of segments!"); } + debugParent(p, "CreateCylinder"); + if (segs < 3 || segs > 100) ErrorLog("CreateCylinder", MultiLang::illegal_number_segments); Entity* e = MeshUtil::createCylinder(Brush(), segs, !!solid); return insertEntity(e, p); } Entity* bbCreateCone(int segs, int solid, Entity* p) { - if(debug) { debugParent(p); if(segs < 3 || segs>100) RTEX("Illegal number of segments!"); } + debugParent(p, "CreateCone"); + if (segs < 3 || segs > 100) ErrorLog("CreateCone", MultiLang::illegal_number_segments); Entity* e = MeshUtil::createCone(Brush(), segs, !!solid); return insertEntity(e, p); } Entity* bbCopyMesh(MeshModel* m, Entity* p) { - debugMesh(m); - debugParent(p); + debugMesh(m, "CopyMesh"); + debugParent(p, "CopyMesh"); MeshModel* t = new MeshModel(); t->add(*m); @@ -669,22 +659,22 @@ Entity* bbCopyMesh(MeshModel* m, Entity* p) { } void bbScaleMesh(MeshModel* m, float x, float y, float z) { - debugMesh(m); + debugMesh(m, "ScaleMesh"); m->transform(scaleMatrix(x, y, z)); } void bbRotateMesh(MeshModel* m, float x, float y, float z) { - debugMesh(m); + debugMesh(m, "RotateMesh"); m->transform(rotationMatrix(x * dtor, y * dtor, z * dtor)); } void bbPositionMesh(MeshModel* m, float x, float y, float z) { - debugMesh(m); + debugMesh(m, "PositionMesh"); m->transform(Vector(x, y, z)); } void bbFitMesh(MeshModel* m, float x, float y, float z, float w, float h, float d, int uniform) { - debugMesh(m); + debugMesh(m, "FitMesh"); Box box(Vector(x, y, z)); box.update(Vector(x + w, y + h, z + d)); const Box& curr_box = m->getBox(); @@ -692,11 +682,11 @@ void bbFitMesh(MeshModel* m, float x, float y, float z, float w, float h, float float y_scale = box.height() / curr_box.height(); float z_scale = box.depth() / curr_box.depth(); Transform t; - if(uniform) { - if(x_scale < y_scale && x_scale < z_scale) { + if (uniform) { + if (x_scale < y_scale && x_scale < z_scale) { y_scale = z_scale = x_scale; } - else if(y_scale < x_scale && y_scale < z_scale) { + else if (y_scale < x_scale && y_scale < z_scale) { x_scale = z_scale = y_scale; } else { @@ -711,73 +701,70 @@ void bbFitMesh(MeshModel* m, float x, float y, float z, float w, float h, float } void bbFlipMesh(MeshModel* m) { - debugMesh(m); + debugMesh(m, "FlipMesh"); m->flipTriangles(); } void bbPaintMesh(MeshModel* m, Brush* b) { - if(debug) { debugMesh(m); debugBrush(b); } + debugMesh(m, "PaintMesh"); + debugBrush(b, "PaintMesh"); m->paint(*b); } void bbAddMesh(MeshModel* src, MeshModel* dest) { - if(debug) { - debugMesh(src); debugMesh(dest); - if(src == dest) RTEX(MultiLang::mesh_cannot_add_to_self); - } + debugMesh(src, "AddMesh"); + debugMesh(dest, "AddMesh"); + if (src == dest) ErrorLog("AddMesh", MultiLang::mesh_cannot_add_to_self); dest->add(*src); } void bbUpdateNormals(MeshModel* m) { - debugMesh(m); + debugMesh(m, "UpdateNormals"); m->updateNormals(); } void bbLightMesh(MeshModel* m, float r, float g, float b, float range, float x, float y, float z) { - debugMesh(m); + debugMesh(m, "LightMesh"); MeshUtil::lightMesh(m, Vector(x, y, z), Vector(r * ctof, g * ctof, b * ctof), range); } float bbMeshWidth(MeshModel* m) { - debugMesh(m); + debugMesh(m, "MeshWidth"); return m->getBox().width(); } float bbMeshHeight(MeshModel* m) { - debugMesh(m); + debugMesh(m, "MeshHeight"); return m->getBox().height(); } float bbMeshDepth(MeshModel* m) { - debugMesh(m); + debugMesh(m, "MeshDepth"); return m->getBox().depth(); } int bbMeshesIntersect(MeshModel* a, MeshModel* b) { - if(debug) { debugMesh(a); debugMesh(b); } + debugMesh(a, "MeshesIntersect"); + debugMesh(b, "MeshesIntersect"); return a->intersects(*b); } int bbCountSurfaces(MeshModel* m) { - debugMesh(m); + debugMesh(m, "CountSurfaces"); return m->getSurfaces().size(); } Surface* bbGetSurface(MeshModel* m, int index) { - if(debug) { - debugMesh(m); - if(index<1 || index>m->getSurfaces().size()) { - RTEX(MultiLang::surface_out_of_range); - } + debugMesh(m, "GetSurface"); + if (index < 1 || index > m->getSurfaces().size()) { + ErrorLog("GetSurface", MultiLang::surface_out_of_range); } return m->getSurfaces()[index - 1]; } void bbMeshCullBox(MeshModel* m, float x, float y, float z, float width, float height, float depth) { - if(debug) { - debugMesh(m); - } + debugMesh(m, "MeshCullBox"); m->setCullBox(Box(Vector(x, y, z), Vector(x + width, y + height, z + depth))); } @@ -786,12 +773,14 @@ void bbMeshCullBox(MeshModel* m, float x, float y, float z, float width, float h // SURFACE COMMANDS // ////////////////////// Surface* bbFindSurface(MeshModel* m, Brush* b) { - if(debug) { debugMesh(m); debugBrush(b); } + debugMesh(m, "FindSurface"); + debugBrush(b, "FindSurface"); return m->findSurface(*b); } Surface* bbCreateSurface(MeshModel* m, Brush* b) { - if(debug) { debugMesh(m); if(b) debugBrush(b); } + debugMesh(m, "CreateSurface"); + if (b) debugBrush(b, "CreateSurface"); Surface* s = b ? m->createSurface(*b) : m->createSurface(Brush()); return s; } @@ -803,7 +792,7 @@ Brush* bbGetSurfaceBrush(Surface* s) { } Brush* bbGetEntityBrush(Model* m) { - debugModel(m); + debugModel(m, "GetEntityBrush"); Brush* br = new Brush(m->getBrush()); brush_set.insert(br); return br; @@ -814,7 +803,7 @@ void bbClearSurface(Surface* s, int verts, int tris) { } void bbPaintSurface(Surface* s, Brush* b) { - debugBrush(b); + debugBrush(b, "PaintSurface"); s->setBrush(*b); } @@ -844,10 +833,10 @@ void bbVertexNormal(Surface* s, int n, float x, float y, float z) { } void bbVertexColor(Surface* s, int n, float r, float g, float b, float a) { - if(r < 0)r = 0; else if(r > 255)r = 255; - if(g < 0)g = 0; else if(g > 255)g = 255; - if(b < 0)b = 0; else if(b > 255)b = 255; - a *= 255; if(a < 0)a = 0; else if(a > 255)a = 255; + if (r < 0)r = 0; else if (r > 255)r = 255; + if (g < 0)g = 0; else if (g > 255)g = 255; + if (b < 0)b = 0; else if (b > 255)b = 255; + a *= 255; if (a < 0)a = 0; else if (a > 255)a = 255; s->setColor(n, (int(a) << 24) | (int(r) << 16) | (int(g) << 8) | int(b)); } @@ -864,55 +853,63 @@ int bbCountTriangles(Surface* s) { } float bbVertexX(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexX", n); return s->getVertex(n).coords.x; } + float bbVertexY(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexY", n); return s->getVertex(n).coords.y; } + float bbVertexZ(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexZ", n); return s->getVertex(n).coords.z; } + float bbVertexNX(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexNX", n); return s->getVertex(n).normal.x; } + float bbVertexNY(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexNY", n); return s->getVertex(n).normal.y; } + float bbVertexNZ(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexNZ", n); return s->getVertex(n).normal.z; } + float bbVertexRed(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexRed", n); return (s->getVertex(n).color & 0xff0000) >> 16; } + float bbVertexGreen(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexGreen", n); return (s->getVertex(n).color & 0xff00) >> 8; } + float bbVertexBlue(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexBlue", n); return s->getVertex(n).color & 0xff; } float bbVertexAlpha(Surface* s, int n) { - debugVertex(s, n); + debugVertex(s, "VertexAlpha", n); return ((s->getVertex(n).color & 0xff000000) >> 24) / 255.0f; } float bbVertexU(Surface* s, int n, int t) { - debugVertex(s, n, t); + debugVertex(s, "VertexU", n, t); return s->getVertex(n).tex_coords[t][0]; } float bbVertexV(Surface* s, int n, int t) { - debugVertex(s, n, t); + debugVertex(s, "VertexV", n, t); return s->getVertex(n).tex_coords[t][1]; } float bbVertexW(Surface* s, int n, int t) { - debugVertex(s, n, t); + debugVertex(s, "VertexW", n, t); return 1; } int bbTriangleVertex(Surface* s, int n, int v) { @@ -923,7 +920,7 @@ int bbTriangleVertex(Surface* s, int n, int v) { // CAMERA COMMANDS // ///////////////////// Entity* bbCreateCamera(Entity* p) { - debugParent(p); + debugParent(p, "CreateCamera"); int x, y, w, h; gx_canvas->getViewport(&x, &y, &w, &h); Camera* c = new Camera(); @@ -932,80 +929,80 @@ Entity* bbCreateCamera(Entity* p) { } void bbCameraZoom(Camera* c, float zoom) { - debugCamera(c); + debugCamera(c, "CameraZoom"); c->setZoom(zoom); } void bbCameraRange(Camera* c, float nr, float fr) { - debugCamera(c); + debugCamera(c, "CameraRange"); c->setRange(nr, fr); } float bbGetCameraRangeNear(Camera* c) { - debugCamera(c); + debugCamera(c, "GetCameraRangeNear"); return c->getFrustumNear(); } float bbGetCameraRangeFar(Camera* c) { - debugCamera(c); + debugCamera(c, "GetCameraRangeFar"); return c->getFrustumFar(); } void bbCameraClsColor(Camera* c, float r, float g, float b) { - debugCamera(c); + debugCamera(c, "CameraClsColor"); c->setClsColor(Vector(r * ctof, g * ctof, b * ctof)); } void bbCameraClsMode(Camera* c, int cls_color, int cls_zbuffer) { - debugCamera(c); + debugCamera(c, "CameraClsMode"); c->setClsMode(cls_color ? true : false, cls_zbuffer ? true : false); } void bbCameraProjMode(Camera* c, int mode) { - debugCamera(c); + debugCamera(c, "CameraProjMode"); c->setProjMode(mode); } void bbCameraViewport(Camera* c, int x, int y, int w, int h) { - debugCamera(c); + debugCamera(c, "CameraViewport"); c->setViewport(x, y, w, h); } void bbCameraFogRange(Camera* c, float nr, float fr) { - debugCamera(c); + debugCamera(c, "CameraFogRange"); c->setFogRange(nr, fr); } float bbGetCameraFogRangeNear(Camera* c) { - debugCamera(c); + debugCamera(c, "GetCameraFogRangeNear"); return c->getFogNear(); } float bbGetCameraFogRangeFar(Camera* c) { - debugCamera(c); + debugCamera(c, "GetCameraFogRangeFar"); return c->getFogFar(); } void bbCameraFogDensity(Camera* c, float den) { - debugCamera(c); + debugCamera(c, "CameraFogDensity"); c->setFogDensity(den); } void bbCameraFogColor(Camera* c, float r, float g, float b) { - debugCamera(c); + debugCamera(c, "CameraFogColor"); c->setFogColor(Vector(r * ctof, g * ctof, b * ctof)); } void bbCameraFogMode(Camera* c, int mode) { - debugCamera(c); + debugCamera(c, "CameraFogMode"); c->setFogMode(mode); } int bbCameraProject(Camera* c, float x, float y, float z) { - debugCamera(c); + debugCamera(c, "CameraProject"); Vector v = -c->getWorldTform() * Vector(x, y, z); const Frustum& f = c->getFrustum(); - if(c->getProjMode() == Camera::PROJ_ORTHO) { + if (c->getProjMode() == Camera::PROJ_ORTHO) { int vp_x, vp_y, vp_w, vp_h; c->getViewport(&vp_x, &vp_y, &vp_w, &vp_h); float nr = c->getFrustumNear(); @@ -1014,9 +1011,9 @@ int bbCameraProject(Camera* c, float x, float y, float z) { ::projected = Vector((v.x / nr_w + .5f) * vp_w, (.5f - v.y / nr_h) * vp_h, nr); return 1; } - if(v.z > 0) { + if (v.z > 0) { float fr = +f.getPlane(Frustum::PLANE_FAR).d; - if(v.z <= fr) { + if (v.z <= fr) { int vp_x, vp_y, vp_w, vp_h; c->getViewport(&vp_x, &vp_y, &vp_w, &vp_h); float nr = c->getFrustumNear(); @@ -1050,7 +1047,7 @@ static Object* doPick(const Line& l, float radius) { } Entity* bbCameraPick(Camera* c, float x, float y) { - debugCamera(c); + debugCamera(c, "CameraPick"); int vp_x, vp_y, vp_w, vp_h; c->getViewport(&vp_x, &vp_y, &vp_w, &vp_h); @@ -1063,7 +1060,7 @@ Entity* bbCameraPick(Camera* c, float x, float y) { y = (.5f - (y / vp_h)) * nr_h; Line l; - if(c->getProjMode() == Camera::PROJ_ORTHO) { + if (c->getProjMode() == Camera::PROJ_ORTHO) { l = c->getWorldTform() * Line(Vector(x, y, 0), Vector(0, 0, fr)); //x,y,fr) ); } else { @@ -1075,7 +1072,7 @@ Entity* bbCameraPick(Camera* c, float x, float y) { } Entity* bbLinePick(float x, float y, float z, float dx, float dy, float dz, float radius) { - debug3d(); + debug3d("LinePick"); Line l(Vector(x, y, z), Vector(dx, dy, dz)); @@ -1083,7 +1080,7 @@ Entity* bbLinePick(float x, float y, float z, float dx, float dy, float dz, floa } Entity* bbEntityPick(Object* src, float range) { - debugEntity(src); + debugEntity(src, "EntityPick"); Line l(src->getWorldPosition(), src->getWorldTform().m.k * range); @@ -1091,15 +1088,16 @@ Entity* bbEntityPick(Object* src, float range) { } int bbEntityVisible(Object* src, Object* dest) { - if(debug) { debugObject(src); debugObject(dest); } - + debugObject(src, "EntityVisible"); + debugObject(dest, "EntityVisible"); return world->checkLOS(src, dest) ? 1 : 0; } int bbEntityInView(Entity* e, Camera* c) { - if(debug) { debugEntity(e); debugCamera(c); } - if(Model* p = e->getModel()) { - if(MeshModel* m = p->getMeshModel()) { + debugEntity(e, "EntityInView"); + debugCamera(c, "EntityInView"); + if (Model* p = e->getModel()) { + if (MeshModel* m = p->getMeshModel()) { const Box& b = m->getBox(); Transform t = -c->getWorldTform() * e->getWorldTform(); Vector p[] = { @@ -1157,29 +1155,29 @@ int bbPickedTriangle() { // LIGHT COMMANDS // //////////////////// Entity* bbCreateLight(int type, Entity* p) { - debugParent(p); - Light* t = new Light(type); //Changed the new to new because internally its just a def for new. + debugParent(p, "CreateLight"); + Light* t = new Light(type); return insertEntity(t, p); } void bbLightColor(Light* light, float r, float g, float b) { - debugLight(light); + debugLight(light, "LightColor"); light->setColor(Vector(r * ctof, g * ctof, b * ctof)); } void bbLightRange(Light* light, float range) { - debugLight(light); + debugLight(light, "LightRange"); light->setRange(range); } void bbLightConeAngles(Light* light, float inner, float outer) { - debugLight(light); + debugLight(light, "LightConeAngles"); inner *= dtor; outer *= dtor; - if(inner < 0) inner = 0; - else if(inner > PI) inner = PI; - if(outer < inner) outer = inner; - else if(outer > PI) outer = PI; + if (inner < 0) inner = 0; + else if (inner > PI) inner = PI; + if (outer < inner) outer = inner; + else if (outer > PI) outer = PI; light->setConeAngles(inner, outer); } @@ -1187,7 +1185,7 @@ void bbLightConeAngles(Light* light, float inner, float outer) { // PIVOT COMMANDS // //////////////////// Entity* bbCreatePivot(Entity* p) { - debugParent(p); + debugParent(p, "CreatePivot"); Pivot* t = new Pivot(); return insertEntity(t, p); } @@ -1196,44 +1194,45 @@ Entity* bbCreatePivot(Entity* p) { // SPRITE COMMANDS // ///////////////////// Entity* bbCreateSprite(Entity* p) { - debugParent(p); + debugParent(p, "CreateSprite"); Sprite* s = new Sprite(); s->setFX(gxScene::FX_FULLBRIGHT); return insertEntity(s, p); } Entity* bbLoadSprite(BBStr* file, int flags, Entity* p) { - debugParent(p); + debugParent(p, "LoadSprite"); Texture t(*file, flags); - delete file; if(!t.getCanvas(0)) return 0; + delete file; + if (!t.getCanvas(0)) return 0; Sprite* s = new Sprite(); s->setTexture(0, t, 0); s->setFX(gxScene::FX_FULLBRIGHT); - if(flags & gxCanvas::CANVAS_TEX_MASK) s->setBlend(gxScene::BLEND_REPLACE); - else if(flags & gxCanvas::CANVAS_TEX_ALPHA) s->setBlend(gxScene::BLEND_ALPHA); + if (flags & gxCanvas::CANVAS_TEX_MASK) s->setBlend(gxScene::BLEND_REPLACE); + else if (flags & gxCanvas::CANVAS_TEX_ALPHA) s->setBlend(gxScene::BLEND_ALPHA); else s->setBlend(gxScene::BLEND_ADD); return insertEntity(s, p); } void bbRotateSprite(Sprite* s, float angle) { - debugSprite(s); + debugSprite(s, "RotateSprite"); s->setRotation(angle * dtor); } void bbScaleSprite(Sprite* s, float x, float y) { - debugSprite(s); + debugSprite(s, "ScaleSprite"); s->setScale(x, y); } void bbHandleSprite(Sprite* s, float x, float y) { - debugSprite(s); + debugSprite(s, "HandleSprite"); s->setHandle(x, y); } void bbSpriteViewMode(Sprite* s, int mode) { - debugSprite(s); + debugSprite(s, "SpriteViewMode"); s->setViewmode(mode); } @@ -1241,7 +1240,7 @@ void bbSpriteViewMode(Sprite* s, int mode) { // MIRROR COMMANDS // ///////////////////// Entity* bbCreateMirror(Entity* p) { - debugParent(p); + debugParent(p, "CreateMirror"); Mirror* t = new Mirror(); return insertEntity(t, p); } @@ -1250,10 +1249,8 @@ Entity* bbCreateMirror(Entity* p) { // PLANE COMMANDS // //////////////////// Entity* bbCreatePlane(int segs, Entity* p) { - if(debug) { - debugParent(p); - if(segs < 1 || segs>20) RTEX("Illegal number of segments!"); - } + debugParent(p, "CreatePlane"); + if (segs < 1 || segs>20) ErrorLog("CreatePlane", MultiLang::illegal_number_segments); PlaneModel* t = new PlaneModel(segs); return insertEntity(t, p); } @@ -1262,29 +1259,29 @@ Entity* bbCreatePlane(int segs, Entity* p) { // MD2 COMMANDS // ////////////////// Entity* bbLoadMD2(BBStr* file, Entity* p) { - debugParent(p); + debugParent(p, "LoadMD2"); MD2Model* t = new MD2Model(*file); delete file; - if(!t->getValid()) { delete t; return 0; } + if (!t->getValid()) { delete t; return 0; } return insertEntity(t, p); } void bbAnimateMD2(MD2Model* m, int mode, float speed, int first, int last, float trans) { - debugMD2(m); + debugMD2(m, "AnimateMD2"); m->startMD2Anim(first, last, mode, speed, trans); } float bbMD2AnimTime(MD2Model* m) { - debugMD2(m); + debugMD2(m, "MD2AnimTime"); return m->getMD2AnimTime(); } int bbMD2AnimLength(MD2Model* m) { - debugMD2(m); + debugMD2(m, "MD2AnimLength"); return m->getMD2AnimLength(); } int bbMD2Animating(MD2Model* m) { - debugMD2(m); + debugMD2(m, "MD2Animating"); return m->getMD2Animating(); } @@ -1292,23 +1289,23 @@ int bbMD2Animating(MD2Model* m) { // BSP Commands // ////////////////// Entity* bbLoadBSP(BBStr* file, float gam, Entity* p) { - debugParent(p); + debugParent(p, "LoadBSP"); CachedTexture::setPath(filenamepath(*file)); Q3BSPModel* t = new Q3BSPModel(*file, gam); delete file; CachedTexture::setPath(""); - if(!t->isValid()) { delete t; return 0; } + if (!t->isValid()) { delete t; return 0; } return insertEntity(t, p); } void bbBSPAmbientLight(Q3BSPModel* t, float r, float g, float b) { - debugBSP(t); + debugBSP(t, "BSPAmbientLight"); t->setAmbient(Vector(r * ctof, g * ctof, b * ctof)); } void bbBSPLighting(Q3BSPModel* t, int lmap) { - debugBSP(t); + debugBSP(t, "BSPLighting"); t->setLighting(!!lmap); } @@ -1334,27 +1331,27 @@ static Vector terrainVector(Terrain* t, float x, float y, float z) { } Entity* bbCreateTerrain(int n, Entity* p) { - debugParent(p); + debugParent(p, "CreateTerrain"); int shift = 0; - while((1 << shift) < n) ++shift; - if((1 << shift) != n) RTEX(MultiLang::illegal_terrain_size); + while ((1 << shift) < n) ++shift; + if ((1 << shift) != n) ErrorLog("CreateTerrain", MultiLang::illegal_terrain_size); Terrain* t = new Terrain(shift); return insertEntity(t, p); } Entity* bbLoadTerrain(BBStr* file, Entity* p) { - debugParent(p); + debugParent(p, "LoadTerrain"); gxCanvas* c = gx_graphics->loadCanvas(*file, gxCanvas::CANVAS_HIGHCOLOR); - if(!c) RTEX(MultiLang::unable_load_heightmap); + if (!c) ErrorLog("LoadTerrain", MultiLang::unable_load_heightmap); int w = c->getWidth(), h = c->getHeight(); - if(w != h) RTEX(MultiLang::terrain_must_be_square); + if (w != h) ErrorLog("LoadTerrain", MultiLang::terrain_must_be_square); int shift = 0; - while((1 << shift) < w) ++shift; - if((1 << shift) != w) RTEX(MultiLang::illegal_terrain_size); + while ((1 << shift) < w) ++shift; + if ((1 << shift) != w) ErrorLog("LoadTerrain", MultiLang::illegal_terrain_size); Terrain* t = new Terrain(shift); c->lock(); - for(int y = 0; y < h; ++y) { - for(int x = 0; x < w; ++x) { + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { int rgb = c->getPixelFast(x, y); int r = (rgb >> 16) & 0xff, g = (rgb >> 8) & 0xff, b = rgb & 0xff; float fp = (r > g ? (r > b ? r : b) : (g > b ? g : b)) / 255.0f; @@ -1367,42 +1364,42 @@ Entity* bbLoadTerrain(BBStr* file, Entity* p) { } void bbTerrainDetail(Terrain* t, int n, int m) { - debugTerrain(t); + debugTerrain(t, "TerrainDetail"); t->setDetail(n, !!m); } void bbTerrainShading(Terrain* t, int enable) { - debugTerrain(t); + debugTerrain(t, "TerrainShading"); t->setShading(!!enable); } float bbTerrainX(Terrain* t, float x, float y, float z) { - debugTerrain(t); + debugTerrain(t, "TerrainX"); return terrainVector(t, x, y, z).x; } float bbTerrainY(Terrain* t, float x, float y, float z) { - debugTerrain(t); + debugTerrain(t, "TerrainY"); return terrainVector(t, x, y, z).y; } float bbTerrainZ(Terrain* t, float x, float y, float z) { - debugTerrain(t); + debugTerrain(t, "TerrainZ"); return terrainVector(t, x, y, z).z; } int bbTerrainSize(Terrain* t) { - debugTerrain(t); + debugTerrain(t, "TerrainSize"); return t->getSize(); } float bbTerrainHeight(Terrain* t, int x, int z) { - debugTerrain(t); + debugTerrain(t, "TerrainHeight"); return t->getHeight(x, z); } void bbModifyTerrain(Terrain* t, int x, int z, float h, int realtime) { - debugTerrain(t); + debugTerrain(t, "ModifyTerrain"); t->setHeight(x, z, h, !!realtime); } @@ -1410,19 +1407,15 @@ void bbModifyTerrain(Terrain* t, int x, int z, float h, int realtime) { // AUDIO COMMANDS // //////////////////// Entity* bbCreateListener(Entity* p, float roll, float dopp, float dist) { - if(debug) { - debugParent(p); - if(listener) RTEX(MultiLang::listener_already_created); - } + debugParent(p, "CreateListener"); + if (listener) ErrorLog("CreateListener", MultiLang::listener_already_created); listener = new Listener(roll, dopp, dist); return insertEntity(listener, p); } gxChannel* bbEmitSound(gxSound* sound, Object* o) { - if(debug) { - debugObject(o); - if(!listener) RTEX(MultiLang::no_listener_created); - } + debugObject(o, "CreateListener"); + if (!listener) ErrorLog("CreateListener", MultiLang::no_listener_created); return o->emitSound(sound); } @@ -1430,58 +1423,52 @@ gxChannel* bbEmitSound(gxSound* sound, Object* o) { // ENTITY COMMANDS // ///////////////////// Entity* bbCopyEntity(Entity* e, Entity* p) { - if(debug) { - debugEntity(e); - debugParent(p); - } + debugEntity(e, "CopyEntity"); + debugParent(p, "CopyEntity"); Entity* t = e->getObject()->copy(); - if(!t) return 0; + if (!t) return 0; return insertEntity(t, p); } void bbFreeEntity(Entity* e) { - if(!e) return; - if(debug) { - debugEntity(e); - erase(e); - } + if (!e) return; + debugEntity(e, "FreeEntity"); + erase(e); delete e; } void bbHideEntity(Entity* e) { - debugEntity(e); + debugEntity(e, "HideEntity"); e->setEnabled(false); e->setVisible(false); } void bbShowEntity(Entity* e) { - debugEntity(e); + debugEntity(e, "ShowEntity"); e->setVisible(true); e->setEnabled(true); e->getObject()->reset(); } int bbEntityHidden(Entity* e) { - debugEntity(e); + debugEntity(e, "EntityHidden"); return !e->visible(); } void bbEntityParent(Entity* e, Entity* p, int global) { - if(debug) { - debugEntity(e); - debugParent(p); - Entity* t = p; - while(t) { - if(t == e) { - RTEX(MultiLang::entity_cannot_parented_itself); - } - t = t->getParent(); + debugEntity(e, "EntityParent"); + debugParent(p, "EntityParent"); + Entity* t = p; + while (t) { + if (t == e) { + ErrorLog("EntityParent", MultiLang::entity_cannot_parented_itself); } + t = t->getParent(); } - if(e->getParent() == p) return; + if (e->getParent() == p) return; - if(global) { + if (global) { Transform t = e->getWorldTform(); e->setParent(p); e->setWorldTform(t); @@ -1493,21 +1480,21 @@ void bbEntityParent(Entity* e, Entity* p, int global) { } int bbCountChildren(Entity* e) { - debugEntity(e); + debugEntity(e, "CountChildren"); int n = 0; - for(Entity* p = e->children(); p; p = p->successor()) ++n; + for (Entity* p = e->children(); p; p = p->successor()) ++n; return n; } Entity* bbGetChild(Entity* e, int index) { - debugEntity(e); + debugEntity(e, "GetChild"); Entity* p = e->children(); - while(--index && p) p = p->successor(); + while (--index && p) p = p->successor(); return p; } Entity* bbFindChild(Entity* e, BBStr* t) { - debugEntity(e); + debugEntity(e, "FindChild"); e = findChild(e, *t); delete t; return e; @@ -1517,12 +1504,12 @@ Entity* bbFindChild(Entity* e, BBStr* t) { // ANIMATION COMMANDS // //////////////////////// int bbLoadAnimSeq(Object* o, BBStr* f) { - debugObject(o); - if(Animator* anim = o->getAnimator()) { + debugObject(o, "LoadAnimSeq"); + if (Animator* anim = o->getAnimator()) { Entity* t = loadEntity(f->c_str(), MeshLoader::HINT_ANIMONLY); delete f; - if(t) { - if(Animator* p = t->getObject()->getAnimator()) { + if (t) { + if (Animator* p = t->getObject()->getAnimator()) { anim->addSeqs(p); } delete t; @@ -1536,37 +1523,37 @@ int bbLoadAnimSeq(Object* o, BBStr* f) { } void bbSetAnimTime(Object* o, float time, int seq) { - debugObject(o); - if(Animator* anim = o->getAnimator()) { + debugObject(o, "SetAnimTime"); + if (Animator* anim = o->getAnimator()) { anim->setAnimTime(time, seq); } else { - RTEX(MultiLang::entity_no_animations); + ErrorLog("SetAnimTime", MultiLang::entity_no_animations); } } void bbAnimate(Object* o, int mode, float speed, int seq, float trans) { - debugObject(o); - if(Animator* anim = o->getAnimator()) { + debugObject(o, "Animate"); + if (Animator* anim = o->getAnimator()) { anim->animate(mode, speed, seq, trans); } else { - RTEX(MultiLang::entity_no_animations); + ErrorLog("Animate", MultiLang::entity_no_animations); } } void bbSetAnimKey(Object* o, int frame, int pos_key, int rot_key, int scl_key) { - debugObject(o); + debugObject(o, "SetAnimKey"); Animation anim = o->getAnimation(); - if(pos_key) anim.setPositionKey(frame, o->getLocalPosition()); - if(rot_key) anim.setRotationKey(frame, o->getLocalRotation()); - if(scl_key) anim.setScaleKey(frame, o->getLocalScale()); + if (pos_key) anim.setPositionKey(frame, o->getLocalPosition()); + if (rot_key) anim.setRotationKey(frame, o->getLocalRotation()); + if (scl_key) anim.setScaleKey(frame, o->getLocalScale()); o->setAnimation(anim); } int bbExtractAnimSeq(Object* o, int first, int last, int seq) { - debugObject(o); - if(Animator* anim = o->getAnimator()) { + debugObject(o, "ExtractAnimSeq"); + if (Animator* anim = o->getAnimator()) { anim->extractSeq(first, last, seq); return anim->numSeqs() - 1; } @@ -1574,9 +1561,9 @@ int bbExtractAnimSeq(Object* o, int first, int last, int seq) { } int bbAddAnimSeq(Object* o, int length) { - debugObject(o); + debugObject(o, "AddAnimSeq"); Animator* anim = o->getAnimator(); - if(anim) { + if (anim) { anim->addSeq(length); } else { @@ -1587,26 +1574,26 @@ int bbAddAnimSeq(Object* o, int length) { } int bbAnimSeq(Object* o) { - debugObject(o); - if(Animator* anim = o->getAnimator()) return anim->animSeq(); + debugObject(o, "AnimSeq"); + if (Animator* anim = o->getAnimator()) return anim->animSeq(); return -1; } float bbAnimTime(Object* o) { - debugObject(o); - if(Animator* anim = o->getAnimator()) return anim->animTime(); + debugObject(o, "AnimTime"); + if (Animator* anim = o->getAnimator()) return anim->animTime(); return -1; } int bbAnimLength(Object* o) { - debugObject(o); - if(Animator* anim = o->getAnimator()) return anim->animLen(); + debugObject(o, "AnimLength"); + if (Animator* anim = o->getAnimator()) return anim->animLen(); return -1; } int bbAnimating(Object* o) { - debugObject(o); - if(Animator* anim = o->getAnimator()) return anim->animating(); + debugObject(o, "Animating"); + if (Animator* anim = o->getAnimator()) return anim->animating(); return 0; } @@ -1614,55 +1601,51 @@ int bbAnimating(Object* o) { // ENTITY SPECIAL FX COMMANDS // //////////////////////////////// void bbPaintEntity(Model* m, Brush* b) { - if(debug) { - debugModel(m); - debugBrush(b); - } + debugModel(m, "PaintEntity"); + debugBrush(b, "PaintEntity"); m->setBrush(*b); } void bbEntityColor(Model* m, float r, float g, float b) { - debugModel(m); + debugModel(m, "EntityColor"); m->setColor(Vector(r * ctof, g * ctof, b * ctof)); } void bbEntityAlpha(Model* m, float alpha) { - debugModel(m); + debugModel(m, "EntityAlpha"); m->setAlpha(alpha); } void bbEntityShininess(Model* m, float shininess) { - debugModel(m); + debugModel(m, "EntityShininess"); m->setShininess(shininess); } void bbEntityTexture(Model* m, Texture* t, int frame, int index) { - debugModel(m); - debugTexture(t); + debugModel(m, "EntityTexture"); + debugTexture(t, "EntityTexture"); m->setTexture(index, *t, frame); } void bbEntityBlend(Model* m, int blend) { - debugModel(m); + debugModel(m, "EntityBlend"); m->setBlend(blend); } void bbEntityFX(Model* m, int fx) { - debugModel(m); + debugModel(m, "EntityFX"); m->setFX(fx); } void bbEntityAutoFade(Model* m, float nr, float fr) { - debugModel(m); + debugModel(m, "EntityAutoFade"); m->setAutoFade(nr, fr); } void bbEntityOrder(Object* o, int n) { - if(debug) { - debugEntity(o); - if(!o->getModel() && !o->getCamera()) { - RTEX(MultiLang::entity_not_model_or_camera); - } + debugEntity(o, "EntityOrder"); + if (!o->getModel() && !o->getCamera()) { + ErrorLog("EntityOrder", MultiLang::entity_not_model_or_camera); } o->setOrder(n); } @@ -1671,83 +1654,77 @@ void bbEntityOrder(Object* o, int n) { // ENTITY PROPERTY COMMANDS // ////////////////////////////// float bbEntityX(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityX"); return global ? e->getWorldPosition().x : e->getLocalPosition().x; } float bbEntityY(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityY"); return global ? e->getWorldPosition().y : e->getLocalPosition().y; } float bbEntityZ(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityZ"); return global ? e->getWorldPosition().z : e->getLocalPosition().z; } float bbEntityPitch(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityPitch"); return quatPitch(global ? e->getWorldRotation() : e->getLocalRotation()) * rtod; } float bbEntityYaw(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityYaw"); return quatYaw(global ? e->getWorldRotation() : e->getLocalRotation()) * rtod; } float bbEntityRoll(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityRoll"); return quatRoll(global ? e->getWorldRotation() : e->getLocalRotation()) * rtod; } float bbEntityScaleX(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityScaleX"); return global ? e->getWorldScale().x : e->getLocalScale().x; } float bbEntityScaleY(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityScaleY"); return global ? e->getWorldScale().y : e->getLocalScale().y; } float bbEntityScaleZ(Entity* e, int global) { - debugEntity(e); + debugEntity(e, "EntityScaleZ"); return global ? e->getWorldScale().z : e->getLocalScale().z; } float bbGetMatElement(Entity* e, int row, int col) { - debugEntity(e); + debugEntity(e, "GetMatElement"); return row < 3 ? e->getWorldTform().m[row][col] : e->getWorldTform().v[col]; } void bbTFormPoint(float x, float y, float z, Entity* src, Entity* dest) { - if(debug) { - if(src) debugEntity(src); - if(dest) debugEntity(dest); - } + if (src) debugEntity(src, "TFormPoint"); + if (dest) debugEntity(dest, "TFormPoint"); tformed = Vector(x, y, z); - if(src) tformed = src->getWorldTform() * tformed; - if(dest) tformed = -dest->getWorldTform() * tformed; + if (src) tformed = src->getWorldTform() * tformed; + if (dest) tformed = -dest->getWorldTform() * tformed; } void bbTFormVector(float x, float y, float z, Entity* src, Entity* dest) { - if(debug) { - if(src) debugEntity(src); - if(dest) debugEntity(dest); - } + if (src) debugEntity(src, "TFormVector"); + if (dest) debugEntity(dest, "TFormVector"); tformed = Vector(x, y, z); - if(src) tformed = src->getWorldTform().m * tformed; - if(dest) tformed = -dest->getWorldTform().m * tformed; + if (src) tformed = src->getWorldTform().m * tformed; + if (dest) tformed = -dest->getWorldTform().m * tformed; } void bbTFormNormal(float x, float y, float z, Entity* src, Entity* dest) { - if(debug) { - if(src) debugEntity(src); - if(dest) debugEntity(dest); - } + if (src) debugEntity(src, "TFormNormal"); + if (dest) debugEntity(dest, "TFormNormal"); tformed = Vector(x, y, z); - if(src) tformed = (src->getWorldTform().m).cofactor() * tformed; - if(dest) tformed = (-dest->getWorldTform().m).cofactor() * tformed; + if (src) tformed = (src->getWorldTform().m).cofactor() * tformed; + if (dest) tformed = (-dest->getWorldTform().m).cofactor() * tformed; tformed.normalize(); } @@ -1775,8 +1752,8 @@ float bbDeltaYaw(Entity* src, Entity* dest) { float x = src->getWorldTform().m.k.yaw(); float y = (dest->getWorldTform().v - src->getWorldTform().v).yaw(); float d = y - x; - if(d < -PI) d += TWOPI; - else if(d >= PI) d -= TWOPI; + if (d < -PI) d += TWOPI; + else if (d >= PI) d -= TWOPI; return d * rtod; } @@ -1784,8 +1761,8 @@ float bbDeltaPitch(Entity* src, Entity* dest) { float x = src->getWorldTform().m.k.pitch(); float y = (dest->getWorldTform().v - src->getWorldTform().v).pitch(); float d = y - x; - if(d < -PI) d += TWOPI; - else if(d >= PI) d -= TWOPI; + if (d < -PI) d += TWOPI; + else if (d >= PI) d -= TWOPI; return d * rtod; } @@ -1793,24 +1770,22 @@ float bbDeltaPitch(Entity* src, Entity* dest) { // ENTITY COLLISION COMMANDS // /////////////////////////////// void bbResetEntity(Object* o) { - debugObject(o); + debugObject(o, "ResetEntity"); o->reset(); } static void entityType(Entity* e, int type) { e->getObject()->setCollisionType(type); e->getObject()->reset(); - for(Entity* p = e->children(); p; p = p->successor()) { + for (Entity* p = e->children(); p; p = p->successor()) { entityType(p, type); } } void bbEntityType(Object* o, int type, int recurs) { - if(debug) { - debugObject(o); - if(type < 0 || type>999) RTEX(MultiLang::entitytype_id_range); - } - if(recurs) entityType(o, type); + debugObject(o, "EntityType"); + if (type < 0 || type > 999) ErrorLog("EntityType", MultiLang::entitytype_id_range); + if (recurs) entityType(o, type); else { o->setCollisionType(type); o->reset(); @@ -1818,109 +1793,109 @@ void bbEntityType(Object* o, int type, int recurs) { } void bbEntityPickMode(Object* o, int mode, int obs) { - debugObject(o); + debugObject(o, "EntityPickMode"); o->setPickGeometry(mode); o->setObscurer(!!obs); } Entity* bbGetParent(Entity* e) { - debugEntity(e); + debugEntity(e, "GetParent"); return e->getParent(); } int bbGetEntityType(Object* o) { - debugObject(o); + debugObject(o, "GetEntityType"); return o->getCollisionType(); } void bbEntityRadius(Object* o, float x_radius, float y_radius) { - debugObject(o); + debugObject(o, "EntityRadius"); Vector radii(x_radius, y_radius ? y_radius : x_radius, x_radius); o->setCollisionRadii(radii); } void bbEntityBox(Object* o, float x, float y, float z, float w, float h, float d) { - debugObject(o); + debugObject(o, "EntityBox"); Box b(Vector(x, y, z)); b.update(Vector(x + w, y + h, z + d)); o->setCollisionBox(b); } Object* bbEntityCollided(Object* o, int type) { - debugObject(o); + debugObject(o, "EntityCollided"); Object::Collisions::const_iterator it; const Object::Collisions& c = o->getCollisions(); - for(it = c.begin(); it != c.end(); ++it) { + for (it = c.begin(); it != c.end(); ++it) { const ObjCollision* cc = *it; - if(cc->with->getCollisionType() == type) return cc->with; + if (cc->with->getCollisionType() == type) return cc->with; } return 0; } int bbCountCollisions(Object* o) { - debugObject(o); + debugObject(o, "CountCollisions"); return o->getCollisions().size(); } float bbCollisionX(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionX", index); return o->getCollisions()[index - 1]->coords.x; } float bbCollisionY(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionY", index); return o->getCollisions()[index - 1]->coords.y; } float bbCollisionZ(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionZ", index); return o->getCollisions()[index - 1]->coords.z; } float bbCollisionNX(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionNX", index); return o->getCollisions()[index - 1]->collision.normal.x; } float bbCollisionNY(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionNY", index); return o->getCollisions()[index - 1]->collision.normal.y; } float bbCollisionNZ(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionNZ", index); return o->getCollisions()[index - 1]->collision.normal.z; } float bbCollisionTime(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionTime", index); return o->getCollisions()[index - 1]->collision.time; } Object* bbCollisionEntity(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionEntity", index); return o->getCollisions()[index - 1]->with; } void* bbCollisionSurface(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionSurface", index); return o->getCollisions()[index - 1]->collision.surface; } int bbCollisionTriangle(Object* o, int index) { - debugColl(o, index); + debugColl(o, "CollisionTriangle", index); return o->getCollisions()[index - 1]->collision.index; } float bbEntityDistance(Entity* src, Entity* dest) { - debugEntity(src); - debugEntity(dest); + debugEntity(src, "EntityDistance"); + debugEntity(dest, "EntityDistance"); return src->getWorldPosition().distance(dest->getWorldPosition()); } float bbEntityDistanceSquared(Entity* src, Entity* dest) { - debugEntity(src); - debugEntity(dest); + debugEntity(src, "EntityDistanceSquared"); + debugEntity(dest, "EntityDistanceSquared"); return src->getWorldPosition().distanceSqr(dest->getWorldPosition()); } @@ -1936,47 +1911,48 @@ float bbDistanceSquared(float x1, float x2, float y1, float y2, float z1, float // ENTITY TRANSFORMATION COMMANDS // //////////////////////////////////// void bbMoveEntity(Entity* e, float x, float y, float z) { - debugEntity(e); + debugEntity(e, "MoveEntity"); e->setLocalPosition(e->getLocalPosition() + e->getLocalRotation() * Vector(x, y, z)); } void bbTurnEntity(Entity* e, float p, float y, float r, int global) { - debugEntity(e); + debugEntity(e, "TurnEntity"); global ? e->setWorldRotation(rotationQuat(p * dtor, y * dtor, r * dtor) * e->getWorldRotation()) : e->setLocalRotation(e->getLocalRotation() * rotationQuat(p * dtor, y * dtor, r * dtor)); } void bbTranslateEntity(Entity* e, float x, float y, float z, int global) { - debugEntity(e); + debugEntity(e, "TranslateEntity"); global ? e->setWorldPosition(e->getWorldPosition() + Vector(x, y, z)) : e->setLocalPosition(e->getLocalPosition() + Vector(x, y, z)); } void bbPositionEntity(Entity* e, float x, float y, float z, int global) { - debugEntity(e); + debugEntity(e, "PositionEntity"); global ? e->setWorldPosition(Vector(x, y, z)) : e->setLocalPosition(Vector(x, y, z)); } void bbScaleEntity(Entity* e, float x, float y, float z, int global) { - debugEntity(e); + debugEntity(e, "ScaleEntity"); global ? e->setWorldScale(Vector(x, y, z)) : e->setLocalScale(Vector(x, y, z)); } void bbRotateEntity(Entity* e, float p, float y, float r, int global) { - debugEntity(e); + debugEntity(e, "RotateEntity"); global ? e->setWorldRotation(rotationQuat(p * dtor, y * dtor, r * dtor)) : e->setLocalRotation(rotationQuat(p * dtor, y * dtor, r * dtor)); } void bbPointEntity(Entity* e, Entity* t, float roll) { - if(debug) { debugEntity(e); debugEntity(t); } + debugEntity(e, "PointEntity"); + debugEntity(t, "PointEntity"); Vector v = t->getWorldTform().v - e->getWorldTform().v; e->setWorldRotation(rotationQuat(v.pitch(), v.yaw(), roll * dtor)); } @@ -1984,7 +1960,7 @@ void bbPointEntity(Entity* e, Entity* t, float roll) { void bbAlignToVector(Entity* e, float nx, float ny, float nz, int axis, float rate) { Vector ax(nx, ny, nz); float l = ax.length(); - if(l <= EPSILON) return; + if (l <= EPSILON) return; ax /= l; Quat q = e->getWorldRotation(); @@ -1992,9 +1968,9 @@ void bbAlignToVector(Entity* e, float nx, float ny, float nz, int axis, float r float dp = ax.dot(tv); - if(dp >= 1 - EPSILON) return; + if (dp >= 1 - EPSILON) return; - if(dp <= -1 + EPSILON) { + if (dp <= -1 + EPSILON) { float an = PI * rate / 2; Vector cp = (axis == 1) ? q.j() : (axis == 2 ? q.k() : q.i()); e->setWorldRotation(Quat(cosf(an), cp * sinf(an)) * q); @@ -2010,42 +1986,42 @@ void bbAlignToVector(Entity* e, float nx, float ny, float nz, int axis, float r // ENTITY MISC COMMANDS // ////////////////////////// void bbNameEntity(Entity* e, BBStr* t) { - debugEntity(e); + debugEntity(e, "NameEntity"); e->setName(*t); delete t; } BBStr* bbEntityName(Entity* e) { - debugEntity(e); + debugEntity(e, "EntityName"); return new BBStr(e->getName()); } BBStr* bbEntityClass(Entity* e) { - debugEntity(e); - if(e->getLight()) return new BBStr("Light"); - else if(e->getCamera()) return new BBStr("Camera"); - else if(e->getMirror()) return new BBStr("Mirror"); - else if(e->getListener()) return new BBStr("Listener"); - else if(Model* t = e->getModel()) { - if(t->getSprite()) return new BBStr("Sprite"); - else if(t->getTerrain()) return new BBStr("Terrain"); - else if(t->getPlaneModel()) return new BBStr("Plane"); - else if(t->getMeshModel()) return new BBStr("Mesh"); - else if(t->getMD2Model()) return new BBStr("MD2"); - else if(t->getBSPModel()) return new BBStr("BSP"); + debugEntity(e, "EntityClass"); + if (e->getLight()) return new BBStr("Light"); + else if (e->getCamera()) return new BBStr("Camera"); + else if (e->getMirror()) return new BBStr("Mirror"); + else if (e->getListener()) return new BBStr("Listener"); + else if (Model* t = e->getModel()) { + if (t->getSprite()) return new BBStr("Sprite"); + else if (t->getTerrain()) return new BBStr("Terrain"); + else if (t->getPlaneModel()) return new BBStr("Plane"); + else if (t->getMeshModel()) return new BBStr("Mesh"); + else if (t->getMD2Model()) return new BBStr("MD2"); + else if (t->getBSPModel()) return new BBStr("BSP"); } return new BBStr("Pivot"); } void bbClearWorld(int e, int b, int t) { - if(e) { - while(Entity::orphans()) bbFreeEntity(Entity::orphans()); + if (e) { + while (Entity::orphans()) bbFreeEntity(Entity::orphans()); } - if(b) { - while(brush_set.size()) bbFreeBrush(*brush_set.begin()); + if (b) { + while (brush_set.size()) bbFreeBrush(*brush_set.begin()); } - if(t) { - while(texture_set.size()) bbFreeTexture(*texture_set.begin()); + if (t) { + while (texture_set.size()) bbFreeTexture(*texture_set.begin()); } } @@ -2057,7 +2033,7 @@ int bbActiveTextures() { void blitz3d_open() { gx_scene = gx_graphics->createScene(0); - if(!gx_scene) RTEX(MultiLang::unable_create_gxscene_instance); + if (!gx_scene) RTEX(MultiLang::unable_create_gxscene_instance); world = new World(); ::projected = Vector(); picked.collision = Collision(); @@ -2072,7 +2048,7 @@ void blitz3d_open() { } void blitz3d_close() { - if(!gx_scene) return; + if (!gx_scene) return; bbClearWorld(1, 1, 1); Texture::clearFilters(); loader_mat_map.clear(); diff --git a/bbruntime/bbfilesystem.cpp b/bbruntime/bbfilesystem.cpp index 44178642..a87d8489 100644 --- a/bbruntime/bbfilesystem.cpp +++ b/bbruntime/bbfilesystem.cpp @@ -30,24 +30,22 @@ struct bbFile : public bbStream { static std::set file_set; -static inline void debugFile(bbFile* f) { - if(debug) { - if(!file_set.count(f)) - RTEX(MultiLang::file_not_exist); +static inline void debugFile(bbFile* f, std::string function) { + if (!file_set.count(f)) { + ErrorLog(function, MultiLang::file_not_exist); } } -static inline void debugDir(gxDir* d) { - if(debug) { - if(!gx_filesys->verifyDir(d)) - RTEX(MultiLang::directory_not_exist); +static inline void debugDir(gxDir* d, std::string function) { + if (!gx_filesys->verifyDir(d)) { + ErrorLog(function, MultiLang::directory_not_exist); } } static bbFile* open(BBStr* f, int n) { std::string t = *f; std::filebuf* buf = new std::filebuf(); - if(buf->open(t.c_str(), n | std::ios_base::binary)) { + if (buf->open(t.c_str(), n | std::ios_base::binary)) { bbFile* fl = new bbFile(buf); file_set.insert(fl); return fl; @@ -69,7 +67,7 @@ bbFile* bbOpenFile(BBStr* f) { } void bbCloseFile(bbFile* f) { - debugFile(f); + debugFile(f, "CloseFile"); file_set.erase(f); delete f; } @@ -92,7 +90,7 @@ void bbCloseDir(gxDir* d) { } BBStr* bbNextFile(gxDir* d) { - debugDir(d); + debugDir(d, "NextFile"); return new BBStr(d->getNextFile()); } @@ -226,14 +224,14 @@ BBStr* bbAbsolutePath(BBStr* path) { } bool filesystem_create() { - if(gx_filesys = gx_runtime->openFileSystem(0)) { + if (gx_filesys = gx_runtime->openFileSystem(0)) { return true; } return false; } bool filesystem_destroy() { - while(file_set.size()) bbCloseFile(*file_set.begin()); + while (file_set.size()) bbCloseFile(*file_set.begin()); gx_runtime->closeFileSystem(gx_filesys); return true; } diff --git a/bbruntime/bbgraphics.cpp b/bbruntime/bbgraphics.cpp index 2652cda9..6d251655 100644 --- a/bbruntime/bbgraphics.cpp +++ b/bbruntime/bbgraphics.cpp @@ -20,7 +20,7 @@ class bbImage } ~bbImage() { - for(int k = 0; k < frames.size(); ++k) + for (int k = 0; k < frames.size(); ++k) gx_graphics->freeCanvas(frames[k]); } const std::vector& getFrames()const @@ -54,45 +54,30 @@ static unsigned curr_clsColor; static std::vector gfx_modes; -static inline void debugImage(bbImage* i, int frame = 0) +static inline void debugImage(bbImage* i, std::string function, int frame = 0) { - if(debug) - { - if (!image_set.count(i)) RTEX(MultiLang::image_not_exist); - if(frame >= i->getFrames().size()) RTEX(MultiLang::image_frame_out_of_range); - } + if (!image_set.count(i)) ErrorLog(function, MultiLang::image_not_exist); + if (frame >= i->getFrames().size()) ErrorLog(function, MultiLang::image_frame_out_of_range); } -static inline void debugFont(gxFont* f) +static inline void debugFont(gxFont* f, std::string function) { - if(debug) - { - if(!gx_graphics->verifyFont(f)) RTEX(MultiLang::font_not_exist); - } + if (!gx_graphics->verifyFont(f)) ErrorLog(function, MultiLang::font_not_exist); } -static inline void debugCanvas(gxCanvas* c) +static inline void debugCanvas(gxCanvas* c, std::string function) { - if(debug) - { - if(!gx_graphics->verifyCanvas(c)) RTEX(MultiLang::buffer_not_exist); - } + if (!gx_graphics->verifyCanvas(c)) ErrorLog(function, MultiLang::buffer_not_exist); } -static inline void debugDriver(int n) +static inline void debugDriver(int n, std::string function) { - if(debug) - { - if(n<1 || n>gx_runtime->numGraphicsDrivers()) RTEX(MultiLang::illegal_graphics_driver_index); - } + if (n < 1 || n > gx_runtime->numGraphicsDrivers()) ErrorLog(function, MultiLang::illegal_graphics_driver_index); } -static inline void debugMode(int n) +static inline void debugMode(int n, std::string function) { - if(debug) - { - if(n<1 || n>gfx_modes.size()) RTEX(MultiLang::illegal_graphics_mode_index); - } + if (n<1 || n>gfx_modes.size()) ErrorLog(function, MultiLang::illegal_graphics_mode_index); } void bbFreeImage(bbImage* i); @@ -101,8 +86,8 @@ static void freeGraphics() { extern void blitz3d_close(); blitz3d_close(); - while(image_set.size()) bbFreeImage(*image_set.begin()); - if(p_canvas) + while (image_set.size()) bbFreeImage(*image_set.begin()); + if (p_canvas) { gx_graphics->freeCanvas(p_canvas); p_canvas = 0; @@ -115,7 +100,7 @@ static void freeGraphics() static int getPixel(gxCanvas* c, float x, float y) { - debugCanvas(c); + debugCanvas(c, "getPixel"); x -= .5f; y -= .5f; float fx = floor(x), fy = floor(y); @@ -145,12 +130,12 @@ static vec2 vrot(float m[2][2], const vec2& v) static float vmin(float a, float b, float c, float d) { - float t = a; if(b < t) t = b; if(c < t) t = c; if(d < t) t = d; return t; + float t = a; if (b < t) t = b; if (c < t) t = c; if (d < t) t = d; return t; } static float vmax(float a, float b, float c, float d) { - float t = a; if(b > t) t = b; if(c > t) t = c; if(d > t) t = d; return t; + float t = a; if (b > t) t = b; if (c > t) t = c; if (d > t) t = d; return t; } static gxCanvas* tformCanvas(gxCanvas* c, float m[2][2], int x_handle, int y_handle) @@ -182,10 +167,10 @@ static gxCanvas* tformCanvas(gxCanvas* c, float m[2][2], int x_handle, int y_han t->lock(); v.y = miny + .5f; - for(int y = 0; y < ih; ++v.y, ++y) + for (int y = 0; y < ih; ++v.y, ++y) { v.x = minx + .5f; - for(int x = 0; x < iw; ++v.x, ++x) + for (int x = 0; x < iw; ++v.x, ++x) { vec2 q = vrot(i, v); unsigned rgb = filter ? getPixel(c, q.x + ox, q.y + oy) : c->getPixel(floor(q.x + ox), floor(q.y + oy)); @@ -202,7 +187,7 @@ static gxCanvas* tformCanvas(gxCanvas* c, float m[2][2], int x_handle, int y_han static bool saveCanvas(gxCanvas* c, const std::string& f) { std::ofstream out(f.c_str(), std::ios::binary); - if(!out.good()) return false; + if (!out.good()) return false; int tempsize = (c->getWidth() * 3 + 3) & ~3; @@ -224,10 +209,10 @@ static bool saveCanvas(gxCanvas* c, const std::string& f) memset(temp, 0, tempsize); c->lock(); - for(int y = c->getHeight() - 1; y >= 0; --y) + for (int y = c->getHeight() - 1; y >= 0; --y) { unsigned char* dest = temp; - for(int x = 0; x < c->getWidth(); ++x) + for (int x = 0; x < c->getWidth(); ++x) { unsigned rgb = c->getPixelFast(x, y); *dest++ = rgb & 0xff; @@ -250,7 +235,7 @@ int bbCountGfxDrivers() BBStr* bbGfxDriverName(int n) { - debugDriver(n); + debugDriver(n, "GfxDriverName"); std::string t; int caps; gx_runtime->graphicsDriverInfo(n - 1, &t, &caps); return new BBStr(t); @@ -258,7 +243,7 @@ BBStr* bbGfxDriverName(int n) void bbSetGfxDriver(int n) { - debugDriver(n); + debugDriver(n, "SetGfxDriver"); gfx_modes.clear(); gx_driver = n - 1; } @@ -267,7 +252,7 @@ int bbCountGfxModes() { gfx_modes.clear(); int n = gx_runtime->numGraphicsModes(gx_driver); - for(int k = 0; k < n; ++k) + for (int k = 0; k < n; ++k) { GfxMode m; gx_runtime->graphicsModeInfo(gx_driver, k, &m.w, &m.h, &m.d, &m.caps); @@ -278,31 +263,31 @@ int bbCountGfxModes() int bbGfxModeWidth(int n) { - debugMode(n); + debugMode(n, "GfxModeWidth"); return gfx_modes[n - 1].w; } int bbGfxModeHeight(int n) { - debugMode(n); + debugMode(n, "GfxModeHeight"); return gfx_modes[n - 1].h; } int bbGfxModeDepth(int n) { - debugMode(n); + debugMode(n, "GfxModeDepth"); return gfx_modes[n - 1].d; } static int modeExists(int w, int h, int d, bool bb3d) { int cnt = gx_runtime->numGraphicsModes(gx_driver); - for(int k = 0; k < cnt; ++k) + for (int k = 0; k < cnt; ++k) { int tw, th, td, tc; gx_runtime->graphicsModeInfo(gx_driver, k, &tw, &th, &td, &tc); - if(bb3d && !(tc & gxRuntime::GFXMODECAPS_3D)) continue; - if(w == tw && h == th && d == td) return 1; + if (bb3d && !(tc & gxRuntime::GFXMODECAPS_3D)) continue; + if (w == tw && h == th && d == td) return 1; } return 0; } @@ -314,7 +299,7 @@ int bbGfxModeExists(int w, int h, int d) int bbGfxDriver3D(int n) { - debugDriver(n); + debugDriver(n, "GfxDriver3D"); std::string t; int caps; gx_runtime->graphicsDriverInfo(n - 1, &t, &caps); return (caps & gxRuntime::GFXMODECAPS_3D) ? 1 : 0; @@ -324,11 +309,11 @@ int bbCountGfxModes3D() { gfx_modes.clear(); int n = gx_runtime->numGraphicsModes(gx_driver); - for(int k = 0; k < n; ++k) + for (int k = 0; k < n; ++k) { GfxMode m; gx_runtime->graphicsModeInfo(gx_driver, k, &m.w, &m.h, &m.d, &m.caps); - if(m.caps & gxRuntime::GFXMODECAPS_3D) gfx_modes.push_back(m); + if (m.caps & gxRuntime::GFXMODECAPS_3D) gfx_modes.push_back(m); } return gfx_modes.size(); } @@ -340,7 +325,7 @@ int bbGfxMode3DExists(int w, int h, int d) int bbGfxMode3D(int n) { - debugMode(n); + debugMode(n, "GfxMode3D"); return gfx_modes[n - 1].caps & gxRuntime::GFXMODECAPS_3D ? 1 : 0; } @@ -363,7 +348,7 @@ int bbAvailVidMem() void bbSetBuffer(gxCanvas* buff) { - debugCanvas(buff); + debugCanvas(buff, "SetBuffer"); gx_canvas = buff; curs_x = curs_y = 0; gx_canvas->setOrigin(0, 0); @@ -380,10 +365,10 @@ gxCanvas* bbGraphicsBuffer() int bbLoadBuffer(gxCanvas* c, BBStr* str) { - debugCanvas(c); + debugCanvas(c, "LoadBuffer"); std::string s = *str; delete str; gxCanvas* t = gx_graphics->loadCanvas(s, 0); - if(!t) return 0; + if (!t) return 0; float m[2][2]; m[0][0] = (float)c->getWidth() / (float)t->getWidth(); m[1][1] = (float)c->getHeight() / (float)t->getHeight(); @@ -399,14 +384,14 @@ int bbLoadBuffer(gxCanvas* c, BBStr* str) int bbSaveBuffer(gxCanvas* c, BBStr* str) { - debugCanvas(c); + debugCanvas(c, "SaveBuffer"); std::string t = *str; delete str; return saveCanvas(c, t) ? 1 : 0; } void bbBufferDirty(gxCanvas* c) { - debugCanvas(c); + debugCanvas(c, "BufferDirty"); c->backup(); } @@ -415,8 +400,8 @@ static void graphics(int w, int h, int d, int flags) freeGraphics(); gx_runtime->closeGraphics(gx_graphics); gx_graphics = gx_runtime->openGraphics(w, h, d, gx_driver, flags); - if(!gx_runtime->idle()) RTEX(0); - if(!gx_graphics) + if (!gx_runtime->idle()) RTEX(0); + if (!gx_graphics) RTEX(MultiLang::unable_create_gxgraphics_instance); curr_clsColor = 0; curr_color = 0xffffffff; @@ -429,16 +414,16 @@ static void graphics(int w, int h, int d, int flags) void bbGraphics(int w, int h, int d, int mode) { int flags = 0; - switch(mode) + switch (mode) { - case 0:flags |= debug ? gxGraphics::GRAPHICS_WINDOWED : 0; break; - case 1:break; - case 2:flags |= gxGraphics::GRAPHICS_WINDOWED; break; - case 3:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED; break; - case 4:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_BORDERLESS; break; - case 6:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; - case 7:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; - default:RTEX(MultiLang::illegal_graphics_mode); + case 0:flags |= debug ? gxGraphics::GRAPHICS_WINDOWED : 0; break; + case 1:break; + case 2:flags |= gxGraphics::GRAPHICS_WINDOWED; break; + case 3:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED; break; + case 4:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_BORDERLESS; break; + case 6:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; + case 7:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; + default:RTEX(MultiLang::illegal_graphics_mode); } graphics(w, h, d, flags); } @@ -446,16 +431,16 @@ void bbGraphics(int w, int h, int d, int mode) void bbGraphics3D(int w, int h, int d, int mode) { int flags = gxGraphics::GRAPHICS_3D; - switch(mode) + switch (mode) { - case 0:flags |= (debug && bbWindowed3D()) ? gxGraphics::GRAPHICS_WINDOWED : 0; break; - case 1:break; - case 2:flags |= gxGraphics::GRAPHICS_WINDOWED; break; - case 3:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED; break; - case 4:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_BORDERLESS; break; - case 6:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; - case 7:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; - default:RTEX(MultiLang::illegal_graphics3d_mode); + case 0:flags |= (debug && bbWindowed3D()) ? gxGraphics::GRAPHICS_WINDOWED : 0; break; + case 1:break; + case 2:flags |= gxGraphics::GRAPHICS_WINDOWED; break; + case 3:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED; break; + case 4:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_BORDERLESS; break; + case 6:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; + case 7:flags |= gxGraphics::GRAPHICS_WINDOWED | gxGraphics::GRAPHICS_SCALED | gxGraphics::GRAPHICS_AUTOSUSPEND; break; + default:RTEX(MultiLang::illegal_graphics3d_mode); } graphics(w, h, d, flags); extern void blitz3d_open(); @@ -467,8 +452,8 @@ void bbEndGraphics() freeGraphics(); gx_runtime->closeGraphics(gx_graphics); gx_graphics = gx_runtime->openGraphics(400, 300, 0, 0, gxGraphics::GRAPHICS_WINDOWED); - if(!gx_runtime->idle()) RTEX(0); - if(gx_graphics) + if (!gx_runtime->idle()) RTEX(0); + if (gx_graphics) { curr_clsColor = 0; curr_color = 0xffffffff; @@ -501,12 +486,12 @@ int bbDesktopHeight() void bbSetGamma(int r, int g, int b, float dr, float dg, float db) { - if(dr < 0) dr = 0; - else if(dr > 255.0f) dr = 255.0f; - if(dg < 0) dg = 0; - else if(dg > 255.0f) dg = 255.0f; - if(db < 0) db = 0; - else if(db > 255.0f) db = 255.0f; + if (dr < 0) dr = 0; + else if (dr > 255.0f) dr = 255.0f; + if (dg < 0) dg = 0; + else if (dg > 255.0f) dg = 255.0f; + if (db < 0) db = 0; + else if (db > 255.0f) db = 255.0f; gx_graphics->setGamma(r, g, b, dr, dg, db); } @@ -548,25 +533,25 @@ gxCanvas* bbBackBuffer() void bbLockBuffer(gxCanvas* buff) { - if(buff) debugCanvas(buff); + if (buff) debugCanvas(buff, "LockBuffer"); (buff ? buff : gx_canvas)->lock(); } void bbUnlockBuffer(gxCanvas* buff) { - if(buff) debugCanvas(buff); + if (buff) debugCanvas(buff, "UnlockBuffer"); (buff ? buff : gx_canvas)->unlock(); } int bbReadPixel(int x, int y, gxCanvas* buff) { - if(buff) debugCanvas(buff); + if (buff) debugCanvas(buff, "ReadPixel"); return (buff ? buff : gx_canvas)->getPixel(x, y); } void bbWritePixel(int x, int y, int argb, gxCanvas* buff) { - if(buff) debugCanvas(buff); + if (buff) debugCanvas(buff, "WritePixel"); (buff ? buff : gx_canvas)->setPixel(x, y, argb); } @@ -598,13 +583,13 @@ int bbScanLine() void bbVWait(int n) { gx_graphics->vwait(); - if(!gx_runtime->idle()) RTEX(0); + if (!gx_runtime->idle()) RTEX(0); } void bbFlip(int vwait) { gx_graphics->flip(vwait ? true : false); - if(!gx_runtime->idle()) RTEX(0); + if (!gx_runtime->idle()) RTEX(0); } int bbGraphicsWidth() @@ -664,7 +649,7 @@ void bbClsColor(int r, int g, int b) void bbSetFont(gxFont* f) { - debugFont(f); + debugFont(f, "SetFont"); gx_canvas->setFont(curr_font = f); } @@ -721,33 +706,33 @@ BBStr* bbConvertToUTF8(BBStr* str) void bbCopyRect(int sx, int sy, int w, int h, int dx, int dy, gxCanvas* src, gxCanvas* dest) { - if(src) debugCanvas(src); + if (src) debugCanvas(src, "CopyRect"); else src = gx_canvas; - if(dest) debugCanvas(dest); + if (dest) debugCanvas(dest, "CopyRect"); else dest = gx_canvas; dest->blit(dx, dy, src, sx, sy, w, h, true); } void bbCopyRectStretch(int sx, int sy, int w, int h, int dx, int dy, int dw, int dh, gxCanvas* src, gxCanvas* dest) { - if(src) debugCanvas(src); + if (src) debugCanvas(src, "CopyRectStretch"); else src = gx_canvas; - if(dest) debugCanvas(dest); + if (dest) debugCanvas(dest, "CopyRectStretch"); else dest = gx_canvas; dest->blitstretch(dx, dy, dw, dh, src, sx, sy, w, h, true); } -gxFont *bbLoadFont( BBStr *name, int height ){ - gxFont *font=gx_graphics->loadFont( *name,height ); +gxFont* bbLoadFont(BBStr* name, int height) { + gxFont* font = gx_graphics->loadFont(*name, height); delete name; return font; } void bbFreeFont(gxFont* f) { - debugFont(f); - if(f == curr_font) bbSetFont(gx_graphics->getDefaultFont()); + debugFont(f, "FreeFont"); + if (f == curr_font) bbSetFont(gx_graphics->getDefaultFont()); gx_graphics->freeFont(f); } @@ -776,7 +761,7 @@ int bbStringHeight(BBStr* str, int encoding) { if (encoding) *str = UTF8::convertToUTF8(str->c_str()); delete str; - return curr_font->getHeight()+curr_font->getRenderOffset(); + return curr_font->getHeight() + curr_font->getRenderOffset(); } gxMovie* bbOpenMovie(BBStr* s) @@ -787,10 +772,10 @@ gxMovie* bbOpenMovie(BBStr* s) int bbDrawMovie(gxMovie* movie, int x, int y, int w, int h) { - if(w < 0) w = movie->getWidth(); - if(h < 0) h = movie->getHeight(); + if (w < 0) w = movie->getWidth(); + if (h < 0) h = movie->getHeight(); int playing = movie->draw(gx_canvas, x, y, w, h); - if(!gx_runtime->idle()) RTEX(0); + if (!gx_runtime->idle()) RTEX(0); return playing; } @@ -818,9 +803,9 @@ bbImage* bbLoadImage(BBStr* s) { std::string t = *s; delete s; gxCanvas* c = gx_graphics->loadCanvas(t, 0); - if(!c) return 0; - if(auto_dirty) c->backup(); - if(auto_midhandle) c->setHandle(c->getWidth() / 2, c->getHeight() / 2); + if (!c) return 0; + if (auto_dirty) c->backup(); + if (auto_midhandle) c->setHandle(c->getWidth() / 2, c->getHeight() / 2); std::vector frames; frames.push_back(c); bbImage* i = new bbImage(frames); @@ -833,38 +818,38 @@ bbImage* bbLoadAnimImage(BBStr* s, int w, int h, int first, int cnt) std::string t = *s; delete s; - if(cnt < 1) RTEX(MultiLang::illegal_frame_count); - if(first < 0) RTEX(MultiLang::illegal_first_frame); + if (cnt < 1) ErrorLog("LoadAnimImage", MultiLang::illegal_frame_count); + if (first < 0) ErrorLog("LoadAnimImage", MultiLang::illegal_first_frame); gxCanvas* pic = gx_graphics->loadCanvas(t, gxCanvas::CANVAS_NONDISPLAY); - if(!pic) return 0; + if (!pic) return 0; //frames per row, per picture int fpr = pic->getWidth() / w; int fpp = pic->getHeight() / h * fpr; - if(first + cnt > fpp) + if (first + cnt > fpp) { gx_graphics->freeCanvas(pic); - RTEX(MultiLang::not_enough_frames_bitmap); + ErrorLog("LoadAnimImage", MultiLang::not_enough_frames_bitmap); } //x,y of first frame... std::vector frames; int src_x = first % fpr * w, src_y = first / fpr * h; - for(int k = 0; k < cnt; ++k) + for (int k = 0; k < cnt; ++k) { gxCanvas* c = gx_graphics->createCanvas(w, h, 0); - if(!c) + if (!c) { - for(--k; k >= 0; --k) gx_graphics->freeCanvas(frames[k]); + for (--k; k >= 0; --k) gx_graphics->freeCanvas(frames[k]); gx_graphics->freeCanvas(pic); return 0; } c->blit(0, 0, pic, src_x, src_y, w, h, true); - if(auto_dirty) c->backup(); - if(auto_midhandle) c->setHandle(c->getWidth() / 2, c->getHeight() / 2); + if (auto_dirty) c->backup(); + if (auto_midhandle) c->setHandle(c->getWidth() / 2, c->getHeight() / 2); frames.push_back(c); - src_x += w; if(src_x + w > pic->getWidth()) { src_x = 0; src_y += h; } + src_x += w; if (src_x + w > pic->getWidth()) { src_x = 0; src_y += h; } } gx_graphics->freeCanvas(pic); bbImage* i = new bbImage(frames); @@ -874,23 +859,23 @@ bbImage* bbLoadAnimImage(BBStr* s, int w, int h, int first, int cnt) bbImage* bbCopyImage(bbImage* i) { - debugImage(i); + debugImage(i, "CopyImage"); std::vector frames; const std::vector& f = i->getFrames(); - for(int k = 0; k < f.size(); ++k) + for (int k = 0; k < f.size(); ++k) { gxCanvas* t = f[k]; gxCanvas* c = gx_graphics->createCanvas(t->getWidth(), t->getHeight(), 0); - if(!c) + if (!c) { - for(--k; k >= 0; --k) gx_graphics->freeCanvas(frames[k]); + for (--k; k >= 0; --k) gx_graphics->freeCanvas(frames[k]); return 0; } int x, y; t->getHandle(&x, &y); t->setHandle(0, 0); c->blit(0, 0, t, 0, 0, t->getWidth(), t->getHeight(), true); - if(auto_dirty) c->backup(); + if (auto_dirty) c->backup(); t->setHandle(x, y); c->setHandle(x, y); c->setMask(t->getMask()); @@ -904,16 +889,16 @@ bbImage* bbCopyImage(bbImage* i) bbImage* bbCreateImage(int w, int h, int n) { std::vector frames; - for(int k = 0; k < n; ++k) + for (int k = 0; k < n; ++k) { gxCanvas* c = gx_graphics->createCanvas(w, h, 0); - if(!c) + if (!c) { - for(--k; k >= 0; --k) gx_graphics->freeCanvas(frames[k]); + for (--k; k >= 0; --k) gx_graphics->freeCanvas(frames[k]); return 0; } - if(auto_dirty) c->backup(); - if(auto_midhandle) c->setHandle(c->getWidth() / 2, c->getHeight() / 2); + if (auto_dirty) c->backup(); + if (auto_midhandle) c->setHandle(c->getWidth() / 2, c->getHeight() / 2); frames.push_back(c); } bbImage* i = new bbImage(frames); @@ -923,11 +908,11 @@ bbImage* bbCreateImage(int w, int h, int n) void bbFreeImage(bbImage* i) { - if(!image_set.erase(i)) return; + if (!image_set.erase(i)) return; const std::vector& f = i->getFrames(); - for(int k = 0; k < f.size(); ++k) + for (int k = 0; k < f.size(); ++k) { - if(f[k] == gx_canvas) + if (f[k] == gx_canvas) { bbSetBuffer(gx_graphics->getFrontCanvas()); break; @@ -938,7 +923,7 @@ void bbFreeImage(bbImage* i) int bbSaveImage(bbImage* i, BBStr* str, int n) { - debugImage(i, n); + debugImage(i, "SaveImage", n); std::string t = *str; delete str; gxCanvas* c = i->getFrames()[n]; return saveCanvas(c, t) ? 1 : 0; @@ -946,7 +931,7 @@ int bbSaveImage(bbImage* i, BBStr* str, int n) void bbGrabImage(bbImage* i, int x, int y, int n) { - debugImage(i, n); + debugImage(i, "GrabImage", n); gxCanvas* c = i->getFrames()[n]; int src_ox, src_oy, dst_hx, dst_hy; gx_canvas->getOrigin(&src_ox, &src_oy); @@ -954,25 +939,25 @@ void bbGrabImage(bbImage* i, int x, int y, int n) x += src_ox - dst_hx; y += src_oy - dst_hy; c->setViewport(0, 0, c->getWidth(), c->getHeight()); c->blit(0, 0, gx_canvas, x, y, c->getWidth(), c->getHeight(), true); - if(auto_dirty) c->backup(); + if (auto_dirty) c->backup(); } gxCanvas* bbImageBuffer(bbImage* i, int n) { - debugImage(i, n); + debugImage(i, "ImageBuffer", n); return i->getFrames()[n]; } void bbDrawImage(bbImage* i, int x, int y, int frame) { - debugImage(i, frame); + debugImage(i, "DrawImage", frame); gxCanvas* c = i->getFrames()[frame]; gx_canvas->blit(x, y, c, 0, 0, c->getWidth(), c->getHeight(), false); } void bbDrawBlock(bbImage* i, int x, int y, int frame) { - debugImage(i, frame); + debugImage(i, "DrawBlock", frame); gxCanvas* c = i->getFrames()[frame]; gx_canvas->blit(x, y, c, 0, 0, c->getWidth(), c->getHeight(), true); } @@ -995,9 +980,9 @@ static void tile(bbImage* i, int x, int y, int frame, bool solid) dx += (x >= 0 ? x % w : w - (-x % w)); dy += (y >= 0 ? y % h : h - (-y % h)); - for(y = -h; y < vp_h; y += h) + for (y = -h; y < vp_h; y += h) { - for(x = -w; x < vp_w; x += w) + for (x = -w; x < vp_w; x += w) { gx_canvas->blit(x + dx, y + dy, c, 0, 0, w, h, solid); } @@ -1006,50 +991,50 @@ static void tile(bbImage* i, int x, int y, int frame, bool solid) void bbTileImage(bbImage* i, int x, int y, int frame) { - debugImage(i, frame); + debugImage(i, "TileImage", frame); tile(i, x, y, frame, false); } void bbTileBlock(bbImage* i, int x, int y, int frame) { - debugImage(i, frame); + debugImage(i, "TileBlock", frame); tile(i, x, y, frame, true); } void bbDrawImageRect(bbImage* i, int x, int y, int r_x, int r_y, int r_w, int r_h, int frame) { - debugImage(i, frame); + debugImage(i, "DrawImageRect", frame); gxCanvas* c = i->getFrames()[frame]; gx_canvas->blit(x, y, c, r_x, r_y, r_w, r_h, false); } void bbDrawBlockRect(bbImage* i, int x, int y, int r_x, int r_y, int r_w, int r_h, int frame) { - debugImage(i, frame); + debugImage(i, "DrawBlockRect", frame); gxCanvas* c = i->getFrames()[frame]; gx_canvas->blit(x, y, c, r_x, r_y, r_w, r_h, true); } void bbMaskImage(bbImage* i, int r, int g, int b) { - debugImage(i); + debugImage(i, "MaskImage"); unsigned argb = (r << 16) | (g << 8) | b; const std::vector& f = i->getFrames(); - for(int k = 0; k < f.size(); ++k) f[k]->setMask(argb); + for (int k = 0; k < f.size(); ++k) f[k]->setMask(argb); } void bbHandleImage(bbImage* i, int x, int y) { - debugImage(i); + debugImage(i, "HandleImage"); const std::vector& f = i->getFrames(); - for(int k = 0; k < f.size(); ++k) f[k]->setHandle(x, y); + for (int k = 0; k < f.size(); ++k) f[k]->setHandle(x, y); } void bbMidHandle(bbImage* i) { - debugImage(i); + debugImage(i, "MidHandle"); const std::vector& f = i->getFrames(); - for(int k = 0; k < f.size(); ++k) f[k]->setHandle(f[k]->getWidth() / 2, f[k]->getHeight() / 2); + for (int k = 0; k < f.size(); ++k) f[k]->setHandle(f[k]->getWidth() / 2, f[k]->getHeight() / 2); } void bbAutoMidHandle(int enable) @@ -1059,19 +1044,19 @@ void bbAutoMidHandle(int enable) int bbImageWidth(bbImage* i) { - debugImage(i); + debugImage(i, "ImageWidth"); return i->getFrames()[0]->getWidth(); } int bbImageHeight(bbImage* i) { - debugImage(i); + debugImage(i, "ImageHeight"); return i->getFrames()[0]->getHeight(); } int bbImageXHandle(bbImage* i) { - debugImage(i); + debugImage(i, "ImageXHandle"); int x, y; i->getFrames()[0]->getHandle(&x, &y); return x; @@ -1079,7 +1064,7 @@ int bbImageXHandle(bbImage* i) int bbImageYHandle(bbImage* i) { - debugImage(i); + debugImage(i, "ImageYHandle"); int x, y; i->getFrames()[0]->getHandle(&x, &y); return y; @@ -1087,8 +1072,8 @@ int bbImageYHandle(bbImage* i) int bbImagesOverlap(bbImage* i1, int x1, int y1, bbImage* i2, int x2, int y2) { - debugImage(i1); - debugImage(i2); + debugImage(i1, "ImagesOverlap"); + debugImage(i2, "ImagesOverlap"); gxCanvas* c1 = i1->getFrames()[0]; gxCanvas* c2 = i2->getFrames()[0]; return c1->collide(x1, y1, c2, x2, y2, true); @@ -1096,8 +1081,8 @@ int bbImagesOverlap(bbImage* i1, int x1, int y1, bbImage* i2, int x2, int y2) int bbImagesCollide(bbImage* i1, int x1, int y1, int f1, bbImage* i2, int x2, int y2, int f2) { - debugImage(i1, f1); - debugImage(i2, f2); + debugImage(i1, "ImagesCollide", f1); + debugImage(i2, "ImagesCollide", f2); gxCanvas* c1 = i1->getFrames()[f1]; gxCanvas* c2 = i2->getFrames()[f2]; return c1->collide(x1, y1, c2, x2, y2, false); @@ -1105,32 +1090,32 @@ int bbImagesCollide(bbImage* i1, int x1, int y1, int f1, bbImage* i2, int x2, in int bbRectsOverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { - if(x1 + w1 <= x2 || x1 >= x2 + w2 || y1 + h1 <= y2 || y1 >= y2 + h2) return 0; + if (x1 + w1 <= x2 || x1 >= x2 + w2 || y1 + h1 <= y2 || y1 >= y2 + h2) return 0; return 1; } int bbImageRectOverlap(bbImage* i, int x, int y, int x2, int y2, int w2, int h2) { - debugImage(i); + debugImage(i, "ImageRectOverlap"); gxCanvas* c = i->getFrames()[0]; return c->rect_collide(x, y, x2, y2, w2, h2, true); } int bbImageRectCollide(bbImage* i, int x, int y, int f, int x2, int y2, int w2, int h2) { - debugImage(i, f); + debugImage(i, "ImageRectCollide", f); gxCanvas* c = i->getFrames()[f]; return c->rect_collide(x, y, x2, y2, w2, h2, false); } void bbTFormImage(bbImage* i, float a, float b, float c, float d) { - debugImage(i); + debugImage(i, "TFormImage"); const std::vector& f = i->getFrames(); int k; - for(k = 0; k < f.size(); ++k) + for (k = 0; k < f.size(); ++k) { - if(f[k] == gx_canvas) + if (f[k] == gx_canvas) { bbSetBuffer(gx_graphics->getFrontCanvas()); break; @@ -1138,7 +1123,7 @@ void bbTFormImage(bbImage* i, float a, float b, float c, float d) } float m[2][2]; m[0][0] = a; m[1][0] = b; m[0][1] = c; m[1][1] = d; - for(k = 0; k < f.size(); ++k) + for (k = 0; k < f.size(); ++k) { gxCanvas* c = f[k]; int hx, hy; c->getHandle(&hx, &hy); @@ -1150,20 +1135,20 @@ void bbTFormImage(bbImage* i, float a, float b, float c, float d) void bbScaleImage(bbImage* i, float w, float h) { - debugImage(i); + debugImage(i, "ScaleImage"); bbTFormImage(i, w, 0, 0, h); } void bbResizeImage(bbImage* i, float w, float h) { - debugImage(i); + debugImage(i, "ResizeImage"); gxCanvas* c = i->getFrames()[0]; bbTFormImage(i, w / (float)c->getWidth(), 0, 0, h / (float)c->getHeight()); } void bbRotateImage(bbImage* i, float d) { - debugImage(i); + debugImage(i, "RotateImage"); d *= -dtor; bbTFormImage(i, cos(d), -sin(d), sin(d), cos(d)); } @@ -1190,14 +1175,14 @@ static gxCanvas* startPrinting() c->setOrigin(0, 0); c->setHandle(0, 0); c->setViewport(0, 0, c->getWidth(), c->getHeight()); - if(c != gx_canvas) + if (c != gx_canvas) { c->setFont(curr_font); c->setColor(curr_color); } int dy = curs_y + curr_font->getHeight() - c->getHeight(); - if(dy > 0) + if (dy > 0) { curs_y = c->getHeight() - curr_font->getHeight(); c->blit(0, 0, c, 0, dy, c->getWidth(), c->getHeight() - dy, true); @@ -1213,8 +1198,8 @@ static void endPrinting(gxCanvas* c) c->setViewport(p_vpx, p_vpy, p_vpw, p_vph); c->setHandle(p_hx, p_hy); c->setOrigin(p_ox, p_oy); - if(c == gx_canvas) c->setColor(curr_color); - if(!gx_runtime->idle()) RTEX(0); + if (c == gx_canvas) c->setColor(curr_color); + if (!gx_runtime->idle()) RTEX(0); } void bbWrite(BBStr* str) @@ -1242,11 +1227,11 @@ BBStr* bbInput(BBStr* prompt) std::string t = *prompt; delete prompt; //get temp canvas - if(!p_canvas || p_canvas->getWidth() < c->getWidth() || p_canvas->getHeight() < curr_font->getHeight() * 2) + if (!p_canvas || p_canvas->getWidth() < c->getWidth() || p_canvas->getHeight() < curr_font->getHeight() * 2) { - if(p_canvas) gx_graphics->freeCanvas(p_canvas); + if (p_canvas) gx_graphics->freeCanvas(p_canvas); p_canvas = gx_graphics->createCanvas(c->getWidth(), curr_font->getHeight() * 2, 0); - if(!p_canvas) + if (!p_canvas) { endPrinting(c); return new BBStr(); @@ -1264,7 +1249,7 @@ BBStr* bbInput(BBStr* prompt) bool go = true; int curs = 0, last_key = 0, last_time, rep_delay; - while(go) + while (go) { //render all text //calc curs x and width @@ -1274,14 +1259,14 @@ BBStr* bbInput(BBStr* prompt) //wait for a key int key = 0, st = gx_runtime->getMilliSecs(), tc = -1; - while(gx_runtime->idle()) + while (gx_runtime->idle()) { int t = gx_runtime->getMilliSecs(); int n = (t - st) / 320; - if(n != tc) + if (n != tc) { tc = n; - if(!(tc & 1)) + if (!(tc & 1)) { //cursor ON c->setColor(curr_clsColor ^ 0xffffff); c->rect(cx, curs_y, cw, curr_font->getHeight(), true); @@ -1294,9 +1279,9 @@ BBStr* bbInput(BBStr* prompt) } c->text(cx, curs_y, str.substr(curs, 1)); } - if(key = gx_keyboard->getKey()) + if (key = gx_keyboard->getKey()) { - if(int asc = gx_input->toAscii(key)) + if (int asc = gx_input->toAscii(key)) { rep_delay = 280; last_key = key; @@ -1305,11 +1290,11 @@ BBStr* bbInput(BBStr* prompt) break; } } - if(last_key && gx_keyboard->keyDown(last_key)) + if (last_key && gx_keyboard->keyDown(last_key)) { - if(t - last_time > rep_delay) + if (t - last_time > rep_delay) { - if(key = gx_input->toAscii(last_key)) + if (key = gx_input->toAscii(last_key)) { last_time += rep_delay; rep_delay = 40; @@ -1322,46 +1307,46 @@ BBStr* bbInput(BBStr* prompt) } //check the key - switch(key) + switch (key) { - case 0: - go = false; - str = ""; - break; - case 8: - if(curs) - { - str = str.substr(0, curs - 1) + str.substr(curs); - --curs; - } - break; - case 27: - curs = 0; str = ""; - break; - case gxInput::ASC_DELETE: - if(curs < str.size()) str = str.substr(0, curs) + str.substr(curs + 1); - break; - case gxInput::ASC_HOME: - curs = 0; - break; - case gxInput::ASC_END: - curs = str.size(); - break; - case gxInput::ASC_LEFT: - if(curs) --curs; - break; - case gxInput::ASC_RIGHT: - if(curs < str.size()) ++curs; - break; - case '\r': - go = false; - break; - default: - if(curr_font->isPrintable(key)) - { - str = str.substr(0, curs) + char(key) + str.substr(curs); - ++curs; - } + case 0: + go = false; + str = ""; + break; + case 8: + if (curs) + { + str = str.substr(0, curs - 1) + str.substr(curs); + --curs; + } + break; + case 27: + curs = 0; str = ""; + break; + case gxInput::ASC_DELETE: + if (curs < str.size()) str = str.substr(0, curs) + str.substr(curs + 1); + break; + case gxInput::ASC_HOME: + curs = 0; + break; + case gxInput::ASC_END: + curs = str.size(); + break; + case gxInput::ASC_LEFT: + if (curs) --curs; + break; + case gxInput::ASC_RIGHT: + if (curs < str.size()) ++curs; + break; + case '\r': + go = false; + break; + default: + if (curr_font->isPrintable(key)) + { + str = str.substr(0, curs) + char(key) + str.substr(curs); + ++curs; + } } //render text @@ -1402,7 +1387,7 @@ bool graphics_create() auto_dirty = true; auto_midhandle = false; gx_graphics = gx_runtime->openGraphics(400, 300, 0, 0, gxGraphics::GRAPHICS_WINDOWED); - if(gx_graphics) + if (gx_graphics) { curr_clsColor = 0; curr_color = 0xffffffff; @@ -1417,7 +1402,7 @@ bool graphics_destroy() { freeGraphics(); gfx_modes.clear(); - if(gx_graphics) + if (gx_graphics) { gx_runtime->closeGraphics(gx_graphics); gx_graphics = 0; @@ -1511,13 +1496,13 @@ void graphics_link(void (*rtSym)(const char* sym, void* pc)) //fonts - rtSym( "%LoadFont$fontname%height=12",bbLoadFont ); - rtSym( "%CurrentFont",bbCurrentFont ); - rtSym( "FreeFont%font",bbFreeFont ); - rtSym( "%FontWidth",bbFontWidth ); - rtSym( "%FontHeight",bbFontHeight ); - rtSym( "%StringWidth$string%encoding=0",bbStringWidth ); - rtSym( "%StringHeight$string%encoding=0",bbStringHeight ); + rtSym("%LoadFont$fontname%height=12", bbLoadFont); + rtSym("%CurrentFont", bbCurrentFont); + rtSym("FreeFont%font", bbFreeFont); + rtSym("%FontWidth", bbFontWidth); + rtSym("%FontHeight", bbFontHeight); + rtSym("%StringWidth$string%encoding=0", bbStringWidth); + rtSym("%StringHeight$string%encoding=0", bbStringHeight); //movies rtSym("%OpenMovie$file", bbOpenMovie); @@ -1573,10 +1558,6 @@ void graphics_link(void (*rtSym)(const char* sym, void* pc)) rtSym("%DesktopWidth", bbDesktopWidth); rtSym("%DesktopHeight", bbDesktopHeight); - -#ifdef OPENCC - rtSym("OpenCC$path", bbOpenCC); -#endif } extern "C" { diff --git a/bbruntime/bbgraphics.h b/bbruntime/bbgraphics.h index 150696a0..a822723e 100644 --- a/bbruntime/bbgraphics.h +++ b/bbruntime/bbgraphics.h @@ -5,20 +5,20 @@ #include "../gxruntime/gxgraphics.h" extern gxGraphics* gx_graphics; -extern gxCanvas* gx_canvas; -extern gxScene* gx_scene; +extern gxCanvas* gx_canvas; +extern gxScene* gx_scene; class bbImage; //general graphics functions int bbCountGfxDrivers(); -BBStr * bbGfxDriverName( int n ); -void bbSetGfxDriver( int n ); -int bbGfxModeExists( int w,int h,int d ); +BBStr* bbGfxDriverName(int n); +void bbSetGfxDriver(int n); +int bbGfxModeExists(int w, int h, int d); int bbCountGfxModes(); -int bbGfxModeWidth( int n ); -int bbGfxModeHeight( int n ); -int bbGfxModeDepth( int n ); +int bbGfxModeWidth(int n); +int bbGfxModeHeight(int n); +int bbGfxModeDepth(int n); int bbGraphicsWidth(); int bbGraphicsHeight(); int bbGraphicsDepth(); @@ -26,43 +26,43 @@ int bbAvailVidMem(); int bbTotalVidMem(); //mode functions -void bbGraphics( int w,int h,int d,int mode ); +void bbGraphics(int w, int h, int d, int mode); gxCanvas* bbFrontBuffer(); gxCanvas* bbBackBuffer(); void bbEndGraphics(); int bbInFocus(); int bbGraphicsLost(); int bbScanLine(); -void bbVWait( int n ); -void bbFlip( int vwait ); +void bbVWait(int n); +void bbFlip(int vwait); //graphics buffer functions -void bbSetBuffer( gxCanvas *buff ); +void bbSetBuffer(gxCanvas* buff); gxCanvas* bbGraphicsBuffer(); -int bbLoadBuffer( gxCanvas *surf,BBStr *str ); -int bbSaveBuffer( gxCanvas *surf,BBStr *str ); +int bbLoadBuffer(gxCanvas* surf, BBStr* str); +int bbSaveBuffer(gxCanvas* surf, BBStr* str); //fast read/write operations... -void bbLockBuffer( gxCanvas *buff ); -void bbUnlockBuffer( gxCanvas *buff ); -int bbReadPixel( int x,int y,gxCanvas *buff ); -void bbWritePixel( int x,int y,int argb,gxCanvas *buff ); -int bbReadPixelFast( int x,int y,gxCanvas *buff ); -void bbWritePixelFast( int x,int y,int argb,gxCanvas *buff ); +void bbLockBuffer(gxCanvas* buff); +void bbUnlockBuffer(gxCanvas* buff); +int bbReadPixel(int x, int y, gxCanvas* buff); +void bbWritePixel(int x, int y, int argb, gxCanvas* buff); +int bbReadPixelFast(int x, int y, gxCanvas* buff); +void bbWritePixelFast(int x, int y, int argb, gxCanvas* buff); //2d rendering functions -void bbOrigin( int x,int y ); -void bbViewport( int x,int y,int w,int h ); -void bbColor( int r,int g,int b ); -void bbClsColor( int r,int g,int b ); +void bbOrigin(int x, int y); +void bbViewport(int x, int y, int w, int h); +void bbColor(int r, int g, int b); +void bbClsColor(int r, int g, int b); void bbCls(); -void bbPlot( int x,int y ); -void bbLine( int x1,int y1,int x2,int y2 ); -void bbRect( int x,int y,int w,int h,int solid ); -void bbOval( int x,int y,int w,int h,int solid ); -void bbText( int x,int y,BBStr *str,int xPos,int yPos ); -void bbGetColor( int x,int y ); +void bbPlot(int x, int y); +void bbLine(int x1, int y1, int x2, int y2); +void bbRect(int x, int y, int w, int h, int solid); +void bbOval(int x, int y, int w, int h, int solid); +void bbText(int x, int y, BBStr* str, int xPos, int yPos); +void bbGetColor(int x, int y); int bbColorRed(); int bbColorGreen(); int bbColorBlue(); @@ -71,52 +71,52 @@ BBStr* bbConvertToANSI(BBStr* str); BBStr* bbConvertToUTF8(BBStr* str); //font functions -gxFont* bbLoadFont( BBStr *name,int height ); -void bbFreeFont( gxFont *f ); -void bbSetFont( gxFont *f ); +gxFont* bbLoadFont(BBStr* name, int height); +void bbFreeFont(gxFont* f); +void bbSetFont(gxFont* f); int bbFontWidth(); int bbFontHeight(); -int bbStringWidth( BBStr *str,int encoding ); -int bbStringHeight( BBStr *str,int encoding ); +int bbStringWidth(BBStr* str, int encoding); +int bbStringHeight(BBStr* str, int encoding); //image functions -bbImage* bbLoadImage( BBStr *s ); -bbImage* bbCopyImage( bbImage *i ); -bbImage* bbCreateImage( int w,int h,int n ); -bbImage* bbLoadAnimImage( BBStr *s,int w,int h,int first,int cnt ); -void bbFreeImage( bbImage *i ); -int bbSaveImage( bbImage *i,BBStr *filename,int frame ); -void bbGrabImage( bbImage *i,int x,int y,int n ); -gxCanvas* bbImageBuffer( bbImage *i,int n ); -void bbDrawImage( bbImage *i,int x,int y,int frame ); -void bbDrawBlock( bbImage *i,int x,int y,int frame ); -void bbTileImage( bbImage *i,int x,int y,int frame ); -void bbTileBlock( bbImage *i,int x,int y,int frame ); -void bbDrawImageRect( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h,int frame ); -void bbDrawBlockRect( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h,int frame ); -void bbMaskImage( bbImage *i,int r,int g,int b ); -void bbHandleImage( bbImage *i,int x,int y ); -void bbScaleImage( bbImage *i,float w,float h ); -void bbResizeImage( bbImage *i,float w,float h ); -void bbRotateImage( bbImage *i,float angle ); -void bbTFormImage( bbImage *i,float a,float b,float c,float d ); -void bbTFormFilter( int enable ); -void bbAutoMidHandle( int enable ); -void bbMidHandle( bbImage *i ); -int bbImageWidth( bbImage *i ); -int bbImageHeight( bbImage *i ); -int bbImageXHandle( bbImage *i ); -int bbImageYHandle( bbImage *i ); -int bbImagesOverlap( bbImage *i1,int x1,int y1,bbImage *i2,int x2,int y2 ); -int bbImagesCollide( bbImage *i1,int x1,int y1,int f1,bbImage *i2,int x2,int y2,int f2 ); -int bbRectsOverlap( int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2 ); -int bbImageRectOverlap( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h ); -int bbImageRectCollide( bbImage *i,int x,int y,int f,int r_x,int r_y,int r_w,int r_h ); +bbImage* bbLoadImage(BBStr* s); +bbImage* bbCopyImage(bbImage* i); +bbImage* bbCreateImage(int w, int h, int n); +bbImage* bbLoadAnimImage(BBStr* s, int w, int h, int first, int cnt); +void bbFreeImage(bbImage* i); +int bbSaveImage(bbImage* i, BBStr* filename, int frame); +void bbGrabImage(bbImage* i, int x, int y, int n); +gxCanvas* bbImageBuffer(bbImage* i, int n); +void bbDrawImage(bbImage* i, int x, int y, int frame); +void bbDrawBlock(bbImage* i, int x, int y, int frame); +void bbTileImage(bbImage* i, int x, int y, int frame); +void bbTileBlock(bbImage* i, int x, int y, int frame); +void bbDrawImageRect(bbImage* i, int x, int y, int r_x, int r_y, int r_w, int r_h, int frame); +void bbDrawBlockRect(bbImage* i, int x, int y, int r_x, int r_y, int r_w, int r_h, int frame); +void bbMaskImage(bbImage* i, int r, int g, int b); +void bbHandleImage(bbImage* i, int x, int y); +void bbScaleImage(bbImage* i, float w, float h); +void bbResizeImage(bbImage* i, float w, float h); +void bbRotateImage(bbImage* i, float angle); +void bbTFormImage(bbImage* i, float a, float b, float c, float d); +void bbTFormFilter(int enable); +void bbAutoMidHandle(int enable); +void bbMidHandle(bbImage* i); +int bbImageWidth(bbImage* i); +int bbImageHeight(bbImage* i); +int bbImageXHandle(bbImage* i); +int bbImageYHandle(bbImage* i); +int bbImagesOverlap(bbImage* i1, int x1, int y1, bbImage* i2, int x2, int y2); +int bbImagesCollide(bbImage* i1, int x1, int y1, int f1, bbImage* i2, int x2, int y2, int f2); +int bbRectsOverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); +int bbImageRectOverlap(bbImage* i, int x, int y, int r_x, int r_y, int r_w, int r_h); +int bbImageRectCollide(bbImage* i, int x, int y, int f, int r_x, int r_y, int r_w, int r_h); //simple print functions -void bbWrite( BBStr *str ); -void bbPrint( BBStr *str ); -BBStr* bbInput( BBStr *prompt ); -void bbLocate( int x,int y ); +void bbWrite(BBStr* str); +void bbPrint(BBStr* str); +BBStr* bbInput(BBStr* prompt); +void bbLocate(int x, int y); #endif \ No newline at end of file diff --git a/bbruntime/bbinput.cpp b/bbruntime/bbinput.cpp index 17fd4555..87dc5830 100644 --- a/bbruntime/bbinput.cpp +++ b/bbruntime/bbinput.cpp @@ -12,11 +12,11 @@ static const float JLT = -1.0f / 3.0f; static const float JHT = 1.0f / 3.0f; bool input_create() { - if(gx_input = gx_runtime->openInput(0)) { - if(gx_keyboard = gx_input->getKeyboard()) { - if(gx_mouse = gx_input->getMouse()) { + if (gx_input = gx_runtime->openInput(0)) { + if (gx_keyboard = gx_input->getKeyboard()) { + if (gx_mouse = gx_input->getMouse()) { gx_joysticks.clear(); - for(int k = 0; k < gx_input->numJoysticks(); ++k) { + for (int k = 0; k < gx_input->numJoysticks(); ++k) { gx_joysticks.push_back(gx_input->getJoystick(k)); } mouse_x = mouse_y = mouse_z = 0; @@ -52,14 +52,14 @@ BBStr* bbTextInput(BBStr* s) { BBStr t = *s; char tBuf[9]; std::vector chars = gx_input->getChars(); - for(int i = 0; i < chars.size(); i++) { - if(chars[i] == 8) { //backspace - if(t.size() > 0) UTF8::popBack(t); + for (int i = 0; i < chars.size(); i++) { + if (chars[i] == 8) { //backspace + if (t.size() > 0) UTF8::popBack(t); } - else if(chars[i] == 127) { + else if (chars[i] == 127) { t.clear(); } - else if(chars[i] >= 32) { + else if (chars[i] >= 32) { int codepointLen = UTF8::encodeCharacter(chars[i], tBuf); tBuf[codepointLen] = '\0'; t += tBuf; @@ -70,10 +70,10 @@ BBStr* bbTextInput(BBStr* s) { } int bbWaitKey() { - for(;;) { - if(!gx_runtime->idle()) RTEX(0); - if(int key = gx_keyboard->getKey()) { - if(key = gx_input->toAscii(key)) return key; + for (;;) { + if (!gx_runtime->idle()) RTEX(0); + if (int key = gx_keyboard->getKey()) { + if (key = gx_input->toAscii(key)) return key; } gx_runtime->delay(20); } @@ -97,9 +97,9 @@ int bbGetMouse() { } int bbWaitMouse() { - for(;;) { - if(!gx_runtime->idle()) RTEX(0); - if(int key = gx_mouse->getKey()) return key; + for (;;) { + if (!gx_runtime->idle()) RTEX(0); + if (int key = gx_mouse->getKey()) return key; gx_runtime->delay(20); } } @@ -151,106 +151,106 @@ int bbJoyType(int port) { } int bbJoyDown(int n, int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->keyDown(n); } int bbJoyHit(int n, int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->keyHit(n); } int bbGetJoy(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getKey(); } int bbWaitJoy(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; - for(;;) { - if(!gx_runtime->idle()) RTEX(0); - if(int key = gx_joysticks[port]->getKey()) return key; + if (port < 0 || port >= gx_joysticks.size()) return 0; + for (;;) { + if (!gx_runtime->idle()) RTEX(0); + if (int key = gx_joysticks[port]->getKey()) return key; gx_runtime->delay(20); } } float bbJoyX(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(0); } float bbJoyY(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(1); } float bbJoyZ(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(2); } float bbJoyU(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(3); } float bbJoyV(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(4); } float bbJoyPitch(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(5) * 180; } float bbJoyYaw(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(6) * 180; } float bbJoyRoll(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(7) * 180; } int bbJoyHat(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; return gx_joysticks[port]->getAxisState(8); } int bbJoyXDir(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; float t = gx_joysticks[port]->getAxisState(0); return t < JLT ? -1 : (t > JHT ? 1 : 0); } int bbJoyYDir(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; float t = gx_joysticks[port]->getAxisState(1); return t < JLT ? -1 : (t > JHT ? 1 : 0); } int bbJoyZDir(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; float t = gx_joysticks[port]->getAxisState(2); return t < JLT ? -1 : (t > JHT ? 1 : 0); } int bbJoyUDir(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; float t = gx_joysticks[port]->getAxisState(3); return t < JLT ? -1 : (t > JHT ? 1 : 0); } int bbJoyVDir(int port) { - if(port < 0 || port >= gx_joysticks.size()) return 0; + if (port < 0 || port >= gx_joysticks.size()) return 0; float t = gx_joysticks[port]->getAxisState(4); return t < JLT ? -1 : (t > JHT ? 1 : 0); } void bbFlushJoy() { - for(int k = 0; k < gx_joysticks.size(); ++k) gx_joysticks[k]->flush(); + for (int k = 0; k < gx_joysticks.size(); ++k) gx_joysticks[k]->flush(); } void bbEnableDirectInput(int enable) { diff --git a/bbruntime/bbmath.cpp b/bbruntime/bbmath.cpp index e7a9e51d..9ab76569 100644 --- a/bbruntime/bbmath.cpp +++ b/bbruntime/bbmath.cpp @@ -32,8 +32,8 @@ int bbIsNaN(float n) { return isnan(n); } //return rand float from 0...1 static inline float rnd() { rnd_state = RND_A * (rnd_state % RND_Q) - RND_R * (rnd_state / RND_Q); - if(rnd_state < 0) rnd_state += RND_M; - if(rnd_state == 0) { + if (rnd_state < 0) rnd_state += RND_M; + if (rnd_state == 0) { rnd_state = RND_R; } return (rnd_state & 65535) / 65536.0f + (.5f / 65536.0f); @@ -44,7 +44,7 @@ float bbRnd(float from, float to) { } int bbRand(int from, int to) { - if(to < from) std::swap(from, to); + if (to < from) std::swap(from, to); return int(rnd() * (to - from + 1)) + from; } diff --git a/bbruntime/bbruntime.cpp b/bbruntime/bbruntime.cpp index 5f114623..ba5a7635 100644 --- a/bbruntime/bbruntime.cpp +++ b/bbruntime/bbruntime.cpp @@ -7,6 +7,7 @@ std::string* ErrorMessagePool::memoryAccessViolation = 0; int ErrorMessagePool::size = 0; +bool ErrorMessagePool::caughtError = false; void bbEnd() { RTEX(0); @@ -35,10 +36,11 @@ void bbRuntimeError(BBStr* str) { RTEX(UTF8::convertToANSI(err)); } -void bbInitErrorMsgs(int number) { +void bbInitErrorMsgs(int number, bool caughtError) { delete[] ErrorMessagePool::memoryAccessViolation; ErrorMessagePool::memoryAccessViolation = new std::string[number]; ErrorMessagePool::size = number; + ErrorMessagePool::caughtError = caughtError; } void bbSetErrorMsg(int pos, BBStr* str) { @@ -48,6 +50,15 @@ void bbSetErrorMsg(int pos, BBStr* str) { delete str; } +BBStr* bbErrorLog() { + std::string str = ""; + if (error_logs.size()) { + str = error_logs[0]; + error_logs.erase(error_logs.begin()); + } + return new BBStr(str); +} + BBStr* bbGetUserLanguage() { wchar_t buf[6]; // should enough GetUserDefaultLocaleName(buf, 6); @@ -217,8 +228,9 @@ void bbruntime_link(void (*rtSym)(const char* sym, void* pc)) { rtSym("Stop", bbStop); rtSym("AppTitle$title$close_prompt=\"\"", bbAppTitle); rtSym("RuntimeError$message", bbRuntimeError); - rtSym("InitErrorMsgs%number", bbInitErrorMsgs); + rtSym("InitErrorMsgs%number%caughtError=0", bbInitErrorMsgs); rtSym("SetErrorMsg%pos$message", bbSetErrorMsg); + rtSym("$ErrorLog", bbErrorLog); rtSym("ExecFile$command", bbExecFile); rtSym("Delay%millisecs", bbDelay); rtSym("%MilliSecs", bbMilliSecs); diff --git a/bbruntime/bbruntime.h b/bbruntime/bbruntime.h index 343b8d9c..b29c8c23 100644 --- a/bbruntime/bbruntime.h +++ b/bbruntime/bbruntime.h @@ -19,6 +19,7 @@ class ErrorMessagePool { public: static std::string* memoryAccessViolation; static int size; + static bool caughtError; }; #endif \ No newline at end of file diff --git a/bbruntime/bbsockets.cpp b/bbruntime/bbsockets.cpp index 1aacc3bb..3af5e21d 100644 --- a/bbruntime/bbsockets.cpp +++ b/bbruntime/bbsockets.cpp @@ -11,7 +11,7 @@ static int read_timeout; static int accept_timeout; static void close(SOCKET sock, int e) { - if(e < 0) { + if (e < 0) { int opt = 1; setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char*)&opt, sizeof(opt)); } @@ -61,22 +61,22 @@ UDPStream::~UDPStream() { } int UDPStream::read(char* buff, int size) { - if(e) return 0; + if (e) return 0; int n = in_buf.size() - in_get; - if(n < size) size = n; + if (n < size) size = n; memcpy(buff, &in_buf[in_get], size); in_get += size; return size; } int UDPStream::write(const char* buff, int size) { - if(e) return 0; + if (e) return 0; out_buf.insert(out_buf.end(), buff, buff + size); return size; } int UDPStream::avail() { - if(e) return 0; + if (e) return 0; return in_buf.size() - in_get; } @@ -86,26 +86,26 @@ int UDPStream::eof() { //fill buffer, return sender int UDPStream::recv() { - if(e) return 0; + if (e) return 0; int tout; - if(recv_timeout) tout = gx_runtime->getMilliSecs() + recv_timeout; - for(;;) { + if (recv_timeout) tout = gx_runtime->getMilliSecs() + recv_timeout; + for (;;) { int dt = 0; - if(recv_timeout) { + if (recv_timeout) { dt = tout - gx_runtime->getMilliSecs(); - if(dt < 0) dt = 0; + if (dt < 0) dt = 0; } fd_set fd = { 1,sock }; timeval tv = { dt / 1000,(dt % 1000) * 1000 }; int n = ::select(0, &fd, 0, 0, &tv); - if(!n) return 0; - if(n != 1) { e = -1; return 0; } + if (!n) return 0; + if (n != 1) { e = -1; return 0; } unsigned long sz = -1; - if(ioctlsocket(sock, FIONREAD, &sz)) { e = -1; return 0; } + if (ioctlsocket(sock, FIONREAD, &sz)) { e = -1; return 0; } in_buf.resize(sz); in_get = 0; int len = sizeof(in_addr); n = ::recvfrom(sock, (char*)in_buf.data(), sz, 0, (sockaddr*)&in_addr, &len); - if(n == SOCKET_ERROR) continue; //{ e=-1;return 0; } + if (n == SOCKET_ERROR) continue; //{ e=-1;return 0; } in_buf.resize(n); return getMsgIP(); } @@ -114,12 +114,12 @@ int UDPStream::recv() { //send, empty buffer int UDPStream::send(int ip, int port) { - if(e) return 0; + if (e) return 0; int sz = out_buf.size(); out_addr.sin_addr.S_un.S_addr = htonl(ip); out_addr.sin_port = htons(port ? port : addr.sin_port); int n = ::sendto(sock, (char*)out_buf.data(), sz, 0, (sockaddr*)&out_addr, sizeof(out_addr)); - if(n != sz) return e = -1; + if (n != sz) return e = -1; out_buf.clear(); return sz; } @@ -177,7 +177,7 @@ class TCPServer { TCPStream::TCPStream(SOCKET s, TCPServer* t) :sock(s), server(t), e(0) { sockaddr_in addr; int len = sizeof(addr); - if(getpeername(s, (sockaddr*)&addr, &len)) { + if (getpeername(s, (sockaddr*)&addr, &len)) { ip = port = 0; return; } @@ -186,55 +186,55 @@ TCPStream::TCPStream(SOCKET s, TCPServer* t) :sock(s), server(t), e(0) { } TCPStream::~TCPStream() { - if(server) server->remove(this); + if (server) server->remove(this); close(sock, e); } int TCPStream::read(char* buff, int size) { - if(e) return 0; + if (e) return 0; char* b = buff, * l = buff + size; int tout; - if(read_timeout) tout = gx_runtime->getMilliSecs() + read_timeout; - while(b < l) { + if (read_timeout) tout = gx_runtime->getMilliSecs() + read_timeout; + while (b < l) { int dt = 0; - if(read_timeout) { + if (read_timeout) { dt = tout - gx_runtime->getMilliSecs(); - if(dt < 0) dt = 0; + if (dt < 0) dt = 0; } fd_set fd = { 1,sock }; timeval tv = { dt / 1000,(dt % 1000) * 1000 }; int n = ::select(0, &fd, 0, 0, &tv); - if(n != 1) { e = -1; break; } + if (n != 1) { e = -1; break; } n = ::recv(sock, b, l - b, 0); - if(n == 0) { e = 1; break; } - if(n == SOCKET_ERROR) { e = -1; break; } + if (n == 0) { e = 1; break; } + if (n == SOCKET_ERROR) { e = -1; break; } b += n; } return b - buff; } int TCPStream::write(const char* buff, int size) { - if(e) return 0; + if (e) return 0; int n = ::send(sock, buff, size, 0); - if(n == SOCKET_ERROR) { e = -1; return 0; } + if (n == SOCKET_ERROR) { e = -1; return 0; } return n; } int TCPStream::avail() { unsigned long t; int n = ::ioctlsocket(sock, FIONREAD, &t); - if(n == SOCKET_ERROR) { e = -1; return 0; } + if (n == SOCKET_ERROR) { e = -1; return 0; } return t; } int TCPStream::eof() { - if(e) return e; + if (e) return e; fd_set fd = { 1,sock }; timeval tv = { 0,0 }; - switch(::select(0, &fd, 0, 0, &tv)) { - case 0:break; - case 1:if(!avail()) e = 1; break; - default:e = -1; + switch (::select(0, &fd, 0, 0, &tv)) { + case 0:break; + case 1:if (!avail()) e = 1; break; + default:e = -1; } return e; } @@ -251,19 +251,19 @@ TCPServer::TCPServer(SOCKET s) :sock(s), e(0) { } TCPServer::~TCPServer() { - while(accepted_set.size()) delete* accepted_set.begin(); + while (accepted_set.size()) delete* accepted_set.begin(); close(sock, e); } TCPStream* TCPServer::accept() { - if(e) return 0; + if (e) return 0; fd_set fd = { 1,sock }; timeval tv = { accept_timeout / 1000,(accept_timeout % 1000) * 1000 }; int n = ::select(0, &fd, 0, 0, &tv); - if(n == 0) return 0; - if(n != 1) { e = -1; return 0; } + if (n == 0) return 0; + if (n != 1) { e = -1; return 0; } SOCKET t = ::accept(sock, 0, 0); - if(t == INVALID_SOCKET) { e = -1; return 0; } + if (t == INVALID_SOCKET) { e = -1; return 0; } TCPStream* s = new TCPStream(t, this); accepted_set.insert(s); return s; @@ -273,21 +273,21 @@ void TCPServer::remove(TCPStream* s) { accepted_set.erase(s); } -static inline void debugUDPStream(UDPStream* p) { - if(debug && !udp_set.count(p)) { - RTEX(MultiLang::udp_stream_not_exist); +static inline void debugUDPStream(UDPStream* p, std::string function) { + if (!udp_set.count(p)) { + ErrorLog(function, MultiLang::udp_stream_not_exist); } } -static inline void debugTCPStream(TCPStream* p) { - if(debug && !tcp_set.count(p)) { - RTEX(MultiLang::tcp_stream_not_exist); +static inline void debugTCPStream(TCPStream* p, std::string function) { + if (!tcp_set.count(p)) { + ErrorLog(function, MultiLang::tcp_stream_not_exist); } } -static inline void debugTCPServer(TCPServer* p) { - if(debug && !server_set.count(p)) { - RTEX(MultiLang::tcp_server_not_exist); +static inline void debugTCPServer(TCPServer* p, std::string function) { + if (!server_set.count(p)) { + ErrorLog(function, MultiLang::tcp_server_not_exist); } } @@ -296,27 +296,25 @@ static std::vector host_ips; int bbCountHostIPs(BBStr* host) { host_ips.clear(); HOSTENT* h = gethostbyname(host->c_str()); - delete host; if(!h) return 0; + delete host; if (!h) return 0; char** p = h->h_addr_list; - while(char* t = *p++) host_ips.push_back(ntohl(*(int*)t)); + while (char* t = *p++) host_ips.push_back(ntohl(*(int*)t)); return host_ips.size(); } int bbHostIP(int index) { - if(debug) { - if(index<1 || index>host_ips.size()) { - RTEX(MultiLang::host_out_of_range); - } + if (index<1 || index>host_ips.size()) { + ErrorLog("HostIP", MultiLang::host_out_of_range); } return host_ips[index - 1]; } UDPStream* bbCreateUDPStream(int port) { - if(!socks_ok) return 0; + if (!socks_ok) return 0; SOCKET s = ::socket(AF_INET, SOCK_DGRAM, 0); - if(s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { sockaddr_in addr = { AF_INET,htons(port) }; - if(!::bind(s, (sockaddr*)&addr, sizeof(addr))) { + if (!::bind(s, (sockaddr*)&addr, sizeof(addr))) { UDPStream* p = new UDPStream(s); udp_set.insert(p); return p; @@ -327,38 +325,38 @@ UDPStream* bbCreateUDPStream(int port) { } void bbCloseUDPStream(UDPStream* p) { - debugUDPStream(p); + debugUDPStream(p, "CloseUDPStream"); udp_set.erase(p); delete p; } int bbRecvUDPMsg(UDPStream* p) { - debugUDPStream(p); + debugUDPStream(p, "RecvUDPMsg"); return p->recv(); } void bbSendUDPMsg(UDPStream* p, int ip, int port) { - debugUDPStream(p); + debugUDPStream(p, "SendUDPMsg"); p->send(ip, port); } int bbUDPStreamIP(UDPStream* p) { - debugUDPStream(p); + debugUDPStream(p, "UDPStreamIP"); return p->getIP(); } int bbUDPStreamPort(UDPStream* p) { - debugUDPStream(p); + debugUDPStream(p, "UDPStreamPort"); return p->getPort(); } int bbUDPMsgIP(UDPStream* p) { - debugUDPStream(p); + debugUDPStream(p, "UDPMsgIP"); return p->getMsgIP(); } int bbUDPMsgPort(UDPStream* p) { - debugUDPStream(p); + debugUDPStream(p, "UDPMsgPort"); return p->getMsgPort(); } @@ -374,35 +372,35 @@ BBStr* bbDottedIP(int ip) { static int findHostIP(const std::string& t) { int ip = inet_addr(t.c_str()); - if(ip != INADDR_NONE) return ip; + if (ip != INADDR_NONE) return ip; HOSTENT* h = gethostbyname(t.c_str()); - if(!h) return -1; + if (!h) return -1; char* p; - for(char** list = h->h_addr_list; p = *list; ++list) { + for (char** list = h->h_addr_list; p = *list; ++list) { return *(int*)p; } return 0; } TCPStream* bbOpenTCPStream(BBStr* server, int port, int local_port) { - if(!socks_ok) { + if (!socks_ok) { delete server; return 0; } int ip = findHostIP(*server); delete server; - if(ip == -1) return 0; + if (ip == -1) return 0; SOCKET s = ::socket(AF_INET, SOCK_STREAM, 0); - if(s != INVALID_SOCKET) { - if(local_port) { + if (s != INVALID_SOCKET) { + if (local_port) { sockaddr_in addr = { AF_INET,htons(local_port) }; - if(::bind(s, (sockaddr*)&addr, sizeof(addr))) { + if (::bind(s, (sockaddr*)&addr, sizeof(addr))) { ::closesocket(s); return 0; } } sockaddr_in addr = { AF_INET,htons(port) }; addr.sin_addr.S_un.S_addr = ip; - if(!::connect(s, (sockaddr*)&addr, sizeof(addr))) { + if (!::connect(s, (sockaddr*)&addr, sizeof(addr))) { TCPStream* p = new TCPStream(s, 0); tcp_set.insert(p); return p; @@ -413,17 +411,17 @@ TCPStream* bbOpenTCPStream(BBStr* server, int port, int local_port) { } void bbCloseTCPStream(TCPStream* p) { - debugTCPStream(p); + debugTCPStream(p, "CloseTCPStream"); tcp_set.erase(p); delete p; } TCPServer* bbCreateTCPServer(int port) { SOCKET s = ::socket(AF_INET, SOCK_STREAM, 0); - if(s != INVALID_SOCKET) { + if (s != INVALID_SOCKET) { sockaddr_in addr = { AF_INET,htons(port) }; - if(!::bind(s, (sockaddr*)&addr, sizeof(addr))) { - if(!::listen(s, SOMAXCONN)) { + if (!::bind(s, (sockaddr*)&addr, sizeof(addr))) { + if (!::listen(s, SOMAXCONN)) { TCPServer* p = new TCPServer(s); server_set.insert(p); return p; @@ -435,15 +433,15 @@ TCPServer* bbCreateTCPServer(int port) { } void bbCloseTCPServer(TCPServer* p) { - debugTCPServer(p); + debugTCPServer(p, "CloseTCPServer"); server_set.erase(p); delete p; } TCPStream* bbAcceptTCPStream(TCPServer* server) { - debugTCPServer(server); - if(!gx_runtime->idle()) RTEX(0); - if(TCPStream* tcp = server->accept()) { + debugTCPServer(server, "AcceptTCPStream"); + if (!gx_runtime->idle()) RTEX(0); + if (TCPStream* tcp = server->accept()) { tcp_set.insert(tcp); return tcp; } @@ -451,12 +449,12 @@ TCPStream* bbAcceptTCPStream(TCPServer* server) { } int bbTCPStreamIP(TCPStream* p) { - debugTCPStream(p); + debugTCPStream(p, "TCPStreamIP"); return p->getIP(); } int bbTCPStreamPort(TCPStream* p) { - debugTCPStream(p); + debugTCPStream(p, "TCPStreamPort"); return p->getPort(); } @@ -501,7 +499,7 @@ BBStr* bbParseDomainTXT(BBStr* txt, BBStr* name) { if ((n = s1.find(s2 + "=")) != std::string::npos) result = s1.substr(n); if ((a = result.find(';')) != std::string::npos) - result = result.substr(s2.length()+1, a - s2.length() - 1); + result = result.substr(s2.length() + 1, a - s2.length() - 1); *txt = result.c_str(); delete name; return txt; @@ -526,10 +524,10 @@ bool sockets_create() { } bool sockets_destroy() { - while(udp_set.size()) bbCloseUDPStream(*udp_set.begin()); - while(tcp_set.size()) bbCloseTCPStream(*tcp_set.begin()); - while(server_set.size()) bbCloseTCPServer(*server_set.begin()); - if(socks_ok) WSACleanup(); + while (udp_set.size()) bbCloseUDPStream(*udp_set.begin()); + while (tcp_set.size()) bbCloseTCPStream(*tcp_set.begin()); + while (server_set.size()) bbCloseTCPServer(*server_set.begin()); + if (socks_ok) WSACleanup(); return true; } diff --git a/bbruntime/bbstream.cpp b/bbruntime/bbstream.cpp index 6ee48370..f0404ac2 100644 --- a/bbruntime/bbstream.cpp +++ b/bbruntime/bbstream.cpp @@ -4,9 +4,9 @@ static std::set stream_set; -void debugStream(bbStream* s) { - if(stream_set.count(s)) return; - RTEX(MultiLang::stream_not_exist); +void debugStream(bbStream* s, std::string function) { + if (stream_set.count(s)) return; + ErrorLog(function, MultiLang::stream_not_exist); } bbStream::bbStream() { @@ -18,116 +18,116 @@ bbStream::~bbStream() { } int bbEof(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "Eof"); return s->eof(); } int bbReadAvail(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadAvail"); return s->avail(); } int bbReadByte(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadByte"); try { int n = 0; s->read((char*)&n, 1); return n; } - catch(std::exception& ex) { - RTEX(MultiLang::readbyte_invalid_byte); + catch (std::exception& ex) { + ErrorLog("ReadByte", MultiLang::readbyte_invalid_byte); } } int bbReadShort(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadShort"); try { int n = 0; s->read((char*)&n, 2); return n; } - catch(std::exception& ex) { - RTEX(MultiLang::readshort_invalid_short); + catch (std::exception& ex) { + ErrorLog("ReadShort", MultiLang::readshort_invalid_short); } } int bbReadInt(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadInt"); try { int n = 0; s->read((char*)&n, 4); return n; } - catch(std::exception& ex) { - RTEX(MultiLang::readint_invalid_int); + catch (std::exception& ex) { + ErrorLog("ReadInt", MultiLang::readint_invalid_int); } } float bbReadFloat(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadFloat"); try { float n = 0; s->read((char*)&n, 4); return n; } - catch(std::exception& ex) { - RTEX(MultiLang::readfloat_invalid_float); + catch (std::exception& ex) { + ErrorLog("ReadFloat", MultiLang::readfloat_invalid_float); } } BBStr* bbReadString(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadString"); try { int len; BBStr* str = new BBStr(); - if(s->read((char*)&len, 4)) { + if (s->read((char*)&len, 4)) { char* buff = new char[len]; - if(s->read(buff, len)) { + if (s->read(buff, len)) { *str = std::string(buff, len); } delete[] buff; } return str; } - catch(std::exception& ex) { - RTEX(MultiLang::readstring_invalid_string); + catch (std::exception& ex) { + ErrorLog("ReadString", MultiLang::readstring_invalid_string); } } BBStr* bbReadLine(bbStream* s) { - if(debug) debugStream(s); + debugStream(s, "ReadLine"); unsigned char c; BBStr* str = new BBStr(); - for(;;) { - if(s->read((char*)&c, 1) != 1) break; - if(c == '\n') break; - if(c != '\r') *str += c; + for (;;) { + if (s->read((char*)&c, 1) != 1) break; + if (c == '\n') break; + if (c != '\r') *str += c; } return str; } void bbWriteByte(bbStream* s, int n) { - if(debug) debugStream(s); + debugStream(s, "WriteByte"); s->write((char*)&n, 1); } void bbWriteShort(bbStream* s, int n) { - if(debug) debugStream(s); + debugStream(s, "WriteShort"); s->write((char*)&n, 2); } void bbWriteInt(bbStream* s, int n) { - if(debug) debugStream(s); + debugStream(s, "WriteInt"); s->write((char*)&n, 4); } void bbWriteFloat(bbStream* s, float n) { - if(debug) debugStream(s); + debugStream(s, "WriteFloat"); s->write((char*)&n, 4); } void bbWriteString(bbStream* s, BBStr* t) { - if(debug) debugStream(s); + debugStream(s, "WriteString"); int n = t->size(); s->write((char*)&n, 4); s->write(t->data(), t->size()); @@ -135,22 +135,21 @@ void bbWriteString(bbStream* s, BBStr* t) { } void bbWriteLine(bbStream* s, BBStr* t) { - if(debug) debugStream(s); + debugStream(s, "WriteLine"); s->write(t->data(), t->size()); s->write("\r\n", 2); delete t; } void bbCopyStream(bbStream* s, bbStream* d, int buff_size) { - if(debug) { - debugStream(s); debugStream(d); - if(buff_size < 1 || buff_size>1024 * 1024) RTEX(MultiLang::illegal_buffer_size); - } + debugStream(s, "CopyStream"); + debugStream(d, "CopyStream"); + if (buff_size < 1 || buff_size>1024 * 1024) ErrorLog("CopyStream", MultiLang::illegal_buffer_size); char* buff = new char[buff_size]; - while(s->eof() == 0 && d->eof() == 0) { + while (s->eof() == 0 && d->eof() == 0) { int n = s->read(buff, buff_size); d->write(buff, n); - if(n < buff_size) break; + if (n < buff_size) break; } delete buff; } diff --git a/bbruntime/bbstream.h b/bbruntime/bbstream.h index 3569000b..ca38a6eb 100644 --- a/bbruntime/bbstream.h +++ b/bbruntime/bbstream.h @@ -25,6 +25,6 @@ class bbStream { virtual int eof() = 0; }; -void debugStream(bbStream* s); +void debugStream(bbStream* s, std::string function); #endif \ No newline at end of file diff --git a/bbruntime/bbstring.cpp b/bbruntime/bbstring.cpp index 781f9ecf..a800cccf 100644 --- a/bbruntime/bbstring.cpp +++ b/bbruntime/bbstring.cpp @@ -5,29 +5,29 @@ #include #include "../MultiLang/MultiLang.h" -#define CHKPOS(x) if( (x)<0 ) RTEX( std::format(MultiLang::string_parameter_positive, __func__).c_str() ); -#define CHKOFF(x) if( (x)<=0 ) RTEX( std::format(MultiLang::string_parameter_greater, __func__ ).c_str() ); +#define CHKPOS(x, func) if(x < 0) ErrorLog(func, MultiLang::string_parameter_positive); +#define CHKOFF(x, func) if(x <= 0) ErrorLog(func, MultiLang::string_parameter_greater); BBStr* bbString(BBStr* s, int n) { BBStr* t = new BBStr(); - while(n-- > 0) *t += *s; + while (n-- > 0) *t += *s; delete s; return t; } BBStr* bbLeft(BBStr* s, int n) { - CHKPOS(n); + CHKPOS(n, "Left"); *s = UTF8::substr(*s, 0, n); return s; } BBStr* bbRight(BBStr* s, int n) { - CHKPOS(n); - n = UTF8::length(*s) - n; if(n < 0) n = 0; + CHKPOS(n, "Right"); + n = UTF8::length(*s) - n; if (n < 0) n = 0; *s = UTF8::substr(*s, n, s->size()); return s; } BBStr* bbReplace(BBStr* s, BBStr* from, BBStr* to) { int n = 0, from_sz = from->size(), to_sz = to->size(); - while(n < s->size() && (n = s->find(*from, n)) != std::string::npos) { + while (n < s->size() && (n = s->find(*from, n)) != std::string::npos) { s->replace(n, from_sz, *to); n += to_sz; } @@ -35,7 +35,7 @@ BBStr* bbReplace(BBStr* s, BBStr* from, BBStr* to) { } int bbInstr(BBStr* s, BBStr* t, int from) { - CHKOFF(from); --from; + CHKOFF(from, "Instr"); --from; int n = UTF8::find(*s, *t, from); delete s; delete t; return n < 0 ? 0 : n + 1; @@ -50,25 +50,25 @@ BBStr* bbSubstr(BBStr* string, int start, int length) { } BBStr* bbMid(BBStr* s, int o, int n) { - CHKOFF(o); --o; - if(o > s->size()) o = s->size(); - if(n >= 0) *s = UTF8::substr(*s, o, n); + CHKOFF(o, "Mid"); --o; + if (o > s->size()) o = s->size(); + if (n >= 0) *s = UTF8::substr(*s, o, n); else *s = UTF8::substr(*s, o, s->size()); return s; } BBStr* bbUpper(BBStr* s) { - for(int k = 0; k < s->size(); ++k) (*s)[k] = toupper((*s)[k]); + for (int k = 0; k < s->size(); ++k) (*s)[k] = toupper((*s)[k]); return s; } BBStr* bbLower(BBStr* s) { - for(int k = 0; k < s->size(); ++k) (*s)[k] = tolower((*s)[k]); + for (int k = 0; k < s->size(); ++k) (*s)[k] = tolower((*s)[k]); return s; } bool isgraph_safe(int chr) { - if(chr > 127) { return true; } + if (chr > 127) { return true; } return isgraph(chr); } @@ -76,26 +76,26 @@ BBStr* bbTrim(BBStr* s) { int n = 0; int p = s->size(); // currently all characters above the standard ASCII range are simply not trimmed - while(n < s->size() && !isgraph_safe((byte)(*s)[n])) ++n; - while(p > n && !isgraph_safe((byte)(*s)[p - 1])) --p; + while (n < s->size() && !isgraph_safe((byte)(*s)[n])) ++n; + while (p > n && !isgraph_safe((byte)(*s)[p - 1])) --p; *s = UTF8::substr(*s, n, p - n); return s; } BBStr* bbLSet(BBStr* s, int n) { - CHKPOS(n); - if(s->size() > n) *s = s->substr(0, n); + CHKPOS(n, "LSet"); + if (s->size() > n) *s = s->substr(0, n); else { - while(s->size() < n) *s += ' '; + while (s->size() < n) *s += ' '; } return s; } BBStr* bbRSet(BBStr* s, int n) { - CHKPOS(n); - if(s->size() > n) *s = s->substr(s->size() - n); + CHKPOS(n, "RSet"); + if (s->size() > n) *s = s->substr(s->size() - n); else { - while(s->size() < n) *s = ' ' + *s; + while (s->size() < n) *s = ' ' + *s; } return s; } diff --git a/bbruntime/bbsys.cpp b/bbruntime/bbsys.cpp index 2c982bef..a586da5e 100644 --- a/bbruntime/bbsys.cpp +++ b/bbruntime/bbsys.cpp @@ -2,4 +2,5 @@ #include "bbsys.h" bool debug; -gxRuntime* gx_runtime; \ No newline at end of file +gxRuntime* gx_runtime; +std::vector error_logs; \ No newline at end of file diff --git a/bbruntime/bbsys.h b/bbruntime/bbsys.h index 59c951a4..a334ee83 100644 --- a/bbruntime/bbsys.h +++ b/bbruntime/bbsys.h @@ -6,11 +6,12 @@ extern bool debug; extern gxRuntime* gx_runtime; +extern std::vector error_logs; struct bbEx { const char* err; bbEx(const char* e) :err(e) { - if(e) gx_runtime->debugError(e); + if (e) gx_runtime->debugError(e); } }; diff --git a/bbruntime/std.h b/bbruntime/std.h index 3ec3d50b..4c894732 100644 --- a/bbruntime/std.h +++ b/bbruntime/std.h @@ -16,4 +16,6 @@ #include +#define ErrorLog(function, log) if (debug) { RTEX(log) } else { error_logs.push_back(std::format("{0}: {1}", function, log)); } + #endif \ No newline at end of file diff --git a/bbruntime/userlibs.cpp b/bbruntime/userlibs.cpp index 9a820cd3..45090aab 100644 --- a/bbruntime/userlibs.cpp +++ b/bbruntime/userlibs.cpp @@ -27,17 +27,17 @@ void _bbLoadLibs(char* p) { std::string home; - if(const char* t = getenv("blitzpath")) home = t; + if (const char* t = getenv("blitzpath")) home = t; - while(*p) { + while (*p) { HMODULE mod = LoadLibrary(p); - if(!mod && home.size()) { + if (!mod && home.size()) { mod = LoadLibrary((home + "/userlibs/" + p).c_str()); } p += strlen(p) + 1; - if(mod) { + if (mod) { _mods.push_back(mod); - while(*p) { + while (*p) { void* proc = GetProcAddress(mod, p); p += strlen(p) + 1; void* ptr = *(void**)p; @@ -46,7 +46,7 @@ void _bbLoadLibs(char* p) { } } else { - while(*p) { + while (*p) { p += strlen(p) + 1; void* ptr = *(void**)p; p += 4; @@ -63,7 +63,7 @@ const char* _bbStrToCStr(BBStr* str) { int size = str->size(); - if(!t.p || t.size < size) { + if (!t.p || t.size < size) { delete[] t.p; t.p = new char[size + 1]; t.size = size; @@ -84,7 +84,7 @@ bool userlibs_create() { } void userlibs_destroy() { - for(; _mods.size(); _mods.pop_back()) FreeLibrary(_mods.back()); + for (; _mods.size(); _mods.pop_back()) FreeLibrary(_mods.back()); } void userlibs_link(void(*rtSym)(const char*, void*)) { diff --git a/bbruntime_dll/bbruntime_dll.cpp b/bbruntime_dll/bbruntime_dll.cpp index bc460e22..c757ba31 100644 --- a/bbruntime_dll/bbruntime_dll.cpp +++ b/bbruntime_dll/bbruntime_dll.cpp @@ -34,13 +34,6 @@ static std::map syms; std::map::iterator sym_it; static gxRuntime* gx_runtime; -/* -* If you using a single variant to handle function names, then you will get error -* sym is a pointer, backup function name is pointer too. -* So, variant of backup name's content will change by sym's content. -* -* How it works? -*/ //Allows userlibs to call DebugLog() and RuntimeError(). //****************************************************** __declspec(dllexport) void __cdecl BlitzDebugLog(const char* msg) @@ -54,13 +47,25 @@ __declspec(dllexport) void __cdecl BlitzRuntimeError(const char* msg) } //****************************************************** -const char* getCharPtr(std::string str) { +inline const char* getCharPtr(std::string str) { char* cha = new char[str.size() + 1]; memcpy(cha, str.c_str(), str.size() + 1); const char* p = cha; return p; } +inline std::string replace_all(const std::string& string, const std::string& pattern, const std::string& newpat) { + std::string str = string; + const uint32_t nsize = newpat.size(); + const uint32_t psize = pattern.size(); + + for (uint32_t pos = str.find(pattern, 0); pos != std::string::npos; pos = str.find(pattern, pos + nsize)) + { + str.replace(pos, psize, newpat); + } + return str; +} + static void rtSym(const char* sym, void* pc) { syms[sym] = pc; std::string symSpare = sym; @@ -89,6 +94,7 @@ static void _cdecl seTranslator(unsigned int u, EXCEPTION_POINTERS* pExp) { s = s + ErrorMessagePool::memoryAccessViolation[i] + "\n"; } } + if (ErrorMessagePool::caughtError) s = replace_all(s, "_CaughtError_", error_logs[error_logs.size() - 1]); RTEX(s.c_str()); } break; diff --git a/blitz/libs.cpp b/blitz/libs.cpp index d4cc1df1..85be9104 100644 --- a/blitz/libs.cpp +++ b/blitz/libs.cpp @@ -19,10 +19,10 @@ std::vector userFuncs; static HMODULE linkerHMOD, runtimeHMOD; static Type* typeof(int c) { - switch(c) { - case '%':return Type::int_type; - case '#':return Type::float_type; - case '$':return Type::string_type; + switch (c) { + case '%':return Type::int_type; + case '#':return Type::float_type; + case '$':return Type::string_type; } return Type::void_type; } @@ -36,20 +36,20 @@ static int next(std::istream& in) { int t = 0; - for(;;) { - while(isspace(in.peek())) in.get(); - if(in.eof()) return curr = 0; - t = in.get(); if(t != ';') break; - while(!in.eof() && in.get() != '\n') {} + for (;;) { + while (isspace(in.peek())) in.get(); + if (in.eof()) return curr = 0; + t = in.get(); if (t != ';') break; + while (!in.eof() && in.get() != '\n') {} } - if(isalpha(t)) { + if (isalpha(t)) { text += (char)t; - while(isalnum(in.peek()) || in.peek() == '_') text += (char)in.get(); + while (isalnum(in.peek()) || in.peek() == '_') text += (char)in.get(); return curr = -1; } - if(t == '\"') { - while(in.peek() != '\"') text = text + (char)in.get(); + if (t == '\"') { + while (in.peek() != '\"') text = text + (char)in.get(); in.get(); return curr = -2; } @@ -59,21 +59,21 @@ static int next(std::istream& in) { static const char* linkRuntime() { - while(const char* sym = runtimeLib->nextSym()) { + while (const char* sym = runtimeLib->nextSym()) { std::string s(sym); int pc = runtimeLib->symValue(sym); //internal? - if(s[0] == '_') { + if (s[0] == '_') { runtimeModule->addSymbol(("_" + s).c_str(), pc); continue; } bool cfunc = false; - if(s[0] == '!') { + if (s[0] == '!') { cfunc = true; s = s.substr(1); } @@ -83,30 +83,30 @@ static const char* linkRuntime() { //global! int start = 0, end, k; Type* t = Type::void_type; - if(!isalpha(s[0])) { start = 1; t = typeof(s[0]); } - for(k = 1; k < s.size(); ++k) { - if(!isalnum(s[k]) && s[k] != '_') break; + if (!isalpha(s[0])) { start = 1; t = typeof(s[0]); } + for (k = 1; k < s.size(); ++k) { + if (!isalnum(s[k]) && s[k] != '_') break; } end = k; DeclSeq* params = new DeclSeq(); std::string n = s.substr(start, end - start); - while(k < s.size()) { + while (k < s.size()) { Type* t = typeof(s[k++]); int from = k; - for(; isalnum(s[k]) || s[k] == '_'; ++k) {} + for (; isalnum(s[k]) || s[k] == '_'; ++k) {} std::string str = s.substr(from, k - from); ConstType* defType = 0; - if(s[k] == '=') { + if (s[k] == '=') { int from = ++k; - if(s[k] == '\"') { - for(++k; s[k] != '\"'; ++k) {} + if (s[k] == '\"') { + for (++k; s[k] != '\"'; ++k) {} std::string t = s.substr(from + 1, k - from - 1); defType = new ConstType(t); ++k; } else { - if(s[k] == '-') ++k; - for(; isdigit(s[k]); ++k) {} - if(t == Type::int_type) { + if (s[k] == '-') ++k; + for (; isdigit(s[k]); ++k) {} + if (t == Type::int_type) { int n = atoi(s.substr(from, k - from)); defType = new ConstType(n); } @@ -137,14 +137,14 @@ static const char* loadUserLib(const std::string& userlib) { std::ifstream in(t.c_str()); next(in); - while(curr) { + while (curr) { - if(curr == '.') { + if (curr == '.') { - if(next(in) != -1) return MultiLang::expect_identifier; + if (next(in) != -1) return MultiLang::expect_identifier; - if(text == "lib") { - if(next(in) != -2) return MultiLang::expect_string_afrer_directive; + if (text == "lib") { + if (next(in) != -2) return MultiLang::expect_string_afrer_directive; lib = text; } @@ -154,53 +154,53 @@ static const char* loadUserLib(const std::string& userlib) { next(in); } - else if(curr == -1) { + else if (curr == -1) { - if(!lib.size()) return MultiLang::function_decl_without_directive; + if (!lib.size()) return MultiLang::function_decl_without_directive; std::string id = text; std::string lower_id = tolower(id); - if(_ulibkws.count(lower_id)) return MultiLang::duplicate_identifier; + if (_ulibkws.count(lower_id)) return MultiLang::duplicate_identifier; _ulibkws.insert(lower_id); Type* ty = 0; - switch(next(in)) { - case '%':ty = Type::int_type; break; - case '#':ty = Type::float_type; break; - case '$':ty = Type::string_type; break; + switch (next(in)) { + case '%':ty = Type::int_type; break; + case '#':ty = Type::float_type; break; + case '$':ty = Type::string_type; break; } - if(ty) next(in); + if (ty) next(in); else ty = Type::void_type; DeclSeq* params = new DeclSeq(); - if(curr != '(') return MultiLang::expect_left_bracket_after_function_identifier; + if (curr != '(') return MultiLang::expect_left_bracket_after_function_identifier; next(in); - if(curr != ')') { - for(;;) { - if(curr != -1) break; + if (curr != ')') { + for (;;) { + if (curr != -1) break; std::string arg = text; Type* ty = 0; - switch(next(in)) { - case '%':ty = Type::int_type; break; - case '#':ty = Type::float_type; break; - case '$':ty = Type::string_type; break; - case '*':ty = Type::null_type; break; + switch (next(in)) { + case '%':ty = Type::int_type; break; + case '#':ty = Type::float_type; break; + case '$':ty = Type::string_type; break; + case '*':ty = Type::null_type; break; } - if(ty) next(in); + if (ty) next(in); else ty = Type::int_type; ConstType* defType = 0; Decl* d = params->insertDecl(arg, ty, DECL_PARAM, defType); - if(curr != ',') break; + if (curr != ',') break; next(in); } } - if(curr != ')') return MultiLang::expect_right_bracket_after_function_identifier; + if (curr != ')') return MultiLang::expect_right_bracket_after_function_identifier; keyWords.push_back(id); @@ -208,9 +208,9 @@ static const char* loadUserLib(const std::string& userlib) { runtimeEnviron->funcDecls->insertDecl(lower_id, fn, DECL_FUNC); - if(next(in) == ':') { //real name? + if (next(in) == ':') { //real name? next(in); - if(curr != -1 && curr != -2) return MultiLang::expect_identifier_or_string_after_alias; + if (curr != -1 && curr != -2) return MultiLang::expect_identifier_or_string_after_alias; id = text; next(in); } @@ -229,18 +229,18 @@ static const char* linkUserLibs() { HANDLE h = FindFirstFile((home + "/userlibs/*.decls").c_str(), &fd); - if(h == INVALID_HANDLE_VALUE) return 0; + if (h == INVALID_HANDLE_VALUE) return 0; const char* err = 0; do { - if(err = loadUserLib(fd.cFileName)) { + if (err = loadUserLib(fd.cFileName)) { static char buf[64]; sprintf(buf, "Error in userlib '%s' - %s", fd.cFileName, err); err = buf; break; } - } while(FindNextFile(h, &fd)); + } while (FindNextFile(h, &fd)); FindClose(h); @@ -252,7 +252,7 @@ static const char* linkUserLibs() { const char* openLibs() { char* p = getenv("blitzpath"); - if(!p) { + if (!p) { char workingDir[128]; GetCurrentDirectory(128, workingDir); home = workingDir; home += "\\\\.."; @@ -263,26 +263,26 @@ const char* openLibs() { } linkerHMOD = LoadLibrary((home + "/bin/linker.dll").c_str()); - if(!linkerHMOD) return MultiLang::unable_open_linker_dll; + if (!linkerHMOD) return MultiLang::unable_open_linker_dll; typedef Linker* (_cdecl* GetLinker)(); GetLinker gl = (GetLinker)GetProcAddress(linkerHMOD, "linkerGetLinker"); - if(!gl) return MultiLang::error_in_linker_dll; + if (!gl) return MultiLang::error_in_linker_dll; linkerLib = gl(); runtimeHMOD = LoadLibrary((home + "/bin/runtime.dll").c_str()); - if(!runtimeHMOD) return MultiLang::unable_open_runtime_dll; + if (!runtimeHMOD) return MultiLang::unable_open_runtime_dll; typedef Runtime* (_cdecl* GetRuntime)(); GetRuntime gr = (GetRuntime)GetProcAddress(runtimeHMOD, "runtimeGetRuntime"); - if(!gr) return MultiLang::error_in_runtime_dll; + if (!gr) return MultiLang::error_in_runtime_dll; runtimeLib = gr(); bcc_ver = VERSION; lnk_ver = linkerLib->version(); run_ver = runtimeLib->version(); - if((lnk_ver >> 16) != (bcc_ver >> 16) || + if ((lnk_ver >> 16) != (bcc_ver >> 16) || (run_ver >> 16) != (bcc_ver >> 16) || (lnk_ver >> 16) != (bcc_ver >> 16)) return MultiLang::library_version_error; @@ -299,9 +299,9 @@ const char* openLibs() { const char* linkLibs() { - if(const char* p = linkRuntime()) return p; + if (const char* p = linkRuntime()) return p; - if(const char* p = linkUserLibs()) return p; + if (const char* p = linkUserLibs()) return p; return 0; } @@ -309,10 +309,10 @@ const char* linkLibs() { void closeLibs() { delete runtimeEnviron; - if(linkerLib) linkerLib->deleteModule(runtimeModule); - if(runtimeLib) runtimeLib->shutdown(); - if(runtimeHMOD) FreeLibrary(runtimeHMOD); - if(linkerHMOD) FreeLibrary(linkerHMOD); + if (linkerLib) linkerLib->deleteModule(runtimeModule); + if (runtimeLib) runtimeLib->shutdown(); + if (runtimeHMOD) FreeLibrary(runtimeHMOD); + if (linkerHMOD) FreeLibrary(linkerHMOD); runtimeEnviron = 0; linkerLib = 0; diff --git a/blitz/main.cpp b/blitz/main.cpp index 7d402e94..ee42da86 100644 --- a/blitz/main.cpp +++ b/blitz/main.cpp @@ -67,28 +67,28 @@ static std::string quickHelp(const std::string& kw) { Environ* e = runtimeEnviron; Decl* d = e->funcDecls->findDecl(tolower(kw)); - if(!d || d->type->funcType() == 0) return "No quick help available for " + kw; + if (!d || d->type->funcType() == 0) return "No quick help available for " + kw; std::string t = kw; FuncType* f = d->type->funcType(); - if(f->returnType == Type::float_type) t += '#'; - else if(f->returnType == Type::string_type) t += '$'; + if (f->returnType == Type::float_type) t += '#'; + else if (f->returnType == Type::string_type) t += '$'; t += " "; - if(f->returnType != Type::void_type) t += "( "; + if (f->returnType != Type::void_type) t += "( "; - for(int k = 0; k < f->params->size(); ++k) { + for (int k = 0; k < f->params->size(); ++k) { std::string s; - if(k) s += ','; + if (k) s += ','; Decl* p = f->params->decls[k]; s += p->name; - if(p->type == Type::float_type) s += '#'; - else if(p->type == Type::string_type) s += '$'; - else if(p->type == Type::void_type) s += '*'; - if(p->defType) s = '[' + s + ']'; + if (p->type == Type::float_type) s += '#'; + else if (p->type == Type::string_type) s += '$'; + else if (p->type == Type::void_type) s += '*'; + if (p->defType) s = '[' + s + ']'; t += s; } - if(f->returnType != Type::void_type) { + if (f->returnType != Type::void_type) { t += f->params->size() ? " )" : ")"; } return t; @@ -96,29 +96,29 @@ static std::string quickHelp(const std::string& kw) { static void dumpKeys(bool lang, bool mod, bool help) { - if(lang) { + if (lang) { std::map::iterator it; std::map& keywords = Toker::getKeywords(); - for(it = keywords.begin(); it != keywords.end(); ++it) { - if(it->first.find(' ') != std::string::npos) continue; + for (it = keywords.begin(); it != keywords.end(); ++it) { + if (it->first.find(' ') != std::string::npos) continue; std::cout << it->first << std::endl; } } - if(!mod) return; + if (!mod) return; - for(int k = 0; k < keyWords.size(); ++k) { + for (int k = 0; k < keyWords.size(); ++k) { std::string t = keyWords[k]; - if(t[0] == '_') continue; - if(!isalpha(t[0])) t = t.substr(1); - for(int n = 0; n < t.size(); ++n) { - if(!isalnum(t[n]) && t[n] != '_') { + if (t[0] == '_') continue; + if (!isalpha(t[0])) t = t.substr(1); + for (int n = 0; n < t.size(); ++n) { + if (!isalnum(t[n]) && t[n] != '_') { t = t.substr(0, n); break; } } - if(help) t = quickHelp(t); + if (help) t = quickHelp(t); std::cout << t << std::endl; } } @@ -138,59 +138,59 @@ int _cdecl main(int argc, char* argv[]) { bool versinfo = false; bool nolaa = false; - for(int k = 1; k < argc; ++k) { + for (int k = 1; k < argc; ++k) { std::string t = argv[k]; t = tolower(t); - if(t == "-h") { + if (t == "-h") { showhelp = true; } - else if(t == "-a") { + else if (t == "-a") { dumpasm = true; } - else if(t == "-q") { + else if (t == "-q") { quiet = true; } - else if(t == "+q") { + else if (t == "+q") { quiet = veryquiet = true; } - else if(t == "-c") { + else if (t == "-c") { compileonly = true; } - else if(t == "-d") { + else if (t == "-d") { debug = true; } - else if(t == "-k") { + else if (t == "-k") { dumpkeys = true; } - else if(t == "+k") { + else if (t == "+k") { dumpkeys = dumphelp = true; } - else if(t == "-v") { + else if (t == "-v") { versinfo = true; } - else if(t == "-o") { - if(out_file.size() || k == argc - 1) usageErr(); + else if (t == "-o") { + if (out_file.size() || k == argc - 1) usageErr(); out_file = argv[++k]; } - else if(t == "-nlaa") { + else if (t == "-nlaa") { nolaa = true; } else { - if(in_file.size() || t[0] == '-' || t[0] == '+') usageErr(); + if (in_file.size() || t[0] == '-' || t[0] == '+') usageErr(); in_file = argv[k]; - for(++k; k < argc; ++k) { + for (++k; k < argc; ++k) { std::string t = argv[k]; - if(t.find(' ') != std::string::npos) t = '\"' + t + '\"'; - if(args.size()) args += ' '; + if (t.find(' ') != std::string::npos) t = '\"' + t + '\"'; + if (args.size()) args += ' '; args += t; } } } std::ifstream debugFile; debugFile.open("debug.txt", std::ios_base::in); - if(debugFile.good()) { + if (debugFile.good()) { char* tmpBuf = new char[1024]; debugFile.getline(tmpBuf, 1024); in_file = tmpBuf; @@ -201,41 +201,41 @@ int _cdecl main(int argc, char* argv[]) { } - if(!debug && !quiet && !veryquiet && !compileonly && + if (!debug && !quiet && !veryquiet && !compileonly && !dumpkeys && !dumphelp && !showhelp && !dumpasm && !versinfo && !in_file.size() && !out_file.size()) { showHelp(); return 0; } - if(out_file.size() && !in_file.size()) usageErr(); + if (out_file.size() && !in_file.size()) usageErr(); - if(const char* er = openLibs()) err(er); + if (const char* er = openLibs()) err(er); - if(const char* er = linkLibs()) err(er); + if (const char* er = linkLibs()) err(er); - if(showhelp) showHelp(); - if(dumpkeys) dumpKeys(true, true, dumphelp); - if(versinfo) versInfo(); + if (showhelp) showHelp(); + if (dumpkeys) dumpKeys(true, true, dumphelp); + if (versinfo) versInfo(); - if(!in_file.size()) return 0; + if (!in_file.size()) return 0; - if(in_file[0] == '\"') { - if(in_file.size() < 3 || in_file[in_file.size() - 1] != '\"') usageErr(); + if (in_file[0] == '\"') { + if (in_file.size() < 3 || in_file[in_file.size() - 1] != '\"') usageErr(); in_file = in_file.substr(1, in_file.size() - 2); } std::ifstream in(in_file.c_str()); - if(!in) err("Unable to open input file."); - if(!quiet) { + if (!in) err("Unable to open input file."); + if (!quiet) { showInfo(); std::cout << "Compiling \"" << in_file << "\"" << std::endl; } int n = in_file.rfind('/'); - if(n == std::string::npos) n = in_file.rfind('\\'); - if(n != std::string::npos) { - if(!n || in_file[n - 1] == ':') ++n; + if (n == std::string::npos) n = in_file.rfind('\\'); + if (n != std::string::npos) { + if (!n || in_file[n - 1] == ':') ++n; SetCurrentDirectory(in_file.substr(0, n).c_str()); } @@ -245,35 +245,35 @@ int _cdecl main(int argc, char* argv[]) { try { //parse - if(!veryquiet) std::cout << "Parsing..." << std::endl; + if (!veryquiet) std::cout << "Parsing..." << std::endl; Toker toker(in); Parser parser(toker); prog = parser.parse(in_file, debug); //semant - if(!veryquiet) std::cout << "Generating..." << std::endl; + if (!veryquiet) std::cout << "Generating..." << std::endl; environ = prog->semant(runtimeEnviron); //translate - if(!veryquiet) std::cout << "Translating..." << std::endl; + if (!veryquiet) std::cout << "Translating..." << std::endl; qstreambuf qbuf; std::iostream asmcode(&qbuf); Codegen_x86 codegen(asmcode, debug); prog->translate(&codegen, userFuncs); - if(dumpasm) { + if (dumpasm) { std::cout << std::endl << std::string(qbuf.data(), qbuf.size()) << std::endl; } //assemble - if(!veryquiet) std::cout << "Assembling..." << std::endl; + if (!veryquiet) std::cout << "Assembling..." << std::endl; module = linkerLib->createModule(); Assem_x86 assem(asmcode, module); assem.assemble(); } - catch(Ex& x) { + catch (Ex& x) { std::string file = '\"' + x.file + '\"'; int row = ((x.pos >> 16) & 65535) + 1, col = (x.pos & 65535) + 1; @@ -283,37 +283,37 @@ int _cdecl main(int argc, char* argv[]) { delete prog; - if(out_file.size()) { - if(!veryquiet) std::cout << "Creating executable \"" << out_file << "\"..." << std::endl; + if (out_file.size()) { + if (!veryquiet) std::cout << "Creating executable \"" << out_file << "\"..." << std::endl; - if(!module->createExe(out_file.c_str(), (home + "/bin/runtime.dll").c_str(), nolaa)) { + if (!module->createExe(out_file.c_str(), (home + "/bin/runtime.dll").c_str(), nolaa)) { err("Error creating executable!"); } - if(!veryquiet) std::cout << "Executable created succesfully." << std::endl; + if (!veryquiet) std::cout << "Executable created succesfully." << std::endl; } - else if(!compileonly) { + else if (!compileonly) { void* entry = module->link(runtimeModule); - if(!entry) return 0; + if (!entry) return 0; HMODULE dbgHandle = 0; Debugger* debugger = 0; - if(debug) { + if (debug) { dbgHandle = LoadLibrary((home + "/bin/debugger.dll").c_str()); - if(dbgHandle) { + if (dbgHandle) { typedef Debugger* (_cdecl* GetDebugger)(Module*, Environ*); GetDebugger gd = (GetDebugger)GetProcAddress(dbgHandle, "debuggerGetDebugger"); - if(gd) debugger = gd(module, environ); + if (gd) debugger = gd(module, environ); } - if(!debugger) err("Error launching debugger!"); + if (!debugger) err("Error launching debugger!"); } - if(!veryquiet) std::cout << "Executing..." << std::endl; + if (!veryquiet) std::cout << "Executing..." << std::endl; runtimeLib->execute((void(*)())entry, args.c_str(), debugger); - if(dbgHandle) FreeLibrary(dbgHandle); + if (dbgHandle) FreeLibrary(dbgHandle); } delete module; diff --git a/blitz3d/animation.cpp b/blitz3d/animation.cpp index 5f7763d3..bdbe08d0 100644 --- a/blitz3d/animation.cpp +++ b/blitz3d/animation.cpp @@ -24,9 +24,9 @@ struct Animation::Rep { //for( next=keys.begin();next!=keys.end() && time>=next->first;++next ){} next = keys.upper_bound((int)time); - if(next == keys.begin()) return next->second.v; + if (next == keys.begin()) return next->second.v; curr = next; --curr; - if(next == keys.end()) return curr->second.v; + if (next == keys.end()) return curr->second.v; float delta = (time - curr->first) / (next->first - curr->first); return (next->second.v - curr->second.v) * delta + curr->second.v; @@ -38,9 +38,9 @@ struct Animation::Rep { //for( next=keys.begin();next!=keys.end() && time>=next->first;++next ){} next = keys.upper_bound((int)time); - if(next == keys.begin()) return next->second; + if (next == keys.begin()) return next->second; curr = next; --curr; - if(next == keys.end()) return curr->second; + if (next == keys.end()) return curr->second; float delta = (time - curr->first) / (next->first - curr->first); return curr->second.slerpTo(next->second, delta); @@ -63,33 +63,33 @@ Animation::Animation(const Animation& t) : Animation::Animation(const Animation& t, int first, int last) : rep(new Rep()) { Rep::KeyList::const_iterator it; - for(it = t.rep->pos_anim.begin(); it != t.rep->pos_anim.end(); ++it) { - if(it->firstfirst>last) continue; + for (it = t.rep->pos_anim.begin(); it != t.rep->pos_anim.end(); ++it) { + if (it->firstfirst>last) continue; rep->setKey(rep->pos_anim, it->first - first, it->second); } - for(it = t.rep->scale_anim.begin(); it != t.rep->scale_anim.end(); ++it) { - if(it->firstfirst>last) continue; + for (it = t.rep->scale_anim.begin(); it != t.rep->scale_anim.end(); ++it) { + if (it->firstfirst>last) continue; rep->setKey(rep->scale_anim, it->first - first, it->second); } - for(it = t.rep->rot_anim.begin(); it != t.rep->rot_anim.end(); ++it) { - if(it->firstfirst>last) continue; + for (it = t.rep->rot_anim.begin(); it != t.rep->rot_anim.end(); ++it) { + if (it->firstfirst>last) continue; rep->setKey(rep->rot_anim, it->first - first, it->second); } } Animation::~Animation() { - if(!--rep->ref_cnt) delete rep; + if (!--rep->ref_cnt) delete rep; } Animation& Animation::operator=(const Animation& t) { ++t.rep->ref_cnt; - if(!--rep->ref_cnt) delete rep; + if (!--rep->ref_cnt) delete rep; rep = t.rep; return *this; } Animation::Rep* Animation::write() { - if(rep->ref_cnt > 1) { + if (rep->ref_cnt > 1) { --rep->ref_cnt; rep = new Rep(*rep); } @@ -124,16 +124,16 @@ int Animation::numPositionKeys()const { } Vector Animation::getScale(float time)const { - if(!rep->scale_anim.size()) return Vector(1, 1, 1); + if (!rep->scale_anim.size()) return Vector(1, 1, 1); return rep->getLinearValue(rep->scale_anim, time); } Vector Animation::getPosition(float time)const { - if(!rep->pos_anim.size()) return Vector(0, 0, 0); + if (!rep->pos_anim.size()) return Vector(0, 0, 0); return rep->getLinearValue(rep->pos_anim, time); } Quat Animation::getRotation(float time)const { - if(!rep->rot_anim.size()) return Quat(); + if (!rep->rot_anim.size()) return Quat(); return rep->getSlerpValue(rep->rot_anim, time); } \ No newline at end of file diff --git a/blitz3d/animator.cpp b/blitz3d/animator.cpp index b5573391..1496cb48 100644 --- a/blitz3d/animator.cpp +++ b/blitz3d/animator.cpp @@ -7,7 +7,7 @@ Animator::Animator(Animator* t) :_seqs(t->_seqs) { _objs.resize(t->_objs.size()); _anims.resize(t->_anims.size()); - for(int k = 0; k < t->_objs.size(); ++k) { + for (int k = 0; k < t->_objs.size(); ++k) { _objs[k] = t->_objs[k]->getLastCopy(); _anims[k].keys = t->_anims[k].keys; } @@ -34,7 +34,7 @@ void Animator::reset() { void Animator::addObjs(Object* obj) { _objs.push_back(obj); - for(Entity* e = obj->children(); e; e = e->successor()) { + for (Entity* e = obj->children(); e; e = e->successor()) { addObjs(e->getObject()); } } @@ -43,7 +43,7 @@ void Animator::addSeq(int frames) { Seq seq; seq.frames = frames; _seqs.push_back(seq); - for(int k = 0; k < _objs.size(); ++k) { + for (int k = 0; k < _objs.size(); ++k) { Object* obj = _objs[k]; _anims[k].keys.push_back(obj->getAnimation()); obj->setAnimation(Animation()); @@ -51,14 +51,14 @@ void Animator::addSeq(int frames) { } void Animator::addSeqs(Animator* t) { - for(int n = 0; n < t->_seqs.size(); ++n) { + for (int n = 0; n < t->_seqs.size(); ++n) { _seqs.push_back(t->_seqs[n]); - for(int k = 0; k < _objs.size(); ++k) { + for (int k = 0; k < _objs.size(); ++k) { int j; - for(j = 0; j < t->_objs.size(); ++j) { - if(_objs[k]->getName() == t->_objs[j]->getName()) break; + for (j = 0; j < t->_objs.size(); ++j) { + if (_objs[k]->getName() == t->_objs[j]->getName()) break; } - if(j == t->_objs.size()) { + if (j == t->_objs.size()) { _anims[k].keys.push_back(Animation()); continue; } @@ -72,7 +72,7 @@ void Animator::extractSeq(int first, int last, int seq) { sq.frames = last - first; _seqs.push_back(sq); - for(int k = 0; k < _objs.size(); ++k) { + for (int k = 0; k < _objs.size(); ++k) { Animation& keys = _anims[k].keys[seq]; _anims[k].keys.push_back(Animation(keys, first, last)); } @@ -80,18 +80,18 @@ void Animator::extractSeq(int first, int last, int seq) { void Animator::updateAnim() { - for(int k = 0; k < _objs.size(); ++k) { + for (int k = 0; k < _objs.size(); ++k) { Object* obj = _objs[k]; const Animation& keys = _anims[k].keys[_seq]; - if(keys.numPositionKeys()) { + if (keys.numPositionKeys()) { obj->setLocalPosition(keys.getPosition(_time)); } - if(keys.numScaleKeys()) { + if (keys.numScaleKeys()) { obj->setLocalScale(keys.getScale(_time)); } - if(keys.numRotationKeys()) { + if (keys.numRotationKeys()) { obj->setLocalRotation(keys.getRotation(_time)); } } @@ -99,34 +99,34 @@ void Animator::updateAnim() { void Animator::updateTrans() { - for(int k = 0; k < _objs.size(); ++k) { + for (int k = 0; k < _objs.size(); ++k) { Object* obj = _objs[k]; const Anim& anim = _anims[k]; - if(anim.pos) obj->setLocalPosition((anim.dest_pos - anim.src_pos) * _trans_time + anim.src_pos); - if(anim.scl) obj->setLocalScale((anim.dest_scl - anim.src_scl) * _trans_time + anim.src_scl); - if(anim.rot) obj->setLocalRotation(anim.src_rot.slerpTo(anim.dest_rot, _trans_time)); + if (anim.pos) obj->setLocalPosition((anim.dest_pos - anim.src_pos) * _trans_time + anim.src_pos); + if (anim.scl) obj->setLocalScale((anim.dest_scl - anim.src_scl) * _trans_time + anim.src_scl); + if (anim.rot) obj->setLocalRotation(anim.src_rot.slerpTo(anim.dest_rot, _trans_time)); } } void Animator::beginTrans() { - for(int k = 0; k < _objs.size(); ++k) { + for (int k = 0; k < _objs.size(); ++k) { Object* obj = _objs[k]; Anim& anim = _anims[k]; const Animation& keys = _anims[k].keys[_seq]; - if(anim.pos = !!keys.numPositionKeys()) { + if (anim.pos = !!keys.numPositionKeys()) { anim.src_pos = obj->getLocalPosition(); anim.dest_pos = keys.getPosition(_time); } - if(anim.scl = !!keys.numScaleKeys()) { + if (anim.scl = !!keys.numScaleKeys()) { anim.src_scl = obj->getLocalScale(); anim.dest_scl = keys.getScale(_time); } - if(anim.rot = !!keys.numRotationKeys()) { + if (anim.rot = !!keys.numRotationKeys()) { anim.src_rot = obj->getLocalRotation(); anim.dest_rot = keys.getRotation(_time); } @@ -134,7 +134,7 @@ void Animator::beginTrans() { } void Animator::setAnimTime(float time, int seq) { - if(seq<0 || seq>_seqs.size()) return; + if (seq<0 || seq>_seqs.size()) return; _mode = 0; _speed = 0; @@ -142,9 +142,9 @@ void Animator::setAnimTime(float time, int seq) { _seq_len = _seqs[_seq].frames; //Ok, mod the anim time! - if(time < 0 || time > _seq_len) { + if (time < 0 || time > _seq_len) { _time = fmod(time, _seq_len); - if(time < 0) { _time += +_seq_len; } + if (time < 0) { _time += +_seq_len; } } else { _time = time; @@ -154,9 +154,9 @@ void Animator::setAnimTime(float time, int seq) { } void Animator::animate(int mode, float speed, int seq, float trans) { - if(!mode && !speed) { _mode = 0; return; } + if (!mode && !speed) { _mode = 0; return; } - if(seq < 0 || seq >= _seqs.size()) return; + if (seq < 0 || seq >= _seqs.size()) return; _seq = seq; _mode = mode; @@ -164,9 +164,9 @@ void Animator::animate(int mode, float speed, int seq, float trans) { _speed = speed; _time = _speed >= 0 ? 0 : _seq_len; - if(trans <= 0) { + if (trans <= 0) { updateAnim(); - if(!_speed) _mode = 0; + if (!_speed) _mode = 0; return; } @@ -178,16 +178,16 @@ void Animator::animate(int mode, float speed, int seq, float trans) { void Animator::update(float elapsed) { - if(!_mode) return; + if (!_mode) return; - if(_mode & 0x8000) { + if (_mode & 0x8000) { _trans_time += _trans_speed * elapsed; - if(_trans_time < 1) { + if (_trans_time < 1) { updateTrans(); return; } _mode &= 0x7fff; - if(!_mode || !_speed) { + if (!_mode || !_speed) { updateAnim(); _mode = 0; return; @@ -197,20 +197,20 @@ void Animator::update(float elapsed) { //do anim... _time += _speed * elapsed; - switch(_mode) { - case ANIM_MODE_LOOP: - _time = fmod(_time, _seq_len); - if(_time < 0) _time += _seq_len; - break; - case ANIM_MODE_PINGPONG: - _time = fmod(_time, _seq_len * 2); - if(_time < 0) _time += _seq_len * 2; - if(_time >= _seq_len) { _time = _seq_len - (_time - _seq_len); _speed = -_speed; } - break; - case ANIM_MODE_ONESHOT: - if(_time < 0) { _time = 0; _mode = 0; } - else if(_time >= _seq_len) { _time = _seq_len; _mode = 0; } - break; + switch (_mode) { + case ANIM_MODE_LOOP: + _time = fmod(_time, _seq_len); + if (_time < 0) _time += _seq_len; + break; + case ANIM_MODE_PINGPONG: + _time = fmod(_time, _seq_len * 2); + if (_time < 0) _time += _seq_len * 2; + if (_time >= _seq_len) { _time = _seq_len - (_time - _seq_len); _speed = -_speed; } + break; + case ANIM_MODE_ONESHOT: + if (_time < 0) { _time = 0; _mode = 0; } + else if (_time >= _seq_len) { _time = _seq_len; _mode = 0; } + break; } updateAnim(); diff --git a/blitz3d/brush.cpp b/blitz3d/brush.cpp index 2b57154c..f02eca71 100644 --- a/blitz3d/brush.cpp +++ b/blitz3d/brush.cpp @@ -21,14 +21,14 @@ struct Brush::Rep { Rep(const Rep& t) : ref_cnt(1), blend(t.blend), max_tex(t.max_tex), rs(t.rs), blend_valid(t.blend_valid) { - for(int k = 0; k < max_tex; ++k) texs[k] = t.texs[k]; + for (int k = 0; k < max_tex; ++k) texs[k] = t.texs[k]; } void* operator new(size_t sz) { static const int GROW = 64; - if(!pool) { + if (!pool) { pool = new Rep[GROW]; - for(int k = 0; k < GROW - 1; ++k) pool[k].next = &pool[k + 1]; + for (int k = 0; k < GROW - 1; ++k) pool[k].next = &pool[k + 1]; pool[GROW - 1].next = 0; } Rep* p = pool; @@ -62,14 +62,14 @@ Brush::Brush(const Brush& a, const Brush& b) : rep->rs.alpha *= b.rep->rs.alpha; rep->rs.shininess += b.rep->rs.shininess; - if(b.rep->blend) rep->blend = b.rep->blend; + if (b.rep->blend) rep->blend = b.rep->blend; rep->rs.fx |= b.rep->rs.fx; - if(b.rep->max_tex > rep->max_tex) rep->max_tex = b.rep->max_tex; + if (b.rep->max_tex > rep->max_tex) rep->max_tex = b.rep->max_tex; - for(int k = 0; k < rep->max_tex; ++k) { - if(b.rep->rs.tex_states[k].canvas) { + for (int k = 0; k < rep->max_tex; ++k) { + if (b.rep->rs.tex_states[k].canvas) { rep->rs.tex_states[k].canvas = b.rep->rs.tex_states[k].canvas; rep->texs[k] = b.rep->texs[k]; } @@ -79,17 +79,17 @@ Brush::Brush(const Brush& a, const Brush& b) : } Brush::~Brush() { - if(!--rep->ref_cnt) delete rep; + if (!--rep->ref_cnt) delete rep; } Brush& Brush::operator=(const Brush& t) { ++t.rep->ref_cnt; - if(!--rep->ref_cnt) delete rep; + if (!--rep->ref_cnt) delete rep; rep = t.rep; return *this; } Brush::Rep* Brush::write()const { - if(rep->ref_cnt > 1) { + if (rep->ref_cnt > 1) { --rep->ref_cnt; rep = new Rep(*rep); } @@ -103,7 +103,7 @@ void Brush::setColor(const Vector& color) { void Brush::setAlpha(float alpha) { float a = rep->rs.alpha; write()->rs.alpha = alpha; - if((a < 1) != (alpha < 1)) rep->blend_valid = false; + if ((a < 1) != (alpha < 1)) rep->blend_valid = false; } void Brush::setShininess(float n) { @@ -128,8 +128,8 @@ void Brush::setTexture(int index, const Texture& t, int n) { rs.tex_states[index].canvas = t.getCanvas(n); rep->max_tex = 0; - for(int k = 0; k < gxScene::MAX_TEXTURES; ++k) { - if(rs.tex_states[k].canvas) rep->max_tex = k + 1; + for (int k = 0; k < gxScene::MAX_TEXTURES; ++k) { + if (rs.tex_states[k].canvas) rep->max_tex = k + 1; } rep->blend_valid = false; } @@ -147,14 +147,14 @@ float Brush::getShininess()const { } int Brush::getBlend()const { - if(rep->blend_valid) return rep->rs.blend; + if (rep->blend_valid) return rep->rs.blend; rep->blend_valid = true; //well, it will be... gxScene::RenderState& rs = rep->rs; //alphatest - if(rep->texs[0].getCanvasFlags() & gxCanvas::CANVAS_TEX_MASK) { + if (rep->texs[0].getCanvasFlags() & gxCanvas::CANVAS_TEX_MASK) { rs.fx |= gxScene::FX_ALPHATEST; } else { @@ -165,23 +165,23 @@ int Brush::getBlend()const { //1 = alpha //2 = multiply //3 = add - if(rep->blend) { - if(rep->blend != gxScene::BLEND_ALPHA) { + if (rep->blend) { + if (rep->blend != gxScene::BLEND_ALPHA) { return rs.blend = rep->blend; } - for(int k = 0; k < rep->max_tex; ++k) { - if(rep->texs[k].isTransparent()) { + for (int k = 0; k < rep->max_tex; ++k) { + if (rep->texs[k].isTransparent()) { return rs.blend = gxScene::BLEND_ALPHA; } } } - else if(rep->max_tex == 1 && rep->texs[0].isTransparent()) { + else if (rep->max_tex == 1 && rep->texs[0].isTransparent()) { //single transparent texture? return rs.blend = gxScene::BLEND_ALPHA; } //vertex alpha or entityalpha? - if((rs.fx & gxScene::FX_VERTEXALPHA) || rs.alpha < 1) { + if ((rs.fx & gxScene::FX_VERTEXALPHA) || rs.alpha < 1) { return rs.blend = gxScene::BLEND_ALPHA; } @@ -198,7 +198,7 @@ Texture Brush::getTexture(int index)const { const gxScene::RenderState& Brush::getRenderState()const { getBlend(); - for(int k = 0; k < rep->max_tex; ++k) { + for (int k = 0; k < rep->max_tex; ++k) { gxScene::RenderState::TexState* ts = &rep->rs.tex_states[k]; ts->matrix = rep->texs[k].getMatrix(); ts->blend = rep->texs[k].getBlend(); diff --git a/blitz3d/cachedtexture.cpp b/blitz3d/cachedtexture.cpp index d4659796..f30c3604 100644 --- a/blitz3d/cachedtexture.cpp +++ b/blitz3d/cachedtexture.cpp @@ -19,8 +19,8 @@ struct CachedTexture::Rep { Rep(int w, int h, int flags, int cnt) : ref_cnt(1), flags(flags), w(w), h(h), first(0) { ++active_texs; - while(cnt-- > 0) { - if(gxCanvas* t = gx_graphics->createCanvas(w, h, flags)) { + while (cnt-- > 0) { + if (gxCanvas* t = gx_graphics->createCanvas(w, h, flags)) { frames.push_back(t); } else break; @@ -30,10 +30,10 @@ struct CachedTexture::Rep { Rep(const std::string& f, int flags, int w, int h, int first, int cnt) : ref_cnt(1), file(f), flags(flags), w(w), h(h), first(first) { ++active_texs; - if(!(flags & gxCanvas::CANVAS_TEX_CUBE)) { - if(w <= 0 || h <= 0 || first < 0 || cnt <= 0) { + if (!(flags & gxCanvas::CANVAS_TEX_CUBE)) { + if (w <= 0 || h <= 0 || first < 0 || cnt <= 0) { w = h = first = 0; - if(gxCanvas* t = gx_graphics->loadCanvas(f, flags)) { + if (gxCanvas* t = gx_graphics->loadCanvas(f, flags)) { frames.push_back(t); } return; @@ -47,22 +47,22 @@ struct CachedTexture::Rep { gxCanvas::CANVAS_TEX_HICOLOR) | gxCanvas::CANVAS_NONDISPLAY; gxCanvas* t = gx_graphics->loadCanvas(f, t_flags); - if(!t) return; - if(!t->getDepth()) { + if (!t) return; + if (!t->getDepth()) { gx_graphics->freeCanvas(t); return; } - if(flags & gxCanvas::CANVAS_TEX_CUBE) { + if (flags & gxCanvas::CANVAS_TEX_CUBE) { int w = t->getWidth() / 6; - if(w * 6 != t->getWidth()) return; + if (w * 6 != t->getWidth()) return; int h = t->getHeight(); gxCanvas* tex = gx_graphics->createCanvas(w, h, flags); - if(tex) { + if (tex) { frames.push_back(tex); - for(int face = 0; face < 6; ++face) { + for (int face = 0; face < 6; ++face) { tex->setCubeFace(face); gx_graphics->copy(tex, 0, 0, tex->getWidth(), tex->getHeight(), t, face * w, 0, w, h); } @@ -72,17 +72,17 @@ struct CachedTexture::Rep { else { int x_tiles = t->getWidth() / w; int y_tiles = t->getHeight() / h; - if(first + cnt > x_tiles * y_tiles) { + if (first + cnt > x_tiles * y_tiles) { gx_graphics->freeCanvas(t); return; } int x = (first % x_tiles) * w; int y = (first / x_tiles) * h; - while(cnt--) { + while (cnt--) { gxCanvas* p = gx_graphics->createCanvas(w, h, flags); gx_graphics->copy(p, 0, 0, p->getWidth(), p->getHeight(), t, x, y, w, h); frames.push_back(p); - x = x + w; if(x + w > t->getWidth()) { x = 0; y = y + h; } + x = x + w; if (x + w > t->getWidth()) { x = 0; y = y + h; } } } gx_graphics->freeCanvas(t); @@ -90,15 +90,15 @@ struct CachedTexture::Rep { ~Rep() { --active_texs; - for(int k = 0; k < frames.size(); ++k) gx_graphics->freeCanvas(frames[k]); + for (int k = 0; k < frames.size(); ++k) gx_graphics->freeCanvas(frames[k]); } }; CachedTexture::Rep* CachedTexture::findRep(const std::string& f, int flags, int w, int h, int first, int cnt) { std::set::const_iterator it; - for(it = rep_set.begin(); it != rep_set.end(); ++it) { + for (it = rep_set.begin(); it != rep_set.end(); ++it) { Rep* rep = *it; - if(rep->file == f && rep->flags == flags && rep->w == w && rep->h == h && rep->first == first && rep->frames.size() == cnt) { + if (rep->file == f && rep->flags == flags && rep->w == w && rep->h == h && rep->first == first && rep->frames.size() == cnt) { ++rep->ref_cnt; return rep; } } @@ -111,19 +111,19 @@ CachedTexture::CachedTexture(int w, int h, int flags, int cnt) : CachedTexture::CachedTexture(const std::string& f_, int flags, int w, int h, int first, int cnt) { std::string f = f_; - if(f.substr(0, 2) == ".\\") f = f.substr(2); - if(path.size()) { + if (f.substr(0, 2) == ".\\") f = f.substr(2); + if (path.size()) { std::string t = path + tolower(filenamefile(f)); - if(rep = findRep(t, flags, w, h, first, cnt)) return; + if (rep = findRep(t, flags, w, h, first, cnt)) return; rep = new Rep(t, flags, w, h, first, cnt); - if(rep->frames.size()) { + if (rep->frames.size()) { rep_set.insert(rep); return; } delete rep; } std::string t = tolower(fullfilename(f)); - if(rep = findRep(t, flags, w, h, first, cnt)) return; + if (rep = findRep(t, flags, w, h, first, cnt)) return; rep = new Rep(t, flags, w, h, first, cnt); rep_set.insert(rep); } @@ -134,7 +134,7 @@ CachedTexture::CachedTexture(const CachedTexture& t) : } CachedTexture::~CachedTexture() { - if(!--rep->ref_cnt) { + if (!--rep->ref_cnt) { rep_set.erase(rep); delete rep; } @@ -142,7 +142,7 @@ CachedTexture::~CachedTexture() { CachedTexture& CachedTexture::operator=(const CachedTexture& t) { ++t.rep->ref_cnt; - if(!--rep->ref_cnt) { + if (!--rep->ref_cnt) { rep_set.erase(rep); delete rep; } @@ -160,7 +160,7 @@ const std::vector& CachedTexture::getFrames()const { void CachedTexture::setPath(const std::string& t) { path = tolower(t); - if(int sz = path.size()) { - if(path[sz - 1] != '/' && path[sz - 1] != '\\') path += '\\'; + if (int sz = path.size()) { + if (path[sz - 1] != '/' && path[sz - 1] != '\\') path += '\\'; } } \ No newline at end of file diff --git a/blitz3d/camera.cpp b/blitz3d/camera.cpp index a8d29574..7815a39c 100644 --- a/blitz3d/camera.cpp +++ b/blitz3d/camera.cpp @@ -59,7 +59,7 @@ void Camera::setFogMode(int mode) { } const Frustum& Camera::getFrustum()const { - if(!local_valid) { + if (!local_valid) { float ar = (float)vp_h / vp_w; frustum_w = frustum_nr * 2 / zoom; frustum_h = frustum_nr * 2 / zoom * ar; @@ -98,11 +98,11 @@ void Camera::getViewport(int* x, int* y, int* w, int* h)const { } bool Camera::beginRenderFrame() { - if(!proj_mode) return false; + if (!proj_mode) return false; getFrustum(); gx_scene->setViewport(vp_x, vp_y, vp_w, vp_h); gx_scene->clear(&(cls_color.x), 1, 1, cls_argb, cls_z); - if(proj_mode == PROJ_ORTHO) { + if (proj_mode == PROJ_ORTHO) { gx_scene->setOrthoProj(frustum_nr, frustum_fr, frustum_w, frustum_h); } else { diff --git a/blitz3d/collision.cpp b/blitz3d/collision.cpp index bd71440c..f8776634 100644 --- a/blitz3d/collision.cpp +++ b/blitz3d/collision.cpp @@ -4,10 +4,10 @@ const float COLLISION_EPSILON = .001f; bool Collision::update(const Line& line, float t, const Vector& n) { - if(t > time) return false; + if (t > time) return false; Plane p(line * t, n); - if(p.n.dot(line.d) >= 0) return false; - if(p.distance(line.o) < -COLLISION_EPSILON) return false; + if (p.n.dot(line.d) >= 0) return false; + if (p.distance(line.o) < -COLLISION_EPSILON) return false; time = t; normal = n; @@ -22,18 +22,18 @@ bool Collision::sphereCollide(const Line& line, float radius, const Vector& dest Line l(line.o - dest, line.d); float a = l.d.dot(l.d); - if(!a) return false; + if (!a) return false; float b = l.o.dot(l.d) * 2; float c = l.o.dot(l.o) - radius * radius; float d = b * b - 4 * a * c; - if(d < 0) return false; + if (d < 0) return false; float t1 = (-b + sqrtf(d)) / (2 * a); float t2 = (-b - sqrtf(d)) / (2 * a); float t = t1 < t2 ? t1 : t2; - if(t > time) return false; + if (t > time) return false; return update(line, t, (l * t).normalized()); } @@ -49,32 +49,32 @@ static bool edgeTest(const Vector& v0, const Vector& v1, const Vector& pn, const //do cylinder test... float a, b, c, d, t1, t2, t; a = (l.d.x * l.d.x + l.d.z * l.d.z); - if(!a) return false; //ray parallel to cylinder + if (!a) return false; //ray parallel to cylinder b = (l.o.x * l.d.x + l.o.z * l.d.z) * 2; c = (l.o.x * l.o.x + l.o.z * l.o.z) - radius * radius; d = b * b - 4 * a * c; - if(d < 0) return false; //ray misses cylinder + if (d < 0) return false; //ray misses cylinder t1 = (-b + sqrtf(d)) / (2 * a); t2 = (-b - sqrtf(d)) / (2 * a); t = t1 < t2 ? t1 : t2; - if(t > curr_coll->time) return false; //intersects too far away + if (t > curr_coll->time) return false; //intersects too far away Vector i = l * t, p; - if(i.y > v0.distance(v1)) return false; //intersection above cylinder - if(i.y >= 0) { + if (i.y > v0.distance(v1)) return false; //intersection above cylinder + if (i.y >= 0) { p.y = i.y; } else { //below bottom of cylinder...do sphere test... a = l.d.dot(l.d); - if(!a) return false; //ray parallel to sphere + if (!a) return false; //ray parallel to sphere b = l.o.dot(l.d) * 2; c = l.o.dot(l.o) - radius * radius; d = b * b - 4 * a * c; - if(d < 0) return false; //ray misses sphere + if (d < 0) return false; //ray misses sphere t1 = (-b + sqrtf(d)) / (2 * a); t2 = (-b - sqrtf(d)) / (2 * a); t = t1 < t2 ? t1 : t2; - if(t > curr_coll->time) return false; + if (t > curr_coll->time) return false; i = l * t; } @@ -85,23 +85,23 @@ bool Collision::triangleCollide(const Line& line, float radius, const Vector& v0 //triangle plane Plane p(v0, v1, v2); - if(p.n.dot(line.d) >= 0) return false; + if (p.n.dot(line.d) >= 0) return false; //move plane out p.d -= radius; float t = p.t_intersect(line); - if(t > time) return false; + if (t > time) return false; //edge planes Plane p0(v0 + p.n, v1, v0), p1(v1 + p.n, v2, v1), p2(v2 + p.n, v0, v2); //intersects triangle? Vector i = line * t; - if(p0.distance(i) >= 0 && p1.distance(i) >= 0 && p2.distance(i) >= 0) { + if (p0.distance(i) >= 0 && p1.distance(i) >= 0 && p2.distance(i) >= 0) { return update(line, t, p.n); } - if(radius <= 0) return false; + if (radius <= 0) return false; return edgeTest(v0, v1, p.n, p0.n, line, radius, this) | @@ -122,7 +122,7 @@ bool Collision::boxCollide(const Line& line, float radius, const Box& box) { bool hit = false; - for(int n = 0; n < 24; n += 4) { + for (int n = 0; n < 24; n += 4) { Vector v0(box.corner(quads[n])), v1(box.corner(quads[n + 1])), @@ -131,12 +131,12 @@ bool Collision::boxCollide(const Line& line, float radius, const Box& box) { //quad plane Plane p(v0, v1, v2); - if(p.n.dot(line.d) >= 0) continue; + if (p.n.dot(line.d) >= 0) continue; //move plane out p.d -= radius; float t = p.t_intersect(line); - if(t > time) return false; + if (t > time) return false; //edge planes Plane @@ -147,12 +147,12 @@ bool Collision::boxCollide(const Line& line, float radius, const Box& box) { //intersects triangle? Vector i = line * t; - if(p0.distance(i) >= 0 && p1.distance(i) >= 0 && p2.distance(i) >= 0 && p3.distance(i) >= 0) { + if (p0.distance(i) >= 0 && p1.distance(i) >= 0 && p2.distance(i) >= 0 && p3.distance(i) >= 0) { hit |= update(line, t, p.n); continue; } - if(radius <= 0) continue; + if (radius <= 0) continue; hit |= edgeTest(v0, v1, p.n, p0.n, line, radius, this) | diff --git a/blitz3d/entity.cpp b/blitz3d/entity.cpp index 01ed11a1..603add88 100644 --- a/blitz3d/entity.cpp +++ b/blitz3d/entity.cpp @@ -9,27 +9,27 @@ enum { }; void Entity::remove() { - if(_parent) { - if(_parent->_children == this) _parent->_children = _succ; - if(_parent->_last_child == this) _parent->_last_child = _pred; + if (_parent) { + if (_parent->_children == this) _parent->_children = _succ; + if (_parent->_last_child == this) _parent->_last_child = _pred; } else { - if(_orphans == this) _orphans = _succ; - if(_last_orphan == this) _last_orphan = _pred; + if (_orphans == this) _orphans = _succ; + if (_last_orphan == this) _last_orphan = _pred; } - if(_succ) _succ->_pred = _pred; - if(_pred) _pred->_succ = _succ; + if (_succ) _succ->_pred = _pred; + if (_pred) _pred->_succ = _succ; } void Entity::insert() { _succ = 0; - if(_parent) { - if(_pred = _parent->_last_child) _pred->_succ = this; + if (_parent) { + if (_pred = _parent->_last_child) _pred->_succ = this; else _parent->_children = this; _parent->_last_child = this; } else { - if(_pred = _last_orphan) _pred->_succ = this; + if (_pred = _last_orphan) _pred->_succ = this; else _orphans = this; _last_orphan = this; } @@ -54,14 +54,14 @@ Entity::Entity(const Entity& e) : } Entity::~Entity() { - while(children()) delete children(); + while (children()) delete children(); remove(); } void Entity::invalidateWorld() { - if(invalid & INVALID_WORLDTFORM) return; + if (invalid & INVALID_WORLDTFORM) return; invalid |= INVALID_WORLDTFORM; - for(Entity* e = _children; e; e = e->_succ) { + for (Entity* e = _children; e; e = e->_succ) { e->invalidateWorld(); } } @@ -72,7 +72,7 @@ void Entity::invalidateLocal() { } const Transform& Entity::getLocalTform()const { - if(invalid & INVALID_LOCALTFORM) { + if (invalid & INVALID_LOCALTFORM) { local_tform.m = Matrix(local_rot); local_tform.m.i *= local_scl.x; local_tform.m.j *= local_scl.y; @@ -84,7 +84,7 @@ const Transform& Entity::getLocalTform()const { } const Transform& Entity::getWorldTform()const { - if(invalid & INVALID_WORLDTFORM) { + if (invalid & INVALID_WORLDTFORM) { world_tform = _parent ? _parent->getWorldTform() * getLocalTform() : getLocalTform(); invalid &= ~INVALID_WORLDTFORM; } @@ -92,7 +92,7 @@ const Transform& Entity::getWorldTform()const { } void Entity::setParent(Entity* p) { - if(_parent == p) return; + if (_parent == p) return; remove(); @@ -116,17 +116,17 @@ void Entity::setEnabled(bool enabled) { } void Entity::enumVisible(std::vector& out) { - if(!_visible) return; - if(Object* o = getObject()) out.push_back(o); - for(Entity* e = _children; e; e = e->_succ) { + if (!_visible) return; + if (Object* o = getObject()) out.push_back(o); + for (Entity* e = _children; e; e = e->_succ) { e->enumVisible(out); } } void Entity::enumEnabled(std::vector& out) { - if(!_enabled) return; - if(Object* o = getObject()) out.push_back(o); - for(Entity* e = _children; e; e = e->_succ) { + if (!_enabled) return; + if (Object* o = getObject()) out.push_back(o); + for (Entity* e = _children; e; e = e->_succ) { e->enumEnabled(out); } } diff --git a/blitz3d/frustum.cpp b/blitz3d/frustum.cpp index 2a42ef58..9609a0fb 100644 --- a/blitz3d/frustum.cpp +++ b/blitz3d/frustum.cpp @@ -19,24 +19,24 @@ Frustum::Frustum(float nr, float fr, float w, float h) { } Frustum::Frustum(const Frustum& f, const Transform& t) { - for(int k = 0; k < 9; ++k) { + for (int k = 0; k < 9; ++k) { verts[k] = t * f.verts[k]; } makePlanes(); } bool Frustum::cull(const Vector v[], int cnt)const { - for(int n = 0; n < 6; ++n) { + for (int n = 0; n < 6; ++n) { int k; - for(k = 0; k < cnt && planes[n].distance(v[k]) < 0; ++k) {} - if(k == cnt) return false; + for (k = 0; k < cnt && planes[n].distance(v[k]) < 0; ++k) {} + if (k == cnt) return false; } return true; } bool Frustum::cull(const Box& b)const { Vector v[8]; - for(int k = 0; k < 8; ++k) v[k] = b.corner(k); + for (int k = 0; k < 8; ++k) v[k] = b.corner(k); return cull(v, 8); } @@ -47,7 +47,7 @@ void Frustum::makePlanes() { planes[PLANE_RIGHT] = Plane(verts[VERT_EYE], verts[VERT_BRFAR], verts[VERT_TRFAR]); planes[PLANE_NEAR] = Plane(verts[VERT_TRNEAR], verts[VERT_TLNEAR], verts[VERT_BLNEAR]); planes[PLANE_FAR] = Plane(verts[VERT_TLFAR], verts[VERT_TRFAR], verts[VERT_BRFAR]); - if(planes[PLANE_NEAR].distance(verts[VERT_EYE]) > 0) { - for(int k = 0; k < 6; ++k) planes[k] = -planes[k]; + if (planes[PLANE_NEAR].distance(verts[VERT_EYE]) > 0) { + for (int k = 0; k < 6; ++k) planes[k] = -planes[k]; } } \ No newline at end of file diff --git a/blitz3d/geom.h b/blitz3d/geom.h index 83b38437..95ee7ff4 100644 --- a/blitz3d/geom.h +++ b/blitz3d/geom.h @@ -78,8 +78,8 @@ class Vector { x -= q.x; y -= q.y; z -= q.z; return *this; } bool operator<(const Vector& q)const { - if(fabs(x - q.x) > EPSILON) return x < q.x ? true : false; - if(fabs(y - q.y) > EPSILON) return y < q.y ? true : false; + if (fabs(x - q.x) > EPSILON) return x < q.x ? true : false; + if (fabs(y - q.y) > EPSILON) return y < q.y ? true : false; return fabs(z - q.z) > EPSILON && z < q.z; } bool operator==(const Vector& q)const { @@ -105,12 +105,12 @@ class Vector { } Vector normalized()const { float l = length(); - if(abs(l) < EPSILON) return Vector(x / EPSILON, y / EPSILON, z / EPSILON); + if (abs(l) < EPSILON) return Vector(x / EPSILON, y / EPSILON, z / EPSILON); return Vector(x / l, y / l, z / l); } void normalize() { float l = length(); - if(abs(l) < EPSILON) { + if (abs(l) < EPSILON) { x /= EPSILON; y /= EPSILON; z /= EPSILON; } else { @@ -226,7 +226,7 @@ struct Quat { } void normalize() { float l = length(); - if(l < EPSILON) { + if (l < EPSILON) { *this = *this / EPSILON; } else { @@ -235,14 +235,14 @@ struct Quat { } Quat normalized()const { float l = length(); - if(l < EPSILON) return *this / EPSILON; + if (l < EPSILON) return *this / EPSILON; return *this / l; } Quat slerpTo(const Quat& q, float a)const { Quat t = q; float d = dot(q), b = 1 - a; - if(d < 0) { t.w = -t.w; t.v = -t.v; d = -d; } - if(d < 1 - EPSILON) { + if (d < 0) { t.w = -t.w; t.v = -t.v; d = -d; } + if (d < 1 - EPSILON) { float om = acosf(d); float si = sinf(om); a = sinf(a * om) / si; @@ -382,12 +382,12 @@ class Box { return Vector(((n & 1) ? b : a).x, ((n & 2) ? b : a).y, ((n & 4) ? b : a).z); } void update(const Vector& q) { - if(q.x < a.x) a.x = q.x; if(q.y < a.y) a.y = q.y; if(q.z < a.z) a.z = q.z; - if(q.x > b.x) b.x = q.x; if(q.y > b.y) b.y = q.y; if(q.z > b.z) b.z = q.z; + if (q.x < a.x) a.x = q.x; if (q.y < a.y) a.y = q.y; if (q.z < a.z) a.z = q.z; + if (q.x > b.x) b.x = q.x; if (q.y > b.y) b.y = q.y; if (q.z > b.z) b.z = q.z; } void update(const Box& q) { - if(q.a.x < a.x) a.x = q.a.x; if(q.a.y < a.y) a.y = q.a.y; if(q.a.z < a.z) a.z = q.a.z; - if(q.b.x > b.x) b.x = q.b.x; if(q.b.y > b.y) b.y = q.b.y; if(q.b.z > b.z) b.z = q.b.z; + if (q.a.x < a.x) a.x = q.a.x; if (q.a.y < a.y) a.y = q.a.y; if (q.a.z < a.z) a.z = q.a.z; + if (q.b.x > b.x) b.x = q.b.x; if (q.b.y > b.y) b.y = q.b.y; if (q.b.z > b.z) b.z = q.b.z; } bool overlaps(const Box& q)const { return @@ -446,7 +446,7 @@ class Transform { } Box operator*(const Box& q)const { Box t((*this * q.corner(0))); - for(int k = 1; k < 8; ++k) t.update(*this * q.corner(k)); + for (int k = 1; k < 8; ++k) t.update(*this * q.corner(k)); return t; } Transform& operator*(const Transform& q)const { @@ -537,21 +537,21 @@ inline Quat matrixQuat(const Matrix& p) { Matrix m = p; m.orthogonalize(); float t = m.i.x + m.j.y + m.k.z, w, x, y, z; - if(t > EPSILON) { + if (t > EPSILON) { t = sqrtf(t + 1) * 2; x = (m.k.y - m.j.z) / t; y = (m.i.z - m.k.x) / t; z = (m.j.x - m.i.y) / t; w = t / 4; } - else if(m.i.x > m.j.y && m.i.x > m.k.z) { + else if (m.i.x > m.j.y && m.i.x > m.k.z) { t = sqrtf(m.i.x - m.j.y - m.k.z + 1) * 2; x = t / 4; y = (m.j.x + m.i.y) / t; z = (m.i.z + m.k.x) / t; w = (m.k.y - m.j.z) / t; } - else if(m.j.y > m.k.z) { + else if (m.j.y > m.k.z) { t = sqrtf(m.j.y - m.k.z - m.i.x + 1) * 2; x = (m.j.x + m.i.y) / t; y = t / 4; diff --git a/blitz3d/listener.cpp b/blitz3d/listener.cpp index e6ab926b..5a088282 100644 --- a/blitz3d/listener.cpp +++ b/blitz3d/listener.cpp @@ -4,7 +4,7 @@ extern gxAudio* gx_audio; Listener::Listener(float roll, float dopp, float dist) { - if(!gx_audio) return; + if (!gx_audio) return; gx_audio->set3dOptions(roll, dopp, dist); renderListener(); @@ -15,14 +15,14 @@ Listener::Listener(const Listener& t) : } Listener::~Listener() { - if(!gx_audio) return; + if (!gx_audio) return; Vector pos, vel, up(0, 1, 1), forward(0, 0, 1); gx_audio->set3dListener(&pos.x, &vel.x, &forward.x, &up.x); } void Listener::renderListener() { - if(!gx_audio) return; + if (!gx_audio) return; const Vector& pos = getWorldTform().v; const Vector& vel = getVelocity(); diff --git a/blitz3d/loader_3ds.cpp b/blitz3d/loader_3ds.cpp index bd4f0194..466ae437 100644 --- a/blitz3d/loader_3ds.cpp +++ b/blitz3d/loader_3ds.cpp @@ -33,7 +33,7 @@ static std::map id_map; static int nextChunk() { in.pubseekoff(chunk_end, std::ios_base::beg); - if(chunk_end == parent_end.back()) return 0; + if (chunk_end == parent_end.back()) return 0; unsigned short id; int len; in.sgetn((char*)&id, 2); in.sgetn((char*)&len, 4); @@ -53,7 +53,7 @@ static void leaveChunk() { static std::string parseString() { std::string t; - while(int c = in.sbumpc()) t += char(c); + while (int c = in.sbumpc()) t += char(c); return t; } @@ -95,14 +95,14 @@ static Vector parseColor() { Vector v; unsigned char rgb[3]; enterChunk(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_RGBF: - in.sgetn((char*)&v, 12); - break; - case CHUNK_RGBB: - in.sgetn((char*)rgb, 3); - v = Vector(rgb[0] / 255.0f, rgb[1] / 255.0f, rgb[2] / 255.0f); + while (int id = nextChunk()) { + switch (id) { + case CHUNK_RGBF: + in.sgetn((char*)&v, 12); + break; + case CHUNK_RGBB: + in.sgetn((char*)rgb, 3); + v = Vector(rgb[0] / 255.0f, rgb[1] / 255.0f, rgb[2] / 255.0f); } } leaveChunk(); @@ -113,10 +113,10 @@ static void parseVertList() { unsigned short cnt; in.sgetn((char*)&cnt, 2); _log("VertList cnt=" + itoa(cnt)); - while(cnt--) { + while (cnt--) { Surface::Vertex v; in.sgetn((char*)&v.coords, 12); - if(conv) v.coords = conv_tform * v.coords; + if (conv) v.coords = conv_tform * v.coords; MeshLoader::addVertex(v); } } @@ -127,7 +127,7 @@ static void parseFaceMat() { Brush mat = materials_map[name]; unsigned short cnt; in.sgetn((char*)&cnt, 2); - while(cnt--) { + while (cnt--) { unsigned short face; in.sgetn((char*)&face, 2); faces[face].brush = mat; @@ -138,22 +138,22 @@ static void parseFaceList() { unsigned short cnt; in.sgetn((char*)&cnt, 2); _log("FaceList cnt=" + itoa(cnt)); - while(cnt--) { + while (cnt--) { unsigned short v[4]; in.sgetn((char*)v, 8); Face3DS face; face.verts[0] = v[0]; face.verts[1] = v[1]; face.verts[2] = v[2]; - if(flip_tris) std::swap(face.verts[1], face.verts[2]); + if (flip_tris) std::swap(face.verts[1], face.verts[2]); faces.push_back(face); } enterChunk(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_FACEMAT: - parseFaceMat(); - break; + while (int id = nextChunk()) { + switch (id) { + case CHUNK_FACEMAT: + parseFaceMat(); + break; } } leaveChunk(); @@ -163,7 +163,7 @@ static void parseMapList() { _log("MapList"); unsigned short cnt; in.sgetn((char*)&cnt, 2); - for(int k = 0; k < cnt; ++k) { + for (int k = 0; k < cnt; ++k) { float uv[2]; in.sgetn((char*)uv, 8); Surface::Vertex& v = MeshLoader::refVertex(k); @@ -181,21 +181,21 @@ static void parseTriMesh(MeshModel* mesh) { MeshLoader::beginMesh(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_VERTLIST: - if(!animonly) parseVertList(); - break; - case CHUNK_MAPLIST: - if(!animonly) parseMapList(); - break; - case CHUNK_FACELIST: - if(!animonly) parseFaceList(); - break; - case CHUNK_TRMATRIX: - in.sgetn((char*)&tform, 48); - if(conv) tform = conv_tform * tform * -conv_tform; - break; + while (int id = nextChunk()) { + switch (id) { + case CHUNK_VERTLIST: + if (!animonly) parseVertList(); + break; + case CHUNK_MAPLIST: + if (!animonly) parseMapList(); + break; + case CHUNK_FACELIST: + if (!animonly) parseFaceList(); + break; + case CHUNK_TRMATRIX: + in.sgetn((char*)&tform, 48); + if (conv) tform = conv_tform * tform * -conv_tform; + break; } } leaveChunk(); @@ -206,18 +206,18 @@ static void parseTriMesh(MeshModel* mesh) { mesh->setWorldTform(tform); - if(animonly) { + if (animonly) { MeshLoader::endMesh(0); return; } Transform inv_tform = -tform; - for(k = 0; k < MeshLoader::numVertices(); ++k) { + for (k = 0; k < MeshLoader::numVertices(); ++k) { Surface::Vertex& v = MeshLoader::refVertex(k); v.coords = inv_tform * v.coords; } - for(k = 0; k < faces.size(); ++k) { + for (k = 0; k < faces.size(); ++k) { const Face3DS& f = faces[k]; MeshLoader::addTriangle(f.verts, f.brush); } @@ -235,15 +235,15 @@ static void parseObject(MeshModel* root) { MeshModel* mesh = 0; enterChunk(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_TRIMESH: - mesh = new MeshModel(); - mesh->setName(name); - mesh->setParent(root); - name_map[name] = mesh; - parseTriMesh(mesh); - break; + while (int id = nextChunk()) { + switch (id) { + case CHUNK_TRIMESH: + mesh = new MeshModel(); + mesh->setName(name); + mesh->setParent(root); + name_map[name] = mesh; + parseTriMesh(mesh); + break; } } leaveChunk(); @@ -254,36 +254,36 @@ static void parseMaterial() { Brush mat; std::string name, tex_name; enterChunk(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_MATNAME: - name = parseString(); - break; - case CHUNK_DIFFUSE: - mat.setColor(parseColor()); - break; - case CHUNK_AMBIENT: - break; - case CHUNK_SPECULAR: - break; - case CHUNK_TEXTURE: - enterChunk(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_MAPFILE: - tex_name = parseString(); - break; - } + while (int id = nextChunk()) { + switch (id) { + case CHUNK_MATNAME: + name = parseString(); + break; + case CHUNK_DIFFUSE: + mat.setColor(parseColor()); + break; + case CHUNK_AMBIENT: + break; + case CHUNK_SPECULAR: + break; + case CHUNK_TEXTURE: + enterChunk(); + while (int id = nextChunk()) { + switch (id) { + case CHUNK_MAPFILE: + tex_name = parseString(); + break; } - leaveChunk(); - break; + } + leaveChunk(); + break; } } - if(tex_name.size()) { + if (tex_name.size()) { mat.setTexture(0, Texture(tex_name, 0), 0); mat.setColor(Vector(1, 1, 1)); } - if(name.size()) { + if (name.size()) { materials_map[name] = mat; } leaveChunk(); @@ -292,14 +292,14 @@ static void parseMaterial() { static void parseScene(MeshModel* root) { _log("Scene"); enterChunk(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_OBJECT: - parseObject(root); - break; - case CHUNK_MATERIAL: - if(!animonly) parseMaterial(); - break; + while (int id = nextChunk()) { + switch (id) { + case CHUNK_OBJECT: + parseObject(root); + break; + case CHUNK_MATERIAL: + if (!animonly) parseMaterial(); + break; } } leaveChunk(); @@ -317,40 +317,40 @@ static void parseAnimKeys(Animation* anim, int type) { Vector pos, axis, scale; float angle; Quat quat; - for(int k = 0; k < cnt; ++k) { + for (int k = 0; k < cnt; ++k) { int time; short flags; in.sgetn((char*)&time, 4); in.sgetn((char*)&flags, 2); float tens = 0, cont = 0, bias = 0, ease_to = 0, ease_from = 0; - if(flags & 1) in.sgetn((char*)&tens, 4); - if(flags & 2) in.sgetn((char*)&cont, 4); - if(flags & 4) in.sgetn((char*)&bias, 4); - if(flags & 8) in.sgetn((char*)&ease_to, 4); - if(flags & 16) in.sgetn((char*)&ease_from, 4); - switch(type) { - case 0xb020: //POS_TRACK_TAG - in.sgetn((char*)&pos, 12); - if(conv) pos = conv_tform * pos; - if(time <= anim_len) anim->setPositionKey(time, pos); - break; - case 0xb021: //ROT_TRACK_TAG - in.sgetn((char*)&angle, 4); - in.sgetn((char*)&axis, 12); - if(axis.length() > EPSILON) { - if(flip_tris) angle = -angle; - if(conv) axis = conv_tform.m * axis; - quat = Quat(cosf(angle / 2), axis.normalized() * sinf(angle / 2)) * quat; - quat.normalize(); - } - if(time <= anim_len) anim->setRotationKey(time, quat); - break; - case 0xb022: //SCL_TRACK_TAG - in.sgetn((char*)&scale, 12); - if(conv) scale = conv_tform.m * scale; - _log("SCL_KEY: time=" + itoa(time) + " scale=" + ftoa(scale.x) + "," + ftoa(scale.y) + "," + ftoa(scale.z)); - if(time <= anim_len) anim->setScaleKey(time, scale); - break; + if (flags & 1) in.sgetn((char*)&tens, 4); + if (flags & 2) in.sgetn((char*)&cont, 4); + if (flags & 4) in.sgetn((char*)&bias, 4); + if (flags & 8) in.sgetn((char*)&ease_to, 4); + if (flags & 16) in.sgetn((char*)&ease_from, 4); + switch (type) { + case 0xb020: //POS_TRACK_TAG + in.sgetn((char*)&pos, 12); + if (conv) pos = conv_tform * pos; + if (time <= anim_len) anim->setPositionKey(time, pos); + break; + case 0xb021: //ROT_TRACK_TAG + in.sgetn((char*)&angle, 4); + in.sgetn((char*)&axis, 12); + if (axis.length() > EPSILON) { + if (flip_tris) angle = -angle; + if (conv) axis = conv_tform.m * axis; + quat = Quat(cosf(angle / 2), axis.normalized() * sinf(angle / 2)) * quat; + quat.normalize(); + } + if (time <= anim_len) anim->setRotationKey(time, quat); + break; + case 0xb022: //SCL_TRACK_TAG + in.sgetn((char*)&scale, 12); + if (conv) scale = conv_tform.m * scale; + _log("SCL_KEY: time=" + itoa(time) + " scale=" + ftoa(scale.x) + "," + ftoa(scale.y) + "," + ftoa(scale.z)); + if (time <= anim_len) anim->setScaleKey(time, scale); + break; } } } @@ -364,62 +364,62 @@ static void parseMeshInfo(MeshModel* root, float curr_time) { unsigned short id = 65535, parent = 65535, flags1, flags2; Box box{ Vector(),Vector() }; Vector box_centre; - while(int chunk_id = nextChunk()) { - switch(chunk_id) { - case 0xb030: //NODE_ID - in.sgetn((char*)&id, 2); - _log("NODE_ID: " + itoa(id)); - break; - case 0xb010: //NODE_HDR - name = parseString(); - in.sgetn((char*)&flags1, 2); - in.sgetn((char*)&flags2, 2); - in.sgetn((char*)&parent, 2); - _log("NODE_HDR: name=" + name + " parent=" + itoa(parent)); - break; - case 0xb011: //INSTANCE NAME - inst = parseString(); - _log("INSTANCE_NAME: " + inst); - break; - case 0xb013: //PIVOT - in.sgetn((char*)&pivot, 12); - if(conv) pivot = conv_tform * pivot; - _log("PIVOT: " + ftoa(pivot.x) + "," + ftoa(pivot.y) + "," + ftoa(pivot.z)); - break; - case 0xb014: //BOUNDBOX - in.sgetn((char*)&box.a, 12); - in.sgetn((char*)&box.b, 12); - box_centre = box.centre(); - if(conv) box_centre = conv_tform * box_centre; - _log("BOUNDBOX: min=" + ftoa(box.a.x) + "," + ftoa(box.a.y) + "," + ftoa(box.a.z) + " max=" + ftoa(box.b.x) + "," + ftoa(box.b.y) + "," + ftoa(box.b.z)); - break; - case 0xb020: //POS_TRACK_TAG - case 0xb021: //ROT_TRACK_TAG - case 0xb022: //SCALE_TRACK_TAG - if(!collapse) parseAnimKeys(&anim, chunk_id); - break; + while (int chunk_id = nextChunk()) { + switch (chunk_id) { + case 0xb030: //NODE_ID + in.sgetn((char*)&id, 2); + _log("NODE_ID: " + itoa(id)); + break; + case 0xb010: //NODE_HDR + name = parseString(); + in.sgetn((char*)&flags1, 2); + in.sgetn((char*)&flags2, 2); + in.sgetn((char*)&parent, 2); + _log("NODE_HDR: name=" + name + " parent=" + itoa(parent)); + break; + case 0xb011: //INSTANCE NAME + inst = parseString(); + _log("INSTANCE_NAME: " + inst); + break; + case 0xb013: //PIVOT + in.sgetn((char*)&pivot, 12); + if (conv) pivot = conv_tform * pivot; + _log("PIVOT: " + ftoa(pivot.x) + "," + ftoa(pivot.y) + "," + ftoa(pivot.z)); + break; + case 0xb014: //BOUNDBOX + in.sgetn((char*)&box.a, 12); + in.sgetn((char*)&box.b, 12); + box_centre = box.centre(); + if (conv) box_centre = conv_tform * box_centre; + _log("BOUNDBOX: min=" + ftoa(box.a.x) + "," + ftoa(box.a.y) + "," + ftoa(box.a.z) + " max=" + ftoa(box.b.x) + "," + ftoa(box.b.y) + "," + ftoa(box.b.z)); + break; + case 0xb020: //POS_TRACK_TAG + case 0xb021: //ROT_TRACK_TAG + case 0xb022: //SCALE_TRACK_TAG + if (!collapse) parseAnimKeys(&anim, chunk_id); + break; } } leaveChunk(); MeshModel* p = root; - if(parent != 65535) { + if (parent != 65535) { std::map::const_iterator it = id_map.find(parent); - if(it == id_map.end()) return; + if (it == id_map.end()) return; p = it->second; } MeshModel* mesh = 0; - if(name == "$$$DUMMY") { + if (name == "$$$DUMMY") { mesh = new MeshModel(); mesh->setName(inst); mesh->setParent(p); } else { std::map::const_iterator it = name_map.find(name); - if(it == name_map.end()) return; + if (it == name_map.end()) return; mesh = it->second; name_map.erase(name); - if(pivot != Vector()) { + if (pivot != Vector()) { mesh->transform(-pivot); } Transform t = @@ -430,7 +430,7 @@ static void parseMeshInfo(MeshModel* root, float curr_time) { mesh->setAnimation(anim); - if(id != 65535) id_map[id] = mesh; + if (id != 65535) id_map[id] = mesh; } static void parseKeyFramer(MeshModel* root) { @@ -438,25 +438,25 @@ static void parseKeyFramer(MeshModel* root) { enterChunk(); std::string file_3ds; unsigned short rev, curr_time = 0; - while(int id = nextChunk()) { - switch(id) { - case 0xb009: //CURR_TIME - in.sgetn((char*)&curr_time, 2); - _log("CURR_TIME: " + itoa(curr_time)); - break; - case 0xb00a: //KFHDR - in.sgetn((char*)&rev, 2); - file_3ds = parseString(); - in.sgetn((char*)&anim_len, 2); - _log("KFHDR: revision=" + itoa(rev) + " 3dsfile=" + file_3ds + " anim_len=" + itoa(anim_len)); - break; - case 0xb002: //object keyframer data... - parseMeshInfo(root, curr_time); - break; + while (int id = nextChunk()) { + switch (id) { + case 0xb009: //CURR_TIME + in.sgetn((char*)&curr_time, 2); + _log("CURR_TIME: " + itoa(curr_time)); + break; + case 0xb00a: //KFHDR + in.sgetn((char*)&rev, 2); + file_3ds = parseString(); + in.sgetn((char*)&anim_len, 2); + _log("KFHDR: revision=" + itoa(rev) + " 3dsfile=" + file_3ds + " anim_len=" + itoa(anim_len)); + break; + case 0xb002: //object keyframer data... + parseMeshInfo(root, curr_time); + break; } } - if(!collapse) { + if (!collapse) { root->setAnimator(new Animator(root, anim_len)); } @@ -467,19 +467,19 @@ static MeshModel* parseFile() { unsigned short id; int len; in.sgetn((char*)&id, 2); in.sgetn((char*)&len, 4); - if(id != CHUNK_MAIN) return 0; + if (id != CHUNK_MAIN) return 0; chunk_end = (int)in.pubseekoff(0, std::ios_base::cur) + len - 6; enterChunk(); MeshModel* root = new MeshModel(); - while(int id = nextChunk()) { - switch(id) { - case CHUNK_SCENE: - parseScene(root); - break; - case CHUNK_KEYFRAMER: - parseKeyFramer(root); - break; + while (int id = nextChunk()) { + switch (id) { + case CHUNK_SCENE: + parseScene(root); + break; + case CHUNK_KEYFRAMER: + parseKeyFramer(root); + break; } } leaveChunk(); @@ -490,15 +490,15 @@ MeshModel* Loader_3DS::load(const std::string& filename, const Transform& t, int conv_tform = t; conv = flip_tris = false; - if(conv_tform != Transform()) { + if (conv_tform != Transform()) { conv = true; - if(conv_tform.m.i.cross(conv_tform.m.j).dot(conv_tform.m.k) < 0) flip_tris = true; + if (conv_tform.m.i.cross(conv_tform.m.j).dot(conv_tform.m.k) < 0) flip_tris = true; } collapse = !!(hint & MeshLoader::HINT_COLLAPSE); animonly = !!(hint & MeshLoader::HINT_ANIMONLY); - if(!in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary)) { + if (!in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary)) { return 0; } diff --git a/blitz3d/loader_b3d.cpp b/blitz3d/loader_b3d.cpp index ea574f74..fe21cedb 100644 --- a/blitz3d/loader_b3d.cpp +++ b/blitz3d/loader_b3d.cpp @@ -27,7 +27,7 @@ static void clear() { static int readChunk() { int header[2]; - if(fread(header, 8, 1, in) < 1) return 0; + if (fread(header, 8, 1, in) < 1) return 0; chunk_stack.push_back(ftell(in) + header[1]); return swap_endian(header[0]); } @@ -70,25 +70,25 @@ static void readFloatArray(float t[], int n) { } static void readColor(unsigned* t) { - float r = readFloat(); if(r < 0) r = 0; else if(r > 1) r = 1; - float g = readFloat(); if(g < 0) g = 0; else if(g > 1) g = 1; - float b = readFloat(); if(b < 0) b = 0; else if(b > 1) b = 1; - float a = readFloat(); if(a < 0) a = 0; else if(a > 1) a = 1; + float r = readFloat(); if (r < 0) r = 0; else if (r > 1) r = 1; + float g = readFloat(); if (g < 0) g = 0; else if (g > 1) g = 1; + float b = readFloat(); if (b < 0) b = 0; else if (b > 1) b = 1; + float a = readFloat(); if (a < 0) a = 0; else if (a > 1) a = 1; *t = (int(a * 255) << 24) | (int(r * 255) << 16) | (int(g * 255) << 8) | int(b * 255); } static std::string readString() { std::string t; - for(;;) { + for (;;) { char c; read(&c, 1); - if(!c) return t; + if (!c) return t; t += c; } } static void readTextures() { - while(chunkSize()) { + while (chunkSize()) { std::string name = readString(); int flags = readInt(); int blend = readInt(); @@ -101,11 +101,11 @@ static void readTextures() { Texture tex(name, flags & 0xffff); tex.setBlend(blend); - if(flags & 0x10000) tex.setFlags(gxScene::TEX_COORDS2); + if (flags & 0x10000) tex.setFlags(gxScene::TEX_COORDS2); - if(pos[0] != 0 || pos[1] != 0) tex.setPosition(pos[0], pos[1]); - if(scl[0] != 1 || scl[1] != 1) tex.setScale(scl[0], scl[1]); - if(rot != 0) tex.setRotation(rot); + if (pos[0] != 0 || pos[1] != 0) tex.setPosition(pos[0], pos[1]); + if (scl[0] != 1 || scl[1] != 1) tex.setScale(scl[0], scl[1]); + if (rot != 0) tex.setRotation(rot); textures.push_back(tex); } @@ -116,7 +116,7 @@ static void readBrushes() { int tex_id[8] = { -1,-1,-1,-1,-1,-1,-1,-1 }; - while(chunkSize()) { + while (chunkSize()) { std::string name = readString(); float col[4]; readFloatArray(col, 4); @@ -133,8 +133,8 @@ static void readBrushes() { bru.setBlend(blend); bru.setFX(fx); - for(int k = 0; k < 8; ++k) { - if(tex_id[k] < 0) continue; + for (int k = 0; k < 8; ++k) { + if (tex_id[k] < 0) continue; bru.setTexture(k, textures[tex_id[k]], 0); } @@ -151,17 +151,17 @@ static int readVertices() { float tc[4] = { 0 }; Surface::Vertex t; - while(chunkSize()) { + while (chunkSize()) { readFloatArray(t.coords, 3); - if(flags & 1) { + if (flags & 1) { readFloatArray(t.normal, 3); } - if(flags & 2) { + if (flags & 2) { readColor(&t.color); } - for(int k = 0; k < tc_sets; ++k) { + for (int k = 0; k < tc_sets; ++k) { readFloatArray(tc, tc_size); - if(k < 2) memcpy(t.tex_coords[k], tc, 8); + if (k < 2) memcpy(t.tex_coords[k], tc, 8); } MeshLoader::addVertex(t); } @@ -172,7 +172,7 @@ static int readVertices() { static void readTriangles() { int brush_id = readInt(); Brush b = brush_id >= 0 ? brushes[brush_id] : Brush(); - while(chunkSize()) { + while (chunkSize()) { int verts[3]; readIntArray(verts, 3); MeshLoader::addTriangle(verts, b); @@ -181,14 +181,14 @@ static void readTriangles() { static int readMesh() { int flags = 0; - while(chunkSize()) { - switch(readChunk()) { - case 'VRTS': - flags = readVertices(); - break; - case 'TRIS': - readTriangles(); - break; + while (chunkSize()) { + switch (readChunk()) { + case 'VRTS': + flags = readVertices(); + break; + case 'TRIS': + readTriangles(); + break; } exitChunk(); } @@ -213,7 +213,7 @@ static Object* readBone() { bones.push_back(bone); - while(chunkSize()) { + while (chunkSize()) { int vert = readInt(); float weight = readFloat(); MeshLoader::addBone(vert, weight, bones.size()); @@ -223,19 +223,19 @@ static Object* readBone() { static void readKeys(Animation& anim) { int flags = readInt(); - while(chunkSize()) { + while (chunkSize()) { int frame = readInt(); - if(flags & 1) { + if (flags & 1) { float pos[3]; readFloatArray(pos, 3); anim.setPositionKey(frame, Vector(pos[0], pos[1], pos[2])); } - if(flags & 2) { + if (flags & 2) { float scl[3]; readFloatArray(scl, 3); anim.setScaleKey(frame, Vector(scl[0], scl[1], scl[2])); } - if(flags & 4) { + if (flags & 4) { float rot[4]; readFloatArray(rot, 4); anim.setRotationKey(frame, Quat(rot[0], Vector(rot[1], rot[2], rot[3]))); @@ -258,35 +258,35 @@ static Object* readObject(Object* parent) { MeshModel* mesh = 0; int mesh_flags, mesh_brush; - while(chunkSize()) { - switch(readChunk()) { - case 'MESH': - MeshLoader::beginMesh(); - obj = mesh = new MeshModel(); - mesh_brush = readInt(); - mesh_flags = readMesh(); - break; - case 'PIVO': //Fix for modern fragMOTION versions. - case 'BONE': - obj = readBone(); - break; - case 'KEYS': - readKeys(keys); - break; - case 'ANIM': - readInt(); - anim_len = readInt(); - readFloat(); - break; - case 'NODE': - if(!obj) obj = new MeshModel(); - readObject(obj); - break; + while (chunkSize()) { + switch (readChunk()) { + case 'MESH': + MeshLoader::beginMesh(); + obj = mesh = new MeshModel(); + mesh_brush = readInt(); + mesh_flags = readMesh(); + break; + case 'PIVO': //Fix for modern fragMOTION versions. + case 'BONE': + obj = readBone(); + break; + case 'KEYS': + readKeys(keys); + break; + case 'ANIM': + readInt(); + anim_len = readInt(); + readFloat(); + break; + case 'NODE': + if (!obj) obj = new MeshModel(); + readObject(obj); + break; } exitChunk(); } - if(!obj) obj = new MeshModel(); + if (!obj) obj = new MeshModel(); obj->setName(name); obj->setLocalPosition(Vector(pos[0], pos[1], pos[2])); @@ -294,23 +294,23 @@ static Object* readObject(Object* parent) { obj->setLocalRotation(Quat(rot[0], Vector(rot[1], rot[2], rot[3]))); obj->setAnimation(keys); - if(mesh) { + if (mesh) { MeshLoader::endMesh(mesh); - if(!(mesh_flags & 1)) mesh->updateNormals(); - if(mesh_brush != -1) mesh->setBrush(brushes[mesh_brush]); + if (!(mesh_flags & 1)) mesh->updateNormals(); + if (mesh_brush != -1) mesh->setBrush(brushes[mesh_brush]); } - if(mesh && bones.size()) { + if (mesh && bones.size()) { bones.insert(bones.begin(), mesh); mesh->setAnimator(new Animator(bones, anim_len)); mesh->createBones(); bones.clear(); } - else if(anim_len) { + else if (anim_len) { obj->setAnimator(new Animator(obj, anim_len)); } - if(parent) obj->setParent(parent); + if (parent) obj->setParent(parent); return obj; } @@ -321,34 +321,34 @@ MeshModel* Loader_B3D::load(const std::string& f, const Transform& conv, int hin animonly = !!(hint & MeshLoader::HINT_ANIMONLY); in = fopen(f.c_str(), "rb"); - if(!in) return 0; + if (!in) return 0; ::clear(); int tag = readChunk(); - if(tag != 'BB3D') { + if (tag != 'BB3D') { fclose(in); return 0; } int version = readInt(); - if(version > 1) { + if (version > 1) { fclose(in); return 0; } Object* obj = 0; - while(chunkSize()) { - switch(readChunk()) { - case 'TEXS': - readTextures(); - break; - case 'BRUS': - readBrushes(); - break; - case 'NODE': - obj = readObject(0); - break; + while (chunkSize()) { + switch (readChunk()) { + case 'TEXS': + readTextures(); + break; + case 'BRUS': + readBrushes(); + break; + case 'NODE': + obj = readObject(0); + break; } exitChunk(); } diff --git a/blitz3d/loader_x.cpp b/blitz3d/loader_x.cpp index 5c6af2da..8b3315db 100644 --- a/blitz3d/loader_x.cpp +++ b/blitz3d/loader_x.cpp @@ -19,47 +19,47 @@ static bool collapse, animonly; static void parseAnimKey(IDirectXFileData* fileData, MeshModel* e) { DWORD sz; int* data; - if(fileData->GetData(0, &sz, (void**)&data) < 0) return; + if (fileData->GetData(0, &sz, (void**)&data) < 0) return; int type = *data++; int cnt = *data++; Animation anim = e->getAnimation(); - for(int k = 0; k < cnt; ++k) { + for (int k = 0; k < cnt; ++k) { int time = *data++; int n = *data++; - if(time > anim_len) anim_len = time; - switch(type) { - case 0: - if(n == 4) { - Quat rot = *(Quat*)data; - if(conv) { - if(fabs(rot.w) < 1 - EPSILON) { - rot.normalize(); - //quat-to-axis/angle - float half = acosf(rot.w); - if(flip_tris) half = -half; - rot = Quat(cosf(half), (conv_tform.m * rot.v).normalized() * sinf(half)); - } - else rot = Quat(); + if (time > anim_len) anim_len = time; + switch (type) { + case 0: + if (n == 4) { + Quat rot = *(Quat*)data; + if (conv) { + if (fabs(rot.w) < 1 - EPSILON) { + rot.normalize(); + //quat-to-axis/angle + float half = acosf(rot.w); + if (flip_tris) half = -half; + rot = Quat(cosf(half), (conv_tform.m * rot.v).normalized() * sinf(half)); } - anim.setRotationKey(time, rot); - } - break; - case 1: - if(n == 3) { - Vector scl = *(Vector*)data; - if(conv) scl = conv_tform.m * scl; - scl.x = fabs(scl.x); scl.y = fabs(scl.y); scl.z = fabs(scl.z); - anim.setScaleKey(time, scl); - } - break; - case 2: - if(n == 3) { - Vector pos = *(Vector*)data; - if(conv) pos = conv_tform * pos; - anim.setPositionKey(time, pos); + else rot = Quat(); } - break; + anim.setRotationKey(time, rot); + } + break; + case 1: + if (n == 3) { + Vector scl = *(Vector*)data; + if (conv) scl = conv_tform.m * scl; + scl.x = fabs(scl.x); scl.y = fabs(scl.y); scl.z = fabs(scl.z); + anim.setScaleKey(time, scl); + } + break; + case 2: + if (n == 3) { + Vector pos = *(Vector*)data; + if (conv) pos = conv_tform * pos; + anim.setPositionKey(time, pos); + } + break; } data += n; } @@ -74,15 +74,15 @@ static void parseAnim(IDirectXFileData* fileData) { MeshModel* frame = 0; //find the frame reference - for(; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { - if(childObj->QueryInterface(IID_IDirectXFileDataReference, (void**)&childRef) >= 0) { - if(childRef->Resolve(&childData) >= 0) { - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMFrame) { + for (; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { + if (childObj->QueryInterface(IID_IDirectXFileDataReference, (void**)&childRef) >= 0) { + if (childRef->Resolve(&childData) >= 0) { + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMFrame) { char name[80]; DWORD len = 80; - if(childData->GetName(name, &len) >= 0) { + if (childData->GetName(name, &len) >= 0) { std::map::iterator it = frames_map.find(name); - if(it != frames_map.end()) frame = it->second; + if (it != frames_map.end()) frame = it->second; } } } @@ -90,9 +90,9 @@ static void parseAnim(IDirectXFileData* fileData) { } childRef->Release(); } - else if(frame && childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) >= 0) { - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMAnimationKey) { + else if (frame && childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) >= 0) { + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMAnimationKey) { parseAnimKey(childData, frame); } } @@ -106,10 +106,10 @@ static void parseAnimSet(IDirectXFileData* fileData) { IDirectXFileObject* childObj; IDirectXFileData* childData; - for(; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { - if(childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMAnimation) { + for (; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { + if (childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMAnimation) { parseAnim(childData); } } @@ -125,17 +125,17 @@ static Brush parseMaterial(IDirectXFileData* fileData) { Brush brush; DWORD sz; float* data; - if(fileData->GetData(0, &sz, (void**)&data) < 0) return brush; + if (fileData->GetData(0, &sz, (void**)&data) < 0) return brush; brush.setColor(Vector(data[0], data[1], data[2])); - if(data[3]) brush.setAlpha(data[3]); + if (data[3]) brush.setAlpha(data[3]); - for(; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { - if(childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMTextureFilename) { + for (; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { + if (childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMTextureFilename) { DWORD sz; char** data; - if(childData->GetData(0, &sz, (void**)&data) >= 0) { + if (childData->GetData(0, &sz, (void**)&data) >= 0) { brush.setTexture(0, Texture(*data, 0), 0); brush.setColor(Vector(1, 1, 1)); } @@ -155,19 +155,19 @@ static void parseMaterialList(IDirectXFileData* fileData, std::vector& ma IDirectXFileDataReference* childRef; //iterate through child objects... - for(; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { - if(childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) >= 0) { - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMMaterial) { + for (; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { + if (childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) >= 0) { + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMMaterial) { mats.push_back(parseMaterial(childData)); } } childData->Release(); } - else if(childObj->QueryInterface(IID_IDirectXFileDataReference, (void**)&childRef) >= 0) { - if(childRef->Resolve(&childData) >= 0) { - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMMaterial) { + else if (childObj->QueryInterface(IID_IDirectXFileDataReference, (void**)&childRef) >= 0) { + if (childRef->Resolve(&childData) >= 0) { + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMMaterial) { mats.push_back(parseMaterial(childData)); } } @@ -190,7 +190,7 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { IDirectXFileData* childData; DWORD sz; int* data; - if(fileData->GetData(0, &sz, (void**)&data) < 0) return; + if (fileData->GetData(0, &sz, (void**)&data) < 0) return; //stuff... std::vector faces; @@ -201,10 +201,10 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { //setup vertices int num_verts = *data++; int k; - for(k = 0; k < num_verts; ++k) { + for (k = 0; k < num_verts; ++k) { Surface::Vertex v; v.coords = *(Vector*)data; - if(conv) v.coords = conv_tform * v.coords; + if (conv) v.coords = conv_tform * v.coords; v.color = 0xffffffff;//Vector(1,1,1); MeshLoader::addVertex(v); data += 3; @@ -212,7 +212,7 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { //setup faces int num_faces = *data++; - for(k = 0; k < num_faces; ++k) { + for (k = 0; k < num_faces; ++k) { faces.push_back(FaceX(data)); data += *data + 1; } @@ -220,24 +220,24 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { bool normals = false; //get material and texture info - for(; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { - if(childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; - if(childData->GetType(&guid) >= 0) { + for (; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { + if (childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; + if (childData->GetType(&guid) >= 0) { DWORD sz; int* data; - if(childData->GetData(0, &sz, (void**)&data) >= 0) { - if(*guid == TID_D3DRMMeshMaterialList) { + if (childData->GetData(0, &sz, (void**)&data) >= 0) { + if (*guid == TID_D3DRMMeshMaterialList) { int num_mats = *data++; int num_faces = *data++; - for(int k = 0; k < num_faces; ++k) { + for (int k = 0; k < num_faces; ++k) { faces[k].mat_index = *data++; } parseMaterialList(childData, mats); } - else if(*guid == TID_D3DRMMeshTextureCoords) { + else if (*guid == TID_D3DRMMeshTextureCoords) { int num_coords = *data++; - if(num_coords == num_verts) { + if (num_coords == num_verts) { float* coords = (float*)data; - for(int k = 0; k < num_coords; ++k) { + for (int k = 0; k < num_coords; ++k) { Surface::Vertex& v = MeshLoader::refVertex(k); float tu = *coords++; float tv = *coords++; v.tex_coords[0][0] = v.tex_coords[1][0] = tu; @@ -245,10 +245,10 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { } } } - else if(*guid == TID_D3DRMMeshVertexColors) { + else if (*guid == TID_D3DRMMeshVertexColors) { int num_colors = *data++; - if(num_colors == num_verts) { - for(int k = 0; k < num_colors; ++k) { + if (num_colors == num_verts) { + for (int k = 0; k < num_colors; ++k) { Surface::Vertex& v = MeshLoader::refVertex(*data++); float* t = (float*)data; v.color = 0xff000000 | (int(t[0] * 255) << 16) | (int(t[1] * 255) << 8) | int(t[2] * 255); @@ -256,11 +256,11 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { } } } - else if(*guid == TID_D3DRMMeshNormals) { + else if (*guid == TID_D3DRMMeshNormals) { int num_normals = *data++; - if(num_normals == num_verts) { + if (num_normals == num_verts) { Matrix co = conv_tform.m.cofactor(); - for(int k = 0; k < num_normals; ++k) { + for (int k = 0; k < num_normals; ++k) { Surface::Vertex& v = MeshLoader::refVertex(k); v.normal = (co * *(Vector*)data).normalized(); data += 3; @@ -272,15 +272,15 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { } childData->Release(); } - if(!mats.size()) mats.push_back(Brush()); + if (!mats.size()) mats.push_back(Brush()); - for(k = 0; k < faces.size(); ++k) { + for (k = 0; k < faces.size(); ++k) { const FaceX& f = faces[k]; int* data = f.data; - int cnt = *data++; if(cnt < 3) continue; + int cnt = *data++; if (cnt < 3) continue; int tri[3]; tri[0] = data[0]; - for(int j = 2; j < cnt; ++j) { + for (int j = 2; j < cnt; ++j) { tri[1] = data[j - 1 + flip_tris]; tri[2] = data[j - flip_tris]; MeshLoader::addTriangle(tri, mats[f.mat_index]); @@ -289,7 +289,7 @@ static void parseMesh(IDirectXFileData* fileData, MeshModel* mesh) { MeshLoader::endMesh(mesh); - if(!normals) mesh->updateNormals(); + if (!normals) mesh->updateNormals(); } static MeshModel* parseFrame(IDirectXFileData* fileData) { @@ -301,31 +301,31 @@ static MeshModel* parseFrame(IDirectXFileData* fileData) { IDirectXFileData* childData; char name[80]; DWORD len = 80; - if(fileData->GetName(name, &len) < 0) return e; + if (fileData->GetName(name, &len) < 0) return e; e->setName(name); frames_map[name] = e; //iterate through child objects... - for(; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { - if(childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; - if(childData->GetType(&guid) >= 0) { - if(*guid == TID_D3DRMFrameTransformMatrix) { + for (; fileData->GetNextObject(&childObj) >= 0; childObj->Release()) { + if (childObj->QueryInterface(IID_IDirectXFileData, (void**)&childData) < 0) continue; + if (childData->GetType(&guid) >= 0) { + if (*guid == TID_D3DRMFrameTransformMatrix) { DWORD size; D3DMATRIX* data; - if(childData->GetData(0, &size, (void**)&data) >= 0) { + if (childData->GetData(0, &size, (void**)&data) >= 0) { Transform tform = Transform(Matrix( Vector(data->_11, data->_12, data->_13), Vector(data->_21, data->_22, data->_23), Vector(data->_31, data->_32, data->_33)), Vector(data->_41, data->_42, data->_43)); - if(conv) tform = conv_tform * tform * -conv_tform; + if (conv) tform = conv_tform * tform * -conv_tform; e->setLocalTform(tform); } } - else if(*guid == TID_D3DRMMesh) { - if(!animonly) parseMesh(childData, e); + else if (*guid == TID_D3DRMMesh) { + if (!animonly) parseMesh(childData, e); } - else if(*guid == TID_D3DRMFrame) { + else if (*guid == TID_D3DRMFrame) { MeshModel* t = parseFrame(childData); t->setParent(e); } @@ -342,33 +342,33 @@ static MeshModel* parseFile(const std::string& file) { IDirectXFileData* fileData; IDirectXFileEnumObject* enumObj; - if(DirectXFileCreate(&xfile) < 0) return 0; + if (DirectXFileCreate(&xfile) < 0) return 0; - if(xfile->RegisterTemplates((VOID*)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES) < 0) { + if (xfile->RegisterTemplates((VOID*)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES) < 0) { xfile->Release(); return 0; } - if(xfile->CreateEnumObject((void*)file.c_str(), DXFILELOAD_FROMFILE, &enumObj) < 0) { + if (xfile->CreateEnumObject((void*)file.c_str(), DXFILELOAD_FROMFILE, &enumObj) < 0) { xfile->Release(); return 0; } anim_len = 0; MeshModel* e = new MeshModel(); - for(; enumObj->GetNextDataObject(&fileData) >= 0; fileData->Release()) { - if(fileData->GetType(&guid) < 0) continue; + for (; enumObj->GetNextDataObject(&fileData) >= 0; fileData->Release()) { + if (fileData->GetType(&guid) < 0) continue; - if(*guid == TID_D3DRMMesh) { - if(!animonly) parseMesh(fileData, e); + if (*guid == TID_D3DRMMesh) { + if (!animonly) parseMesh(fileData, e); } - else if(*guid == TID_D3DRMFrame) { + else if (*guid == TID_D3DRMFrame) { MeshModel* t = parseFrame(fileData); t->setParent(e); } - else if(*guid == TID_D3DRMAnimationSet) { - if(!collapse) parseAnimSet(fileData); + else if (*guid == TID_D3DRMAnimationSet) { + if (!collapse) parseAnimSet(fileData); } } - if(!collapse) { + if (!collapse) { e->setAnimator(new Animator(e, anim_len)); } @@ -380,9 +380,9 @@ static MeshModel* parseFile(const std::string& file) { MeshModel* Loader_X::load(const std::string& filename, const Transform& t, int hint) { conv_tform = t; conv = flip_tris = false; - if(conv_tform != Transform()) { + if (conv_tform != Transform()) { conv = true; - if(conv_tform.m.i.cross(conv_tform.m.j).dot(conv_tform.m.k) < 0) flip_tris = true; + if (conv_tform.m.i.cross(conv_tform.m.j).dot(conv_tform.m.k) < 0) flip_tris = true; } collapse = !!(hint & MeshLoader::HINT_COLLAPSE); animonly = !!(hint & MeshLoader::HINT_ANIMONLY); diff --git a/blitz3d/md2model.cpp b/blitz3d/md2model.cpp index 8428582f..64a15123 100644 --- a/blitz3d/md2model.cpp +++ b/blitz3d/md2model.cpp @@ -24,24 +24,24 @@ MD2Model::MD2Model(const MD2Model& t) : } MD2Model::~MD2Model() { - if(!--rep->ref_cnt) delete rep; - if(trans_verts) delete[] trans_verts; + if (!--rep->ref_cnt) delete rep; + if (trans_verts) delete[] trans_verts; } void MD2Model::startMD2Anim(int first, int last, int mode, float speed, float trans) { - if(last < first) std::swap(first, last); + if (last < first) std::swap(first, last); - if(first < 0) first = 0; - else if(first >= rep->numFrames()) first = rep->numFrames() - 1; + if (first < 0) first = 0; + else if (first >= rep->numFrames()) first = rep->numFrames() - 1; - if(last < 0) last = 0; - else if(last >= rep->numFrames()) last = rep->numFrames() - 1; + if (last < 0) last = 0; + else if (last >= rep->numFrames()) last = rep->numFrames() - 1; - if(trans > 0) { - if(!trans_verts) trans_verts = new MD2Rep::Vert[rep->numVertices()]; + if (trans > 0) { + if (!trans_verts) trans_verts = new MD2Rep::Vert[rep->numVertices()]; - if(anim_mode & 0x8000) rep->render(trans_verts, anim_time, trans_time); + if (anim_mode & 0x8000) rep->render(trans_verts, anim_time, trans_time); else rep->render(trans_verts, render_a, render_b, render_t); trans_speed = 1.0f / trans; trans_time = 0; @@ -55,7 +55,7 @@ void MD2Model::startMD2Anim(int first, int last, int mode, float speed, float tr anim_time = ((mode & 0x7fff) == Animator::ANIM_MODE_LOOP || anim_speed >= 0) ? anim_first : anim_last; anim_mode = mode; - if(!anim_speed || !anim_len) { + if (!anim_speed || !anim_len) { render_a = render_b = anim_time; render_t = 0; anim_mode &= 0x8000; @@ -64,55 +64,55 @@ void MD2Model::startMD2Anim(int first, int last, int mode, float speed, float tr void MD2Model::animate(float e) { Model::animate(e); - if(!anim_mode) return; - if(anim_mode & 0x8000) { + if (!anim_mode) return; + if (anim_mode & 0x8000) { trans_time += trans_speed; - if(trans_time < 1) return; + if (trans_time < 1) return; anim_mode &= ~0x8000; - if(!anim_mode) return; + if (!anim_mode) return; } anim_time = anim_time + anim_speed * e; - if(anim_time < anim_first) { - switch(anim_mode) { - case Animator::ANIM_MODE_LOOP: - anim_time += anim_len; - break; - case Animator::ANIM_MODE_PINGPONG: - anim_time = anim_first + (anim_first - anim_time); - anim_speed = -anim_speed; - break; - default: - anim_time = anim_first; - anim_mode = 0; - break; + if (anim_time < anim_first) { + switch (anim_mode) { + case Animator::ANIM_MODE_LOOP: + anim_time += anim_len; + break; + case Animator::ANIM_MODE_PINGPONG: + anim_time = anim_first + (anim_first - anim_time); + anim_speed = -anim_speed; + break; + default: + anim_time = anim_first; + anim_mode = 0; + break; } } - else if(anim_time >= anim_last) { - switch(anim_mode) { - case Animator::ANIM_MODE_LOOP: - anim_time -= anim_len; - break; - case Animator::ANIM_MODE_PINGPONG: - anim_time = anim_last - (anim_time - anim_last); - anim_speed = -anim_speed; - break; - default: - anim_time = anim_last; - anim_mode = 0; - break; + else if (anim_time >= anim_last) { + switch (anim_mode) { + case Animator::ANIM_MODE_LOOP: + anim_time -= anim_len; + break; + case Animator::ANIM_MODE_PINGPONG: + anim_time = anim_last - (anim_time - anim_last); + anim_speed = -anim_speed; + break; + default: + anim_time = anim_last; + anim_mode = 0; + break; } } render_a = floor(anim_time); render_b = render_a + 1; - if(anim_mode == Animator::ANIM_MODE_LOOP && render_b == anim_last) render_b = anim_first; + if (anim_mode == Animator::ANIM_MODE_LOOP && render_b == anim_last) render_b = anim_first; render_t = anim_time - render_a; } bool MD2Model::render(const RenderContext& rc) { static Frustum f; new(&f) Frustum(rc.getWorldFrustum(), -getRenderTform()); - if(!f.cull(rep->getBox())) return false; + if (!f.cull(rep->getBox())) return false; - if(anim_mode & 0x8000) { + if (anim_mode & 0x8000) { rep->render(this, trans_verts, anim_time, trans_time); } else { diff --git a/blitz3d/md2rep.cpp b/blitz3d/md2rep.cpp index dd64b205..9e1bdbf6 100644 --- a/blitz3d/md2rep.cpp +++ b/blitz3d/md2rep.cpp @@ -61,9 +61,9 @@ MD2Rep::MD2Rep(const std::string& f) : std::filebuf in; md2_header header; - if(!in.open(f.c_str(), std::ios_base::in | std::ios_base::binary)) return; - if(in.sgetn((char*)&header, sizeof(header)) != sizeof(header)) return; - if(header.magic != '2PDI' || header.version != 8) return; + if (!in.open(f.c_str(), std::ios_base::in | std::ios_base::binary)) return; + if (in.sgetn((char*)&header, sizeof(header)) != sizeof(header)) return; + if (header.magic != '2PDI' || header.version != 8) return; n_frames = header.numFrames; n_tris = header.numTriangles; @@ -85,14 +85,14 @@ MD2Rep::MD2Rep(const std::string& f) : std::map t_map; int k; - for(k = 0; k < n_tris; ++k) { + for (k = 0; k < n_tris; ++k) { t_tri tr; - for(int j = 0; j < 3; ++j) { + for (int j = 0; j < 3; ++j) { t_vert t; t.i = md2_tris[k].verts[j]; t.uv = md2_tris[k].uvs[j]; std::map::iterator it = t_map.find(t); - if(it == t_map.end()) { + if (it == t_map.end()) { //create new vert tr.verts[j] = t_map[t] = t_verts.size(); t_verts.push_back(t); @@ -118,7 +118,7 @@ MD2Rep::MD2Rep(const std::string& f) : md2_verts.resize(header.numVertices); //read in frames - for(k = 0; k < n_frames; ++k) { + for (k = 0; k < n_frames; ++k) { char t_buff[16]; Frame* fr = &frames[k]; in.sgetn((char*)&fr->scale, 12); @@ -132,7 +132,7 @@ MD2Rep::MD2Rep(const std::string& f) : in.sgetn((char*)md2_verts.data(), header.numVertices * sizeof(md2_vert)); fr->verts.resize(n_verts); - for(int j = 0; j < n_verts; ++j) { + for (int j = 0; j < n_verts; ++j) { Vertex* v = &fr->verts[j]; const t_vert& tv = t_verts[j]; const md2_vert& mv = md2_verts[tv.i]; @@ -147,23 +147,23 @@ MD2Rep::MD2Rep(const std::string& f) : //create mesh and setup tris mesh = gx_graphics->createMesh(n_verts, n_tris, 0); mesh->lock(true); - for(k = 0; k < n_tris; ++k) { + for (k = 0; k < n_tris; ++k) { const t_tri& t = t_tris[k]; mesh->setTriangle(k, t.verts[0], t.verts[2], t.verts[1]); } mesh->unlock(); //build normals - if(!normals) { + if (!normals) { normals = (Vector*)md2norms; - for(int k = 0; k < sizeof(md2norms) / 12; ++k) { + for (int k = 0; k < sizeof(md2norms) / 12; ++k) { normals[k] = Vector(normals[k].y, normals[k].z, normals[k].x); } } } MD2Rep::~MD2Rep() { - if(mesh) gx_graphics->freeMesh(mesh); + if (mesh) gx_graphics->freeMesh(mesh); } void MD2Rep::render(Vert* v, int frame, float time) { @@ -172,7 +172,7 @@ void MD2Rep::render(Vert* v, int frame, float time) { const Vertex* v_b = frame_b.verts.data(); const Vector scale_b = frame_b.scale, trans_b = frame_b.trans; - for(int k = 0; k < n_verts; ++v, ++v_b, ++k) { + for (int k = 0; k < n_verts; ++v, ++v_b, ++k) { const Vector t_b(v_b->x * scale_b.x + trans_b.x, v_b->y * scale_b.y + trans_b.y, v_b->z * scale_b.z + trans_b.z); const Vector& n_b = normals[v_b->n]; @@ -192,7 +192,7 @@ void MD2Rep::render(Vert* v, int render_a, int render_b, float render_t) { const Vertex* v_a = frame_a.verts.data(); const Vertex* v_b = frame_b.verts.data(); - for(int k = 0; k < n_verts; ++v, ++v_a, ++v_b, ++k) { + for (int k = 0; k < n_verts; ++v, ++v_a, ++v_b, ++k) { const Vector t_a(v_a->x * scale_a.x + trans_a.x, v_a->y * scale_a.y + trans_a.y, v_a->z * scale_a.z + trans_a.z); const Vector t_b(v_b->x * scale_b.x + trans_b.x, v_b->y * scale_b.y + trans_b.y, v_b->z * scale_b.z + trans_b.z); @@ -216,7 +216,7 @@ void MD2Rep::render(Model* model, int render_a, int render_b, float render_t) { const Vertex* v_b = frame_b.verts.data(); mesh->lock(true); - for(int k = 0; k < n_verts; ++uv, ++v_a, ++v_b, ++k) { + for (int k = 0; k < n_verts; ++uv, ++v_a, ++v_b, ++k) { const Vector t_a(v_a->x * scale_a.x + trans_a.x, v_a->y * scale_a.y + trans_a.y, v_a->z * scale_a.z + trans_a.z); const Vector t_b(v_b->x * scale_b.x + trans_b.x, v_b->y * scale_b.y + trans_b.y, v_b->z * scale_b.z + trans_b.z); @@ -245,7 +245,7 @@ void MD2Rep::render(Model* model, const Vert* v_a, int render_b, float render_t) const Vertex* v_b = frame_b.verts.data(); mesh->lock(true); - for(int k = 0; k < n_verts; ++uv, ++v_a, ++v_b, ++k) { + for (int k = 0; k < n_verts; ++uv, ++v_a, ++v_b, ++k) { const Vector t_b(v_b->x * scale_b.x + trans_b.x, v_b->y * scale_b.y + trans_b.y, v_b->z * scale_b.z + trans_b.z); const Vector t((t_b - v_a->coords) * render_t + v_a->coords); diff --git a/blitz3d/meshcollider.cpp b/blitz3d/meshcollider.cpp index 1ff9b7eb..28483ac7 100644 --- a/blitz3d/meshcollider.cpp +++ b/blitz3d/meshcollider.cpp @@ -11,17 +11,17 @@ extern gxRuntime* gx_runtime; static bool triTest(const Vector a[3], const Vector b[3]) { bool pb0 = false, pb1 = false, pb2 = false; Plane p(a[0], a[1], a[2]), p0, p1, p2; - for(int k = 0; k < 3; ++k) { + for (int k = 0; k < 3; ++k) { Line l(b[k], b[(k + 1) % 3] - b[k]); float t = p.t_intersect(l); - if(t < 0 || t>1) continue; + if (t < 0 || t>1) continue; Vector i = l * t; - if(!pb0) { p0 = Plane(a[0] + p.n, a[1], a[0]); pb0 = true; } - if(p0.distance(i) < 0) continue; - if(!pb1) { p1 = Plane(a[1] + p.n, a[2], a[1]); pb1 = true; } - if(p1.distance(i) < 0) continue; - if(!pb2) { p2 = Plane(a[2] + p.n, a[0], a[2]); pb2 = true; } - if(p2.distance(i) < 0) continue; + if (!pb0) { p0 = Plane(a[0] + p.n, a[1], a[0]); pb0 = true; } + if (p0.distance(i) < 0) continue; + if (!pb1) { p1 = Plane(a[1] + p.n, a[2], a[1]); pb1 = true; } + if (p1.distance(i) < 0) continue; + if (!pb2) { p2 = Plane(a[2] + p.n, a[0], a[2]); pb2 = true; } + if (p2.distance(i) < 0) continue; return true; } return false; @@ -35,7 +35,7 @@ MeshCollider::MeshCollider(const std::vector& verts, const std::vector ts; tri_centres.clear(); - for(int k = 0; k < triangles.size(); ++k) { + for (int k = 0; k < triangles.size(); ++k) { const MeshCollider::Triangle& t = triangles[k]; const Vector& v0 = vertices[t.verts[0]].coords; const Vector& v1 = vertices[t.verts[1]].coords; @@ -52,7 +52,7 @@ MeshCollider::~MeshCollider() { bool MeshCollider::collide(const Line& line, float radius, Collision* curr_coll, const Transform& t) { - if(!tree) return false; + if (!tree) return false; //create local box Box box(line); @@ -63,20 +63,20 @@ bool MeshCollider::collide(const Line& line, float radius, Collision* curr_coll, } bool MeshCollider::collide(const Box& line_box, const Line& line, float radius, const Transform& tform, Collision* curr_coll, MeshCollider::Node* node) { - if(!line_box.overlaps(node->box)) { + if (!line_box.overlaps(node->box)) { return false; } bool hit = false; - if(!node->triangles.size()) { - if(node->left) hit |= collide(line_box, line, radius, tform, curr_coll, node->left); - if(node->right) hit |= collide(line_box, line, radius, tform, curr_coll, node->right); + if (!node->triangles.size()) { + if (node->left) hit |= collide(line_box, line, radius, tform, curr_coll, node->left); + if (node->right) hit |= collide(line_box, line, radius, tform, curr_coll, node->right); return hit; } stats3d[0] += node->triangles.size(); - for(int k = 0; k < node->triangles.size(); ++k) { + for (int k = 0; k < node->triangles.size(); ++k) { const Triangle& tri = triangles[node->triangles[k]]; const Vector& t_v0 = vertices[tri.verts[0]].coords; @@ -87,9 +87,9 @@ bool MeshCollider::collide(const Box& line_box, const Line& line, float radius, Box tri_box(t_v0); tri_box.update(t_v1); tri_box.update(t_v2); - if(!tri_box.overlaps(line_box)) continue; + if (!tri_box.overlaps(line_box)) continue; - if(!curr_coll->triangleCollide(line, radius, tform * t_v0, tform * t_v1, tform * t_v2)) continue; + if (!curr_coll->triangleCollide(line, radius, tform * t_v0, tform * t_v1, tform * t_v2)) continue; curr_coll->surface = tri.surface; curr_coll->index = tri.index; @@ -101,9 +101,9 @@ bool MeshCollider::collide(const Box& line_box, const Line& line, float radius, Box MeshCollider::nodeBox(const std::vector& tris) { Box box; - for(int k = 0; k < tris.size(); ++k) { + for (int k = 0; k < tris.size(); ++k) { const Triangle& t = triangles[tris[k]]; - for(int j = 0; j < 3; ++j) box.update(vertices[t.verts[j]].coords); + for (int j = 0; j < 3; ++j) box.update(vertices[t.verts[j]].coords); } return box; } @@ -119,7 +119,7 @@ MeshCollider::Node* MeshCollider::createLeaf(const std::vector& tris) { MeshCollider::Node* MeshCollider::createNode(const std::vector& tris) { - if(tris.size() <= MAX_COLL_TRIS) return createLeaf(tris); + if (tris.size() <= MAX_COLL_TRIS) return createLeaf(tris); Node* c = new Node; c->box = nodeBox(tris); @@ -127,17 +127,17 @@ MeshCollider::Node* MeshCollider::createNode(const std::vector& tris) { //find longest axis // float max = c->box.width(); - if(c->box.height() > max) max = c->box.height(); - if(c->box.depth() > max) max = c->box.depth(); + if (c->box.height() > max) max = c->box.height(); + if (c->box.depth() > max) max = c->box.depth(); int axis = 0; - if(max == c->box.height()) axis = 1; - else if(max == c->box.depth()) axis = 2; + if (max == c->box.height()) axis = 1; + else if (max == c->box.depth()) axis = 2; //sort by axis // int k; std::multimap axis_map; - for(k = 0; k < tris.size(); ++k) { + for (k = 0; k < tris.size(); ++k) { std::pair p(tri_centres[tris[k]][axis], tris[k]); axis_map.insert(p); } @@ -146,7 +146,7 @@ MeshCollider::Node* MeshCollider::createNode(const std::vector& tris) { // std::vector new_tris; std::multimap::iterator it = axis_map.begin(); - for(k = axis_map.size() / 2; k--; ++it) { + for (k = axis_map.size() / 2; k--; ++it) { new_tris.push_back(it->second); } c->left = createNode(new_tris); @@ -154,7 +154,7 @@ MeshCollider::Node* MeshCollider::createNode(const std::vector& tris) { //generate right node // new_tris.clear(); - for(; it != axis_map.end(); ++it) { + for (; it != axis_map.end(); ++it) { new_tris.push_back(it->second); } c->right = createNode(new_tris); @@ -166,16 +166,16 @@ bool MeshCollider::intersects(const MeshCollider& c, const Transform& t)const { static Vector a[MAX_COLL_TRIS][3], b[3]; - if(!(t * tree->box).overlaps(c.tree->box)) return false; - for(int k = 0; k < leaves.size(); ++k) { + if (!(t * tree->box).overlaps(c.tree->box)) return false; + for (int k = 0; k < leaves.size(); ++k) { Node* p = leaves[k]; Box box = t * p->box; bool tformed = false; - for(int j = 0; j < c.leaves.size(); ++j) { + for (int j = 0; j < c.leaves.size(); ++j) { Node* q = c.leaves[j]; - if(!box.overlaps(q->box)) continue; - if(!tformed) { - for(int n = 0; n < p->triangles.size(); ++n) { + if (!box.overlaps(q->box)) continue; + if (!tformed) { + for (int n = 0; n < p->triangles.size(); ++n) { const Triangle& tri = triangles[p->triangles[n]]; a[n][0] = t * vertices[tri.verts[0]].coords; a[n][1] = t * vertices[tri.verts[1]].coords; @@ -183,13 +183,13 @@ bool MeshCollider::intersects(const MeshCollider& c, const Transform& t)const { } tformed = true; } - for(int n = 0; n < q->triangles.size(); ++n) { + for (int n = 0; n < q->triangles.size(); ++n) { const Triangle& tri = c.triangles[q->triangles[n]]; b[0] = c.vertices[tri.verts[0]].coords; b[1] = c.vertices[tri.verts[1]].coords; b[2] = c.vertices[tri.verts[2]].coords; - for(int t = 0; t < p->triangles.size(); ++t) { - if(trisIntersect(a[t], b)) return true; + for (int t = 0; t < p->triangles.size(); ++t) { + if (trisIntersect(a[t], b)) return true; } } } diff --git a/compiler/exprnode.cpp b/compiler/exprnode.cpp index 04f4aabb..6aba49cd 100644 --- a/compiler/exprnode.cpp +++ b/compiler/exprnode.cpp @@ -684,7 +684,7 @@ ExprNode* AfterNode::semant(Environ* e) { TNode* AfterNode::translate(Codegen* g) { TNode* t = expr->translate(g); - if(g->debug) t = jumpf(t, "__bbNullObjEx"); + //if(g->debug) t = jumpf(t, "__bbNullObjEx"); return call("__bbObjNext", t); } @@ -701,7 +701,7 @@ ExprNode* BeforeNode::semant(Environ* e) { TNode* BeforeNode::translate(Codegen* g) { TNode* t = expr->translate(g); - if(g->debug) t = jumpf(t, "__bbNullObjEx"); + //if(g->debug) t = jumpf(t, "__bbNullObjEx"); return call("__bbObjPrev", t); } diff --git a/compiler/stmtnode.cpp b/compiler/stmtnode.cpp index 30dd2247..6297e90f 100644 --- a/compiler/stmtnode.cpp +++ b/compiler/stmtnode.cpp @@ -488,9 +488,9 @@ void InsertNode::semant(Environ* e) { void InsertNode::translate(Codegen* g) { TNode* t1 = expr1->translate(g); - if(g->debug) t1 = jumpf(t1, "__bbNullObjEx"); + //if(g->debug) t1 = jumpf(t1, "__bbNullObjEx"); TNode* t2 = expr2->translate(g); - if(g->debug) t2 = jumpf(t2, "__bbNullObjEx"); + //if(g->debug) t2 = jumpf(t2, "__bbNullObjEx"); std::string s = before ? "__bbObjInsBefore" : "__bbObjInsAfter"; g->code(call(s, t1, t2)); } diff --git a/compiler/varnode.cpp b/compiler/varnode.cpp index 79fb69e0..d6baf858 100644 --- a/compiler/varnode.cpp +++ b/compiler/varnode.cpp @@ -114,9 +114,9 @@ void FieldVarNode::semant(Environ* e) { TNode* FieldVarNode::translate(Codegen* g) { TNode* t = expr->translate(g); - if(g->debug) t = jumpf(t, "__bbNullObjEx"); - t = mem(t); if(g->debug) t = jumpf(t, "__bbNullObjEx"); - return add(t, iconst(sem_field->offset)); + t = call("__bbObjLoad", t); + t = call("__bbFieldPtrAdd", t, iconst(sem_field->offset)); + return t; } //////////////// diff --git a/config/config.h b/config/config.h index f12ce035..489174f9 100644 --- a/config/config.h +++ b/config/config.h @@ -1,9 +1,9 @@ #ifndef CONFIG_H #define CONFIG_H -#define BASE_VER 1129 +#define BASE_VER 1130 #define PRO_F 0x010000 #define VERSION (BASE_VER|PRO_F) -#define CHINESE_TRAD +//#define CHINESE_SIMP #endif \ No newline at end of file