/** Creates a plugin info * @return orxPLUGIN_INFO / orxNULL */ static orxPLUGIN_INFO *orxFASTCALL orxPlugin_CreatePluginInfo() { orxPLUGIN_INFO *pstPluginInfo; /* Creates a plugin info */ pstPluginInfo = (orxPLUGIN_INFO *)orxBank_Allocate(sstPlugin.pstPluginBank); /* Valid? */ if(pstPluginInfo != orxNULL) { /* Inits it */ orxMemory_Zero(pstPluginInfo, sizeof(orxPLUGIN_INFO)); /* Undefines plugin handle */ pstPluginInfo->hPluginHandle = orxHANDLE_UNDEFINED; /* Creates function bank */ pstPluginInfo->pstFunctionBank = orxBank_Create(orxPLUGIN_KU32_FUNCTION_BANK_SIZE, sizeof(orxPLUGIN_FUNCTION_INFO), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Valid? */ if(pstPluginInfo->pstFunctionBank != orxNULL) { /* Creates function hash table */ pstPluginInfo->pstFunctionTable = orxHashTable_Create(orxPLUGIN_KU32_FUNCTION_BANK_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Invalid? */ if(pstPluginInfo->pstFunctionTable == orxNULL) { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Invalid function hash table."); /* Frees previously allocated data */ orxBank_Delete(pstPluginInfo->pstFunctionBank); orxBank_Free(sstPlugin.pstPluginBank, pstPluginInfo); /* Not successful */ pstPluginInfo = orxNULL; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Invalid function bank."); /* Frees previously allocated data */ orxBank_Free(sstPlugin.pstPluginBank, pstPluginInfo); /* Not successful */ pstPluginInfo = orxNULL; } } /* Done! */ return pstPluginInfo; }
static orxSTATUS orxFASTCALL Init() { #define orxFONTGEN_DECLARE_PARAM(SN, LN, SD, LD, FN) {orxPARAM_KU32_FLAG_STOP_ON_ERROR, SN, LN, SD, LD, &FN}, orxU32 i; orxSTATUS eResult = orxSTATUS_SUCCESS; orxPARAM astParamList[] = { orxFONTGEN_DECLARE_PARAM("o", "output", "Font output name", "Font base output name: .png will be added to the image and .ini will be added to the config file", ProcessOutputParams) orxFONTGEN_DECLARE_PARAM("s", "size", "Size (height) of characters", "Height to use for characters defined with this font", ProcessSizeParams) orxFONTGEN_DECLARE_PARAM("p", "padding", "Character padding", "Extra padding added to all characters on both dimensions (width and height)", ProcessPaddingParams) orxFONTGEN_DECLARE_PARAM("f", "font", "Input font file", "TrueType font (usually .ttf) used to generate all the required glyphs", ProcessFontParams) orxFONTGEN_DECLARE_PARAM("t", "textlist", "List of input text files", "List of text files containing all the characters that will be displayed using this font", ProcessInputParams) orxFONTGEN_DECLARE_PARAM("m", "monospace", "Monospaced font", "Will output a monospace (ie. fixed-width) font", ProcessMonospaceParams) orxFONTGEN_DECLARE_PARAM("a", "advance", "Use glyph advance values for non-monospace fonts", "In non-monospace mode only: the font's original glyph advance values will be used instead of packing glyphs as efficiently as possible", ProcessAdvanceParams) }; // Clears static controller orxMemory_Zero(&sstFontGen, sizeof(orxFONTGEN_STATIC)); // Creates character table sstFontGen.pstCharacterTable = orxHashTable_Create(orxFONTGEN_KU32_CHARACTER_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); // Creates glyph bank sstFontGen.pstGlyphBank = orxBank_Create(orxFONTGEN_KU32_CHARACTER_TABLE_SIZE, sizeof(orxFONTGEN_GLYPH), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); // For all params but last for(i = 0; (i < (sizeof(astParamList) / sizeof(astParamList[0])) - 1) && (eResult != orxSTATUS_FAILURE); i++) { // Registers param eResult = orxParam_Register(&astParamList[i]); } // Not in monospace mode? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_MONOSPACE)) { // Logs message orxFONTGEN_LOG(MODE, "Output mode set to non-monospace."); // Registers last param eResult = orxParam_Register(&astParamList[(sizeof(astParamList) / sizeof(astParamList[0])) - 1]); // Not using original advance values? if(!orxFLAG_TEST(sstFontGen.u32Flags, orxFONTGEN_KU32_STATIC_FLAG_ADVANCE)) { // Logs message orxFONTGEN_LOG(PACKING, "Characters will be packed."); } } // Done! return eResult; }
/** Create a new hash table and return it. * @param[in] _u32NbKey Number of keys that will be inserted. * @param[in] _u32Flags Flags used by the hash table * @param[in] _eMemType Memory type to use * @return Returns the hashtable pointer or orxNULL if failed. */ orxHASHTABLE *orxFASTCALL orxHashTable_Create(orxU32 _u32NbKey, orxU32 _u32Flags, orxMEMORY_TYPE _eMemType) { orxHASHTABLE *pstHashTable; orxU32 u32Size; orxU32 u32Flags; /* Checks */ orxASSERT(_eMemType < orxMEMORY_TYPE_NUMBER); orxASSERT(_u32NbKey > 0); /* Gets Power of Two size */ u32Size = orxMath_GetNextPowerOfTwo(_u32NbKey); /* Allocate memory for a hash table */ pstHashTable = (orxHASHTABLE *)orxMemory_Allocate(sizeof(orxHASHTABLE) + (u32Size * sizeof(orxHASHTABLE_CELL *)), _eMemType); /* Enough memory ? */ if(pstHashTable != orxNULL) { /* Set flags */ if(_u32Flags == orxHASHTABLE_KU32_FLAG_NOT_EXPANDABLE) { u32Flags = orxBANK_KU32_FLAG_NOT_EXPANDABLE; } else { u32Flags = orxBANK_KU32_FLAG_NONE; } /* Clean values */ orxMemory_Zero(pstHashTable, sizeof(orxHASHTABLE) + (u32Size * sizeof(orxHASHTABLE_CELL *))); /* Allocate bank for cells */ pstHashTable->pstBank = orxBank_Create((orxU16)u32Size, sizeof(orxHASHTABLE_CELL), u32Flags, _eMemType); /* Correct bank allocation ? */ if(pstHashTable->pstBank != orxNULL) { /* Stores its size */ pstHashTable->u32Size = u32Size; } else { /* Allocation problem, returns orxNULL */ orxMemory_Free(pstHashTable); pstHashTable = orxNULL; } } return pstHashTable; }
/** Creates a clock * @param[in] _fTickSize Tick size for the clock (in seconds) * @param[in] _eType Type of the clock * @return orxCLOCK / orxNULL */ orxCLOCK *orxFASTCALL orxClock_Create(orxFLOAT _fTickSize, orxCLOCK_TYPE _eType) { orxCLOCK *pstClock; /* Checks */ orxASSERT(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY); orxASSERT(_fTickSize >= orxFLOAT_0); /* Creates clock */ pstClock = orxCLOCK(orxStructure_Create(orxSTRUCTURE_ID_CLOCK)); /* Valid? */ if(pstClock != orxNULL) { /* Creates function bank */ pstClock->pstFunctionBank = orxBank_Create(orxCLOCK_KU32_FUNCTION_BANK_SIZE, sizeof(orxCLOCK_FUNCTION_STORAGE), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Valid? */ if(pstClock->pstFunctionBank != orxNULL) { /* Inits clock */ pstClock->stClockInfo.fTickSize = _fTickSize; pstClock->stClockInfo.eType = _eType; pstClock->stClockInfo.eModType = orxCLOCK_MOD_TYPE_NONE; orxStructure_SetFlags(pstClock, orxCLOCK_KU32_FLAG_NONE, orxCLOCK_KU32_MASK_ALL); /* Increases counter */ orxStructure_IncreaseCounter(pstClock); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Couldn't create clock function storage."); /* Deletes clock */ orxStructure_Delete(pstClock); /* Not allocated */ pstClock = orxNULL; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Couldn't allocate bank for clock."); } /* Done! */ return pstClock; }
/** Inits the plugin module * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxPlugin_Init() { orxSTATUS eResult = orxSTATUS_FAILURE; /* Not already Initialized? */ if(!(sstPlugin.u32Flags & orxPLUGIN_KU32_STATIC_FLAG_READY)) { /* Cleans control structure */ orxMemory_Zero(&sstPlugin, sizeof(orxPLUGIN_STATIC)); /* Creates an empty spst_plugin_list */ sstPlugin.pstPluginBank = orxBank_Create(orxPLUGIN_CORE_ID_NUMBER, sizeof(orxPLUGIN_INFO), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Is bank valid? */ if(sstPlugin.pstPluginBank != orxNULL) { #ifndef __orxEMBEDDED__ orxPARAM stParams; #endif /* !__orxEMBEDDED__ */ /* Updates status flags */ sstPlugin.u32Flags = orxPLUGIN_KU32_STATIC_FLAG_READY; /* Registers all core plugins */ orxPlugin_RegisterCorePlugins(); #ifdef __orxEMBEDDED__ /* Updates all modules */ orxPlugin_UpdateAllModule(); #else /* __orxEMBEDDED__ */ /* Inits the param structure */ orxMemory_Zero(&stParams, sizeof(orxPARAM)); stParams.pfnParser = orxPlugin_ProcessParams; stParams.u32Flags = orxPARAM_KU32_FLAG_MULTIPLE_ALLOWED; stParams.zShortName = "p"; stParams.zLongName = "plugin"; stParams.zShortDesc = "Loads the specified plugins."; stParams.zLongDesc = "Loads the specified plugins from the current execution folder. More than one plugin can be specified. They can be core or user plugins."; /* Registers it */ orxParam_Register(&stParams); #endif /* __orxEMBEDDED__ */ /* Successful */ eResult = orxSTATUS_SUCCESS; } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Failed to create bank."); /* Bank not created */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Tried to initialize plugin module when it was already initialized."); /* Already initialized */ eResult = orxSTATUS_SUCCESS; } /* Done! */ return eResult; }
/** Adds an event handler with user-defined context * @param[in] _eEventType Concerned type of event * @param[in] _pfnHandler Event handler to add * @param[in] _pContext Context that will be stored in events sent to this handler * return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxEvent_AddHandlerWithContext(orxEVENT_TYPE _eEventType, orxEVENT_HANDLER _pfnEventHandler, void *_pContext) { orxEVENT_HANDLER_STORAGE *pstStorage; orxSTATUS eResult = orxSTATUS_FAILURE; /* Checks */ orxASSERT(orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)); orxASSERT(_pfnEventHandler != orxNULL); /* Gets corresponding storage */ pstStorage = (_eEventType < orxEVENT_TYPE_CORE_NUMBER) ? sstEvent.astCoreHandlerStorageList[_eEventType] : (orxEVENT_HANDLER_STORAGE *)orxHashTable_Get(sstEvent.pstHandlerStorageTable, _eEventType); /* No storage yet? */ if(pstStorage == orxNULL) { /* Allocates it */ pstStorage = (orxEVENT_HANDLER_STORAGE *)orxBank_Allocate(sstEvent.pstHandlerStorageBank); /* Success? */ if(pstStorage != orxNULL) { /* Creates its bank */ pstStorage->pstBank = orxBank_Create(orxEVENT_KU32_HANDLER_BANK_SIZE, sizeof(orxEVENT_HANDLER_INFO), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Success? */ if(pstStorage->pstBank != orxNULL) { /* Clears its list */ orxMemory_Zero(&(pstStorage->stList), sizeof(orxLINKLIST)); /* Is a core event handler? */ if(_eEventType < orxEVENT_TYPE_CORE_NUMBER) { /* Stores it */ sstEvent.astCoreHandlerStorageList[_eEventType] = pstStorage; } else { /* Tries to add it to the table */ if(orxHashTable_Add(sstEvent.pstHandlerStorageTable, _eEventType, pstStorage) == orxSTATUS_FAILURE) { /* Deletes its bank */ orxBank_Delete(pstStorage->pstBank); /* Frees storage */ orxBank_Free(sstEvent.pstHandlerStorageBank, pstStorage); pstStorage = orxNULL; } } } else { /* Frees storage */ orxBank_Free(sstEvent.pstHandlerStorageBank, pstStorage); pstStorage = orxNULL; } } } /* Valid? */ if(pstStorage != orxNULL) { orxEVENT_HANDLER_INFO *pstInfo; /* Allocates a new handler info */ pstInfo = (orxEVENT_HANDLER_INFO *)orxBank_Allocate(pstStorage->pstBank); /* Valid? */ if(pstInfo != orxNULL) { /* Clears its node */ orxMemory_Zero(&(pstInfo->stNode), sizeof(orxLINKLIST_NODE)); /* Stores its handler */ pstInfo->pfnHandler = _pfnEventHandler; /* Stores context */ pstInfo->pContext = _pContext; /* Adds it to the list */ eResult = orxLinkList_AddEnd(&(pstStorage->stList), &(pstInfo->stNode)); } } /* Done! */ return eResult; }
/** Inits the event module * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxEvent_Init() { orxSTATUS eResult = orxSTATUS_FAILURE; /* Not already Initialized? */ if(!orxFLAG_TEST(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY)) { /* Cleans control structure */ orxMemory_Zero(&sstEvent, sizeof(orxEVENT_STATIC)); /* Creates handler storage table */ sstEvent.pstHandlerStorageTable = orxHashTable_Create(orxEVENT_KU32_HANDLER_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Success? */ if(sstEvent.pstHandlerStorageTable != orxNULL) { /* Creates handler storage bank */ sstEvent.pstHandlerStorageBank = orxBank_Create(orxEVENT_KU32_STORAGE_BANK_SIZE, sizeof(orxEVENT_HANDLER_STORAGE), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Success? */ if(sstEvent.pstHandlerStorageBank != orxNULL) { /* Inits Flags */ orxFLAG_SET(sstEvent.u32Flags, orxEVENT_KU32_STATIC_FLAG_READY, orxEVENT_KU32_STATIC_MASK_ALL); /* Success */ eResult = orxSTATUS_SUCCESS; } else { /* Deletes table */ orxHashTable_Delete(sstEvent.pstHandlerStorageTable); /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Event module failed to create bank."); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Event module failed to create hash table."); /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_SYSTEM, "Event module already loaded."); /* Already initialized */ eResult = orxSTATUS_SUCCESS; } /* Done! */ return eResult; }
/** Inits clock module * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxClock_Init() { orxSTATUS eResult = orxSTATUS_FAILURE; /* Not already Initialized? */ if(!(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY)) { /* Registers structure type */ eResult = orxSTRUCTURE_REGISTER(CLOCK, orxSTRUCTURE_STORAGE_TYPE_LINKLIST, orxMEMORY_TYPE_MAIN, orxCLOCK_KU32_BANK_SIZE, orxNULL); /* Successful? */ if(eResult != orxSTATUS_FAILURE) { /* Cleans control structure */ orxMemory_Zero(&sstClock, sizeof(orxCLOCK_STATIC)); /* Creates timer bank */ sstClock.pstTimerBank = orxBank_Create(orxCLOCK_KU32_TIMER_BANK_SIZE, sizeof(orxCLOCK_TIMER_STORAGE), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Valid? */ if(sstClock.pstTimerBank != orxNULL) { /* Creates reference table */ sstClock.pstReferenceTable = orxHashTable_Create(orxCLOCK_KU32_REFERENCE_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN); /* Valid? */ if(sstClock.pstReferenceTable != orxNULL) { orxCLOCK *pstClock; /* No mod type by default */ sstClock.eModType = orxCLOCK_MOD_TYPE_NONE; /* Gets init time */ sstClock.dTime = orxSystem_GetTime(); /* Inits Flags */ sstClock.u32Flags = orxCLOCK_KU32_STATIC_FLAG_READY; /* Gets main clock tick size */ orxConfig_PushSection(orxCLOCK_KZ_CONFIG_SECTION); sstClock.fMainClockTickSize = (orxConfig_HasValue(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY) && orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY) > orxFLOAT_0) ? (orxFLOAT_1 / orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY)) : orxFLOAT_0; orxConfig_PopSection(); /* Creates default full speed core clock */ pstClock = orxClock_Create(sstClock.fMainClockTickSize, orxCLOCK_TYPE_CORE); /* Success? */ if(pstClock != orxNULL) { /* Sets it as its own owner */ orxStructure_SetOwner(pstClock, pstClock); /* Updates result */ eResult = orxSTATUS_SUCCESS; } else { /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Deletes timer bank */ orxBank_Delete(sstClock.pstTimerBank); sstClock.pstTimerBank = orxNULL; /* Updates result */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Failed creating clock bank."); /* Clock bank not created */ eResult = orxSTATUS_FAILURE; } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Failed to register link list structure."); } } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Tried to initialize clock module when it was already initialized."); /* Already initialized */ eResult = orxSTATUS_SUCCESS; } /* Done! */ return eResult; }