www.pudn.com > RCApp-src.zip > ModelManager.cpp
/* RedEye Project (http://members.ozemail.com.au/~ndmcevoy/) Copyright (C) 2003 Nick McEvoy This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------- Commented for use with Doxygen (http://www.doxygen.org) ----------------------------------------------------------------- */ /*! \file ModelManager.cpp * \brief Model manager. * * This file contains the model manager. */ // GLUT includes #include// RedEye includes #include "ModelManager.h" #include "SoundManager.h" #include "RCDefs.h" #include "Engine.h" #include "Status.h" #include "GUI.h" //! The one and only instance reModelManager* reModelManager::mpInstance = NULL; reModelManager::reModelManager() : mModelList(false) { } reModelManager::~reModelManager() { DestroyDatabase(); mpInstance = NULL; } reModelManager* reModelManager::GetInstance() { if (mpInstance == NULL) { mpInstance = new reModelManager; } return mpInstance; } void reModelManager::CreateDatabase() { printf("reModelManager::CreateDatabase() - creating models...\n"); // Set up the path to the data files ssgModelPath("models") ; ssgTexturePath("textures") ; // Get models TiXmlNode* pNode = reGetGameEngine()->GetXMLLevelNode(); pNode = pNode->FirstChild("Models"); pNode = pNode->FirstChild("Model"); TiXmlNode* pElement = pNode->ToElement(); while (pElement) { const char* psName = reGetXMLAttribute(pElement, "name", ""); const char* psFile = reGetXMLAttribute(pElement, "file", ""); bool bClearTravMask = reGetXMLAttribute(pElement, "clear_trav_mask", false); // Keep sound going reGetSoundManager()->Update(); // Load model LoadModel(psName, psFile, bClearTravMask); pElement = pElement->NextSiblingElement(); } printf("reModelManager::CreateDatabase() - done\n"); } void reModelManager::DestroyDatabase() { printf("reModelManager::DestroyDatabase() - destroying models...\n"); // Destroy object models LISTPOSITION pos = mModelList.GetHeadPosition(); while (pos) { ssgEntity* pEntity = mModelList.GetNext(pos); ssgDeRefDelete(pEntity); } mModelList.RemoveAll(); printf("reModelManager::DestroyDatabase() - done\n"); } ssgEntity* reModelManager::GetModel(const char* sName) { LISTPOSITION pos = mModelList.GetHeadPosition(); while (pos) { ssgEntity* pEntity = mModelList.GetNext(pos); if (strcmp(pEntity->getName(), sName) == 0) return pEntity; // Found } return NULL; // Not found } void reModelManager::LoadModel(const char* sName, const char* sFileName, bool bClearTravMaskBits) { printf("reModelManager::LoadModel() - loading <%s>\n", sFileName); // Display status text char sText[RE_STRING_MAX]; sprintf(sText, "Loading: <%s:%s>", sName, sFileName); reGetGameGUI()->SetText(reGameGUI::eStatusText, sText, true); reGetGameEngine()->Display(); // Load object ssgEntity* pObject = ssgLoadAC3D(sFileName); if (pObject) { pObject->ref(); pObject->setName(sName); if (bClearTravMaskBits) pObject->clrTraversalMaskBits(SSGTRAV_ISECT|SSGTRAV_HOT); mModelList.AddTail(pObject); } reGetGameGUI()->SetText(reGameGUI::eStatusText, "", false); reGetGameEngine()->Display(); }