/** Adds a node as a sibling of another one * @param[in] _pstRefNode Reference node (add as a sibling of this one) * @param[in] _pstNode Node to add * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTree_AddSibling(orxTREE_NODE *_pstRefNode, orxTREE_NODE *_pstNode) { orxSTATUS eResult = orxSTATUS_SUCCESS; orxTREE *pstTree; /* Checks */ orxASSERT(_pstRefNode != orxNULL); orxASSERT(_pstNode != orxNULL); /* Isn't already in a tree? */ if(_pstNode->pstTree == orxNULL) { /* Gets tree */ pstTree = _pstRefNode->pstTree; /* Valid? */ if(pstTree != orxNULL) { /* Isn't the root? */ if(pstTree->pstRoot != _pstRefNode) { /* Checks */ orxASSERT(_pstRefNode->pstParent != orxNULL); /* Adds it in the tree */ _pstNode->pstParent = _pstRefNode->pstParent; _pstNode->pstSibling = _pstRefNode->pstSibling; _pstNode->pstTree = pstTree; _pstNode->pstChild = orxNULL; /* Updates ref node */ _pstRefNode->pstSibling = _pstNode; /* Updates counter */ pstTree->u32Counter++; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Can't add a node as a sibling of the root node."); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Destination's tree is invalid."); /* No tree found */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Node is already in a tree, use MoveAsChild instead."); /* Already in a tree */ eResult = orxSTATUS_FAILURE; } /* 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; }
/** 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; }
/** Sets camera parent * @param[in] _pstCamera Concerned camera * @param[in] _pParent Parent structure to set (object, camera or frame) / orxNULL * @return orsSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxCamera_SetParent(orxCAMERA *_pstCamera, void *_pParent) { orxFRAME *pstFrame; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstCamera); orxASSERT((_pParent == orxNULL) || (((orxSTRUCTURE *)(_pParent))->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE) < orxSTRUCTURE_ID_NUMBER); /* Gets frame */ pstFrame = _pstCamera->pstFrame; /* No parent? */ if(_pParent == orxNULL) { /* Removes parent */ orxFrame_SetParent(pstFrame, orxNULL); } else { /* Depending on parent ID */ switch(orxStructure_GetID(_pParent)) { case orxSTRUCTURE_ID_CAMERA: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxCAMERA(_pParent)->pstFrame); break; } case orxSTRUCTURE_ID_FRAME: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxFRAME(_pParent)); break; } case orxSTRUCTURE_ID_OBJECT: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxOBJECT_GET_STRUCTURE(orxOBJECT(_pParent), FRAME)); break; } case orxSTRUCTURE_ID_SPAWNER: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxSpawner_GetFrame(orxSPAWNER(_pParent))); break; } default: { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Invalid ID for structure."); /* Updates result */ eResult = orxSTATUS_FAILURE; break; } } } /* 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; }
static orxSTATUS orxFASTCALL ParseTextFile(const orxSTRING _zFileName) { orxFILE *pstFile; orxSTATUS eResult; // Opens file pstFile = orxFile_Open(_zFileName, orxFILE_KU32_FLAG_OPEN_READ | orxFILE_KU32_FLAG_OPEN_BINARY); // Success? if(pstFile) { orxCHAR acBuffer[orxFONTGEN_KU32_BUFFER_SIZE]; orxU32 u32Size, u32Offset, u32Counter; orxBOOL bFirst; // While file isn't empty for(u32Size = (orxU32)orxFile_Read(acBuffer, sizeof(orxCHAR), orxFONTGEN_KU32_BUFFER_SIZE, pstFile), u32Offset = 0, u32Counter = 0, bFirst = orxTRUE; u32Size > 0; u32Size = (orxU32)orxFile_Read(acBuffer + u32Offset, sizeof(orxCHAR), orxFONTGEN_KU32_BUFFER_SIZE - u32Offset, pstFile) + u32Offset, bFirst = orxFALSE) { orxCHAR *pc, *pcNext; // Has UTF-8 BOM? if((bFirst != orxFALSE) && (orxString_NCompare(acBuffer, orxFONTGEN_KZ_UTF8_BOM, orxFONTGEN_KU32_UTF8_BOM_LENGTH) == 0)) { // Skips it pc = acBuffer + orxFONTGEN_KU32_UTF8_BOM_LENGTH; } else { // Starts at the beginning of the buffer pc = acBuffer; } // For all characters for(pcNext = orxNULL; pc < acBuffer + u32Size; pc = pcNext) { orxU32 u32CharacterCodePoint; // Reads it u32CharacterCodePoint = orxString_GetFirstCharacterCodePoint(pc, (const orxSTRING *)&pcNext); // Non EOL? if((u32CharacterCodePoint != orxCHAR_CR) && (u32CharacterCodePoint != orxCHAR_LF)) { // Valid? if(u32CharacterCodePoint != orxU32_UNDEFINED) { // Not already in table? if(orxHashTable_Get(sstFontGen.pstCharacterTable, u32CharacterCodePoint) == orxNULL) { orxU32 u32GlyphIndex; // Gets character's glyph index u32GlyphIndex = (orxU32)FT_Get_Char_Index(sstFontGen.pstFontFace, (FT_ULong)u32CharacterCodePoint); // Valid? if(u32GlyphIndex) { orxFONTGEN_GLYPH *pstGlyph; // Allocates glyph pstGlyph = (orxFONTGEN_GLYPH *)orxBank_Allocate(sstFontGen.pstGlyphBank); // Checks orxASSERT(pstGlyph); // Inits it pstGlyph->u32Index = u32GlyphIndex; pstGlyph->u32CodePoint = u32CharacterCodePoint; // Adds it if(orxHashTable_Add(sstFontGen.pstCharacterTable, u32CharacterCodePoint, (void *)pstGlyph) != orxSTATUS_FAILURE) { orxFONTGEN_GLYPH *pstSearchGlyph; // Finds position for(pstSearchGlyph = (orxFONTGEN_GLYPH *)orxLinkList_GetFirst(&sstFontGen.stGlyphList); pstSearchGlyph && (u32CharacterCodePoint > pstSearchGlyph->u32CodePoint); pstSearchGlyph = (orxFONTGEN_GLYPH *)orxLinkList_GetNext(&pstSearchGlyph->stNode)); // Valid? if(pstSearchGlyph) { // Adds it before orxLinkList_AddBefore(&pstSearchGlyph->stNode, &pstGlyph->stNode); } else { // Adds it at the end orxLinkList_AddEnd(&sstFontGen.stGlyphList, &pstGlyph->stNode); } // Updates counter u32Counter++; } else { // Logs message orxFONTGEN_LOG(LOAD, "Character '0x%X': couldn't add to table, skipping.", u32CharacterCodePoint); } } else { // Adds it orxHashTable_Add(sstFontGen.pstCharacterTable, u32CharacterCodePoint, (void *)sstFontGen.pstCharacterTable); // Logs message orxFONTGEN_LOG(LOAD, "Character '0x%X': glyph not found in font, skipping.", u32CharacterCodePoint); } } } else { // End of buffer? if(pcNext >= acBuffer + u32Size) { // Stops break; } else { // Logs message orxFONTGEN_LOG(LOAD, "Invalid character code point '0x%X', skipping.", u32CharacterCodePoint); } } } } // Has remaining buffer? if((pc != acBuffer) && (pcNext > pc)) { // Updates offset u32Offset = (orxU32)(orxMIN(pcNext, acBuffer + u32Size) - pc); // Copies it at the beginning of the buffer orxMemory_Copy(acBuffer, pc, u32Offset); } else { // Clears offset u32Offset = 0; } } // Logs message orxFONTGEN_LOG(LOAD, "'%s': added %d characters.", _zFileName, u32Counter); // Updates result eResult = orxSTATUS_SUCCESS; } else { // Updates result eResult = orxSTATUS_FAILURE; } // 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; }
/** 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; }
/** 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; }
/** Computes next screenshot index * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ static orxINLINE orxSTATUS orxScreenshot_ComputeIndex() { const orxSTRING zDirectory; const orxSTRING zBaseName; const orxSTRING zExtension; orxU32 u32Digits; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstScreenshot.u32Flags & orxSCREENSHOT_KU32_STATIC_FLAG_READY) /* Uses default directory, base name, extension & digits */ zDirectory = orxSCREENSHOT_KZ_DEFAULT_DIRECTORY_NAME; zBaseName = orxSCREENSHOT_KZ_DEFAULT_BASE_NAME; zExtension = orxSCREENSHOT_KZ_DEFAULT_EXTENSION; u32Digits = orxSCREENSHOT_KU32_DEFAULT_DIGITS; /* Pushes section */ if((orxConfig_HasSection(orxSCREENSHOT_KZ_CONFIG_SECTION) != orxFALSE) && (orxConfig_PushSection(orxSCREENSHOT_KZ_CONFIG_SECTION) != orxSTATUS_FAILURE)) { const orxSTRING zValue; orxU32 u32Value; /* Gets directory name */ zValue = orxConfig_GetString(orxSCREENSHOT_KZ_CONFIG_DIRECTORY); /* Valid? */ if((zValue != orxNULL) && (zValue != orxSTRING_EMPTY)) { /* Stores it */ zDirectory = zValue; } /* Gets screenshot base name */ zValue = orxConfig_GetString(orxSCREENSHOT_KZ_CONFIG_BASE_NAME); /* Valid? */ if((zValue != orxNULL) && (zValue != orxSTRING_EMPTY)) { /* Stores it */ zBaseName = zValue; } /* Gets screenshot extension */ zValue = orxConfig_GetString(orxSCREENSHOT_KZ_CONFIG_EXTENSION); /* Valid? */ if((zValue != orxNULL) && (zValue != orxSTRING_EMPTY)) { /* Stores it */ zExtension = zValue; } /* Gets digit number */ if((u32Value = orxConfig_GetU32(orxSCREENSHOT_KZ_CONFIG_DIGITS)) > 0) { /* Stores it */ u32Digits = u32Value; } /* Pops previous section */ orxConfig_PopSection(); } /* Valid? */ if(orxFile_Exists(zDirectory) != orxFALSE) { do { /* Gets file to find name */ orxString_NPrint(sstScreenshot.acScreenshotBuffer, orxSCREENSHOT_KU32_BUFFER_SIZE - 1, "%s/%s%0*d.%s", zDirectory, zBaseName, u32Digits, sstScreenshot.u32ScreenshotIndex + 1, zExtension); /* Updates screenshot index */ sstScreenshot.u32ScreenshotIndex++; } /* Till not found */ while(orxFile_Exists(sstScreenshot.acScreenshotBuffer) != orxFALSE); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SCREENSHOT, "Invalid directory [%s]. Please create it to enable screenshots.", zDirectory); /* Can't find folder */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
void InfoWindow::OnTextAccepted (const string& widgetName) { orxASSERT (false); }
orxBOOL orxFASTCALL orxMouse_GLFW_IsButtonPressed(orxMOUSE_BUTTON _eButton) { orxBOOL bResult; /* Checks */ orxASSERT((sstMouse.u32Flags & orxMOUSE_KU32_STATIC_FLAG_READY) == orxMOUSE_KU32_STATIC_FLAG_READY); orxASSERT(_eButton < orxMOUSE_BUTTON_NUMBER); /* Depending on button */ switch(_eButton) { case orxMOUSE_BUTTON_LEFT: { /* Updates result */ bResult = (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT) != GL_FALSE) ? orxTRUE : orxFALSE; break; } case orxMOUSE_BUTTON_RIGHT: { /* Updates result */ bResult = (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT) != GL_FALSE) ? orxTRUE : orxFALSE; break; } case orxMOUSE_BUTTON_MIDDLE: { /* Updates result */ bResult = (glfwGetMouseButton(GLFW_MOUSE_BUTTON_MIDDLE) != GL_FALSE) ? orxTRUE : orxFALSE; break; } case orxMOUSE_BUTTON_EXTRA_1: { /* Updates result */ bResult = (glfwGetMouseButton(GLFW_MOUSE_BUTTON_4) != GL_FALSE) ? orxTRUE : orxFALSE; break; } case orxMOUSE_BUTTON_EXTRA_2: { /* Updates result */ bResult = (glfwGetMouseButton(GLFW_MOUSE_BUTTON_5) != GL_FALSE) ? orxTRUE : orxFALSE; break; } case orxMOUSE_BUTTON_WHEEL_UP: { /* Updates result */ bResult = (sstMouse.fInternalWheelMove > orxFLOAT_0) ? orxTRUE : orxFALSE; break; } case orxMOUSE_BUTTON_WHEEL_DOWN: { /* Updates result */ bResult = (sstMouse.fInternalWheelMove < orxFLOAT_0) ? orxTRUE : orxFALSE; break; } default: { /* Updates result */ bResult = orxFALSE; break; } } /* Done! */ return bResult; }
/** Removes a node from its tree * @param[in] _pstNode Concerned node * @param[in] _bBranchRemove Remove the whole branch or only the single node * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ static orxSTATUS orxFASTCALL orxTree_PrivateRemove(orxTREE_NODE *_pstNode, orxBOOL _bBranchRemove) { orxTREE *pstTree; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(_pstNode != orxNULL); /* Gets tree */ pstTree = _pstNode->pstTree; /* Remove the whole branch? */ if(_bBranchRemove != orxFALSE) { /* Isn't root? */ if(pstTree->pstRoot != _pstNode) { /* Was firt child? */ if(_pstNode->pstParent->pstChild == _pstNode) { /* Udpates parent */ _pstNode->pstParent->pstChild = _pstNode->pstSibling; } else { orxTREE_NODE *pstChild; /* Finds left sibling */ for(pstChild = _pstNode->pstParent->pstChild; pstChild->pstSibling != _pstNode; pstChild = pstChild->pstSibling); /* Updates it */ pstChild->pstSibling = _pstNode->pstSibling; } /* Updates node */ _pstNode->pstParent = orxNULL; _pstNode->pstSibling = orxNULL; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Node isn't root."); /* Can't process */ eResult = orxSTATUS_FAILURE; } } /* Remove completely from tree */ else { /* Is root? */ if(pstTree->pstRoot == _pstNode) { /* Is the last node in tree? */ if(pstTree->u32Counter == 1) { /* Removes it */ pstTree->pstRoot = orxNULL; /* Updates node */ orxMemory_Zero(_pstNode, sizeof(orxTREE_NODE)); /* Updates counter */ pstTree->u32Counter = 0; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Node is not last one in tree."); /* Can't process */ eResult = orxSTATUS_FAILURE; } } else { orxTREE_NODE *pstNewChild; /* Had child? */ if(_pstNode->pstChild != orxNULL) { orxTREE_NODE *pstChild; /* Updates all children but last */ for(pstChild = _pstNode->pstChild; pstChild->pstSibling != orxNULL; pstChild = pstChild->pstSibling) { /* Updates it */ pstChild->pstParent = _pstNode->pstParent; } /* Updates last child */ pstChild->pstParent = _pstNode->pstParent; pstChild->pstSibling = _pstNode->pstSibling; /* New parent's child is previous first child */ pstNewChild = _pstNode->pstChild; } /* No child */ else { /* New parent's child is previous sibling */ pstNewChild = _pstNode->pstSibling; } /* Was first child? */ if(_pstNode->pstParent->pstChild == _pstNode) { /* Updates parent */ _pstNode->pstParent->pstChild = pstNewChild; } /* Not first child */ else { orxTREE_NODE *pstChild; /* Find left sibling */ for(pstChild = _pstNode->pstParent->pstChild; pstChild->pstSibling != _pstNode; pstChild = pstChild->pstSibling); /* Updates it */ pstChild->pstSibling = pstNewChild; } /* Updates node */ orxMemory_Zero(_pstNode, sizeof(orxTREE_NODE)); /* Updates counter */ pstTree->u32Counter--; } } /* Done! */ return eResult; }
/** Moves a node as a child of another one of the same tree * @param[in] _pstRefNode Reference node (move as a child of this one) * @param[in] _pstNode Node to move * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTree_MoveAsChild(orxTREE_NODE *_pstRefNode, orxTREE_NODE *_pstNode) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(_pstRefNode != orxNULL); orxASSERT(_pstNode != orxNULL); /* Is already in the same tree? */ if(_pstNode->pstTree == _pstRefNode->pstTree) { orxTREE_NODE *pstTest; /* Checks for preventing tree from turning into graph */ for(pstTest = _pstRefNode; (pstTest != orxNULL) && (pstTest != _pstNode); pstTest = pstTest->pstParent); /* No graph cycle found? */ if(pstTest == orxNULL) { /* Removes it from its place */ eResult = orxTree_PrivateRemove(_pstNode, orxTRUE); /* Success? */ if(eResult != orxSTATUS_FAILURE) { /* Adds it at new place */ _pstNode->pstParent = _pstRefNode; _pstNode->pstSibling = _pstRefNode->pstChild; /* Updates ref node */ _pstRefNode->pstChild = _pstNode; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Failed to remove node from current tree when attempting to move."); } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Graph cycle found, invalid move."); /* Can't process */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Attempted to move node between two different trees."); /* Not already in the tree */ 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; }
/** Inits a module recursively */ orxSTATUS orxFASTCALL orxModule_Init(orxMODULE_ID _eModuleID) { orxU64 u64Depend; orxU32 u32Index; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(orxMODULE_ID_NUMBER <= orxMODULE_ID_MAX_NUMBER); orxASSERT(_eModuleID < orxMODULE_ID_NUMBER); /* Increases loop counter */ sstModule.u32InitLoopCounter++; /* Is module registered? */ if(sstModule.astModuleInfo[_eModuleID].u32StatusFlags & orxMODULE_KU32_STATUS_FLAG_REGISTERED) { /* Is not initialized? */ if(!(sstModule.astModuleInfo[_eModuleID].u32StatusFlags & (orxMODULE_KU32_STATUS_FLAG_INITIALIZED|orxMODULE_KU32_STATUS_FLAG_PENDING))) { /* For all dependencies */ for(u64Depend = sstModule.astModuleInfo[_eModuleID].u64DependFlags, u32Index = 0; u64Depend != (orxU64)0; u64Depend >>= 1, u32Index++) { /* Depends? */ if(u64Depend & (orxU64)1) { /* Not already initialized */ if(!(sstModule.astModuleInfo[u32Index].u32StatusFlags & (orxMODULE_KU32_STATUS_FLAG_INITIALIZED|orxMODULE_KU32_STATUS_FLAG_PENDING))) { /* Inits it */ eResult = orxModule_Init((orxMODULE_ID)u32Index); /* Success ? */ if(eResult != orxSTATUS_FAILURE) { /* Updates flags */ sstModule.astModuleInfo[u32Index].u64ParentFlags |= (orxU64)1 << _eModuleID; } else { /* Stops init here */ break; } } } } /* Success? */ if(eResult != orxSTATUS_FAILURE) { /* For all optional dependencies */ for(u64Depend = sstModule.astModuleInfo[_eModuleID].u64OptionalDependFlags, u32Index = 0; u64Depend != (orxU64)0; u64Depend >>= 1, u32Index++) { /* Depends? */ if(u64Depend & (orxU64)1) { /* Not already initialized */ if(!(sstModule.astModuleInfo[u32Index].u32StatusFlags & orxMODULE_KU32_STATUS_FLAG_INITIALIZED)) { /* Inits it */ if(orxModule_Init((orxMODULE_ID)u32Index) != orxSTATUS_FAILURE) { /* Updates flags */ sstModule.astModuleInfo[u32Index].u64ParentFlags |= (orxU64)1 << _eModuleID; } } } } /* Not already initialized */ if(!(sstModule.astModuleInfo[_eModuleID].u32StatusFlags & orxMODULE_KU32_STATUS_FLAG_INITIALIZED)) { /* Updates temp flag */ sstModule.astModuleInfo[_eModuleID].u32StatusFlags |= orxMODULE_KU32_STATUS_FLAG_PENDING; /* Calls module init function */ eResult = (sstModule.astModuleInfo[_eModuleID].pfnInit != orxNULL) ? sstModule.astModuleInfo[_eModuleID].pfnInit() : orxSTATUS_SUCCESS; /* Successful? */ if(eResult != orxSTATUS_FAILURE) { /* Updates initialized flag */ sstModule.astModuleInfo[_eModuleID].u32StatusFlags |= orxMODULE_KU32_STATUS_FLAG_INITIALIZED; } else { /* Updates temp flag */ sstModule.astModuleInfo[_eModuleID].u32StatusFlags &= ~orxMODULE_KU32_STATUS_FLAG_PENDING; } } } } } else {
/** Gets key literal name * @param[in] _eKey Concerned key * @return Key's name */ const orxSTRING orxFASTCALL orxKeyboard_GetKeyName(orxKEYBOARD_KEY _eKey) { const orxSTRING zResult; #define orxKEYBOARD_DECLARE_KEY_NAME(KEY) case orxKEYBOARD_KEY_##KEY: zResult = orxKEYBOARD_KZ_LITERAL_PREFIX#KEY; break /* Checks */ orxASSERT(_eKey < orxKEYBOARD_KEY_NUMBER); /* Depending on key */ switch(_eKey) { orxKEYBOARD_DECLARE_KEY_NAME(A); orxKEYBOARD_DECLARE_KEY_NAME(B); orxKEYBOARD_DECLARE_KEY_NAME(C); orxKEYBOARD_DECLARE_KEY_NAME(D); orxKEYBOARD_DECLARE_KEY_NAME(E); orxKEYBOARD_DECLARE_KEY_NAME(F); orxKEYBOARD_DECLARE_KEY_NAME(G); orxKEYBOARD_DECLARE_KEY_NAME(H); orxKEYBOARD_DECLARE_KEY_NAME(I); orxKEYBOARD_DECLARE_KEY_NAME(J); orxKEYBOARD_DECLARE_KEY_NAME(K); orxKEYBOARD_DECLARE_KEY_NAME(L); orxKEYBOARD_DECLARE_KEY_NAME(M); orxKEYBOARD_DECLARE_KEY_NAME(N); orxKEYBOARD_DECLARE_KEY_NAME(O); orxKEYBOARD_DECLARE_KEY_NAME(P); orxKEYBOARD_DECLARE_KEY_NAME(Q); orxKEYBOARD_DECLARE_KEY_NAME(R); orxKEYBOARD_DECLARE_KEY_NAME(S); orxKEYBOARD_DECLARE_KEY_NAME(T); orxKEYBOARD_DECLARE_KEY_NAME(U); orxKEYBOARD_DECLARE_KEY_NAME(V); orxKEYBOARD_DECLARE_KEY_NAME(W); orxKEYBOARD_DECLARE_KEY_NAME(X); orxKEYBOARD_DECLARE_KEY_NAME(Y); orxKEYBOARD_DECLARE_KEY_NAME(Z); orxKEYBOARD_DECLARE_KEY_NAME(0); orxKEYBOARD_DECLARE_KEY_NAME(1); orxKEYBOARD_DECLARE_KEY_NAME(2); orxKEYBOARD_DECLARE_KEY_NAME(3); orxKEYBOARD_DECLARE_KEY_NAME(4); orxKEYBOARD_DECLARE_KEY_NAME(5); orxKEYBOARD_DECLARE_KEY_NAME(6); orxKEYBOARD_DECLARE_KEY_NAME(7); orxKEYBOARD_DECLARE_KEY_NAME(8); orxKEYBOARD_DECLARE_KEY_NAME(9); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_0); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_1); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_2); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_3); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_4); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_5); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_6); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_7); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_8); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_9); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_RETURN); orxKEYBOARD_DECLARE_KEY_NAME(NUMPAD_DECIMAL); orxKEYBOARD_DECLARE_KEY_NAME(NUM_LOCK); orxKEYBOARD_DECLARE_KEY_NAME(SCROLL_LOCK); orxKEYBOARD_DECLARE_KEY_NAME(CAPS_LOCK); orxKEYBOARD_DECLARE_KEY_NAME(F1); orxKEYBOARD_DECLARE_KEY_NAME(F2); orxKEYBOARD_DECLARE_KEY_NAME(F3); orxKEYBOARD_DECLARE_KEY_NAME(F4); orxKEYBOARD_DECLARE_KEY_NAME(F5); orxKEYBOARD_DECLARE_KEY_NAME(F6); orxKEYBOARD_DECLARE_KEY_NAME(F7); orxKEYBOARD_DECLARE_KEY_NAME(F8); orxKEYBOARD_DECLARE_KEY_NAME(F9); orxKEYBOARD_DECLARE_KEY_NAME(F10); orxKEYBOARD_DECLARE_KEY_NAME(F11); orxKEYBOARD_DECLARE_KEY_NAME(F12); orxKEYBOARD_DECLARE_KEY_NAME(F13); orxKEYBOARD_DECLARE_KEY_NAME(F14); orxKEYBOARD_DECLARE_KEY_NAME(F15); orxKEYBOARD_DECLARE_KEY_NAME(UP); orxKEYBOARD_DECLARE_KEY_NAME(RIGHT); orxKEYBOARD_DECLARE_KEY_NAME(DOWN); orxKEYBOARD_DECLARE_KEY_NAME(LEFT); orxKEYBOARD_DECLARE_KEY_NAME(ESCAPE); orxKEYBOARD_DECLARE_KEY_NAME(SPACE); orxKEYBOARD_DECLARE_KEY_NAME(RETURN); orxKEYBOARD_DECLARE_KEY_NAME(BACKSPACE); orxKEYBOARD_DECLARE_KEY_NAME(TAB); orxKEYBOARD_DECLARE_KEY_NAME(PAGEUP); orxKEYBOARD_DECLARE_KEY_NAME(PAGEDOWN); orxKEYBOARD_DECLARE_KEY_NAME(END); orxKEYBOARD_DECLARE_KEY_NAME(HOME); orxKEYBOARD_DECLARE_KEY_NAME(INSERT); orxKEYBOARD_DECLARE_KEY_NAME(DELETE); orxKEYBOARD_DECLARE_KEY_NAME(ADD); orxKEYBOARD_DECLARE_KEY_NAME(SUBTRACT); orxKEYBOARD_DECLARE_KEY_NAME(MULTIPLY); orxKEYBOARD_DECLARE_KEY_NAME(DIVIDE); orxKEYBOARD_DECLARE_KEY_NAME(PAUSE); orxKEYBOARD_DECLARE_KEY_NAME(RALT); orxKEYBOARD_DECLARE_KEY_NAME(RCTRL); orxKEYBOARD_DECLARE_KEY_NAME(RSHIFT); orxKEYBOARD_DECLARE_KEY_NAME(RSYSTEM); orxKEYBOARD_DECLARE_KEY_NAME(LALT); orxKEYBOARD_DECLARE_KEY_NAME(LCTRL); orxKEYBOARD_DECLARE_KEY_NAME(LSHIFT); orxKEYBOARD_DECLARE_KEY_NAME(LSYSTEM); orxKEYBOARD_DECLARE_KEY_NAME(MENU); orxKEYBOARD_DECLARE_KEY_NAME(LBRACKET); orxKEYBOARD_DECLARE_KEY_NAME(RBRACKET); orxKEYBOARD_DECLARE_KEY_NAME(SEMICOLON); orxKEYBOARD_DECLARE_KEY_NAME(COMMA); orxKEYBOARD_DECLARE_KEY_NAME(PERIOD); orxKEYBOARD_DECLARE_KEY_NAME(QUOTE); orxKEYBOARD_DECLARE_KEY_NAME(SLASH); orxKEYBOARD_DECLARE_KEY_NAME(BACKSLASH); orxKEYBOARD_DECLARE_KEY_NAME(BACKQUOTE); orxKEYBOARD_DECLARE_KEY_NAME(EQUAL); orxKEYBOARD_DECLARE_KEY_NAME(DASH); default: { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_KEYBOARD, "No name defined for key #%d.", _eKey); /* Updates result */ zResult = orxSTRING_EMPTY; } } /* Done! */ return zResult; }
/** Loads a plugin using OS common library extension + release/debug suffixes * @param[in] _zPluginFileName The complete path of the plugin file, without its library extension * @param[in] _zPluginName The name that the plugin will be given in the plugin list * @return The plugin handle on success, orxHANDLE_UNDEFINED on failure */ orxHANDLE orxFASTCALL orxPlugin_LoadUsingExt(const orxSTRING _zPluginFileName, const orxSTRING _zPluginName) { orxHANDLE hResult = orxHANDLE_UNDEFINED; #ifdef __orxPLUGIN_DYNAMIC__ orxCHAR zFileName[256]; #ifdef __orxDEBUG__ orxSTRING zDebugSuffix; /* Pushes section */ orxConfig_PushSection(orxPLUGIN_KZ_CONFIG_SECTION); #endif /* __ orxDEBUG__ */ /* Checks */ orxASSERT(sstPlugin.u32Flags & orxPLUGIN_KU32_STATIC_FLAG_READY); orxASSERT(_zPluginFileName != orxNULL); orxASSERT(orxString_GetLength(_zPluginFileName) + orxMAX(orxString_GetLength(orxConfig_GetString(orxPLUGIN_KZ_CONFIG_DEBUG_SUFFIX)), orxString_GetLength(orxPLUGIN_KZ_DEFAULT_DEBUG_SUFFIX)) < 252); orxASSERT(_zPluginName != orxNULL); /* Inits buffer */ zFileName[sizeof(zFileName) - 1] = orxCHAR_NULL; #ifdef __orxDEBUG__ /* Gets debug suffix */ zDebugSuffix = (orxSTRING)((orxConfig_HasValue(orxPLUGIN_KZ_CONFIG_DEBUG_SUFFIX) != orxFALSE) ? orxConfig_GetString(orxPLUGIN_KZ_CONFIG_DEBUG_SUFFIX) : orxPLUGIN_KZ_DEFAULT_DEBUG_SUFFIX); /* Gets complete name */ orxString_NPrint(zFileName, sizeof(zFileName) - 1, "%s%s.%s", _zPluginFileName, zDebugSuffix, szPluginLibraryExt); /* Loads it */ hResult = orxPlugin_Load(zFileName, _zPluginName); /* Not valid? */ if(hResult == orxHANDLE_UNDEFINED) { #endif /* __orxDEBUG__ */ /* Gets complete name */ orxString_NPrint(zFileName, sizeof(zFileName) - 1, "%s.%s", _zPluginFileName, szPluginLibraryExt); /* Loads it */ hResult = orxPlugin_Load(zFileName, _zPluginName); #ifdef __orxDEBUG__ } /* Pops previous section */ orxConfig_PopSection(); #endif /* __orxDEBUG__ */ #else /* __orxPLUGIN_DYNAMIC__ */ /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Ignoring function call: this version of orx has been compiled without dynamic plugin support."); #endif /* __orxPLUGIN_DYNAMIC__ */ /* Done! */ return hResult; }
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); }
/** Registers a plugin * @param[in] _pstSysPlugin Concerned plugin * @param[in] _pstPluginInfo Info of the plugin to register * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ static orxSTATUS orxPlugin_RegisterPlugin(orxPLUGIN_INFO *_pstPluginInfo) { orxPLUGIN_INIT_FUNCTION pfnInit; orxU32 u32UserFunctionNumber; orxPLUGIN_USER_FUNCTION_INFO *astUserFunctionInfo; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(_pstPluginInfo != orxNULL); /* Gets init function */ pfnInit = (orxPLUGIN_INIT_FUNCTION)orxPlugin_GetFunctionAddress(_pstPluginInfo->pstSysPlugin, orxPLUGIN_KZ_INIT_FUNCTION_NAME); /* Valid? */ if(pfnInit != orxNULL) { orxU32 i; /* Calls it */ eResult = pfnInit(&u32UserFunctionNumber, &astUserFunctionInfo); /* Adds all functions to plugin info */ for(i = 0; (eResult != orxSTATUS_FAILURE) && (i < u32UserFunctionNumber); i++) { /* Is function valid? */ if(astUserFunctionInfo[i].pfnFunction != orxNULL) { orxPLUGIN_FUNCTION_INFO *pstFunctionInfo; /* Creates function info */ pstFunctionInfo = orxPlugin_CreateFunctionInfo(_pstPluginInfo); /* Copies info */ pstFunctionInfo->pfnFunction = astUserFunctionInfo[i].pfnFunction; pstFunctionInfo->eFunctionID = astUserFunctionInfo[i].eFunctionID; pstFunctionInfo->zFunctionArgs = astUserFunctionInfo[i].zFunctionArgs; pstFunctionInfo->zFunctionName = astUserFunctionInfo[i].zFunctionName; /* Adds function info in plugin info structure */ orxHashTable_Add(_pstPluginInfo->pstFunctionTable, pstFunctionInfo->eFunctionID, pstFunctionInfo); /* Is it a core function? */ if(pstFunctionInfo->eFunctionID & orxPLUGIN_KU32_FLAG_CORE_ID) { /* Registers core function */ eResult = orxPlugin_RegisterCoreFunction(pstFunctionInfo->eFunctionID, pstFunctionInfo->pfnFunction, orxFALSE); } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Invalid function."); /* Updates result */ eResult = orxSTATUS_FAILURE; } } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Failed to get function address."); /* Can't load plugin */ eResult = orxSTATUS_FAILURE; } /* 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; }
/** Loads a plugin (using its exact complete name) * @param[in] _zPluginFileName The complete path of the plugin file, including its extension * @param[in] _zPluginName The name that the plugin will be given in the plugin list * @return The plugin handle on success, orxHANDLE_UNDEFINED on failure */ orxHANDLE orxFASTCALL orxPlugin_Load(const orxSTRING _zPluginFileName, const orxSTRING _zPluginName) { orxHANDLE hPluginHandle = orxHANDLE_UNDEFINED; #ifdef __orxPLUGIN_DYNAMIC__ orxSYSPLUGIN pstSysPlugin; orxPLUGIN_INFO *pstPluginInfo; /* Checks */ orxASSERT(sstPlugin.u32Flags & orxPLUGIN_KU32_STATIC_FLAG_READY); orxASSERT(_zPluginFileName != orxNULL); orxASSERT(_zPluginName != orxNULL); /* Opens plugin */ pstSysPlugin = orxPLUGIN_OPEN(_zPluginFileName); /* Valid? */ if(pstSysPlugin != orxNULL) { /* Creates plugin info */ pstPluginInfo = orxPlugin_CreatePluginInfo(); /* Valid? */ if(pstPluginInfo != orxNULL) { /* Stores plugin info */ pstPluginInfo->pstSysPlugin = pstSysPlugin; pstPluginInfo->hPluginHandle = (orxHANDLE)pstPluginInfo; /* Registers plugin */ if(orxPlugin_RegisterPlugin(pstPluginInfo) != orxSTATUS_FAILURE) { /* Stores plugin name */ pstPluginInfo->zPluginName = _zPluginName; /* Gets plugin handle */ hPluginHandle = pstPluginInfo->hPluginHandle; } else { /* Logs an error */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Couldn't register the plugin <%s>, closing it.", _zPluginFileName); /* Closes plugin */ orxPLUGIN_CLOSE(pstSysPlugin); /* Deletes allocated plugin info */ orxPlugin_DeletePluginInfo(pstPluginInfo); /* Empty plugin */ hPluginHandle = orxHANDLE_UNDEFINED; } } else { /* Logs an error */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Couldn't create a plugin info for plugin <%s>.", _zPluginFileName); /* Closes plugin */ orxPLUGIN_CLOSE(pstSysPlugin); } } else { /* Logs an error */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Couldn't load the plugin <%s>.", _zPluginFileName); } #else /* __orxPLUGIN_DYNAMIC__ */ /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Ignoring function call: this version of orx has been compiled without dynamic plugin support."); #endif /* __orxPLUGIN_DYNAMIC__ */ /* Returns its handle */ return hPluginHandle; }
/** 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; }
/** Adds a track */ static orxINLINE orxTIMELINE_TRACK *orxTimeLine_CreateTrack(const orxSTRING _zTrackID) { orxTIMELINE_TRACK *pstResult = orxNULL; /* Pushes section */ if((orxConfig_HasSection(_zTrackID) != orxFALSE) && (orxConfig_PushSection(_zTrackID) != orxSTATUS_FAILURE)) { orxU32 u32KeyCounter; /* Gets number of keys */ u32KeyCounter = orxConfig_GetKeyCounter(); /* Valid? */ if(u32KeyCounter > 0) { orxU32 u32EventCounter = 0, i; #ifdef __orxMSVC__ orxFLOAT *afTimeList = (orxFLOAT *)alloca(u32KeyCounter * sizeof(orxFLOAT)); #else /* __orxMSVC__ */ orxFLOAT afTimeList[u32KeyCounter]; #endif /* __orxMSVC__ */ /* For all time entries */ for(i = 0; i < u32KeyCounter; i++) { /* Inits it */ afTimeList[i] = orxFLOAT_MAX; } /* For all config keys */ for(i = 0; i < u32KeyCounter; i++) { const orxSTRING zKey; orxFLOAT fTime; /* Gets it */ zKey = orxConfig_GetKey(i); /* Is a valid time stamp? */ if((orxString_ToFloat(zKey, &fTime, orxNULL) != orxSTATUS_FAILURE) && (fTime >= orxFLOAT_0)) { /* Stores it */ afTimeList[i] = fTime; /* Updates event counter */ u32EventCounter += orxConfig_GetListCounter(zKey); } else { /* Not keep in cache, immediate nor loop? */ if((orxString_Compare(orxTIMELINE_KZ_CONFIG_KEEP_IN_CACHE, zKey) != 0) && (orxString_Compare(orxTIMELINE_KZ_CONFIG_IMMEDIATE, zKey) != 0) && (orxString_Compare(orxTIMELINE_KZ_CONFIG_LOOP, zKey) != 0)) { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "TimeLine track [%s]: ignoring invalid key (%s).", _zTrackID, zKey); } } } /* Allocates track */ pstResult = (orxTIMELINE_TRACK *)orxMemory_Allocate(sizeof(orxTIMELINE_TRACK) + (u32EventCounter * sizeof(orxTIMELINE_TRACK_EVENT)), orxMEMORY_TYPE_MAIN); /* Valid? */ if(pstResult != orxNULL) { /* Stores its ID */ pstResult->u32ID = orxString_GetID(orxConfig_GetCurrentSection()); /* Adds it to reference table */ if(orxHashTable_Set(sstTimeLine.pstTrackTable, pstResult->u32ID, pstResult) != orxSTATUS_FAILURE) { orxU32 u32EventIndex, u32Flags = orxTIMELINE_TRACK_KU32_FLAG_NONE; /* For all events */ for(u32EventIndex = 0; u32EventIndex < u32EventCounter;) { const orxSTRING zKey; orxFLOAT fTime; orxU32 u32KeyIndex, u32ListCounter; /* Finds time to add next */ for(fTime = orxFLOAT_MAX, u32KeyIndex = orxU32_UNDEFINED, i = 0; i < u32KeyCounter; i++) { /* Is sooner? */ if(afTimeList[i] < fTime) { /* Stores it */ fTime = afTimeList[i]; u32KeyIndex = i; } } /* Checks */ orxASSERT(u32KeyIndex != orxU32_UNDEFINED); /* Gets corresponding key */ zKey = orxConfig_GetKey(u32KeyIndex); /* For all events */ for(i = 0, u32ListCounter = orxConfig_GetListCounter(zKey); i < u32ListCounter; i++, u32EventIndex++) { /* Checks */ orxASSERT(u32EventIndex < u32EventCounter); /* Stores event */ pstResult->astEventList[u32EventIndex].fTimeStamp = fTime; pstResult->astEventList[u32EventIndex].zEventText = orxString_Store(orxConfig_GetListString(zKey, i)); } /* Clears time entry */ afTimeList[u32KeyIndex] = orxFLOAT_MAX; } /* Stores its reference */ pstResult->zReference = orxString_GetFromID(pstResult->u32ID); /* Updates track counters */ pstResult->u32RefCounter = 1; pstResult->u32EventCounter = u32EventCounter; /* Should keep in cache? */ if(orxConfig_GetBool(orxTIMELINE_KZ_CONFIG_KEEP_IN_CACHE) != orxFALSE) { /* Increases its reference counter to keep it in cache table */ pstResult->u32RefCounter++; /* Updates flags */ u32Flags |= orxTIMELINE_TRACK_KU32_FLAG_CACHED; } /* Should loop? */ if(orxConfig_GetBool(orxTIMELINE_KZ_CONFIG_LOOP) != orxFALSE) { /* Updates flags */ u32Flags |= orxTIMELINE_TRACK_KU32_FLAG_LOOP; } /* Is immediate? */ if(orxConfig_GetBool(orxTIMELINE_KZ_CONFIG_IMMEDIATE) != orxFALSE) { /* Updates flags */ u32Flags |= orxTIMELINE_TRACK_KU32_FLAG_IMMEDIATE; } /* Stores flags */ pstResult->u32Flags = u32Flags; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Failed to add track to hashtable."); /* Deletes it */ orxMemory_Free(pstResult); /* Updates result */ pstResult = orxNULL; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't create TimeLine track [%s]: memory allocation failure.", _zTrackID); } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't create TimeLine track [%s]: config section is empty.", _zTrackID); } /* Pops previous section */ orxConfig_PopSection(); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't create TimeLine track [%s]: config section not found.", _zTrackID); } /* Done! */ return pstResult; }
/** Adds a sound using its config ID * @param[in] _pstSoundPointer Concerned SoundPointer * @param[in] _zSoundConfigID Config ID of the sound to add * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxSoundPointer_AddSoundFromConfig(orxSOUNDPOINTER *_pstSoundPointer, const orxSTRING _zSoundConfigID) { orxU32 u32Index; orxSTATUS eResult; /* Checks */ orxASSERT(sstSoundPointer.u32Flags & orxSOUNDPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstSoundPointer); orxASSERT((_zSoundConfigID != orxNULL) && (_zSoundConfigID != orxSTRING_EMPTY)); /* Finds an empty slot */ for(u32Index = 0; (u32Index < orxSOUNDPOINTER_KU32_SOUND_NUMBER) && (_pstSoundPointer->astSoundList[u32Index].pstSound != orxNULL); u32Index++); /* Not found? */ if(u32Index == orxSOUNDPOINTER_KU32_SOUND_NUMBER) { orxFLOAT fShortestDuration; orxU32 u32ShortestIndex; /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "No free slot to play sound <%s>, replacing shortest one.", _zSoundConfigID); /* Gets first index */ u32ShortestIndex = (_pstSoundPointer->u32LastAddedIndex == 0) ? 1 : 0; /* Gets its duration */ fShortestDuration = orxSound_GetDuration(_pstSoundPointer->astSoundList[u32ShortestIndex].pstSound); /* For all other sounds */ for(u32Index = u32ShortestIndex + 1; (u32Index < orxSOUNDPOINTER_KU32_SOUND_NUMBER); u32Index++) { /* Not the latest added one? */ if(u32Index != _pstSoundPointer->u32LastAddedIndex) { orxFLOAT fDuration; /* Gets its duration */ fDuration = orxSound_GetDuration(_pstSoundPointer->astSoundList[u32Index].pstSound); /* Shorter? */ if(fDuration < fShortestDuration) { /* Selects it */ u32ShortestIndex = u32Index; } } } /* Removes it */ orxSoundPointer_RemoveSound(_pstSoundPointer, _pstSoundPointer->astSoundList[u32ShortestIndex].pstSound); /* Updates index */ u32Index = u32ShortestIndex; } /* Found? */ if(u32Index < orxSOUNDPOINTER_KU32_SOUND_NUMBER) { orxSOUND *pstSound; /* Creates sound */ pstSound = orxSound_CreateFromConfig(_zSoundConfigID); /* Valid? */ if(pstSound != orxNULL) { orxSOUND_EVENT_PAYLOAD stPayload; orxOBJECT *pstOwner; /* Increases its reference counter */ orxStructure_IncreaseCounter(pstSound); /* Adds it to holder */ _pstSoundPointer->astSoundList[u32Index].pstSound = pstSound; /* Updates its owner */ orxStructure_SetOwner(pstSound, _pstSoundPointer); /* Updates its flags */ orxFLAG_SET(_pstSoundPointer->astSoundList[u32Index].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_INTERNAL | orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY, orxSOUNDPOINTER_HOLDER_KU32_MASK_ALL); /* Stores it as last added sound */ _pstSoundPointer->u32LastAddedIndex = u32Index; /* Gets its owner object */ pstOwner = orxOBJECT(orxStructure_GetOwner(_pstSoundPointer)); /* Valid? */ if(pstOwner != orxNULL) { orxVECTOR vPosition; /* Updates its position */ orxSound_SetPosition(pstSound, orxObject_GetWorldPosition(pstOwner, &vPosition)); } /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxSOUND_EVENT_PAYLOAD)); stPayload.pstSound = pstSound; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_SOUND, orxSOUND_EVENT_ADD, pstOwner, pstOwner, &stPayload); /* Updates result */ eResult = orxSTATUS_SUCCESS; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "Could not find object named '%s' in config.", _zSoundConfigID); /* Clears last added sound index */ _pstSoundPointer->u32LastAddedIndex = orxU32_UNDEFINED; /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "Failed to find an empty slot to put sound <%s> into.", _zSoundConfigID); /* Updates result */ eResult = orxSTATUS_FAILURE; } /* 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; }
/** Adds a 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_AddDelayedFXFromConfig(orxFXPOINTER *_pstFXPointer, const orxSTRING _zFXConfigID, orxFLOAT _fDelay) { orxU32 u32Index; orxSTATUS eResult; /* Checks */ orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstFXPointer); orxASSERT((_zFXConfigID != orxNULL) && (_zFXConfigID != orxSTRING_EMPTY)); orxASSERT(_fDelay >= orxFLOAT_0); /* Finds an empty slot */ for(u32Index = 0; (u32Index < orxFXPOINTER_KU32_FX_NUMBER) && (_pstFXPointer->astFXList[u32Index].pstFX != orxNULL); u32Index++); /* Found? */ if(u32Index < orxFXPOINTER_KU32_FX_NUMBER) { orxFX *pstFX; /* Creates FX */ pstFX = orxFX_CreateFromConfig(_zFXConfigID); /* Valid? */ if(pstFX != orxNULL) { orxSTRUCTURE *pstOwner; orxFX_EVENT_PAYLOAD stPayload; /* Gets owner */ pstOwner = orxStructure_GetOwner(_pstFXPointer); /* Increases its reference counter */ orxStructure_IncreaseCounter(pstFX); /* Adds it to holder */ _pstFXPointer->astFXList[u32Index].pstFX = pstFX; /* Inits its start time */ _pstFXPointer->astFXList[u32Index].fStartTime = _pstFXPointer->fTime + _fDelay; /* Updates its owner */ orxStructure_SetOwner(pstFX, _pstFXPointer); /* Updates its flags */ orxFLAG_SET(_pstFXPointer->astFXList[u32Index].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_INTERNAL, orxFXPOINTER_HOLDER_KU32_MASK_ALL); /* 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_ADD, pstOwner, pstOwner, &stPayload); /* Updates result */ eResult = orxSTATUS_SUCCESS; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Loading FX <%s> from config failed.", _zFXConfigID); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "Failed to find an empty slot to put FX <%s> into.", _zFXConfigID); /* Updates result */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
/** Deletes a TimeLine * @param[in] _pstTimeLine Concerned TimeLine * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTimeLine_Delete(orxTIMELINE *_pstTimeLine) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstTimeLine); /* Decreases counter */ orxStructure_DecreaseCounter(_pstTimeLine); /* Not referenced? */ if(orxStructure_GetRefCounter(_pstTimeLine) == 0) { orxTIMELINE_EVENT_PAYLOAD stPayload; orxSTRUCTURE *pstOwner; orxU32 i; /* Gets owner */ pstOwner = orxStructure_GetOwner(_pstTimeLine); /* Inits event payload */ orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD)); stPayload.pstTimeLine = _pstTimeLine; /* For all tracks */ for(i = 0; i < orxTIMELINE_KU32_TRACK_NUMBER; i++) { /* Valid? */ if(_pstTimeLine->astTrackList[i].pstTrack != orxNULL) { orxTIMELINE_TRACK *pstTrack; /* Gets track */ pstTrack = _pstTimeLine->astTrackList[i].pstTrack; /* Removes its reference */ _pstTimeLine->astTrackList[i].pstTrack = orxNULL; /* Updates payload */ stPayload.zTrackName = pstTrack->zReference; /* Sends event */ orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_REMOVE, pstOwner, pstOwner, &stPayload); /* Deletes it */ orxTimeLine_DeleteTrack(pstTrack); } } /* Deletes structure */ orxStructure_Delete(_pstTimeLine); } else { /* Referenced by others */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }
/** Synchronizes FX times with an other orxFXPointer if they share common FXs * @param[in] _pstFXPointer Concerned FXPointer * @param[in] _pstModel Model FX pointer to use for synchronization * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFXPointer_Synchronize(orxFXPOINTER *_pstFXPointer, const orxFXPOINTER *_pstModel) { orxS32 i; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstFXPointer); orxSTRUCTURE_ASSERT(_pstModel); /* For all FXs */ for(i = 0; i < orxFXPOINTER_KU32_FX_NUMBER; i++) { orxFXPOINTER_HOLDER *pstFX; /* Gets it */ pstFX = &_pstFXPointer->astFXList[i]; /* Valid? */ if(pstFX != orxNULL) { orxS32 j; /* For all FXs on model */ for(j = 0; j < orxFXPOINTER_KU32_FX_NUMBER; j++) { const orxFXPOINTER_HOLDER *pstModelFX; /* Gets it */ pstModelFX = &_pstModel->astFXList[j]; /* Valid? */ if(pstModelFX != orxNULL) { /* Matches? */ if(pstModelFX->pstFX == pstFX->pstFX) { /* Synchronizes start time */ pstFX->fStartTime = pstModelFX->fStartTime; /* Updates result */ eResult = orxSTATUS_SUCCESS; break; } } } /* Not found? */ if(j == orxFXPOINTER_KU32_FX_NUMBER) { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't synchronize FX <%s> as it wasn't found on model.", orxFX_GetName(pstFX->pstFX)); } } } /* Succes? */ if(eResult != orxSTATUS_FAILURE) { /* Updates global time */ _pstFXPointer->fTime = _pstModel->fTime; } /* Done! */ return eResult; }
/** Adds a node as a parent of another one * @param[in] _pstRefNode Reference node (add as a parent of this one) * @param[in] _pstNode Node to add * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxTree_AddParent(orxTREE_NODE *_pstRefNode, orxTREE_NODE *_pstNode) { orxSTATUS eResult = orxSTATUS_SUCCESS; orxTREE *pstTree; /* Checks */ orxASSERT(_pstRefNode != orxNULL); orxASSERT(_pstNode != orxNULL); /* Isn't already in a tree? */ if(_pstNode->pstTree == orxNULL) { /* Gets tree */ pstTree = _pstRefNode->pstTree; /* Valid? */ if(pstTree != orxNULL) { /* Adds it in the tree */ _pstNode->pstChild = _pstRefNode; _pstNode->pstParent = _pstRefNode->pstParent; _pstNode->pstTree = pstTree; _pstNode->pstSibling = _pstRefNode->pstSibling; /* Updates parent? */ if(_pstRefNode->pstParent != orxNULL) { /* Was first child? */ if(_pstRefNode->pstParent->pstChild == _pstRefNode) { /* Updates parent */ _pstRefNode->pstParent->pstChild = _pstNode; } else { orxTREE_NODE *pstChild; /* Finds left sibling */ for(pstChild = _pstRefNode->pstParent->pstChild; pstChild->pstSibling != _pstRefNode; pstChild = pstChild->pstSibling); /* Updates sibling */ pstChild->pstSibling = _pstNode; } } else { /* Checks node was the root */ orxASSERT(pstTree->pstRoot == _pstRefNode); /* Updates new root */ pstTree->pstRoot = _pstNode; } /* Updates ref node */ _pstRefNode->pstParent = _pstNode; _pstRefNode->pstSibling = orxNULL; /* Updates counter */ pstTree->u32Counter++; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Parent node's tree is invalid."); /* No tree found */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Node is already in a tree, use MoveAsChild instead."); /* Already in a tree */ eResult = orxSTATUS_FAILURE; } /* Done! */ return eResult; }