📄 oasisroot.cpp
字号:
/******************************************************************************
* This source file is part of Bad Camel Gaming
* Copyright (C) 2003 Zephie Greyvenstein
* See Readme.html for acknowledgements
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/******************************************************************************
* FILENAME : oasisRoot.cpp
* DESCRIPTION : Class for initialising the systems
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
#include "oasisRoot.h"
#include "oasisException.h"
#include "oasisGraphicsSystem.h"
#include "oasisFrameListenerSystem.h"
#include "oasisObjectSystem.h"
#include "oasisPhysicsSystem.h"
#include "oasisConsoleSystem.h"
#include "oasisCameraSystem.h"
#include "oasisSoundSystem.h"
#include "oasisInputSystem.h"
#include "oasisPhysicsSystem.h"
#include "oasisScriptSystem.h"
/// Include Ogre stuff
#include "OgreRoot.h"
#include "OgreLogManager.h"
#include "OgreStringConverter.h"
namespace Oasis {
template< > root *singleton< root >::singletonPtr = 0;
root::root( const string &configFile, uint32 flags ) {
runningSystems.clear( );
initedSystems = 0;
tempSystem = NULL;
// Since ogre has just about all the core functionality needed
// for a game ( resource loading etc ), we get it going
// Create the root for ogre
//ogreRoot = new Ogre::Root( configFile, "oasis.cfg", "oasis.log" );
ogreRoot = new Ogre::Root( configFile );
if ( !ogreRoot ) {
oasisError( exception::ET_NULL_POINTER,
"CORE SUBSYSTEM FAILED TO INITIALISE",
"root::( )" );
} else {
Ogre::LogManager::getSingleton( ).
logMessage( "Core subsystem has been successfully INITIALISED" );
}
if ( flags ) {
startSystems( flags );
}
}
root::~root( ) {
// Kill all subsystems
systemVector::reverse_iterator it;
for ( it = runningSystems.rbegin( ); it != runningSystems.rend( ); ++it ) {
_logState( ( *it )->getSystemName( ), SS_DEINITIALISED );
delete ( *it );
}
runningSystems.clear( );
initedSystems = 0;
if ( ogreRoot ) {
delete ogreRoot;
}
}
root &root::get( void ) {
return singleton< root >::get( );
}
root *root::getPtr( void ) {
return singleton< root >::getPtr( );
}
void root::loadDirectoryResources( const string &resourcePath ) {
directories.push_back( resourcePath );
Ogre::ResourceManager::addCommonArchiveEx( resourcePath, "FileSystem" );
}
void root::loadZipResources( const string &zipFile ) {
Ogre::ResourceManager::addCommonArchiveEx( zipFile, "Zip" );
}
void root::startSystems( uint32 flags ) {
if ( !flags ) {
return;
}
// First resolve deps
_resolveDependencies( flags );
if ( flags & SS_SCRIPT ) {
_startSystem( SS_SCRIPT );
}
if ( flags & SS_GRAPHICS ) {
_startSystem( SS_GRAPHICS );
}
if ( flags & SS_FRAMELISTENER ) {
_startSystem( SS_FRAMELISTENER );
}
if ( flags & SS_INPUT ) {
_startSystem( SS_INPUT );
}
if ( flags & SS_CONSOLE ) {
_startSystem( SS_CONSOLE );
}
if ( flags & SS_SOUND ) {
_startSystem( SS_SOUND );
}
if ( flags & SS_CAMERA ) {
_startSystem( SS_CAMERA );
}
if ( flags & SS_PHYSICS ) {
_startSystem( SS_PHYSICS );
}
if ( flags & SS_OBJECT ) {
_startSystem( SS_OBJECT );
}
}
void root::resetAll( void ) {
// Reset all systems
systemVector::iterator it;
for ( it = runningSystems.begin( ); it != runningSystems.end( ); ++it ) {
( *it )->reset( );
}
}
void root::updateAll( real time ) {
// Update all systems
systemVector::iterator it;
for ( it = runningSystems.begin( ); it != runningSystems.end( ); ++it ) {
( *it )->update( time );
}
}
void root::doAutoLoop( void ) {
ogreRoot->startRendering( );
}
void root::_startSystem( SubSystem systemToStart ) {
if ( initedSystems & systemToStart ) {
return;
}
switch( systemToStart ) {
case SS_GRAPHICS:
tempSystem = new graphicsSystem( );
break;
case SS_FRAMELISTENER:
tempSystem = new frameListenerSystem( );
break;
case SS_SCRIPT:
tempSystem = new scriptSystem( );
break;
case SS_INPUT:
tempSystem = new inputSystem( );
break;
case SS_CONSOLE:
tempSystem = new consoleSystem( );
break;
case SS_SOUND:
tempSystem = new soundSystem( );
break;
case SS_CAMERA:
tempSystem = new cameraSystem( );
break;
case SS_PHYSICS:
tempSystem = new physicsSystem( );
break;
case SS_OBJECT:
tempSystem = new objectSystem( );
break;
}
if ( !tempSystem ) {
oasisError( exception::ET_NULL_POINTER,
Ogre::StringConverter::toString( systemToStart ) +
" subsystem failed to initialise",
"root::startSystem" );
} else {
// Reset the system
tempSystem->reset( );
// Log it's state
_logState( tempSystem->getSystemName( ), SS_INITIALISED );
runningSystems.push_back( tempSystem );
initedSystems |= systemToStart;
}
}
void root::_resolveDependencies( uint32 &flags ) {
// Console needs script and input
if ( flags & SS_CONSOLE ) {
if ( !( flags & SS_SCRIPT ) ) {
flags |= SS_SCRIPT;
}
if ( !( flags & SS_INPUT ) ) {
flags |= SS_INPUT;
}
}
// Camera, Input and console need listener
if ( ( flags & SS_INPUT ) |
( flags & SS_CONSOLE ) |
( flags & SS_CAMERA ) |
( flags & SS_PHYSICS ) ) {
if ( !( flags & SS_FRAMELISTENER ) ) {
flags |= SS_FRAMELISTENER;
}
}
// A bunch of things need graphics
if ( ( flags & SS_CONSOLE ) |
( flags & SS_INPUT ) |
( flags & SS_FRAMELISTENER ) |
( flags & SS_CAMERA ) ) {
if ( !( flags & SS_GRAPHICS ) ) {
flags |= SS_GRAPHICS;
}
}
}
void root::_logState( const string &name, SystemState state ) {
string message = name + " subsystem has been successfully ";
switch ( state ) {
case SS_INITIALISED:
message += "INITIALISED";
break;
case SS_DEINITIALISED:
message += "DEINITIALISING";
break;
}
Ogre::LogManager::getSingleton( ).logMessage( message );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -