void Menu_Game_Exit(void *info) { Base_State *gState = info; struct menu_Game *menu = gState->info; while(menu->nameList != NULL) { mem_Free(menu->nameList->data); list_Pop(&menu->nameList); } while(menu->campaignNameList != NULL) { mem_Free(menu->campaignNameList->data); list_Pop(&menu->campaignNameList); } /*Clear up ui*/ uiSpine_Clean(&menu->spine); /*Remove any graphics that should not be drawn*/ gKer_FlushGraphics(); mem_Free(menu); return; }
void lex_FreeBuffer(SLexerBuffer* buffer) { if (buffer) { if (buffer->buffer) { mem_Free(buffer->buffer); } else { internalerror("buf->pBufferStart not initialized"); } mem_Free(buffer); } else { internalerror("Argument must not be NULL"); } }
void vLevel_LoadCustomSurface_0(Vent_Level *l, Level_Tag *tag, FILE *levelFile) { const int version = 0; char surfacePathLimit[255]; int ID = 0; int numRotated = 0; int rotationDeg = 0; int x = 0; int y = 0; char *directory = NULL; char *name = NULL; /*Load the custom surfaces*/ for(x = 0; x < tag->amount; x++) { fscanf(levelFile, "%s%d%d", surfacePathLimit, &ID, &numRotated); /*update for version 1 of load custom surface*/ string_Split(surfacePathLimit, &directory, &name, '/'); file_Log(ker_Log(), P_OUT, "Loading custom surface(%d) from: %s --> [%s] [%s]\n", ID, surfacePathLimit, directory, name); vLevel_SurfaceInsert(&l->surfacesLoaded, directory, name, ID); mem_Free(directory); mem_Free(name); if(numRotated > 0) { //file_Log(ker_Log(), 1, "Creating %d rotations of surface(%d)\n", numRotated, ID); for(y = 0; y < numRotated; y++) { fscanf(levelFile, "%d", &rotationDeg); vLevel_SurfaceInsertRotation(l->surfacesLoaded, ID, rotationDeg); //file_Log(ker_Log(), 1, "\t%d rotation\n", rotationDeg); } } fscanf(levelFile, "\n"); } return; }
void *mem_Realloc(void *pOld, uint_t nSize) #endif { void *p; if (pOld == NULL) #if DEBUG_MEMORY_ENABLE return _mem_Malloc(nSize, fn, line); #else return mem_Malloc(nSize); #endif if (nSize == 0) { #if DEBUG_MEMORY_ENABLE _mem_Free(pOld, fn, line); #else mem_Free(pOld); #endif return NULL; } mem_Lock(); #if DEBUG_MEMORY_ENABLE p = _rt_realloc(pOld, nSize); #else p = rt_realloc(pOld, nSize); #endif mem_Unlock(); #if DEBUG_MEMORY_ENABLE mem_DebugRealloc(p, pOld, fn, line); #endif return p; }
int surf_Quit(void) { surf_Free_All(); mem_Free(surf_C.surfacesDIR); return 0; }
void list_Delete_Node(struct list **head, struct list *dList) { if(dList == *head) { if((*head)->next != NULL) (*head)->next->previous = (*head)->previous; /*Set the previous to point to the end of the list*/ *head = (*head)->next; } else { dList->previous->next = dList->next; if(dList->next != NULL) dList->next->previous = dList->previous; if(dList == (*head)->previous) /*If dList is at the end*/ { if(dList->previous != *head) (*head)->previous = dList->previous; else (*head)->previous = NULL; } } #ifdef MEM_TRACK mem_Free(dList); #else free(dList); #endif return; }
void drawManager_AddType(Draw_Manager *dM, Draw_Type *dT) { int x = 0; Draw_Type **newArray = NULL; dM->numTypes ++; /*Create the new array to hold the draw types*/ newArray = (Draw_Type **)mem_Alloc(dM->numTypes * sizeof(Draw_Type *)); for(x = 0; x < (dM->numTypes - 1); x++) { newArray[x] = dM->drawTypes[x]; } newArray[x] = dT; /*Release the array in the draw manager and replace it with the new one*/ if(dM->drawTypes != NULL) { mem_Free(dM->drawTypes); } dM->drawTypes = newArray; return; }
/* Function: drawType_ReleaseExcess Description - If there are any unused nodes with a specific type then it will delete them. The maximum total layers that will be deleted is specified by 'amount'. Returns the amount of nodes that have been deleted. 2 arguments: Draw_Layer *dT - The type of unused nodes to remove. int amount - The maximum amount of unused nodes to remove, if < 0 then all will be removed. */ int drawType_ReleaseExcess(Draw_Type *dT, int amount) { int x = 0; if(amount < 0) amount = dT->totalFree; if(dT->totalFree > 0) { for(x = 0; x < amount; x++) { /*Delete all the unused nodes*/ drawObject_Clean(dT->unusedObjectList->data); mem_Free(dT->unusedObjectList->data); list_Pop(&dT->unusedObjectList); dT->totalFree --; if(dT->totalFree == 0) { x ++; break; } } *dT->totalObjectLocations = *dT->totalObjectLocations - x; return x; } return 0; }
/* Function: drawObject_Clean Description - Cleans up a draw object. 1 argument: Draw_Object *drawObject - The draw object to clean up. */ void drawObject_Clean(Draw_Object *drawObject) { mem_Free(drawObject->object); drawObject->type = NULL; return; }
/* Function: drawLayer_Release Description - This function either removes or sets a node in the list as inactive. Inactive nodes can be reused later to save there being another call to malloc. 3 arguments: Draw_Layer *dL - The layer that the node to remove is located. struct list *node - The node that is to be removed/set inactive. int remove - If 1 then the node will be deleted, otherwise it can be reused. */ void drawLayer_Release(Draw_Layer *dL, struct list *node, int remove) { Draw_Object *drawObj = node->data; //printf("Layer(REM): %d, Total %d, Used %d, Free %d\n", dL->layer, dL->totalNodes, dL->totalUsed, dL->totalFree); if(remove == 1) { drawObject_Clean(node->data); mem_Free(node->data); list_Delete_Node(&dL->objectList, node); dL->totalNodes --; *dL->totalObjectLocations = *dL->totalObjectLocations - 1; } else { /*Remove the node from the list*/ list_Unlink_Node(&dL->objectList, node); /*Place it at the head of the unused list*/ list_Push_Node(&drawObj->type->unusedObjectList, node, node->data, node->info); drawObj->type->totalFree ++; } return; }
void SOCKETFIFO_Flush (void) { SocketFifoElement_t element; while (SOCKETFIFO_Pop(&element)) { if (element.freedata) { mem_Free(element.data); } } }
SLexerBuffer* lex_CreateFileBuffer(FILE* fileHandle) { char strterm = 0; char* pFile; bool bWasSpace = true; SLexerBuffer* pBuffer = (SLexerBuffer*) mem_Alloc(sizeof(SLexerBuffer)); memset(pBuffer, 0, sizeof(SLexerBuffer)); size_t size = fsize(fileHandle); pFile = (char*) mem_Alloc(size); size = fread(pFile, sizeof(uint8_t), size, fileHandle); pBuffer->buffer = (char*) mem_Alloc(size + 1); char* dest = pBuffer->buffer; char* mem = pFile; while (mem < pFile + size) { if (*mem == '"' || *mem == '\'') { strterm = *mem; *dest++ = *mem++; while (*mem && *mem != strterm) { if (*mem == '\\') *dest++ = *mem++; *dest++ = *mem++; } *dest++ = *mem++; bWasSpace = false; } else if ((mem[0] == 10 && mem[1] == 13) || (mem[0] == 13 && mem[1] == 10)) { *dest++ = '\n'; mem += 2; bWasSpace = true; } else if (mem[0] == 10 || mem[0] == 13) { *dest++ = '\n'; mem += 1; bWasSpace = true; } else if (*mem == ';' || (bWasSpace && mem[0] == '*')) { ++mem; while (*mem && *mem != 13 && *mem != 10) ++mem; bWasSpace = false; } else { bWasSpace = isspace((uint8_t) *mem) ? true : false; *dest++ = *mem++; } } *dest++ = '\n'; pBuffer->bufferSize = dest - pBuffer->buffer; pBuffer->atLineStart = true; mem_Free(pFile); return pBuffer; }
//------------------------------------------------------------------------- // //------------------------------------------------------------------------- static void regloader_Close(p_reg_loader p, uint_t nType) { if (p->ste == REGLOADER_S_NEED_SYNC) regloader_Save(p, nType); mem_Free(p->data); p->size = 0; p->hit = 0; }
//------------------------------------------------------------------------- // //------------------------------------------------------------------------- int reg_ArithmeticCopy(uint_t nDestDa, uint_t nDestReg, uint_t nSrcDa, uint_t nSrcReg, uint_t nType, uint32_t nParam, uint_t nSave) { int nLen; uint64_t nTemp; void *pBuf; nLen = reg_GetRegSize(nSrcReg); if (nLen < 0) return 0; if (nType == REG_O_COPY) { pBuf = mem_Malloc(nLen); if (pBuf == NULL) return 0; reg_Get(nSrcDa, nSrcReg, pBuf); reg_Set(nDestDa, nDestReg, pBuf, nSave); mem_Free(pBuf); } else { if (nLen > 8) return 0; nTemp = 0; reg_Get(nSrcDa, nSrcReg, &nTemp); switch (nType) { case REG_O_ADD: nTemp += nParam; break; case REG_O_SUB: nTemp -= nParam; break; case REG_O_MUL: nTemp *= nParam; break; case REG_O_DIV: nTemp /= nParam; break; case REG_O_OR: //或 nTemp |= nParam; break; case REG_O_AND: //与 nTemp &= nParam; break; case REG_O_SETBIT: //置位 SETBIT(nTemp, nParam); break; case REG_O_CLRBIT: //清位 CLRBIT(nTemp, nParam); break; default: break; } reg_Set(nDestDa, nDestReg, &nTemp, nSave); } return nLen; }
/* Function: drawManager_Clean Description - Deletes all the layers in the draw manager. Also removes any remaining draw objects in the manager. 1 argument: Draw_Manager *dM - The draw manager to clean. */ void drawManager_Clean(Draw_Manager *dM) { /*Delete all the layers and the objects inside of them*/ drawManager_CleanLayers(dM); /*Delete all the draw types*/ for(dM->numTypes = dM->numTypes; dM->numTypes > 0; dM->numTypes --) { drawType_Clean(dM->drawTypes[dM->numTypes - 1]); mem_Free(dM->drawTypes[dM->numTypes - 1]); } if(dM->drawTypes != NULL) { mem_Free(dM->drawTypes); } return; }
/* Function: vLevel_LoadHeader Description - Loads a level header from a file. 3 arguments: Vent_Level_Header *header - The level header to be loaded into. char *directory - The directory name of the level to load. char *name - The file name of the level to load. */ void vLevel_LoadHeader(Vent_Level_Header *header, char *directory, char *name) { char *loadFolder = directory; char *loadName = (char *)mem_Malloc(strlen(loadFolder) + strlen(name) + 1, __LINE__, __FILE__); int finishedLoading = 0; FILE *load = NULL; Level_Tag tag; /*Setup the default values of the header*/ vLevel_SetupHeader(header, NULL, 0, 0); /*Find the level file*/ strcpy(loadName, loadFolder); strcat(loadName, name); load = fopen(loadName, "r"); if(load == NULL) { file_Log(ker_Log(), 1, "Error: Could not load level file for header. (%s)\n", loadName); return; } while(vLevel_TagVerify(&tag, load) == 1 && finishedLoading == 0) { switch(tag.type) { case TAG_HEADER: if(tag.version < HEADER_VERSIONS) { vLevel_LoadHeaderVer[tag.version](header, &tag, load); finishedLoading = 1; } break; default: file_Log(ker_Log(), 1, "Error unknown tag type (while searching for header) %s -> %d\n", tag.name, tag.type); break; } } fclose(load); mem_Free(loadName); return; }
void control_CleanKeys(Control_Keys *keys) { if(keys->keys != NULL) { mem_Free(keys->keys); keys->keys = NULL; } keys->numKeys = 0; return; }
void drawManager_CleanLayers(Draw_Manager *dM) { while(dM->layers != NULL) { drawLayer_Clean(dM->layers->data); mem_Free(dM->layers->data); list_Pop(&dM->layers); } return; }
/* Function: uiTextInput_Clean Description - Clean up any allocated memory created by the text input structure. 1 argument: Ui_TextInput *textInput - The text input structure to clean up */ void uiTextInput_Clean(Ui_TextInput *textInput) { uiButton_Clean(&textInput->button); mem_Free(textInput->inputText); sprite_Clean(&textInput->sMarker); depWatcher_Clean(&textInput->dW); return; }
void aiModule_Clean(Ai_Module *aiMod) { while(aiMod->globalList != NULL) { aiState_Clean(aiMod->globalList->data); mem_Free(aiMod->globalList->data); list_Pop(&aiMod->globalList); } while(aiMod->localList != NULL) { aiState_Clean(aiMod->localList->data); mem_Free(aiMod->localList->data); list_Pop(&aiMod->localList); } aiMod->highestPriority = aiMod->lowestPriority = NULL; return; }
void uiButtonChain_Clean(Ui_ButtonChain *bChain) { bChain->currentList = NULL; bChain->currentButton = NULL; while(bChain->bList != NULL) { uiButton_Clean(bChain->bList->data); mem_Free(bChain->bList->data); list_Pop(&bChain->bList); } return; }
/* Function: vLevel_Save Description - Function that saves a level in the /Level/ folder. 3 arguments: Vent_Level *l - the level to save char *directory - the name of the directory to save the level in char *name - the name to save the level as, .map will be appended to this */ void vLevel_Save(Vent_Level *l, char *directory, char *name) { char *saveFolder = directory; char *saveName = (char *)mem_Malloc(strlen(saveFolder) + strlen(name) + strlen(".map") + 1, __LINE__, __FILE__); int x = 0; FILE *save = NULL; strcpy(saveName, saveFolder); strcat(saveName, name); strcat(saveName, ".map"); save = fopen(saveName, "w"); if(save == NULL) { printf("Error could not save level %s\n", saveName); return; } l->header.numCustomSurfaces = vLevel_GetCustomSurfaces(l); /*Structure of the level in a file - First write the object tag - [TAGNAME] objectAmount tagVersion Then below that write all the object data. */ vLevel_SaveHeader(&l->header, save); vLevel_SaveCustomSurface(l, save); vLevel_SaveTile(l, save); vLevel_SaveSupply(l, save); vLevel_SaveNode(l, save); vLevel_SaveEdge(l, save); vLevel_SaveTag(save, 0, TAG_END); fclose(save); mem_Free(saveName); return; }
/** * Put an element back into its pool. * * @param type the pool where to put mem * @param mem the memp element to free */ void memp_free(memp_t type, void *mem) { rt_uint32_t level; level = rt_hw_interrupt_disable(); if (type == MEMP_TCP_PCB && mem) { tcp_pcbs --; } rt_hw_interrupt_enable(level); LWIP_DEBUGF(MEMP_DEBUG, ("memp free %s, mem 0x%x\n", memp_desc[type], mem)); /* release this memory */ mem_Free(mem); }
void list_Pop(struct list **head) { struct list *listStart = *head; if((*head)->next != NULL) (*head)->next->previous = (*head)->previous; /*Set the previous to point to the end of the list*/ *head = (*head)->next; #ifdef MEM_TRACK mem_Free(listStart); #else free(listStart); #endif return; }
static void MM_QuitCampaign(Ui_Button *button) { Base_State *gState = button->info->dataArray[0]; int accepted = (int)button->info->dataArray[1]; struct menu_Game *menu = gState->info; char *campaignName = (char *)mem_Malloc(strlen(menu->selectedCampaign) + 1, __LINE__, __FILE__); strcpy(campaignName, menu->selectedCampaign); /*Fix the campaign name*/ string_RemoveExt(campaignName); /*Revert to the main ui section*/ uiSpine_Close(uiSpine_GetEntity(&menu->spine, "Spine:Campaign")); /*If the campaign chosen was accepted*/ if(accepted == 1) { vPlayer_LoadCampaign(menu->player, campaignName); if(menu->player->playCampaign == 1 && menu->player->campaign != NULL) { menu->selectedCampaign = menu->player->campaign->name; menu->player->levelDirectory = kernel_GetPath("PTH_VentLevels"); } else { menu->player->levelDirectory = kernel_GetPath("PTH_VentCustomLevels"); } /*Repopulate the level scroll*/ MM_RepopulateLevels(gState); } timer_StopSkip(&menu->spine.sTimer, 0, 1); control_Pause(500); mem_Free(campaignName); return; }
void list_ClearAll(struct list **listHead) { struct list *dataFetch; while(*listHead != NULL) { dataFetch = *listHead; #ifdef MEM_TRACK mem_Free(dataFetch->data); #else free(dataFetch->data); #endif list_Pop(listHead); } return; }
int aiModule_DestroyState(Ai_Module *aiMod, struct list **headList, struct list *currentNode, Ai_State *a) { list_Delete_Node(headList, currentNode);/*Remove the state from the list*/ /*Make sure the state is not in the lowest/highest priority tracking in the ai module*/ if(a == aiMod->highestPriority) { aiMod->highestPriority = NULL; } if(a == aiMod->lowestPriority) { aiMod->lowestPriority = NULL; } /*Release any memory allocated for the state*/ aiState_Clean(a); mem_Free(a); /*and delete the state*/ return 0; }
/* Function: control_Clear Description - Removes all keys in an event. Returns the number of keys removed. 1 argument: Control_Event *c - should point to the event that needs the keys removed. */ int control_Clear(Control_Event *c) { Control_Keys *keys = NULL; int numRemoved = 0; while(c->eventKeys != NULL) { keys = c->eventKeys->data; if(keys != NULL) { control_CleanKeys(keys); mem_Free(keys); } list_Pop(&c->eventKeys); numRemoved ++; } return numRemoved; }
/* Function: drawLayer_Clean Description - Removes and cleans up all objects in the layer. 1 argument: Draw_Layer *layer - The layer to clean up. */ void drawLayer_Clean(Draw_Layer *layer) { Draw_Object *drawObj = NULL; while(layer->objectList != NULL) { drawObj = layer->objectList->data; if(drawObj->type->cleanFunction != NULL) { drawObj->type->cleanFunction(drawObj); } drawObject_Clean(drawObj); mem_Free(drawObj); *layer->totalObjectLocations = *layer->totalObjectLocations - 1; list_Pop(&layer->objectList); } return; }
void MM_RepopulateLevels(Base_State *gState) { struct menu_Game *menu = gState->info; Ui_ButtonScroll *scroll = NULL; /*Clean up the current level scroll*/ scroll = uiSpine_RemoveEntity(&menu->spine, "Scroll:Levels"); uiButtonScroll_Clean(scroll); mem_Free(scroll); /*Add in the new one*/ scroll = MM_CreateLevelScroll(gState); uiSpine_AddScroll(&menu->spine, scroll, "Scroll:Levels"); menu->player->levelChosen = "None"; vLevel_SetupHeader(&menu->levelHeader, "None", 0, 0); uiSpine_MapEntity(&menu->spine); return; }