/** Gets a track duration using its config ID * @param[in] _zTrackID Config ID of the concerned track * @return Duration if found, -orxFLOAT_1 otherwise */ orxFLOAT orxFASTCALL orxTimeLine_GetTrackDuration(const orxSTRING _zTrackID) { orxTIMELINE_TRACK *pstTrack; orxU32 u32TrackID; orxFLOAT fResult; /* Checks */ orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY); orxASSERT((_zTrackID != orxNULL) && (_zTrackID != orxSTRING_EMPTY)); /* Gets track CRC */ u32TrackID = orxString_ToCRC(_zTrackID); /* Gets it */ if((pstTrack = (orxTIMELINE_TRACK *)orxHashTable_Get(sstTimeLine.pstTrackTable, u32TrackID)) != orxNULL) { /* Updates result */ fResult = pstTrack->astEventList[pstTrack->u32EventCounter - 1].fTimeStamp; } else { /* Updates result */ fResult = -orxFLOAT_1; } /* Done! */ return fResult; }
/** Adds a unique delayed FX using its config ID * @param[in] _pstFXPointer Concerned FXPointer * @param[in] _zFXConfigID Config ID of the FX to add * @param[in] _fDelay Delay time * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFXPointer_AddUniqueDelayedFXFromConfig(orxFXPOINTER *_pstFXPointer, const orxSTRING _zFXConfigID, orxFLOAT _fDelay) { orxU32 i, u32ID; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstFXPointer); orxASSERT((_zFXConfigID != orxNULL) && (_zFXConfigID != orxSTRING_EMPTY)); orxASSERT(_fDelay >= orxFLOAT_0); /* 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) { /* Updates result */ eResult = orxSTATUS_FAILURE; break; } } } /* Success? */ if(eResult != orxSTATUS_FAILURE) { /* Adds delayed FX */ eResult = orxFXPointer_AddDelayedFXFromConfig(_pstFXPointer, _zFXConfigID, _fDelay); } /* Done! */ return eResult; }
/** Removes a track using its config ID * @param[in] _pstTimeLine Concerned TimeLine * @param[in] _zTrackID Config ID of the track to remove * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTimeLine_RemoveTrackFromConfig(orxTIMELINE *_pstTimeLine, const orxSTRING _zTrackID) { orxU32 u32Index, u32TrackID; orxSTRUCTURE *pstOwner; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY); orxASSERT((_zTrackID != orxNULL) && (_zTrackID != orxSTRING_EMPTY)); /* Gets owner */ pstOwner = orxStructure_GetOwner(_pstTimeLine); /* Gets track ID */ u32TrackID = orxString_ToCRC(_zTrackID); /* For all tracks */ for(u32Index = 0; u32Index < orxTIMELINE_KU32_TRACK_NUMBER; u32Index++) { /* Is defined? */ if(_pstTimeLine->astTrackList[u32Index].pstTrack != orxNULL) { /* Do IDs match? */ if(_pstTimeLine->astTrackList[u32Index].pstTrack->u32ID == u32TrackID) { orxTIMELINE_EVENT_PAYLOAD stPayload; orxTIMELINE_TRACK *pstTrack; /* Gets track */ pstTrack = _pstTimeLine->astTrackList[u32Index].pstTrack; /* Removes its reference */ _pstTimeLine->astTrackList[u32Index].pstTrack = orxNULL; /* 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_REMOVE, pstOwner, pstOwner, &stPayload); /* Deletes it */ orxTimeLine_DeleteTrack(pstTrack); break; } } } /* Done! */ return eResult; }
/** Gets camera given its name * @param[in] _zName Camera name * @return orxCAMERA / orxNULL */ orxCAMERA *orxFASTCALL orxCamera_Get(const orxSTRING _zName) { orxCAMERA *pstResult; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); orxASSERT(_zName != orxNULL); /* Updates result */ pstResult = (orxCAMERA *)orxHashTable_Get(sstCamera.pstReferenceTable, orxString_ToCRC(_zName)); /* Done! */ return pstResult; }
/** Deletes a camera * @param[in] _pstCamera Camera to delete * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxCamera_Delete(orxCAMERA *_pstCamera) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstCamera); /* Not referenced? */ if(orxStructure_GetRefCounter(_pstCamera) == 0) { /* Removes frame reference */ orxStructure_DecreaseCounter(_pstCamera->pstFrame); /* Deletes frame*/ orxFrame_Delete(_pstCamera->pstFrame); /* Is referenced? */ if(orxStructure_TestFlags(_pstCamera, orxCAMERA_KU32_FLAG_REFERENCED) != orxFALSE) { /* Removes it from reference table */ orxHashTable_Remove(sstCamera.pstReferenceTable, orxString_ToCRC(_pstCamera->zReference)); } /* Has reference? */ if(_pstCamera->zReference != orxNULL) { /* Unprotects it */ orxConfig_ProtectSection(_pstCamera->zReference, orxFALSE); } /* Deletes structure */ orxStructure_Delete(_pstCamera); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot delete camera while it is still referenced."); /* Referenced by others */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
/** Gets clock given its name * @param[in] _zName Clock name * @return orxCLOCK / orxNULL */ orxCLOCK *orxFASTCALL orxClock_Get(const orxSTRING _zName) { orxCLOCK *pstResult; /* Checks */ orxASSERT(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY); orxASSERT(_zName != orxNULL); /* Valid name? */ if(_zName != orxSTRING_EMPTY) { /* Updates result */ pstResult = (orxCLOCK *)orxHashTable_Get(sstClock.pstReferenceTable, orxString_ToCRC(_zName)); } else { /* Clears result */ pstResult = orxNULL; } /* Done! */ return pstResult; }
/** 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; }
/** Removes a sound using its config ID * @param[in] _pstSoundPointer Concerned SoundPointer * @param[in] _zSoundConfigID Config ID of the sound to remove * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxSoundPointer_RemoveSoundFromConfig(orxSOUNDPOINTER *_pstSoundPointer, const orxSTRING _zSoundConfigID) { orxU32 i, u32ID; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(sstSoundPointer.u32Flags & orxSOUNDPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstSoundPointer); orxASSERT((_zSoundConfigID != orxNULL) && (_zSoundConfigID != orxSTRING_EMPTY)); /* Gets sound ID */ u32ID = orxString_ToCRC(_zSoundConfigID); /* 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) { /* Found? */ if(orxString_ToCRC(orxSound_GetName(pstSound)) == u32ID) { 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); /* 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; break; } } } /* Done! */ return eResult; }
/** Creates a camera from config * @param[in] _zConfigID Config ID * @ return orxCAMERA / orxNULL */ orxCAMERA *orxFASTCALL orxCamera_CreateFromConfig(const orxSTRING _zConfigID) { orxCAMERA *pstResult; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); /* Search for camera */ pstResult = orxCamera_Get(_zConfigID); /* Not already created? */ if(pstResult == orxNULL) { /* Pushes section */ if((orxConfig_HasSection(_zConfigID) != orxFALSE) && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE)) { /* Creates 2D default camera */ pstResult = orxCamera_Create(orxCAMERA_KU32_FLAG_2D); /* Valid? */ if(pstResult != orxNULL) { orxVECTOR vPosition; orxFLOAT fNear, fFar, fWidth, fHeight; /* Gets frustum info */ fNear = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_NEAR); fFar = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_FAR); fWidth = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_WIDTH); fHeight = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_HEIGHT); /* Applies it */ orxCamera_SetFrustum(pstResult, fWidth, fHeight, fNear, fFar); /* Has zoom? */ if(orxConfig_HasValue(orxCAMERA_KZ_CONFIG_ZOOM) != orxFALSE) { orxFLOAT fZoom; /* Gets config zoom */ fZoom = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_ZOOM); /* Valid? */ if(fZoom > orxFLOAT_0) { /* Applies it */ orxCamera_SetZoom(pstResult, fZoom); } } /* Has a position? */ if(orxConfig_GetVector(orxCAMERA_KZ_CONFIG_POSITION, &vPosition) != orxNULL) { /* Updates camera position */ orxCamera_SetPosition(pstResult, &vPosition); } /* Updates object rotation */ orxCamera_SetRotation(pstResult, orxMATH_KF_DEG_TO_RAD * orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_ROTATION)); /* Stores its reference key */ pstResult->zReference = orxConfig_GetCurrentSection(); /* Protects it */ orxConfig_ProtectSection(pstResult->zReference, orxTRUE); /* Adds it to reference table */ orxHashTable_Add(sstCamera.pstReferenceTable, orxString_ToCRC(pstResult->zReference), pstResult); /* Updates status flags */ orxStructure_SetFlags(pstResult, orxCAMERA_KU32_FLAG_REFERENCED, orxCAMERA_KU32_FLAG_NONE); } /* Pops previous section */ orxConfig_PopSection(); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot find config section named (%s).", _zConfigID); /* Updates result */ pstResult = orxNULL; } } /* Done! */ return pstResult; }
/** 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; }
/** Event handler */ static orxSTATUS orxFASTCALL orxTimeLine_EventHandler(const orxEVENT *_pstEvent) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Add or update? */ if((_pstEvent->eID == orxRESOURCE_EVENT_ADD) || (_pstEvent->eID == orxRESOURCE_EVENT_UPDATE)) { orxRESOURCE_EVENT_PAYLOAD *pstPayload; /* Gets payload */ pstPayload = (orxRESOURCE_EVENT_PAYLOAD *)_pstEvent->pstPayload; /* Is config group? */ if(pstPayload->u32GroupID == orxString_ToCRC(orxCONFIG_KZ_RESOURCE_GROUP)) { orxHANDLE hIterator; orxU64 u64Key; orxTIMELINE_TRACK *pstTrack; /* For all tracks */ for(hIterator = orxHashTable_GetNext(sstTimeLine.pstTrackTable, orxHANDLE_UNDEFINED, &u64Key, (void **)&pstTrack); hIterator != orxHANDLE_UNDEFINED; hIterator = orxHashTable_GetNext(sstTimeLine.pstTrackTable, hIterator, &u64Key, (void **)&pstTrack)) { /* Match origin? */ if(orxConfig_GetOriginID(pstTrack->zReference) == pstPayload->u32NameID) { orxTIMELINE *pstTimeLine; orxTIMELINE_TRACK *pstNewTrack; orxU32 u32Counter, u32ID, u32Flags; const orxSTRING zReference; /* Backups counter, ID, flags & reference */ u32Counter = pstTrack->u32RefCounter; u32ID = pstTrack->u32ID; u32Flags = orxFLAG_GET(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_MASK_BACKUP); zReference = pstTrack->zReference; /* Deletes it (but keeps it reference in the hashtable to prevent infinite loop upon table changes) */ orxMemory_Free(pstTrack); /* Creates new track */ pstNewTrack = orxTimeLine_CreateTrack(zReference); /* Success? */ if(pstNewTrack != orxNULL) { /* Restores its counter */ pstNewTrack->u32RefCounter = u32Counter; /* Restores its flags */ orxFLAG_SET(pstNewTrack->u32Flags, u32Flags, orxTIMELINE_TRACK_KU32_MASK_BACKUP); } else { /* Removes old reference from the table */ orxHashTable_Remove(sstTimeLine.pstTrackTable, u32ID); } /* For all timelines */ for(pstTimeLine = orxTIMELINE(orxStructure_GetFirst(orxSTRUCTURE_ID_TIMELINE)); pstTimeLine != orxNULL; pstTimeLine = orxTIMELINE(orxStructure_GetNext(pstTimeLine))) { orxU32 u32Index; /* For all its track */ for(u32Index = 0; u32Index < orxTIMELINE_KU32_TRACK_NUMBER; u32Index++) { /* Matches? */ if(pstTimeLine->astTrackList[u32Index].pstTrack == pstTrack) { /* Updates its data */ pstTimeLine->astTrackList[u32Index].pstTrack = pstNewTrack; } } } } } } } /* Done! */ return eResult; }
/** Event handler * @param[in] _pstEvent Sent event * @return orxSTATUS_SUCCESS if handled / orxSTATUS_FAILURE otherwise */ static orxSTATUS orxFASTCALL orxText_EventHandler(const orxEVENT *_pstEvent) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Locale? */ if(_pstEvent->eType == orxEVENT_TYPE_LOCALE) { /* Select language event? */ if(_pstEvent->eID == orxLOCALE_EVENT_SELECT_LANGUAGE) { orxTEXT *pstText; /* For all texts */ for(pstText = orxTEXT(orxStructure_GetFirst(orxSTRUCTURE_ID_TEXT)); pstText != orxNULL; pstText = orxTEXT(orxStructure_GetNext(pstText))) { const orxSTRING zLocaleKey; /* Gets its corresponding locale string */ zLocaleKey = orxText_GetLocaleKey(pstText, orxTEXT_KZ_CONFIG_STRING); /* Valid? */ if(zLocaleKey != orxNULL) { const orxSTRING zText; /* Gets its localized value */ zText = orxLocale_GetString(zLocaleKey); /* Valid? */ if(*zText != orxCHAR_NULL) { /* Updates text */ orxText_SetString(pstText, zText); } } /* Gets its corresponding locale font */ zLocaleKey = orxText_GetLocaleKey(pstText, orxTEXT_KZ_CONFIG_FONT); /* Valid? */ if(zLocaleKey != orxNULL) { orxFONT *pstFont; /* Creates font */ pstFont = orxFont_CreateFromConfig(orxLocale_GetString(zLocaleKey)); /* Valid? */ if(pstFont != orxNULL) { /* Updates text */ if(orxText_SetFont(pstText, pstFont) != orxSTATUS_FAILURE) { /* Sets its owner */ orxStructure_SetOwner(pstFont, pstText); /* Updates flags */ orxStructure_SetFlags(pstText, orxTEXT_KU32_FLAG_INTERNAL, orxTEXT_KU32_FLAG_NONE); } else { /* Sets default font */ orxText_SetFont(pstText, orxFONT(orxFont_GetDefaultFont())); } } } } } } /* Resource */ else { /* Checks */ orxASSERT(_pstEvent->eType == orxEVENT_TYPE_RESOURCE); /* Add or update? */ if((_pstEvent->eID == orxRESOURCE_EVENT_ADD) || (_pstEvent->eID == orxRESOURCE_EVENT_UPDATE)) { orxRESOURCE_EVENT_PAYLOAD *pstPayload; /* Gets payload */ pstPayload = (orxRESOURCE_EVENT_PAYLOAD *)_pstEvent->pstPayload; /* Is config group? */ if(pstPayload->u32GroupID == orxString_ToCRC(orxCONFIG_KZ_RESOURCE_GROUP)) { orxTEXT *pstText; /* For all texts */ for(pstText = orxTEXT(orxStructure_GetFirst(orxSTRUCTURE_ID_TEXT)); pstText != orxNULL; pstText = orxTEXT(orxStructure_GetNext(pstText))) { /* Match origin? */ if(orxConfig_GetOriginID(pstText->zReference) == pstPayload->u32NameID) { /* Re-processes its config data */ orxText_ProcessConfigData(pstText); } } } } } /* Done! */ return eResult; }
/** Deletes a clock * @param[in] _pstClock Concerned clock * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxClock_Delete(orxCLOCK *_pstClock) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstClock); /* Decreases counter */ orxStructure_DecreaseCounter(_pstClock); /* Not referenced? */ if(orxStructure_GetRefCounter(_pstClock) == 0) { /* Not locked? */ if(!orxStructure_TestFlags(_pstClock, orxCLOCK_KU32_FLAG_UPDATE_LOCK)) { orxCLOCK_TIMER_STORAGE *pstTimerStorage; /* For all stored timers */ for(pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetFirst(&(_pstClock->stTimerList)); pstTimerStorage != orxNULL; pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetFirst(&(_pstClock->stTimerList))) { /* Removes it */ orxLinkList_Remove(&(pstTimerStorage->stNode)); /* Deletes it */ orxBank_Free(sstClock.pstTimerBank, pstTimerStorage); } /* Deletes function bank */ orxBank_Delete(_pstClock->pstFunctionBank); /* Is referenced? */ if(orxStructure_TestFlags(_pstClock, orxCLOCK_KU32_FLAG_REFERENCED)) { /* Removes it from reference table */ orxHashTable_Remove(sstClock.pstReferenceTable, orxString_ToCRC(_pstClock->zReference)); } /* Has reference? */ if(_pstClock->zReference != orxNULL) { /* Unprotects it */ orxConfig_ProtectSection(_pstClock->zReference, orxFALSE); } /* Deletes clock */ orxStructure_Delete(_pstClock); } else { /* Increases counter */ orxStructure_IncreaseCounter(_pstClock); /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Can't delete clock <%s> as it's currently locked for processing!", orxStructure_TestFlags(_pstClock, orxCLOCK_KU32_FLAG_REFERENCED) ? _pstClock->zReference : orxSTRING_EMPTY); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Referenced by others */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
/** Creates a clock from config * @param[in] _zConfigID Config ID * @ return orxCLOCK / orxNULL */ orxCLOCK *orxFASTCALL orxClock_CreateFromConfig(const orxSTRING _zConfigID) { orxCLOCK *pstResult; /* Checks */ orxASSERT(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY); /* Search for clock */ pstResult = orxClock_Get(_zConfigID); /* Found? */ if(pstResult != orxNULL) { /* Increases counter */ orxStructure_IncreaseCounter(pstResult); } else { /* Pushes section */ if((orxConfig_HasSection(_zConfigID) != orxFALSE) && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE)) { orxFLOAT fFrequency; /* Gets its frequency */ fFrequency = orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_FREQUENCY); /* Creates clock */ pstResult = orxClock_Create((fFrequency > orxFLOAT_0) ? orxFLOAT_1 / fFrequency : orxFLOAT_0, orxCLOCK_TYPE_USER); /* Valid? */ if(pstResult != orxNULL) { /* Has a modifier? */ if(orxConfig_HasValue(orxCLOCK_KZ_CONFIG_MODIFIER_TYPE) != orxFALSE) { orxFLOAT fModifierValue; /* Gets its value */ fModifierValue = orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MODIFIER_VALUE); /* Valid? */ if(fModifierValue > orxFLOAT_0) { const orxSTRING zModifierType; orxCLOCK_MOD_TYPE eModifierType; /* Gets modifier type */ zModifierType = orxConfig_GetString(orxCLOCK_KZ_CONFIG_MODIFIER_TYPE); /* Capped? */ if(orxString_ICompare(zModifierType, orxCLOCK_KZ_MODIFIER_CAPPED) == 0) { /* Updates modifier value */ fModifierValue = orxFLOAT_1 / fModifierValue; /* Updates modifier type */ eModifierType = orxCLOCK_MOD_TYPE_MAXED; } /* Fixed? */ else if(orxString_ICompare(zModifierType, orxCLOCK_KZ_MODIFIER_FIXED) == 0) { /* Updates modifier value */ fModifierValue = orxFLOAT_1 / fModifierValue; /* Updates modifier type */ eModifierType = orxCLOCK_MOD_TYPE_FIXED; } /* Multiply? */ else if(orxString_ICompare(zModifierType, orxCLOCK_KZ_MODIFIER_MULTIPLY) == 0) { /* Updates modifier type */ eModifierType = orxCLOCK_MOD_TYPE_MULTIPLY; } /* None */ else { /* Updates modifier type */ eModifierType = orxCLOCK_MOD_TYPE_NONE; } /* Updates clock */ orxClock_SetModifier(pstResult, eModifierType, fModifierValue); } } /* Stores its reference key */ pstResult->zReference = orxConfig_GetCurrentSection(); /* Protects it */ orxConfig_ProtectSection(pstResult->zReference, orxTRUE); /* Adds it to reference table */ orxHashTable_Add(sstClock.pstReferenceTable, orxString_ToCRC(pstResult->zReference), pstResult); /* Updates status flags */ orxStructure_SetFlags(pstResult, orxCLOCK_KU32_FLAG_REFERENCED, orxCLOCK_KU32_FLAG_NONE); } /* Pops previous section */ orxConfig_PopSection(); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot find config section named (%s).", _zConfigID); /* Updates result */ pstResult = orxNULL; } } /* Done! */ return pstResult; }