static orxSTATUS orxFASTCALL Init() { #define orxFONTGEN_DECLARE_PARAM(SN, LN, SD, LD, FN) {orxPARAM_KU32_FLAG_STOP_ON_ERROR, SN, LN, SD, LD, &FN}, orxU32 i; orxSTATUS eResult = orxSTATUS_SUCCESS; orxPARAM astParamList[] = { orxFONTGEN_DECLARE_PARAM("o", "output", "Font output name", "Font base output name: .png will be added to the image and .ini will be added to the config file", ProcessOutputParams) orxFONTGEN_DECLARE_PARAM("s", "size", "Size (height) of characters", "Height to use for characters defined with this font", ProcessSizeParams) orxFONTGEN_DECLARE_PARAM("p", "padding", "Character padding", "Extra padding added to all characters on both dimensions (width and height)", ProcessPaddingParams) orxFONTGEN_DECLARE_PARAM("f", "font", "Input font file", "TrueType font (usually .ttf) used to generate all the required glyphs", ProcessFontParams) orxFONTGEN_DECLARE_PARAM("t", "textlist", "List of input text files", "List of text files containing all the characters that will be displayed using this font", ProcessInputParams) orxFONTGEN_DECLARE_PARAM("m", "monospace", "Monospaced font", "Will output a monospace (ie. fixed-width) font", ProcessMonospaceParams) orxFONTGEN_DECLARE_PARAM("a", "advance", "Use glyph advance values for non-monospace fonts", "In non-monospace mode only: the font's original glyph advance values will be used instead of packing glyphs as efficiently as possible", ProcessAdvanceParams) }; // Clears static controller orxMemory_Zero(&sstFontGen, sizeof(orxFONTGEN_STATIC)); // Creates character table sstFontGen.pstCharacterTable = orxHashTable_Create(orxFONTGEN_KU32_CHARACTER_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); // Creates glyph bank sstFontGen.pstGlyphBank = orxBank_Create(orxFONTGEN_KU32_CHARACTER_TABLE_SIZE, sizeof(orxFONTGEN_GLYPH), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); // For all params but last for(i = 0; (i < (sizeof(astParamList) / sizeof(astParamList[0])) - 1) && (eResult != orxSTATUS_FAILURE); i++) { // Registers param eResult = orxParam_Register(&astParamList[i]); } // Not in monospace mode? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_MONOSPACE)) { // Logs message orxFONTGEN_LOG(MODE, "Output mode set to non-monospace."); // Registers last param eResult = orxParam_Register(&astParamList[(sizeof(astParamList) / sizeof(astParamList[0])) - 1]); // Not using original advance values? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_ADVANCE)) { // Logs message orxFONTGEN_LOG(PACKING, "Characters will be packed."); } } // Done! return eResult; }
/** Clears cache (if any TimeLine track is still in active use, it'll remain in memory until not referenced anymore) * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTimeLine_ClearCache() { orxTIMELINE_TRACK *pstTrack, *pstNewTrack; orxU64 u64Key; orxHANDLE hIterator, hNextIterator; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY); /* For all tracks */ for(hIterator = orxHashTable_GetNext(sstTimeLine.pstTrackTable, orxHANDLE_UNDEFINED, &u64Key, (void **)&pstTrack); hIterator != orxHANDLE_UNDEFINED; hIterator = hNextIterator, pstTrack = pstNewTrack) { /* Gets next track */ hNextIterator = orxHashTable_GetNext(sstTimeLine.pstTrackTable, hIterator, &u64Key, (void **)&pstNewTrack); /* Is cached? */ if(orxFLAG_TEST(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_FLAG_CACHED)) { /* Updates its flags */ orxFLAG_SET(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_FLAG_NONE, orxTIMELINE_TRACK_KU32_FLAG_CACHED); /* Deletes its extra reference */ orxTimeLine_DeleteTrack(pstTrack); } } /* Done! */ return eResult; }
/** Sends an event * @param[in] _pstEvent Event to send */ orxSTATUS orxFASTCALL orxEvent_Send(orxEVENT *_pstEvent) { orxEVENT_HANDLER_STORAGE *pstStorage; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)); orxASSERT(_pstEvent != orxNULL); /* Gets corresponding storage */ pstStorage = (_pstEvent->eType < orxEVENT_TYPE_CORE_NUMBER) ? sstEvent.astCoreHandlerStorageList[_pstEvent->eType] : (orxEVENT_HANDLER_STORAGE *)orxHashTable_Get(sstEvent.pstHandlerStorageTable, _pstEvent->eType); /* Valid? */ if(pstStorage != orxNULL) { orxEVENT_HANDLER_INFO *pstInfo; /* Main thread? */ if(orxThread_GetCurrent() == orxTHREAD_KU32_MAIN_THREAD_ID) { /* Updates event send counter */ sstEvent.s32EventSendCounter++; } /* For all handlers */ for(pstInfo = (orxEVENT_HANDLER_INFO *)orxLinkList_GetFirst(&(pstStorage->stList)); pstInfo != orxNULL; pstInfo = (orxEVENT_HANDLER_INFO *)orxLinkList_GetNext(&(pstInfo->stNode))) { /* Stores context */ _pstEvent->pContext = pstInfo->pContext; /* Calls it */ if((pstInfo->pfnHandler)(_pstEvent) == orxSTATUS_FAILURE) { /* Updates result */ eResult = orxSTATUS_FAILURE; break; } } /* Clears context */ _pstEvent->pContext = orxNULL; /* Main thread? */ if(orxThread_GetCurrent() == orxTHREAD_KU32_MAIN_THREAD_ID) { /* Updates event send counter */ sstEvent.s32EventSendCounter--; } } /* Done! */ return eResult; }
/** Removes an event handler which matches given context * @param[in] _eEventType Concerned type of event * @param[in] _pfnEventHandler Event handler to remove * @param[in] _pContext Context of the handler to remove, orxNULL for removing all occurrences regardless of their context * return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxEvent_RemoveHandlerWithContext(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler, void *_pContext) { orxEVENT_HANDLER_STORAGE *pstStorage; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)); orxASSERT(_pfnEventHandler != orxNULL); /* Gets corresponding storage */ pstStorage = (_eEventType < orxEVENT_TYPE_CORE_NUMBER) ? sstEvent.astCoreHandlerStorageList[_eEventType] : (orxEVENT_HANDLER_STORAGE *)orxHashTable_Get(sstEvent.pstHandlerStorageTable, _eEventType); /* Valid? */ if(pstStorage != orxNULL) { orxEVENT_HANDLER_INFO *pstInfo; /* For all handlers */ for(pstInfo = (orxEVENT_HANDLER_INFO *)orxLinkList_GetFirst(&(pstStorage->stList)); pstInfo != orxNULL; pstInfo = (orxEVENT_HANDLER_INFO *)orxLinkList_GetNext(&(pstInfo->stNode))) { /* Found? */ if((pstInfo->pfnHandler == _pfnEventHandler) && ((_pContext == orxNULL) || (_pContext == _pfnEventHandler) || (_pContext == pstInfo->pContext))) { /* Removes it from list */ orxLinkList_Remove(&(pstInfo->stNode)); /* Frees it */ orxBank_Free(pstStorage->pstBank, pstInfo); /* Updates result */ eResult = orxSTATUS_SUCCESS; /* Should only remove one? */ if(_pContext == _pfnEventHandler) { /* Stops */ break; } } } } else { /* Defaults to success */ eResult = orxSTATUS_SUCCESS; } /* Done! */ return eResult; }
/** Is currently sending an event? * @return orxTRUE / orxFALSE */ orxBOOL orxFASTCALL orxEvent_IsSending() { orxBOOL bResult; /* Checks */ orxASSERT(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)); /* Updates result */ bResult = (sstEvent.s32EventSendCounter != 0) ? orxTRUE : orxFALSE; /* Done! */ return bResult; }
/** Deletes an FXPointer * @param[in] _pstFXPointer Concerned FXPointer * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFXPointer_Delete(orxFXPOINTER *_pstFXPointer) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstFXPointer); /* Decreases counter */ orxStructure_DecreaseCounter(_pstFXPointer); /* Not referenced? */ if(orxStructure_GetRefCounter(_pstFXPointer) == 0) { orxU32 i; /* For all FXs */ for(i = 0; i < orxFXPOINTER_KU32_FX_NUMBER; i++) { /* Valid? */ if(_pstFXPointer->astFXList[i].pstFX != orxNULL) { /* Decreases its reference counter */ orxStructure_DecreaseCounter(_pstFXPointer->astFXList[i].pstFX); /* Is internal? */ if(orxFLAG_TEST(_pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_INTERNAL)) { /* Removes its owner */ orxStructure_SetOwner(_pstFXPointer->astFXList[i].pstFX, orxNULL); /* Deletes it */ orxFX_Delete(_pstFXPointer->astFXList[i].pstFX); } } } /* Deletes structure */ orxStructure_Delete(_pstFXPointer); } else { /* Referenced by others */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
/** Exits from the event module */ void orxFASTCALL orxEvent_Exit() { /* Initialized? */ if(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)) { /* Deletes hashtable */ orxHashTable_Delete(sstEvent.pstHandlerStorageTable); /* Deletes bank */ orxBank_Delete(sstEvent.pstHandlerStorageBank); /* Updates flags */ orxFLAG_SET(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_NONE, orxEVENT_KU32_STATIC_MASK_ALL); } return; }
/** Sends a simple event * @param[in] _eEventType Event type * @param[in] _eEventID Event ID * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxEvent_SendShort(orxEVENT_TYPE _eEventType, orxENUM _eEventID) { orxEVENT stEvent; orxSTATUS eResult; /* Checks */ orxASSERT(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)); /* Inits event */ orxMemory_Zero(&stEvent, sizeof(orxEVENT)); stEvent.eType = _eEventType; stEvent.eID = _eEventID; /* Sends it */ eResult = orxEvent_Send(&stEvent); /* Done! */ return eResult; }
/** Is a given log level enabled? * @param[in] _eLevel Concerned debug level */ orxBOOL orxFASTCALL _orxDebug_IsLevelEnabled(orxDEBUG_LEVEL _eLevel) { orxBOOL bResult; /* All levels? */ if(_eLevel == orxDEBUG_LEVEL_ALL) { /* Updates result */ bResult = orxFLAG_TEST_ALL(sstDebug.u32LevelFlags, 0xFFFFFFFF) ? orxTRUE : orxFALSE; } else { /* Checks */ orxASSERT(_eLevel < orxDEBUG_LEVEL_NUMBER); /* Updates result */ bResult = orxFLAG_TEST(sstDebug.u32LevelFlags, 1 << _eLevel) ? orxTRUE : orxFALSE; } /* Done! */ return bResult; }
/** Updates the SoundPointer (Callback for generic structure update calling) * @param[in] _pstStructure Generic Structure or the concerned Body * @param[in] _pstCaller Structure of the caller * @param[in] _pstClockInfo Clock info used for time updates * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ static orxSTATUS orxFASTCALL orxSoundPointer_Update(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo) { orxSOUNDPOINTER *pstSoundPointer; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Profiles */ orxPROFILER_PUSH_MARKER("orxSoundPointer_Update"); /* Checks */ orxASSERT(sstSoundPointer.u32Flags & orxSOUNDPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstStructure); orxSTRUCTURE_ASSERT(_pstCaller); /* Gets sound pointer */ pstSoundPointer = orxSOUNDPOINTER(_pstStructure); /* Is enabled? */ if(orxSoundPointer_IsEnabled(pstSoundPointer) != orxFALSE) { orxU32 i; /* For all Sounds */ for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++) { orxSOUND *pstSound; /* Gets sound */ pstSound = pstSoundPointer->astSoundList[i].pstSound; /* Valid? */ if(pstSound != orxNULL) { /* Should auto play? */ if(orxFLAG_TEST(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY)) { /* Plays it */ orxSound_Play(pstSound); /* Updates its flags */ orxFLAG_SET(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY); } /* Delegates update to the sound */ orxStructure_Update(pstSound, _pstCaller, _pstClockInfo); /* Is sound stopped? */ if(orxSound_GetStatus(pstSound) == orxSOUND_STATUS_STOP) { /* Removes it */ orxSoundPointer_RemoveSound(pstSoundPointer, pstSound); } } } } /* Profiles */ orxPROFILER_POP_MARKER(); /* Done! */ return eResult; }
/** Event handler */ static orxSTATUS orxFASTCALL orxSoundPointer_EventHandler(const orxEVENT *_pstEvent) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Depending on event ID */ switch(_pstEvent->eID) { /* Pause / disable */ case orxOBJECT_EVENT_PAUSE: case orxOBJECT_EVENT_DISABLE: { orxSOUNDPOINTER *pstSoundPointer; /* Gets sound pointer */ pstSoundPointer = orxOBJECT_GET_STRUCTURE(orxOBJECT(_pstEvent->hSender), SOUNDPOINTER); /* Valid? */ if(pstSoundPointer != orxNULL) { orxU32 i; /* For all Sounds */ for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++) { /* Valid? */ if(pstSoundPointer->astSoundList[i].pstSound != orxNULL) { /* Is playing? */ if(orxSound_GetStatus(pstSoundPointer->astSoundList[i].pstSound) == orxSOUND_STATUS_PLAY) { /* Pauses it */ orxSound_Pause(pstSoundPointer->astSoundList[i].pstSound); /* Updates its status */ orxFLAG_SET(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PAUSE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE); /* Delegates update to the sound */ orxStructure_Update(pstSoundPointer->astSoundList[i].pstSound, orxStructure_GetOwner(pstSoundPointer), orxNULL); } } } } break; } /* Unpause / enable */ case orxOBJECT_EVENT_UNPAUSE: case orxOBJECT_EVENT_ENABLE: { orxSOUNDPOINTER *pstSoundPointer; /* Gets sound pointer */ pstSoundPointer = orxOBJECT_GET_STRUCTURE(orxOBJECT(_pstEvent->hSender), SOUNDPOINTER); /* Valid? */ if(pstSoundPointer != orxNULL) { orxU32 i; /* For all Sounds */ for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++) { /* Valid? */ if(pstSoundPointer->astSoundList[i].pstSound != orxNULL) { /* Is auto-paused? */ if(orxFLAG_TEST(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PAUSE)) { /* Resumes it */ orxSound_Play(pstSoundPointer->astSoundList[i].pstSound); /* Updates its status */ orxFLAG_SET(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PAUSE); /* Delegates update to the sound */ orxStructure_Update(pstSoundPointer->astSoundList[i].pstSound, orxStructure_GetOwner(pstSoundPointer), orxNULL); } } } } break; } default: { break; } } /* Done! */ return eResult; }
/** Creates a camera * @param[in] _u32Flags Camera flags (2D / ...) * @return Created orxCAMERA / orxNULL */ orxCAMERA *orxFASTCALL orxCamera_Create(orxU32 _u32Flags) { orxCAMERA *pstCamera = orxNULL; orxFRAME *pstFrame; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); orxASSERT((_u32Flags & orxCAMERA_KU32_MASK_USER_ALL) == _u32Flags); /* Creates camera */ pstCamera = orxCAMERA(orxStructure_Create(orxSTRUCTURE_ID_CAMERA)); /* Valid? */ if(pstCamera != orxNULL) { /* Creates frame */ pstFrame = orxFrame_Create(orxFRAME_KU32_FLAG_NONE); /* Valid? */ if(pstFrame != orxNULL) { /* 2D? */ if(orxFLAG_TEST(_u32Flags, orxCAMERA_KU32_FLAG_2D)) { /* Stores frame */ pstCamera->pstFrame = pstFrame; /* Increases its reference counter */ orxStructure_IncreaseCounter(pstFrame); /* Updates flags */ orxStructure_SetFlags(pstCamera, orxCAMERA_KU32_FLAG_2D, orxCAMERA_KU32_FLAG_NONE); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Camera currently only supports 2d."); /* Fress partially allocated camera */ orxFrame_Delete(pstFrame); orxStructure_Delete(pstCamera); /* Updates result */ pstCamera = orxNULL; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Failed to create camera's frame."); /* Fress partially allocated camera */ orxStructure_Delete(pstCamera); /* Updates result */ pstCamera = orxNULL; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Failed to create camera."); } /* Done! */ return pstCamera; }
static void Run() { // Ready? if(orxFLAG_TEST_ALL(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_MASK_READY)) { orxU32 u32Counter; // Gets glyph list's counter u32Counter = orxLinkList_GetCounter(&sstFontGen.stGlyphList); // Valid? if(u32Counter) { orxS32 s32Width, s32Height, s32BaseLine, s32MaxAscend, s32MaxDescend; orxSTRING *azWidthList = orxNULL; orxFLOAT fWidth, fHeight; orxU8 *pu8ImageBuffer; // Not monospaced? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_MONOSPACE)) { orxU32 i; // Allocates width list azWidthList = (orxSTRING *)orxMemory_Allocate(u32Counter * sizeof(orxSTRING), orxMEMORY_TYPE_MAIN); // Checks orxASSERT(azWidthList); // For all strings for(i = 0; i < u32Counter; i++) { azWidthList[i] = (orxSTRING)orxMemory_Allocate(8 * sizeof(orxCHAR), orxMEMORY_TYPE_MAIN); } } // No font name? if(!sstFontGen.zFontName) { // Uses default one sstFontGen.zFontName = orxString_Duplicate(orxFONTGEN_KZ_DEFAULT_NAME); // Logs message orxFONTGEN_LOG(OUTPUT, "No output name specified, defaulting to '%s'.", orxFONTGEN_KZ_DEFAULT_NAME); } // Is not monospaced? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_MONOSPACE)) { orxFONTGEN_GLYPH *pstGlyph; orxS32 s32LargestWidth = 0; // For all defined glyphs for(pstGlyph = (orxFONTGEN_GLYPH *)orxLinkList_GetFirst(&sstFontGen.stGlyphList); pstGlyph; pstGlyph = (orxFONTGEN_GLYPH *)orxLinkList_GetNext(&pstGlyph->stNode)) { orxS32 s32CharacterWidth; FT_Error eError; // Loads rendered glyph eError = FT_Load_Glyph(sstFontGen.pstFontFace, (FT_UInt)pstGlyph->u32Index, FT_LOAD_RENDER); orxASSERT(!eError); // Use original advance value? if(orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_ADVANCE)) { // Gets character width s32CharacterWidth = sstFontGen.pstFontFace->glyph->advance.x >> 6; } else { // Gets character width s32CharacterWidth = orxMAX((orxS32)sstFontGen.pstFontFace->glyph->bitmap_left, 0) + (orxS32)sstFontGen.pstFontFace->glyph->bitmap.width; } // Updates largest character width s32LargestWidth = orxMAX(s32LargestWidth, s32CharacterWidth); }
/** Sets relative graphic pivot * @param[in] _pstGraphic Concerned graphic * @param[in] _u32AlignFlags Alignment flags * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxGraphic_SetRelativePivot(orxGRAPHIC *_pstGraphic, orxU32 _u32AlignFlags) { orxVECTOR vSize; orxSTATUS eResult; /* Checks */ orxASSERT(sstGraphic.u32Flags & orxGRAPHIC_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstGraphic); orxASSERT((_u32AlignFlags & orxGRAPHIC_KU32_MASK_ALIGN) == _u32AlignFlags); orxASSERT(_pstGraphic->fWidth >= orxFLOAT_0); orxASSERT(_pstGraphic->fHeight >= orxFLOAT_0); /* Valid size? */ if(orxGraphic_GetSize(_pstGraphic, &vSize) != orxNULL) { orxFLOAT fHeight, fWidth; /* Gets graphic size */ fWidth = vSize.fX; fHeight = vSize.fY; /* Pivot left? */ if(orxFLAG_TEST(_u32AlignFlags, orxGRAPHIC_KU32_FLAG_ALIGN_LEFT)) { /* Updates x position */ _pstGraphic->vPivot.fX = orxFLOAT_0; } /* Align right? */ else if(orxFLAG_TEST(_u32AlignFlags, orxGRAPHIC_KU32_FLAG_ALIGN_RIGHT)) { /* Updates x position */ _pstGraphic->vPivot.fX = fWidth; } /* Align center */ else { /* Updates x position */ _pstGraphic->vPivot.fX = orx2F(0.5f) * fWidth; } /* Align top? */ if(orxFLAG_TEST(_u32AlignFlags, orxGRAPHIC_KU32_FLAG_ALIGN_TOP)) { /* Updates y position */ _pstGraphic->vPivot.fY = orxFLOAT_0; } /* Align bottom? */ else if(orxFLAG_TEST(_u32AlignFlags, orxGRAPHIC_KU32_FLAG_ALIGN_BOTTOM)) { /* Updates y position */ _pstGraphic->vPivot.fY = fHeight; } /* Align center */ else { /* Updates y position */ _pstGraphic->vPivot.fY = orx2F(0.5f) * fHeight; } /* Truncate? */ if(orxFLAG_TEST(_u32AlignFlags, orxGRAPHIC_KU32_FLAG_ALIGN_TRUNCATE)) { /* Updates position */ orxVector_Floor(&(_pstGraphic->vPivot), &(_pstGraphic->vPivot)); } /* Round? */ else if(orxFLAG_TEST(_u32AlignFlags, orxGRAPHIC_KU32_FLAG_ALIGN_ROUND)) { /* Updates position */ orxVector_Round(&(_pstGraphic->vPivot), &(_pstGraphic->vPivot)); } /* Updates status */ orxStructure_SetFlags(_pstGraphic, _u32AlignFlags | orxGRAPHIC_KU32_FLAG_HAS_PIVOT | orxGRAPHIC_KU32_FLAG_RELATIVE_PIVOT, orxGRAPHIC_KU32_MASK_ALIGN); /* Updates result */ eResult = orxSTATUS_SUCCESS; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Invalid size retrieved from graphic."); /* Updates result */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
/** Adds a track to a TimeLine from config * @param[in] _pstTimeLine Concerned TimeLine * @param[in] _zTrackID Config ID * return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTimeLine_AddTrackFromConfig(orxTIMELINE *_pstTimeLine, const orxSTRING _zTrackID) { orxU32 u32Index; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxSTRUCTURE_ASSERT(_pstTimeLine); orxASSERT((_zTrackID != orxNULL) && (_zTrackID != orxSTRING_EMPTY)); /* Checks */ orxSTRUCTURE_ASSERT(_pstTimeLine); /* Finds an empty track */ for(u32Index = 0; (u32Index < orxTIMELINE_KU32_TRACK_NUMBER) && (_pstTimeLine->astTrackList[u32Index].pstTrack != orxNULL); u32Index++); /* Found? */ if(u32Index < orxTIMELINE_KU32_TRACK_NUMBER) { orxTIMELINE_TRACK *pstTrack; orxU32 u32ID; /* Gets track ID */ u32ID = orxString_ToCRC(_zTrackID); /* Search for reference */ pstTrack = (orxTIMELINE_TRACK *)orxHashTable_Get(sstTimeLine.pstTrackTable, u32ID); /* Found? */ if(pstTrack != orxNULL) { /* Increases counter */ pstTrack->u32RefCounter++; } else { /* Creates track */ pstTrack = orxTimeLine_CreateTrack(_zTrackID); } /* Valid? */ if(pstTrack != orxNULL) { orxTIMELINE_EVENT_PAYLOAD stPayload; orxSTRUCTURE *pstOwner; /* Gets owner */ pstOwner = orxStructure_GetOwner(_pstTimeLine); /* Updates track holder */ _pstTimeLine->astTrackList[u32Index].pstTrack = pstTrack; _pstTimeLine->astTrackList[u32Index].fStartTime = _pstTimeLine->fTime; _pstTimeLine->astTrackList[u32Index].u32NextEventIndex = 0; _pstTimeLine->astTrackList[u32Index].u32Flags = orxTIMELINE_HOLDER_KU32_FLAG_NONE; /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD)); stPayload.pstTimeLine = _pstTimeLine; stPayload.zTrackName = pstTrack->zReference; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_ADD, pstOwner, pstOwner, &stPayload); /* Updates timeline flags */ orxStructure_SetFlags(_pstTimeLine, orxTIMELINE_KU32_FLAG_DIRTY, orxTIMELINE_KU32_FLAG_NONE); /* Is immediate? */ if(orxFLAG_TEST(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_FLAG_IMMEDIATE)) { /* Updates it */ orxTimeLine_Update(orxSTRUCTURE(_pstTimeLine), pstOwner, orxNULL); } /* Updates result */ eResult = orxSTATUS_SUCCESS; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "No room for a new track in TimeLine, can't add track <%s>.", _zTrackID); } /* Done! */ return eResult; }
/** Removes all sounds * @param[in] _pstSoundPointer Concerned SoundPointer * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxSoundPointer_RemoveAllSounds(orxSOUNDPOINTER *_pstSoundPointer) { orxU32 i; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(sstSoundPointer.u32Flags & orxSOUNDPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstSoundPointer); /* For all slots */ for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++) { orxSOUND *pstSound; /* Gets sound */ pstSound = _pstSoundPointer->astSoundList[i].pstSound; /* Valid? */ if(pstSound != orxNULL) { orxSOUND_EVENT_PAYLOAD stPayload; orxSTRUCTURE *pstOwner; /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxSOUND_EVENT_PAYLOAD)); stPayload.pstSound = pstSound; /* Gets owner */ pstOwner = orxStructure_GetOwner(_pstSoundPointer); /* Wasn't stopped? */ if(orxSound_GetStatus(pstSound) != orxSOUND_STATUS_STOP) { /* Sends stop event */ orxEVENT_SEND(orxEVENT_TYPE_SOUND, orxSOUND_EVENT_STOP, pstOwner, pstOwner, &stPayload); } /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_SOUND, orxSOUND_EVENT_REMOVE, pstOwner, pstOwner, &stPayload); /* Decreases its reference counter */ orxStructure_DecreaseCounter(pstSound); /* Was last added sound? */ if(_pstSoundPointer->u32LastAddedIndex == i) { /* Clears last added sound index */ _pstSoundPointer->u32LastAddedIndex = orxU32_UNDEFINED; } /* Removes its reference */ _pstSoundPointer->astSoundList[i].pstSound = orxNULL; /* Is internal? */ if(orxFLAG_TEST(_pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_INTERNAL)) { /* Removes its owner */ orxStructure_SetOwner(pstSound, orxNULL); /* Deletes it */ orxSound_Delete(pstSound); } /* Updates result */ eResult = orxSTATUS_SUCCESS; } } /* Done! */ return eResult; }
/** Inits the event module * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxEvent_Init() { orxSTATUS eResult = orxSTATUS_FAILURE; /* Not already Initialized? */ if(!orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)) { /* Cleans control structure */ orxMemory_Zero(&sstEvent, sizeof(orxEVENT_STATIC)); /* Creates handler storage table */ sstEvent.pstHandlerStorageTable = orxHashTable_Create(orxEVENT_KU32_HANDLER_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Success? */ if(sstEvent.pstHandlerStorageTable != orxNULL) { /* Creates handler storage bank */ sstEvent.pstHandlerStorageBank = orxBank_Create(orxEVENT_KU32_STORAGE_BANK_SIZE, sizeof(orxEVENT_HANDLER_STORAGE), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Success? */ if(sstEvent.pstHandlerStorageBank != orxNULL) { /* Inits Flags */ orxFLAG_SET(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY, orxEVENT_KU32_STATIC_MASK_ALL); /* Success */ eResult = orxSTATUS_SUCCESS; } else { /* Deletes table */ orxHashTable_Delete(sstEvent.pstHandlerStorageTable); /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Event module failed to create bank."); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Event module failed to create hash table."); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Event module already loaded."); /* Already initialized */ eResult = orxSTATUS_SUCCESS; } /* Done! */ return eResult; }
/** Adds an event handler with user-defined context * @param[in] _eEventType Concerned type of event * @param[in] _pfnHandler Event handler to add * @param[in] _pContext Context that will be stored in events sent to this handler * return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxEvent_AddHandlerWithContext(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler, void *_pContext) { orxEVENT_HANDLER_STORAGE *pstStorage; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)); orxASSERT(_pfnEventHandler != orxNULL); /* Gets corresponding storage */ pstStorage = (_eEventType < orxEVENT_TYPE_CORE_NUMBER) ? sstEvent.astCoreHandlerStorageList[_eEventType] : (orxEVENT_HANDLER_STORAGE *)orxHashTable_Get(sstEvent.pstHandlerStorageTable, _eEventType); /* No storage yet? */ if(pstStorage == orxNULL) { /* Allocates it */ pstStorage = (orxEVENT_HANDLER_STORAGE *)orxBank_Allocate(sstEvent.pstHandlerStorageBank); /* Success? */ if(pstStorage != orxNULL) { /* Creates its bank */ pstStorage->pstBank = orxBank_Create(orxEVENT_KU32_HANDLER_BANK_SIZE, sizeof(orxEVENT_HANDLER_INFO), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Success? */ if(pstStorage->pstBank != orxNULL) { /* Clears its list */ orxMemory_Zero(&(pstStorage->stList), sizeof(orxLINKLIST)); /* Is a core event handler? */ if(_eEventType < orxEVENT_TYPE_CORE_NUMBER) { /* Stores it */ sstEvent.astCoreHandlerStorageList[_eEventType] = pstStorage; } else { /* Tries to add it to the table */ if(orxHashTable_Add(sstEvent.pstHandlerStorageTable, _eEventType, pstStorage) == orxSTATUS_FAILURE) { /* Deletes its bank */ orxBank_Delete(pstStorage->pstBank); /* Frees storage */ orxBank_Free(sstEvent.pstHandlerStorageBank, pstStorage); pstStorage = orxNULL; } } } else { /* Frees storage */ orxBank_Free(sstEvent.pstHandlerStorageBank, pstStorage); pstStorage = orxNULL; } } } /* Valid? */ if(pstStorage != orxNULL) { orxEVENT_HANDLER_INFO *pstInfo; /* Allocates a new handler info */ pstInfo = (orxEVENT_HANDLER_INFO *)orxBank_Allocate(pstStorage->pstBank); /* Valid? */ if(pstInfo != orxNULL) { /* Clears its node */ orxMemory_Zero(&(pstInfo->stNode), sizeof(orxLINKLIST_NODE)); /* Stores its handler */ pstInfo->pfnHandler = _pfnEventHandler; /* Stores context */ pstInfo->pContext = _pContext; /* Adds it to the list */ eResult = orxLinkList_AddEnd(&(pstStorage->stList), &(pstInfo->stNode)); } } /* Done! */ return eResult; }
/** Updates the FXPointer (Callback for generic structure update calling) * @param[in] _pstStructure Generic Structure or the concerned Body * @param[in] _pstCaller Structure of the caller * @param[in] _pstClockInfo Clock info used for time updates * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ static orxSTATUS orxFASTCALL orxFXPointer_Update(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo) { orxFXPOINTER *pstFXPointer; orxOBJECT *pstObject; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Profiles */ orxPROFILER_PUSH_MARKER("orxFXPointer_Update"); /* Checks */ orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstStructure); orxSTRUCTURE_ASSERT(_pstCaller); /* Gets FXPointer */ pstFXPointer = orxFXPOINTER(_pstStructure); /* Gets calling object */ pstObject = orxOBJECT(_pstCaller); /* Is enabled? */ if(orxFXPointer_IsEnabled(pstFXPointer) != orxFALSE) { orxFLOAT fLastTime; orxU32 i; orxSTRUCTURE *pstOwner; /* Gets owner */ pstOwner = orxStructure_GetOwner(pstFXPointer); /* Backups last time */ fLastTime = pstFXPointer->fTime; /* Computes its new time cursor */ pstFXPointer->fTime += _pstClockInfo->fDT; /* For all FXs */ for(i = 0; i < orxFXPOINTER_KU32_FX_NUMBER; i++) { orxFX *pstFX; /* Gets FX */ pstFX = pstFXPointer->astFXList[i].pstFX; /* Valid? */ if(pstFX != orxNULL) { orxFLOAT fFXLocalStartTime, fFXLocalEndTime; /* Gets FX local times */ fFXLocalStartTime = fLastTime - pstFXPointer->astFXList[i].fStartTime; fFXLocalEndTime = pstFXPointer->fTime - pstFXPointer->astFXList[i].fStartTime; /* Is the FX reached? */ if(fFXLocalEndTime >= orxFLOAT_0) { /* Is the first time? */ if(!orxFLAG_TEST(pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_PLAYED)) { orxFX_EVENT_PAYLOAD stPayload; /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxFX_EVENT_PAYLOAD)); stPayload.pstFX = pstFX; stPayload.zFXName = orxFX_GetName(pstFX); /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_START, pstOwner, pstOwner, &stPayload); } /* Updates its status */ orxFLAG_SET(pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_PLAYED, orxFXPOINTER_HOLDER_KU32_FLAG_NONE); /* Applies FX from last time to now */ if(orxFX_Apply(pstFX, pstObject, fFXLocalStartTime, fFXLocalEndTime) == orxSTATUS_FAILURE) { orxFX_EVENT_PAYLOAD stPayload; /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxFX_EVENT_PAYLOAD)); stPayload.pstFX = pstFX; stPayload.zFXName = orxFX_GetName(pstFX); /* Is a looping FX? */ if(orxFX_IsLooping(pstFX) != orxFALSE) { /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_LOOP, pstOwner, pstOwner, &stPayload); /* Updates its start time */ pstFXPointer->astFXList[i].fStartTime = pstFXPointer->fTime; } else { /* Decreases its reference counter */ orxStructure_DecreaseCounter(pstFX); /* Removes its reference */ pstFXPointer->astFXList[i].pstFX = orxNULL; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_STOP, pstOwner, pstOwner, &stPayload); /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_REMOVE, pstOwner, pstOwner, &stPayload); /* Is internal? */ if(orxFLAG_TEST(pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_INTERNAL)) { /* Removes its owner */ orxStructure_SetOwner(pstFX, orxNULL); /* Deletes it */ orxFX_Delete(pstFX); } } } } } } } /* Profiles */ orxPROFILER_POP_MARKER(); /* Done! */ return eResult; }
/** Updates the TimeLine (Callback for generic structure update calling) * @param[in] _pstStructure Generic Structure or the concerned Body * @param[in] _pstCaller Structure of the caller * @param[in] _pstClockInfo Clock info used for time updates * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ static orxSTATUS orxFASTCALL orxTimeLine_Update(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo) { orxTIMELINE *pstTimeLine; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Profiles */ orxPROFILER_PUSH_MARKER("orxTimeLine_Update"); /* Checks */ orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstStructure); orxSTRUCTURE_ASSERT(_pstCaller); /* Gets TimeLine */ pstTimeLine = orxTIMELINE(_pstStructure); /* Is enabled? */ if(orxTimeLine_IsEnabled(pstTimeLine) != orxFALSE) { orxU32 i; /* Cleans its flags */ orxStructure_SetFlags(pstTimeLine, orxTIMELINE_KU32_FLAG_NONE, orxTIMELINE_KU32_FLAG_DIRTY); /* Has clock info? */ if(_pstClockInfo != orxNULL) { /* Computes its new time cursor */ pstTimeLine->fTime += _pstClockInfo->fDT; } /* For all tracks */ for(i = 0; i < orxTIMELINE_KU32_TRACK_NUMBER; i++) { orxTIMELINE_TRACK *pstTrack; /* Is timeline dirty? */ if(orxStructure_TestFlags(pstTimeLine, orxTIMELINE_KU32_FLAG_DIRTY)) { orxU32 j; /* For all previous tracks */ for(j = 0; j < i; j++) { /* Is defined? */ if(pstTimeLine->astTrackList[j].pstTrack != orxNULL) { /* Hasn't been updated? */ if(!orxFLAG_TEST(pstTimeLine->astTrackList[j].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_UPDATED)) { /* Selects it */ i = j; break; } } } } /* Gets track */ pstTrack = pstTimeLine->astTrackList[i].pstTrack; /* Valid and not already updated? */ if((pstTrack != orxNULL) && (!orxFLAG_TEST(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_UPDATED))) { orxFLOAT fTrackLocalTime; /* Gets track local time */ fTrackLocalTime = pstTimeLine->fTime - pstTimeLine->astTrackList[i].fStartTime; /* Has time come? */ if(fTrackLocalTime >= orxFLOAT_0) { orxTIMELINE_EVENT_PAYLOAD stPayload; orxU32 u32EventIndex; /* Is the first time? */ if(!orxFLAG_TEST(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_PLAYED)) { /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD)); stPayload.pstTimeLine = pstTimeLine; stPayload.zTrackName = pstTrack->zReference; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_START, _pstCaller, _pstCaller, &stPayload); } /* Updates its status */ orxFLAG_SET(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_PLAYED | orxTIMELINE_HOLDER_KU32_FLAG_UPDATED, orxTIMELINE_HOLDER_KU32_FLAG_NONE); /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD)); stPayload.pstTimeLine = pstTimeLine; stPayload.zTrackName = pstTrack->zReference; /* For all recently past events */ for(u32EventIndex = pstTimeLine->astTrackList[i].u32NextEventIndex; (u32EventIndex < pstTrack->u32EventCounter) && (fTrackLocalTime >= pstTrack->astEventList[u32EventIndex].fTimeStamp); u32EventIndex++) { /* Updates payload */ stPayload.zEvent = pstTrack->astEventList[u32EventIndex].zEventText; stPayload.fTimeStamp = pstTrack->astEventList[u32EventIndex].fTimeStamp; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRIGGER, _pstCaller, _pstCaller, &stPayload); } /* Is over? */ if(u32EventIndex >= pstTrack->u32EventCounter) { orxTIMELINE_TRACK *pstTrack; /* Gets track */ pstTrack = pstTimeLine->astTrackList[i].pstTrack; /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD)); stPayload.pstTimeLine = pstTimeLine; stPayload.zTrackName = pstTrack->zReference; /* Is a looping track? */ if(orxFLAG_TEST(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_FLAG_LOOP)) { /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_LOOP, _pstCaller, _pstCaller, &stPayload); /* Resets track */ pstTimeLine->astTrackList[i].u32NextEventIndex = 0; pstTimeLine->astTrackList[i].fStartTime = pstTimeLine->fTime; } else { /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_STOP, _pstCaller, _pstCaller, &stPayload); /* Removes its reference */ pstTimeLine->astTrackList[i].pstTrack = orxNULL; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_REMOVE, _pstCaller, _pstCaller, &stPayload); /* Deletes it */ orxTimeLine_DeleteTrack(pstTrack); } } else { /* Updates next event index */ pstTimeLine->astTrackList[i].u32NextEventIndex = u32EventIndex; } } } } /* For all tracks */ for(i = 0; i < orxTIMELINE_KU32_TRACK_NUMBER; i++) { /* Clears its update flag */ orxFLAG_SET(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_NONE, orxTIMELINE_HOLDER_KU32_FLAG_UPDATED); } } /* Profiles */ orxPROFILER_POP_MARKER(); /* Done! */ return eResult; }
/** Removes an FX using its config ID * @param[in] _pstFXPointer Concerned FXPointer * @param[in] _zFXConfigID Config ID of the FX to remove * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFXPointer_RemoveFXFromConfig(orxFXPOINTER *_pstFXPointer, const orxSTRING _zFXConfigID) { orxU32 i, u32ID; orxSTRUCTURE *pstOwner; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstFXPointer); orxASSERT((_zFXConfigID != orxNULL) && (_zFXConfigID != orxSTRING_EMPTY)); /* Gets owner */ pstOwner = orxStructure_GetOwner(_pstFXPointer); /* Gets ID */ u32ID = orxString_ToCRC(_zFXConfigID); /* For all slots */ for(i = 0; i < orxFXPOINTER_KU32_FX_NUMBER; i++) { orxFX *pstFX; /* Gets FX */ pstFX = _pstFXPointer->astFXList[i].pstFX; /* Valid? */ if(pstFX != orxNULL) { /* Found? */ if(orxString_ToCRC(orxFX_GetName(pstFX)) == u32ID) { orxFX_EVENT_PAYLOAD stPayload; /* Decreases its reference counter */ orxStructure_DecreaseCounter(pstFX); /* Removes its reference */ _pstFXPointer->astFXList[i].pstFX = orxNULL; /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxFX_EVENT_PAYLOAD)); stPayload.pstFX = pstFX; stPayload.zFXName = orxFX_GetName(pstFX); /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_REMOVE, pstOwner, pstOwner, &stPayload); /* Is internal? */ if(orxFLAG_TEST(_pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_INTERNAL)) { /* Removes its owner */ orxStructure_SetOwner(pstFX, orxNULL); /* Deletes it */ orxFX_Delete(pstFX); } /* Updates result */ eResult = orxSTATUS_SUCCESS; break; } } } /* Done! */ return eResult; }
/** Logs given debug text * @param[in] _eLevel Debug level associated with this output * @param[in] _zFunction Calling function name * @param[in] _zFile Calling file name * @param[in] _u32Line Calling file line * @param[in] _zFormat Printf formatted text */ void orxCDECL _orxDebug_Log(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zFormat, ...) { /* Is level enabled? */ if(orxFLAG_TEST(sstDebug.u32LevelFlags, (1 << _eLevel))) { orxCHAR zBuffer[orxDEBUG_KS32_BUFFER_OUTPUT_SIZE], zLog[orxDEBUG_KS32_BUFFER_OUTPUT_SIZE], *pcBuffer = zBuffer; va_list stArgs; /* Empties current buffer */ pcBuffer[0] = orxCHAR_NULL; /* Full Time Stamp? */ if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_FULL_TIMESTAMP) { time_t u32Time; /* Inits Log Time */ time(&u32Time); pcBuffer += strftime(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE, orxDEBUG_KZ_DATE_FULL_FORMAT, localtime(&u32Time)); } /* Time Stamp? */ else if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_TIMESTAMP) { time_t u32Time; /* Inits Log Time */ time(&u32Time); pcBuffer += strftime(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE, orxDEBUG_KZ_DATE_FORMAT, localtime(&u32Time)); } /* Log Type? */ if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_TYPE) { #ifdef __orxMSVC__ pcBuffer += _snprintf(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), " [%s]", orxDebug_GetLevelString(_eLevel)); #else /* __orxMSVC__ */ pcBuffer += snprintf(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), " [%s]", orxDebug_GetLevelString(_eLevel)); #endif /* __orxMSVC__ */ } /* Log FUNCTION, FILE & LINE? */ if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_TAGGED) { const orxSTRING zFile; /* Skips complete path */ zFile = orxString_SkipPath(_zFile); #ifdef __orxMSVC__ /* Writes info */ pcBuffer += _snprintf(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), " [%s:%s():%u]", zFile, _zFunction, _u32Line); #else /* __orxMSVC__ */ /* Writes info */ pcBuffer += snprintf(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), " [%s:%s():%u]", zFile, _zFunction, (unsigned int)_u32Line); #endif /* __orxMSVC__ */ } /* Debug Log */ va_start(stArgs, _zFormat); vsnprintf(zLog, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), _zFormat, stArgs); zLog[orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer) - 1] = '\0'; va_end(stArgs); #ifdef __orxMSVC__ pcBuffer += _snprintf(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), (pcBuffer == zBuffer) ? "%s%s" : " %s%s", zLog, orxSTRING_EOL); #else /* __orxMSVC__ */ pcBuffer += snprintf(pcBuffer, orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer), (pcBuffer == zBuffer) ? "%s%s" : " %s%s", zLog, orxSTRING_EOL); #endif /* __orxMSVC__ */ pcBuffer[orxDEBUG_KS32_BUFFER_OUTPUT_SIZE - (pcBuffer - zBuffer) - 1] = '\0'; /* Use file? */ if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_FILE) { FILE *pstFile; if(_eLevel == orxDEBUG_LEVEL_LOG) { #if !defined(__orxANDROID__) && !defined(__orxANDROID_ANDROID__) /* Needs to open the file? */ if(sstDebug.pstLogFile == orxNULL) { /* Opens it */ sstDebug.pstLogFile = fopen(sstDebug.zLogFile, "ab+"); } #endif /* !__orxANDROID__ && !__orxANDROID_NATIVE__ */ pstFile = sstDebug.pstLogFile; } else { #if !defined(__orxANDROID__) && !defined(__orxANDROID_ANDROID__) /* Needs to open the file? */ if(sstDebug.pstDebugFile == orxNULL) { /* Opens it */ sstDebug.pstDebugFile = fopen(sstDebug.zDebugFile, "ab+"); } #endif /* !__orxANDROID__ && !__orxANDROID_NATIVE__ */ pstFile = sstDebug.pstDebugFile; } /* Valid? */ if(pstFile != orxNULL) { fprintf(pstFile, "%s", zBuffer); fflush(pstFile); } } /* Terminal Display? */ if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_TERMINAL) { #if defined(__orxANDROID__) || defined(__orxANDROID_NATIVE__) #define LOG_TAG "orxDebug" #define LOGI(...) __android_log_write(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) #define LOGD(...) __android_log_write(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) if(_eLevel == orxDEBUG_LEVEL_LOG) { LOGI(zBuffer); } else { LOGD(zBuffer); } #else /* __orxANDROID__ || __orxANDROID_NATIVE__ */ FILE *pstFile; if(_eLevel == orxDEBUG_LEVEL_LOG) { pstFile = stdout; } else { pstFile = stderr; } fprintf(pstFile, "%s", zBuffer); fflush(pstFile); #endif /* __orxANDROID__ || __orxANDROID_NATIVE__ */ } /* Console Display? */ if(sstDebug.u32DebugFlags & orxDEBUG_KU32_STATIC_FLAG_CONSOLE) { /* Is console initialized? */ if(orxModule_IsInitialized(orxMODULE_ID_CONSOLE) != orxFALSE) { /* Logs it */ orxConsole_Log(zBuffer); } } } /* Done */ return; }