static void MFMaterial_Destroy(MFResource *pRes) { MFMaterial *pMaterial = (MFMaterial*)pRes; MFStateBlock_Destroy(pMaterial->pMaterialState); pMaterial->pType->materialCallbacks.pDestroyInstance(pMaterial); MFHeap_Free(pMaterial->pInstanceData); MFHeap_Free(pMaterial); }
void MFPoolHeapCollection::Destroy() { for(int i = 0; i < numHeaps; ++i) { pHeaps[i]->Destroy(); // TODO: *** FIX ME!!! MFHeap_Free(pHeaps[i]); } MFHeap_Free(pHeaps); }
MF_API MFVertexBuffer *MFVertex_CreateVertexBuffer(const MFVertexDeclaration *pVertexFormat, int numVerts, MFVertexBufferType type, void *pVertexBufferMemory, const char *pName) { int nameLen = pName ? MFString_Length(pName) + 1 : 0; MFVertexBuffer *pVB; if(type == MFVBType_Scratch) pVB = (MFVertexBuffer*)MFRenderer_AllocateScratchMemory(sizeof(MFVertexBuffer) + nameLen); else pVB = (MFVertexBuffer*)MFHeap_Alloc(sizeof(MFVertexBuffer) + nameLen); MFZeroMemory(pVB, sizeof(MFVertexBuffer)); if(pName) pName = MFString_Copy((char*)&pVB[1], pName); pVB->pVertexDeclatation = pVertexFormat; pVB->bufferType = type; pVB->numVerts = numVerts; if(!MFVertex_CreateVertexBufferPlatformSpecific(pVB, pVertexBufferMemory)) { if(type != MFVBType_Scratch) MFHeap_Free(pVB); return NULL; } if(type == MFVBType_Scratch) { // add to a scratch list that will be cleaned up later... pVB->pNextScratchBuffer = gpScratchBufferList; gpScratchBufferList = pVB; } else MFResource_AddResource(pVB, MFRT_VertexBuffer, (uint32)(MFUtil_HashPointer(pVB) & 0xFFFFFFFF), pName); return pVB; }
MF_API void MFVertex_UnlockIndexBuffer(MFIndexBuffer *pIndexBuffer) { MFDebug_Assert(pIndexBuffer, "NULL index buffer"); MFDebug_Assert(pIndexBuffer->bLocked, "Index buffer not locked!"); ID3D11Buffer *pIB = (ID3D11Buffer*)pIndexBuffer->pPlatformData; if(pIB) pIB->Release(); D3D11_BUFFER_DESC bd; MFZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_IMMUTABLE; bd.ByteWidth = sizeof(WORD) * pIndexBuffer->numIndices; bd.BindFlags = D3D11_BIND_INDEX_BUFFER; D3D11_SUBRESOURCE_DATA initData; MFZeroMemory(&initData, sizeof(initData)); initData.pSysMem = pIndexBuffer->pLocked; HRESULT hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &pIB); MFDebug_Assert(SUCCEEDED(hr), "Couldn't create index buffer!"); if (FAILED(hr)) return; pIndexBuffer->pPlatformData = pIB; MFHeap_Free(pIndexBuffer->pLocked); pIndexBuffer->pLocked = NULL; pIndexBuffer->bLocked = false; }
int F3DFile::ReadMD2(const char *pFilename) { pModel = this; size_t size; char *pFile = MFFileSystem_Load(pFilename, &size); if(!pFile) { MFDebug_Warn(2, MFStr("Failed to open MD2 file %s", pFilename)); return 1; } int a; for(a=(int)MFString_Length(pFilename)-1; a>=0; --a) { if(pFilename[a] == '/' || pFilename[a] == '\\') { break; } } pModel->name = pFilename + a+1; pModel->name.TruncateExtension(); ParseMD2File(pFile, size); MFHeap_Free(pFile); return 0; }
int F3DFile::ReadOBJ(const char *pFilename) { pModel = this; MFFile *pFile = MFFileSystem_Open(pFilename, MFOF_Read); if(!pFile) { MFDebug_Warn(2, MFStr("Failed to open OBJ file %s", pFilename)); return 1; } uint64 size = MFFile_Seek(pFile, 0, MFSeek_End); MFFile_Seek(pFile, 0, MFSeek_Begin); char *pMem = (char*)MFHeap_Alloc((size_t)size+1); MFFile_Read(pFile, pMem, size); pMem[size] = 0; MFFile_Close(pFile); ParseOBJFile(pMem); MFHeap_Free(pMem); return 0; }
int F3DFile::ReadMD2(const char *pFilename) { pModel = this; size_t size; char *pFile = MFFileSystem_Load(pFilename, &size); if(!pFile) { MFDebug_Warn(2, MFStr("Failed to open MD2 file %s", pFilename)); return 1; } int a; for(a=MFString_Length(pFilename)-1; a>=0; --a) { if(pFilename[a] == '/' || pFilename[a] == '\\') { break; } } MFString_Copy(pModel->name, &pFilename[a+1]); pModel->name[MFString_Length(pModel->name) - 4] = 0; ParseMD2File(pFile, size); MFHeap_Free(pFile); return 0; }
MF_API int MFFileSystem_Dismount(const char *pMountpoint) { GET_MODULE_DATA(MFFileSystemState); MFMount *pT = MFFileSystem_FindVolume(pMountpoint); if(pT) { // dismount pModuleData->ppFileSystemList[pT->volumeInfo.fileSystem]->callbacks.FSDismount(pT); // remove mount if(pModuleData->pMountList == pT) pModuleData->pMountList = pT->pNext; if(pModuleData->pMountListEnd == pT) pModuleData->pMountListEnd = pT->pPrev; if(pT->pNext) pT->pNext->pPrev = pT->pPrev; if(pT->pPrev) pT->pPrev->pNext = pT->pNext; MFHeap_Free(pT); return 0; } // coundnt find mount.. return -1; }
void MFFileSystem_UnregisterFileSystem(MFFileSystemHandle filesystemHandle) { MFDebug_Assert((uint32)filesystemHandle < gDefaults.filesys.maxFileSystems, "Invalid filesystem"); GET_MODULE_DATA(MFFileSystemState); MFFileSystem *pFS = pModuleData->ppFileSystemList[filesystemHandle]; MFDebug_Assert(pFS, "Filesystem not mounted"); if(pFS->callbacks.UnregisterFS) pFS->callbacks.UnregisterFS(); if(pFS->thread) { // terminate job thread MFJob *pJob = NewJob(pFS); PostJob(pFS, pJob); while(pJob->status != MFJS_Finished) { // yield } MFThread_DestroySemaphore(pFS->semaphore); pFS->jobs.Deinit(); MFHeap_Free(pFS->ppJobQueue); } pModuleData->gFileSystems.Destroy(pFS); pModuleData->ppFileSystemList[filesystemHandle] = NULL; }
MF_API void MFInput_EnableBufferedInput(bool bEnable, int frequency) { gInputFrequency = frequency; if(!gInputThread) { for(int i=0; i<MFInput_MaxInputID; ++i) { gInputEvents[IDD_Gamepad][i] = (MFInputEvent*)MFHeap_Alloc(sizeof(MFInputEvent)*MaxEvents); gNumEvents[IDD_Gamepad][i] = 0; } gInputMutex = MFThread_CreateMutex("MFInput Mutex"); gInputThread = MFThread_CreateThread("MFInput Thread", &MFInput_Thread, NULL); } else { bInputTerminate = true; MFThread_Join(gInputThread); gInputThread = NULL; MFThread_DestroyMutex(gInputMutex); for(int i=0; i<MFInput_MaxInputID; ++i) { MFHeap_Free(gInputEvents[IDD_Gamepad][i]); } } }
MF_API void MFAnimation_Destroy(MFAnimation *pAnimation) { // release the template MFResource_Release(pAnimation->pTemplate); // free the instance MFHeap_Free(pAnimation); }
void MFView_DeinitModule() { /// free view stack if(gpViewStack) { MFHeap_Free(gpViewStack); gpViewStack = NULL; } }
void MFPoolHeap::Destroy() { MFDebug_Assert(itemSize != 0, "Not initialised"); itemSize = 0; if(bOwnStorage) MFHeap_Free(pStorage); }
void DestroyVorbisStream(MFAudioStream *pStream) { MFVorbisStream *pVS = (MFVorbisStream*)pStream->pStreamData; pVS->pInfo = NULL; ov_clear(&pVS->vorbisFile); MFHeap_Free(pVS); }
int F3DFile::ReadASE(const char *pFilename) { char *pMem = MFFileSystem_Load(pFilename, NULL, true); ParseASEFile(pMem, this); MFHeap_Free(pMem); return 0; }
void MFDisplay_DeinitModulePlatformSpecific() { if(gpDisplayAdaptors) MFHeap_Free(gpDisplayAdaptors); // FreeModes(); XCloseDisplay(xdisplay); }
MF_API void MFIntSound_CreateRuntimeData(MFIntSound *pSound, void **ppOutput, size_t *pSize, MFPlatform platform) { *ppOutput = NULL; MFAudioStream *pStream = (MFAudioStream*)pSound->pInternal; // decode audio into buffer size_t sampleSize = (pSound->soundTemplate.bitsPerSample * pSound->soundTemplate.numChannels) >> 3; size_t bytesAllocated = 44100 * sampleSize; size_t bytes = 0; char *pAudioData = (char*)MFHeap_Alloc(bytesAllocated); size_t read; do { // read samples from stream read = MFSound_ReadStreamSamples(pStream, pAudioData + bytes, bytesAllocated - bytes); bytes += read; // if we fill the buffer, increase it's size if(bytes == bytesAllocated) { bytesAllocated *= 4; pAudioData = (char*)MFHeap_Realloc(pAudioData, bytesAllocated); } } while(read); // calculate the number of samples from the bytes read int numSamples = (int)(bytes / sampleSize); // construct MFSoundTemplate size_t templateBytes = sizeof(MFSoundTemplate) + sizeof(char*)*pSound->soundTemplate.numStreams + sampleSize*numSamples; MFSoundTemplate *pTemplate = (MFSoundTemplate*)MFHeap_Alloc(templateBytes); MFCopyMemory(pTemplate, &pSound->soundTemplate, sizeof(MFSoundTemplate)); pTemplate->numSamples = numSamples; pTemplate->ppStreams = (char**)&pTemplate[1]; pTemplate->ppStreams[0] = (char*)&pTemplate->ppStreams[1]; // copy sample data MFCopyMemory(pTemplate->ppStreams[0], pAudioData, sampleSize * numSamples); // free decode buffer MFHeap_Free(pAudioData); // fix down pointers for(int a=0; a<pTemplate->numStreams; a++) MFFixUp(pTemplate->ppStreams[a], pTemplate, false); MFFixUp(pTemplate->ppStreams, pTemplate, false); // return template data *ppOutput = pTemplate; if(pSize) *pSize = templateBytes; }
MF_API void MFRenderer_Destroy(MFRenderer *pRenderer) { for(int a=0; a<pRenderer->numLayers; ++a) { if(pRenderer->pLayers[a].pRenderTarget) MFRenderTarget_Release(pRenderer->pLayers[a].pRenderTarget); } MFHeap_Free(pRenderer); }
MF_API void MFCollision_DestroyField(MFCollisionItem *pField) { MFCollision_ClearField(pField); MFCollisionField *pFieldData = (MFCollisionField*)pField->pTemplate->pCollisionTemplateData; pFieldData->itemList.Deinit(); MFHeap_Free(pField->pTemplate); MFCollision_DestroyCollisionItem(pField); }
void MFObjectPool::Deinit() { if(!pMemory) return; MFThread_LockMutex(mutex); if(pNext) { pNext->Deinit(); MFHeap_Free(pNext); pNext = NULL; } MFThread_DestroyMutex(mutex); if(bOwnMemory) MFHeap_Free(pMemory); pMemory = NULL; }
static void MFVertex_DestroyVertexBuffer(MFResource *pRes) { MFVertexBuffer *pVertexBuffer = (MFVertexBuffer*)pRes; MFDebug_Assert(pVertexBuffer->bufferType != MFVBType_Scratch, "Scratch buffers should not be freed!"); if(pVertexBuffer->bufferType == MFVBType_Scratch) return; MFVertex_DestroyVertexBufferPlatformSpecific(pVertexBuffer); MFHeap_Free(pVertexBuffer); }
void MFObjectPoolGroup::Deinit() { MFThread_LockMutex(mutex); for(int a=0; a<numPools; ++a) pPools[a].Deinit(); MFThread_DestroyMutex(mutex); MFHeap_Free(pConfig); }
MF_API void MFWindow_Destroy(MFWindow *_pWindow) { MFWindow_PC *pWindow = (MFWindow_PC*)_pWindow; // TODO: destroy associated display here? if(!DestroyWindow(pWindow->hWnd)) MFDebug_Warn(1, "Couldn't destroy window!"); MFHeap_Free(pWindow); }
MF_API int MFModel_Destroy(MFModel *pModel) { // free instance data if(pModel->pAnimation) MFAnimation_Destroy(pModel->pAnimation); // decrement and possibly free template --pModel->pTemplate->refCount; int refCount = pModel->pTemplate->refCount; if(!pModel->pTemplate->refCount) { MFModelDataChunk *pChunk = MFModel_GetDataChunk(pModel->pTemplate, MFChunkType_SubObjects); if(pChunk) { MFModelSubObject *pSubobjects = (MFModelSubObject*)pChunk->pData; for(int a=0; a<pChunk->count; a++) { // MFMaterial_Destroy(pSubobjects[a].pMaterial); for(int b=0; b<pSubobjects[a].numMeshChunks; b++) { MFModel_DestroyMeshChunk(MFModel_GetMeshChunk(pModel, a, b)); } } } // remove it from the registry // TODO: this is a scanning destroy, do this by hash...? gModelBank.Destroy(pModel->pTemplate->pName); MFHeap_Free(pModel->pTemplate); } //free instance MFHeap_Free(pModel); return refCount; }
void MFPoolHeapExpanding::Destroy() { MFPoolHeap *pHeap = heap.GetNextHeap(); while(pHeap != NULL) { MFPoolHeap *pNextHeap = pHeap->GetNextHeap(); pHeap->Destroy(); MFHeap_Free(pHeap); pHeap = pNextHeap; } heap.Destroy(); }
static void DestroyOutputDevice(MFDevice *pDevice) { MFMidiPC_MidiOutputDevice *pDev = (MFMidiPC_MidiOutputDevice*)pDevice->pInternal; if (pDev->hMidiOut) { MFDebug_Warn(1, MFStr("MIDI output device not closed: %s", pDevice->strings[MFDS_ID])); midiOutReset(pDev->hMidiOut); midiOutClose(pDev->hMidiOut); } MFHeap_Free(pDev); }
MF_API void MFCollision_ClearField(MFCollisionItem *pField) { MFCollisionField *pFieldData = (MFCollisionField*)pField->pTemplate->pCollisionTemplateData; if(pFieldData->pppItems) { MFHeap_Free(pFieldData->pppItems); pFieldData->pppItems = NULL; } pFieldData->itemList.Clear(); }
MF_API MFTexture* MFTexture_CreateRenderTarget(const char *pName, int width, int height, MFTextureFormat targetFormat) { MFTexture *pTexture = MFTexture_FindTexture(pName); if(!pTexture) { pTexture = &gTextureBank.Create(pName); if(targetFormat & TexFmt_SelectNicest) { targetFormat = TexFmt_A8R8G8B8; } pTexture->pTemplateData = (MFTextureTemplateData*)MFHeap_AllocAndZero(sizeof(MFTextureTemplateData) + sizeof(MFTextureSurfaceLevel)); pTexture->pTemplateData->pSurfaces = (MFTextureSurfaceLevel*)&pTexture->pTemplateData[1]; pTexture->pTemplateData->magicNumber = MFMAKEFOURCC('F','T','E','X'); pTexture->pTemplateData->imageFormat = targetFormat; pTexture->pTemplateData->mipLevels = 1; pTexture->pTemplateData->flags = TEX_RenderTarget; pTexture->pTemplateData->pSurfaces->width = width; pTexture->pTemplateData->pSurfaces->height = height; pTexture->pTemplateData->pSurfaces->bitsPerPixel = MFTexture_GetBitsPerPixel(pTexture->pTemplateData->imageFormat); pTexture->pTemplateData->pSurfaces->xBlocks = width; pTexture->pTemplateData->pSurfaces->yBlocks = height; pTexture->pTemplateData->pSurfaces->bitsPerBlock = pTexture->pTemplateData->pSurfaces->bitsPerPixel; pTexture->pTemplateData->pSurfaces->pImageData = NULL; pTexture->pTemplateData->pSurfaces->bufferLength = 0; pTexture->pTemplateData->pSurfaces->pPaletteEntries = NULL; pTexture->pTemplateData->pSurfaces->paletteBufferLength = 0; pTexture->refCount = 1; MFString_CopyN(pTexture->name, pName, sizeof(pTexture->name) - 1); pTexture->name[sizeof(pTexture->name) - 1] = 0; D3DFORMAT platformFormat = (D3DFORMAT)MFTexture_GetPlatformFormatID(targetFormat, MFDD_D3D9); HRESULT hr = pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, platformFormat, D3DPOOL_DEFAULT, (IDirect3DTexture9**)&pTexture->pInternalData, NULL); if(hr != D3D_OK) { MFHeap_Free(pTexture->pTemplateData); gTextureBank.DestroyItem(*pTexture); pTexture = NULL; } } else { pTexture->refCount++; } return pTexture; }
void MFMat_Standard_DestroyInstance(MFMaterial *pMaterial) { MFCALLSTACK; MFMat_Standard_Data *pData = (MFMat_Standard_Data*)pMaterial->pInstanceData; for(uint32 a=0; a<pData->textureCount; a++) { MFTexture_Destroy(pData->pTextures[a]); } MFHeap_Free(pMaterial->pInstanceData); }
void MFFileSystem_ReleaseToc(MFTOCEntry *pEntry, int numEntries) { MFCALLSTACK; for(int a=0; a<numEntries; a++) { if(pEntry[a].info.attributes & MFFA_Directory) { MFFileSystem_ReleaseToc(pEntry[a].pChildren, pEntry[a].numChildren); } } MFHeap_Free(pEntry); }