void cAStarHandler::AddOpenNode(cAINode *apAINode, cAStarNode *apParent, float afDistance) { //TODO: free path check with dynamic objects here. //TODO: Some pooling here would be good. cAStarNode *pNode = hplNew( cAStarNode, (apAINode) ); //Check if it is in closed list. tAStarNodeSetIt it = m_setClosedList.find(pNode); if(it != m_setClosedList.end()){ hplDelete(pNode); return; } //Try to add it to the open list std::pair<tAStarNodeSetIt, bool> testPair = m_setOpenList.insert(pNode); if(testPair.second == false){ hplDelete(pNode); return; } pNode->mfDistance = afDistance; pNode->mfCost = Cost(afDistance,apAINode,apParent) + Heuristic(pNode->mpAINode->GetPosition(), mvGoal); pNode->mpParent = apParent; }
cMapHandlerSoundCallback::cMapHandlerSoundCallback(cInit *apInit) { mpInit = apInit; /////////////////////////////////////////// //Load all sounds that can heard by enemies tString sFile = "sounds/EnemySounds.dat"; TiXmlDocument* pXmlDoc = hplNew( TiXmlDocument, (sFile.c_str()) ); if(pXmlDoc->LoadFile()==false){ Error("Couldn't load XML file '%s'!\n",sFile.c_str()); hplDelete( pXmlDoc ); return; } //Get the root. TiXmlElement* pRootElem = pXmlDoc->RootElement(); TiXmlElement* pChildElem = pRootElem->FirstChildElement(); for(; pChildElem != NULL; pChildElem = pChildElem->NextSiblingElement()) { tString sName = cString::ToString(pChildElem->Attribute("name"),""); mvEnemyHearableSounds.push_back(sName); } hplDelete( pXmlDoc ); }
cMapHandler::~cMapHandler(void) { if(mpMapChangeTexture)mpInit->mpGame->GetResources()->GetTextureManager()->Destroy(mpMapChangeTexture); hplDelete(mpSoundCallback ); hplDelete( mpWorldCache ); }
cPortalContainer::~cPortalContainer() { hplDelete(mpEntityCallback); hplDelete(mpNormalEntityCallback); STLMapDeleteAll(m_mapSectors); }
bool cResources::LoadResourceDirsFile(const tString &asFile) { TiXmlDocument* pXmlDoc = hplNew( TiXmlDocument, (asFile.c_str()) ); if(pXmlDoc->LoadFile()==false) { Error("Couldn't load XML file '%s'!\n",asFile.c_str()); hplDelete( pXmlDoc); return false; } //Get the root. TiXmlElement* pRootElem = pXmlDoc->RootElement(); TiXmlElement* pChildElem = pRootElem->FirstChildElement(); for(; pChildElem != NULL; pChildElem = pChildElem->NextSiblingElement()) { tString sPath = cString::ToString(pChildElem->Attribute("Path"),""); if(sPath==""){ continue; } if(sPath[0]=='/' || sPath[0]=='\\') sPath = sPath.substr(1); AddResourceDir(sPath); } hplDelete(pXmlDoc); return true; }
cWorld3D::~cWorld3D() { if(cHaptic::GetIsUsed()) { //mpHaptic->GetLowLevel()->DestroyAllShapes(); //Not so good to do it here.. } STLDeleteAll(mlstMeshEntities); STLDeleteAll(mlstLights); STLDeleteAll(mlstBillboards); STLDeleteAll(mlstBeams); STLDeleteAll(mlstColliders); STLDeleteAll(mlstParticleSystems); STLDeleteAll(mlstStartPosEntities); STLMapDeleteAll(m_mapAreaEntities); STLDeleteAll(mlstAINodeContainers); STLDeleteAll(mlstAStarHandlers); STLMapDeleteAll(m_mapTempNodes); if(mpScript){ mpResources->GetScriptManager()->Destroy(mpScript); } if(mpPhysicsWorld && mbAutoDeletePhysicsWorld) mpPhysics->DestroyWorld(mpPhysicsWorld); //So that bodies can stop sound entities on destruction. STLDeleteAll(mlstSoundEntities); hplDelete(mpPortalContainer); hplDelete(mpRootNode); }
void cImageManager::Destroy(iResourceBase* apResource) { //Lower the user num for the the resource. If it is 0 then lower the //user num for the TextureFrame and delete the resource. If the Texture //frame reaches 0 it is deleted as well. cResourceImage *pImage = static_cast<cResourceImage*>(apResource); cFrameTexture *pFrame = pImage->GetFrameTexture(); cFrameBitmap *pBmpFrame = pImage->GetFrameBitmap(); //pImage->GetFrameBitmap()->FlushToTexture(); Not needed? //Log("Users Before: %d\n",pImage->GetUserCount()); //Log("Framepics Before: %d\n",pFrame->GetPicCount()); pImage->DecUserCount();//dec frame count as well.. is that ok? //Log("---\n"); //Log("Destroyed Image: '%s' Users: %d\n",pImage->GetName().c_str(),pImage->GetUserCount()); //Log("Frame %d has left Pics: %d\n",pFrame,pFrame->GetPicCount()); if(pImage->HasUsers()==false) { pFrame->DecPicCount(); // Doing it here now instead. pBmpFrame->DecPicCount(); RemoveResource(apResource); hplDelete(apResource); //Log("deleting image and dec fram to %d images!\n",pFrame->GetPicCount()); } if(pFrame->IsEmpty()) { //Log(" Deleting frame..."); //Delete the bitmap frame that has this this frame. for(tFrameBitmapListIt it=mlstBitmapFrames.begin();it!=mlstBitmapFrames.end();++it) { cFrameBitmap *pBmpFrame = *it; if(pBmpFrame->GetFrameTexture() == pFrame) { //Log("and bitmap..."); hplDelete(pBmpFrame); mlstBitmapFrames.erase(it); break; } } //delete from list m_mapTextureFrames.erase(pFrame->GetHandle()); hplDelete(pFrame); //Log(" Deleted frame!\n"); } //Log("---\n"); }
iFontData* cFontManager::CreateFontData(const tString& asName, int alSize,unsigned short alFirstChar, unsigned short alLastChar) { tString sPath; iFontData* pFont; tString asNewName = cString::ToLowerCase(asName); BeginLoad(asName); //asNewName = cString::SetFileExt(asName,"ttf"); pFont = static_cast<iFontData*>(this->FindLoadedResource(asNewName,sPath)); if(pFont==NULL && sPath!="") { pFont = mpGraphics->GetLowLevel()->CreateFontData(asNewName); pFont->SetUp(mpGraphics->GetDrawer(),mpLowLevelResources,mpGui); tString sExt = cString::ToLowerCase(cString::GetFileExt(asName)); //True Type Font if(sExt == "ttf") { if(pFont->CreateFromFontFile(sPath,alSize,alFirstChar,alLastChar)==false){ hplDelete(pFont); EndLoad(); return NULL; } } //Angel code font type else if(sExt == "fnt") { if(pFont->CreateFromBitmapFile(sPath)==false){ hplDelete(pFont); EndLoad(); return NULL; } } else { Error("Font '%s' has an unkown extension!\n",asName.c_str()); hplDelete(pFont); EndLoad(); return NULL; } //mpResources->GetImageManager()->FlushAll(); AddResource(pFont); } if(pFont)pFont->IncUserCount(); else Error("Couldn't create font '%s'\n",asNewName.c_str()); EndLoad(); return pFont; }
cSound::~cSound() { Log("Exiting Sound Module\n"); Log("--------------------------------------------------------\n"); hplDelete(mpSoundHandler); hplDelete(mpMusicHandler); Log("--------------------------------------------------------\n\n"); }
bool cMusicHandler::Play(const tString& asFileName,float afVolume, float afFadeStepSize, bool abLoop) { bool bSongIsPlaying = false; if(mpLock!=NULL){ mpLock->msFileName = asFileName; mpLock->mfVolume = afVolume; mpLock->mbLoop = abLoop; return true; } if(mpMainSong != NULL) if(asFileName == mpMainSong->msFileName) bSongIsPlaying = true; if(!bSongIsPlaying) { //Put the previous song in the fading queue if(mpMainSong != NULL) { mpMainSong->mfVolumeAdd = afFadeStepSize; mlstFadingSongs.push_back(mpMainSong); } //If there the song to be played is in the fade que, stop it. tMusicEntryListIt it = mlstFadingSongs.begin(); while(it != mlstFadingSongs.end()) { cMusicEntry* pSong = *it; if(pSong->msFileName == asFileName) { pSong->mfVolume= 0; pSong->mpStream->Stop(); hplDelete(pSong->mpStream); hplDelete(pSong); it = mlstFadingSongs.erase(it); } else { it++; } } //add it and set its properties mpMainSong = hplNew( cMusicEntry, () ); if(LoadAndStart(asFileName, mpMainSong,0,abLoop)==false){ hplDelete(mpMainSong); mpMainSong = NULL; return false; } } else { if(mpMainSong->mfMaxVolume == afVolume)return true;
cRenderList::~cRenderList() { Clear(); hplDelete(mTempNode.mpState); hplDelete(m_poolRenderState); hplDelete(m_poolRenderNode); g_poolRenderState = NULL; g_poolRenderNode = NULL; }
void cPreMenu::LoadConfig() { //////////////////////////////////////////////// //Load the document TiXmlDocument *pXmlDoc = hplNew( TiXmlDocument, ("config/startup.cfg") ); if(pXmlDoc->LoadFile()==false){ Error("Couldn't load XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } //////////////////////////////////////////////// //Load the root TiXmlElement *pRootElem = pXmlDoc->FirstChildElement(); if(pRootElem==NULL){ Error("Couldn't load root from XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } //////////////////////////////////////////////// //Load the Main element. TiXmlElement *pMainElem = pRootElem->FirstChildElement("Main"); if(pMainElem==NULL){ Error("Couldn't load Main element from XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } mbShowText = cString::ToBool(pMainElem->Attribute("ShowText"),false); //////////////////////////////////////////////// //Load the Logos element. TiXmlElement *pLogosParentElem = pRootElem->FirstChildElement("Logos"); if(pLogosParentElem==NULL){ Error("Couldn't load Logs element from XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } //////////////////////////////////////////////// //Get logos TiXmlElement *pLogoElem = pLogosParentElem->FirstChildElement("Logo"); for(; pLogoElem != NULL; pLogoElem = pLogoElem->NextSiblingElement("Logo")) { tString sFile = cString::ToString(pLogoElem->Attribute("File"),""); mvTexNames.push_back(sFile); //Log("Texture %s\n",sFile.c_str()); } hplDelete( pXmlDoc ); }
iVideoStream* cVideoManager::CreateVideo(const tString& asName) { BeginLoad(asName); tString sPath = mpFileSearcher->GetFilePath(asName); if(sPath == "") { EndLoad(); Error("Video file '%s' could not be found!\n",asName.c_str()); return NULL; } iVideoStreamLoader *pLoader = GetLoader(asName); if(pLoader==NULL) { Error("Could not find a loader for '%s'\n",asName.c_str()); return NULL; } iVideoStream *pVideo = pLoader->Create(asName); if(pVideo->LoadFromFile(sPath)==false) { EndLoad(); hplDelete(pVideo); Error("Could not load video '%s'\n",asName.c_str()); return NULL; } AddResource(pVideo); EndLoad(); return pVideo; }
void iGameEntity::RemoveCollideScript(eGameCollideScriptType aType,const tString &asEntity) { tGameCollideScriptMapIt it = m_mapCollideCallbacks.find(asEntity); if(it != m_mapCollideCallbacks.end()) { cGameCollideScript *pCallback = it->second; pCallback->msFuncName[aType] = ""; //if there are no functions left, erase if(pCallback->msFuncName[0]=="" && pCallback->msFuncName[1]=="" && pCallback->msFuncName[2]=="") { if(mbUpdatingCollisionCallbacks) { pCallback->mbDeleteMe = true; } else { hplDelete( pCallback ); m_mapCollideCallbacks.erase(it); } } } else { Warning("Entity '%s' callback doesn't exist in '%s'\n",asEntity.c_str(),msName.c_str()); } }
cSoundEntityData* cSoundEntityManager::CreateSoundEntity(const tString& asName) { tString sPath; cSoundEntityData* pSoundEntity; tString asNewName; BeginLoad(asName); asNewName = cString::SetFileExt(asName,"snt"); pSoundEntity = static_cast<cSoundEntityData*>(this->FindLoadedResource(asNewName,sPath)); if(pSoundEntity==NULL && sPath!="") { pSoundEntity = hplNew( cSoundEntityData, (asNewName) ); if(pSoundEntity->CreateFromFile(sPath)) { AddResource(pSoundEntity); } else { hplDelete(pSoundEntity); pSoundEntity =NULL; } } if(pSoundEntity)pSoundEntity->IncUserCount(); else Error("Couldn't create SoundEntity '%s'\n",asNewName.c_str()); EndLoad(); return pSoundEntity; }
iGpuProgram* cGpuProgramManager::CreateProgram(const tString& asName,const tString& asEntry, eGpuProgramType aType) { tString sPath; iGpuProgram* pProgram; pProgram = static_cast<iGpuProgram*>(FindLoadedResource(asName,sPath)); BeginLoad(asName); if(pProgram==NULL && sPath!="") { pProgram = mpLowLevelGraphics->CreateGpuProgram(asName, aType); if(pProgram->CreateFromFile(sPath,asEntry)==false) { Error("Couldn't create program '%s'\n",asName.c_str()); hplDelete(pProgram); EndLoad(); return NULL; } AddResource(pProgram); } if(pProgram)pProgram->IncUserCount(); else Error("Couldn't load program '%s'\n",asName.c_str()); EndLoad(); return pProgram; }
void iGameEntity::AddCollideScript(eGameCollideScriptType aType,const tString &asFunc, const tString &asEntity) { cGameCollideScript *pCallback; //Check if the function already exist tGameCollideScriptMapIt it = m_mapCollideCallbacks.find(asEntity); if(it != m_mapCollideCallbacks.end()) { pCallback = it->second; } else { pCallback = hplNew( cGameCollideScript, () ); //Get the entity iGameEntity *pEntity = mpInit->mpMapHandler->GetGameEntity(asEntity); if(pEntity==NULL) { Warning("Couldn't find entity '%s'\n",asEntity.c_str()); hplDelete( pCallback ); return; } //Set the entity pCallback->mpEntity = pEntity; //Add to container m_mapCollideCallbacks.insert(tGameCollideScriptMap::value_type(asEntity,pCallback)); } pCallback->msFuncName[aType] = asFunc; }
void cGameMessageHandler::Update(float afTimeStep) { if(mpInit->mpPlayer->IsDead()) { STLDeleteAll(mlstMessages); mlstMessages.clear(); return; } int lCount=0; tGameMessageListIt it = mlstMessages.begin(); for(;it != mlstMessages.end(); ++lCount) { cGameMessage *pMess = *it; pMess->Update(afTimeStep); if(lCount==0 && pMess->mbActive==false) { hplDelete( pMess ); it = mlstMessages.erase(it); } else { ++it; } } }
void cPhysicsBodyNewton::DeleteLowLevel() { //Log(" Newton body %d\n", (size_t)mpNewtonBody); NewtonDestroyBody(mpNewtonWorld,mpNewtonBody); //Log(" Callback\n"); hplDelete(mpCallback); }
cSubMesh::~cSubMesh() { if(mpMaterial)mpMaterialManager->Destroy(mpMaterial); if(mpVtxBuffer) hplDelete(mpVtxBuffer); if(mpVertexBones) hplDeleteArray(mpVertexBones); if(mpVertexWeights) hplDeleteArray(mpVertexWeights); }
void cVideoManager::Destroy(iResourceBase* apResource) { if(apResource) { RemoveResource(apResource); hplDelete(apResource); } }
void cImageManager::DeleteAllBitmapFrames() { FlushAll(); for(tFrameBitmapListIt it=mlstBitmapFrames.begin();it!=mlstBitmapFrames.end();) { hplDelete(*it); it = mlstBitmapFrames.erase(it); } }
void cImageEntityManager::Destroy(iResourceBase* apResource) { apResource->DecUserCount(); if(apResource->HasUsers()==false){ RemoveResource(apResource); hplDelete(apResource); } }
void cGraphicsDrawer::ClearBackgrounds() { tBackgroundImageMapIt it= m_mapBackgroundImages.begin(); for(; it != m_mapBackgroundImages.end(); it++) { hplDelete(it->second); } m_mapBackgroundImages.clear(); }
cMusicHandler::~cMusicHandler() { if(mpMainSong){ hplDelete(mpMainSong->mpStream); hplDelete(mpMainSong); } tMusicEntryListIt it = mlstFadingSongs.begin(); while(it != mlstFadingSongs.end()) { cMusicEntry* pSong = *it; hplDelete(pSong->mpStream); hplDelete(pSong); it = mlstFadingSongs.erase(it); //it++; } }
cSoundHandler::~cSoundHandler() { tSoundEntryListIt it; it = mlstGuiSounds.begin(); while(it != mlstGuiSounds.end()) { it->mpSound->Stop(); hplDelete(it->mpSound); it = mlstGuiSounds.erase(it); } it = mlstWorldSounds.begin(); while(it != mlstWorldSounds.end()) { it->mpSound->Stop(); hplDelete(it->mpSound); it = mlstWorldSounds.erase(it); } }
cGridMap2D::~cGridMap2D() { for(tGrid2DObjectMapIt it=m_mapAllObjects.begin(); it!=m_mapAllObjects.end(); it++) { it->second->Destroy(); hplDelete(it->second); } m_mapAllObjects.clear(); }
cLowLevelSystemSDL::~cLowLevelSystemSDL() { /*Release all runnings contexts */ mpScriptEngine->Release(); hplDelete(mpScriptOutput); //perhaps not the best thing to skip :) //if(gpLogWriter) hplDelete(gpLogWriter); //gpLogWriter = NULL; }
void cSoundEntityManager::Preload(const tString& asFile) { cSoundEntityData *pData = CreateSoundEntity(asFile); if(pData == NULL) { Warning("Couldn't preload sound '%s'\n",asFile.c_str()); return; } if(pData->GetMainSoundName() != ""){ iSoundChannel *pChannel = mpSound->GetSoundHandler()->CreateChannel(pData->GetMainSoundName(),0); if(pChannel) hplDelete(pChannel); } if(pData->GetStartSoundName() != ""){ iSoundChannel *pChannel = mpSound->GetSoundHandler()->CreateChannel(pData->GetStartSoundName(),0); if(pChannel) hplDelete(pChannel); } if(pData->GetStopSoundName() != ""){ iSoundChannel *pChannel = mpSound->GetSoundHandler()->CreateChannel(pData->GetStopSoundName(),0); if(pChannel) hplDelete(pChannel); } }
cScene::~cScene() { Log("Exiting Scene Module\n"); Log("--------------------------------------------------------\n"); STLDeleteAll(mlstWorld3D); STLDeleteAll(mlstCamera); hplDelete(mpCollider2D); Log("--------------------------------------------------------\n\n"); }