From: <vo...@us...> - 2008-10-26 15:28:39
|
Revision: 930 http://opde.svn.sourceforge.net/opde/?rev=930&view=rev Author: volca Date: 2008-10-26 15:28:35 +0000 (Sun, 26 Oct 2008) Log Message: ----------- Migrating the testing viewer to Opde::Root Modified Paths: -------------- trunk/src/main/GameLoadState.cpp trunk/src/main/GamePlayState.cpp trunk/src/main/GameStateManager.cpp trunk/src/main/GameStateManager.h trunk/src/main/Root.cpp trunk/src/main/Root.h Modified: trunk/src/main/GameLoadState.cpp =================================================================== --- trunk/src/main/GameLoadState.cpp 2008-10-26 14:18:30 UTC (rev 929) +++ trunk/src/main/GameLoadState.cpp 2008-10-26 15:28:35 UTC (rev 930) @@ -45,7 +45,7 @@ template<> GameLoadState* Singleton<GameLoadState>::ms_Singleton = 0; GameLoadState::GameLoadState() : mSceneMgr(NULL), mOverlayMgr(NULL), mLoaded(false) { - mRoot = Root::getSingletonPtr(); + mRoot = Ogre::Root::getSingletonPtr(); mOverlayMgr = OverlayManager::getSingletonPtr(); mServiceMgr = ServiceManager::getSingletonPtr(); Modified: trunk/src/main/GamePlayState.cpp =================================================================== --- trunk/src/main/GamePlayState.cpp 2008-10-26 14:18:30 UTC (rev 929) +++ trunk/src/main/GamePlayState.cpp 2008-10-26 15:28:35 UTC (rev 930) @@ -87,7 +87,7 @@ mSceneDetailIndex = 0; mNumScreenShots = 0; - mRoot = Root::getSingletonPtr(); + mRoot = Ogre::Root::getSingletonPtr(); mOverlayMgr = OverlayManager::getSingletonPtr(); mConsole = new ConsoleFrontend(); Modified: trunk/src/main/GameStateManager.cpp =================================================================== --- trunk/src/main/GameStateManager.cpp 2008-10-26 14:18:30 UTC (rev 929) +++ trunk/src/main/GameStateManager.cpp 2008-10-26 15:28:35 UTC (rev 930) @@ -65,17 +65,15 @@ GameStateManager::GameStateManager(std::string GameType) : mStateStack(), mTerminate(false), - mLogger(NULL), mRoot(NULL), - mStdLog(NULL), mConsoleBackend(NULL), mServiceMgr(NULL), - mDTypeScriptLdr(NULL), - mPLDefScriptLdr(NULL), - mDirArchiveFactory(NULL), - mCrfArchiveFactory(NULL), + mInputService(NULL), mConfigService(NULL) { mGameType = GameType; + + mRoot = new Opde::Root(SERVICE_ALL, "opde.log"); + mRoot->registerCustomScriptLoaders(); } GameStateManager::~GameStateManager() { @@ -92,28 +90,7 @@ state->exit(); } - delete mDTypeScriptLdr; // Unregisters itself - mDTypeScriptLdr = NULL; - - delete mPLDefScriptLdr; // Unregisters itself - mPLDefScriptLdr = NULL; - - // Delete the service manager - delete mServiceMgr; - mServiceMgr = NULL; - - CustomImageCodec::shutdown(); - - delete mConsoleBackend; delete mRoot; - - delete mDirArchiveFactory; - delete mCrfArchiveFactory; - - // Release the loggers - delete mLogger; - delete mStdLog; - delete mFileLog; } GameStateManager& GameStateManager::getSingleton(void) { @@ -160,43 +137,17 @@ bool GameStateManager::run() { // Initialize opde logger and console backend - mLogger = new Logger(); - - mStdLog = new StdLog(); - mFileLog = new FileLog("opde.log"); - - mLogger->registerLogListener(mFileLog); - - LOG_INFO("Starting openDarkEngine %d.%d.%d (%s)\n", OPDE_VER_MAJOR, OPDE_VER_MINOR, OPDE_VER_PATCH, OPDE_CODE_NAME); - // Create an ogre's root - mRoot = new Root(); + mOgreRoot = Ogre::Root::getSingletonPtr(); - mDirArchiveFactory = new Ogre::CaseLessFileSystemArchiveFactory(); - // TODO: mCrfArchiveFactory = new Ogre::CrfArchiveFactory(); - - Ogre::ArchiveManager::getSingleton().addArchiveFactory(mDirArchiveFactory); - // TODO: Ogre::ArchiveManager::getSingleton().addArchiveFactory(mCrfArchiveFactory); - - CustomImageCodec::startup(); - - mConsoleBackend = new Opde::ConsoleBackend(); - - // So console will write the messages from the logger - mLogger->registerLogListener(mConsoleBackend); - + mConsoleBackend = Opde::ConsoleBackend::getSingletonPtr(); mConsoleBackend->putMessage("==Console Starting=="); - // Create the service manager - mServiceMgr = new ServiceManager(SERVICE_ALL); assert(ServiceManager::getSingletonPtr() != 0); if (ServiceManager::getSingletonPtr() == 0) LOG_FATAL("Rotten tomatoes!"); - // Register the worldrep service factory - registerServiceFactories(); - mConfigService = static_pointer_cast<ConfigService>(ServiceManager::getSingleton().getService("ConfigService")); mConfigService->loadParams("opde.cfg"); @@ -229,9 +180,8 @@ setupInputSystem(); - // TODO: Broadcast to all services: bootstrapFinished - mServiceMgr->bootstrapFinished(); - + mRoot->bootstrapFinished(); + ps->bootstrapFinished(); // Push the initial state @@ -244,7 +194,7 @@ while( !mTerminate ) { // Calculate time since last frame and remember current time for next frame mTimeLastFrame = lTimeCurrentFrame; - lTimeCurrentFrame = mRoot->getTimer()->getMilliseconds(); + lTimeCurrentFrame = mOgreRoot->getTimer()->getMilliseconds(); unsigned long lTimeSinceLastFrame = lTimeCurrentFrame - mTimeLastFrame; @@ -255,7 +205,7 @@ mInputService->captureInputs(); // Render next frame - mRoot->renderOneFrame(); + mOgreRoot->renderOneFrame(); // Deal with platform specific issues Ogre::WindowEventUtilities::messagePump(); @@ -274,62 +224,23 @@ return true; } - void GameStateManager::registerServiceFactories() { - // register the service factories - new WorldRepServiceFactory(); - new BinaryServiceFactory(); - new GameServiceFactory(); - new ConfigServiceFactory(); - new LinkServiceFactory(); - new PropertyServiceFactory(); - new InheritServiceFactory(); - new RenderServiceFactory(); - new DatabaseServiceFactory(); - new InputServiceFactory(); - new LoopServiceFactory(); - new ObjectServiceFactory(); - } - /// Method which will define the source of resources (other than current folder) void GameStateManager::setupResources(void) { // First, register the script loaders... - - // Allocate and register the DType script loader. Registers itself - mDTypeScriptLdr = new DTypeScriptLoader(); - - // Allocate and register the PLDef script loader. Registers itself - mPLDefScriptLdr = new PLDefScriptLoader(); - // Load resource paths from config file - ConfigFile cf; + String configName = "resources.cfg"; //Load the resources according to the game type, if game type not specified, load the default if((mGameType == "T1") || (mGameType == "t1")) - cf.load("thief1.cfg"); + configName = "thief1.cfg"; else if((mGameType == "T2") || (mGameType == "t2")) - cf.load("thief2.cfg"); + configName = "thief2.cfg"; else if((mGameType == "SS2") || (mGameType == "ss2")) - cf.load("shock2.cfg"); - else - cf.load("resources.cfg"); + configName = "shock2.cfg"; - // Go through all sections & settings in the file - ConfigFile::SectionIterator seci = cf.getSectionIterator(); - - String secName, typeName, archName; - - while (seci.hasMoreElements()) { - secName = seci.peekNextKey(); - ConfigFile::SettingsMultiMap *settings = seci.getNext(); - ConfigFile::SettingsMultiMap::iterator i; - - for (i = settings->begin(); i != settings->end(); ++i) { - typeName = i->first; - archName = i->second; - ResourceGroupManager::getSingleton().addResourceLocation( - archName, typeName, secName); - } - } + + + mRoot->loadResourceConfig(configName); } void GameStateManager::setupInputSystem() { Modified: trunk/src/main/GameStateManager.h =================================================================== --- trunk/src/main/GameStateManager.h 2008-10-26 14:18:30 UTC (rev 929) +++ trunk/src/main/GameStateManager.h 2008-10-26 15:28:35 UTC (rev 930) @@ -35,10 +35,9 @@ #include <stack> +#include "Root.h" #include "OpdeSingleton.h" #include "GameState.h" -#include "stdlog.h" -#include "filelog.h" #include "ConsoleBackend.h" #include "OpdeServiceManager.h" #include "ConfigService.h" @@ -50,14 +49,8 @@ namespace Opde { - /** The game state manager. A main piece of code, which controls the flow of the program. Also dispatcher for input device events. - * A state is a class inheriting GameState abstract class, which controls a single state of the game. GameState's instance - * then receives events from keyboard and other input devices, event for frame update, etc. - * - * @note This class should implements a custom game loop. - * - * @see GameState - * @todo add OIS::JoyStickListener + /** The game state manager. A temporary piece of code that enables opde testing. + * @warning This code is here only for testing purposes, and will go away later on */ class GameStateManager : public Singleton<GameStateManager>, public DirectInputListener { public: @@ -85,9 +78,6 @@ * @return true if game should procede, false otherwise */ bool run(); protected: - /** Registers all the service factories */ - void registerServiceFactories(); - /** Loads the resources from the resources.cfg */ void setupResources(void); @@ -114,36 +104,23 @@ unsigned long mTimeLastFrame; /// Stderr logger - StdLog* mStdLog; - FileLog* mFileLog; - ConsoleBackend* mConsoleBackend; - Logger *mLogger; + /// Opde::root + Opde::Root *mRoot; + Ogre::Root *mOgreRoot; - // --- Ogre instances - Ogre::Root *mRoot; - - // Service manager handle - ServiceManager* mServiceMgr; - - // Loader for the DType scripts - DTypeScriptLoader* mDTypeScriptLdr; - - // Loader for the PLDef scripts - PLDefScriptLoader* mPLDefScriptLdr; - - - Ogre::ArchiveFactory* mDirArchiveFactory; - - Ogre::ArchiveFactory* mCrfArchiveFactory; - - // config service + /// config service reference ConfigServicePtr mConfigService; + /// input service reference InputServicePtr mInputService; + /// Type of the game (t1,t2,ss2) std::string mGameType; + + /// Service manager ref + ServiceManager* mServiceMgr; }; } Modified: trunk/src/main/Root.cpp =================================================================== --- trunk/src/main/Root.cpp 2008-10-26 14:18:30 UTC (rev 929) +++ trunk/src/main/Root.cpp 2008-10-26 15:28:35 UTC (rev 930) @@ -61,7 +61,7 @@ template<> Root* Singleton<Root>::ms_Singleton = 0; // ------------------------------------------------------- - Root::Root(uint serviceMask) : + Root::Root(uint serviceMask, char* logFileName) : mLogger(NULL), mServiceMgr(NULL), mOgreRoot(NULL), @@ -77,6 +77,12 @@ mLogger = new Logger(); + if (logFileName) { + logToFile(logFileName); + } + + LOG_INFO("Starting openDarkEngine %d.%d.%d (%s)", OPDE_VER_MAJOR, OPDE_VER_MINOR, OPDE_VER_PATCH, OPDE_CODE_NAME); + mServiceMgr = new ServiceManager(mServiceMask); // To supress logging of OGRE (we'll use a plugin for our logger for Ogre logs) Modified: trunk/src/main/Root.h =================================================================== --- trunk/src/main/Root.h 2008-10-26 14:18:30 UTC (rev 929) +++ trunk/src/main/Root.h 2008-10-26 15:28:35 UTC (rev 930) @@ -53,8 +53,10 @@ class OPDELIB_EXPORT Root : public Singleton<Root> { public: /** Initializes the opde core - * @param serviceMask the mask of the services which should be used (others will be ignored and unreachable) */ - Root(uint serviceMask = SERVICE_ALL); + * @param serviceMask the mask of the services which should be used (others will be ignored and unreachable) + * @param logFileName - optional log file name - when specified, logging to file will be initialized automatically + */ + Root(uint serviceMask = SERVICE_ALL, char* logFileName = NULL); /** stops the opde core, does cleanup */ ~Root(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |