summaryrefslogtreecommitdiffstats
path: root/source/cRoot.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 22:57:08 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 22:57:08 +0100
commitb5b920dedaa62302795b0b8f3db84a0650d236e0 (patch)
treef46d1ec70d6519fff2a75f45c08fe37bf4b5538c /source/cRoot.cpp
parentforogt to update all of cPlayer.cpp for player based gamemode. (diff)
downloadcuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.gz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.bz2
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.lz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.xz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.zst
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.zip
Diffstat (limited to 'source/cRoot.cpp')
-rw-r--r--source/cRoot.cpp82
1 files changed, 78 insertions, 4 deletions
diff --git a/source/cRoot.cpp b/source/cRoot.cpp
index 55ee28576..518275088 100644
--- a/source/cRoot.cpp
+++ b/source/cRoot.cpp
@@ -24,9 +24,15 @@
cRoot* cRoot::s_Root = 0;
+typedef std::map< std::string, cWorld* > WorldMap;
+struct cRoot::sRootState
+{
+ cWorld* pDefaultWorld;
+ WorldMap WorldsByName;
+};
+
cRoot::cRoot()
: m_Server( 0 )
- , m_World( 0 )
, m_MonsterConfig( 0 )
, m_GroupManager( 0 )
, m_RecipeChecker( 0 )
@@ -37,6 +43,7 @@ cRoot::cRoot()
, m_bStop( false )
, m_bRestart( false )
, m_InputThread( 0 )
+ , m_pState( new sRootState )
{
s_Root = this;
}
@@ -44,6 +51,7 @@ cRoot::cRoot()
cRoot::~cRoot()
{
s_Root = 0;
+ delete m_pState;
}
void cRoot::InputThread(void* a_Params)
@@ -93,8 +101,7 @@ void cRoot::Start()
m_GroupManager = new cGroupManager();
m_RecipeChecker = new cRecipeChecker();
m_FurnaceRecipe = new cFurnaceRecipe();
- m_World = new cWorld();
- m_World->InitializeSpawn();
+ LoadWorlds();
m_PluginManager = new cPluginManager(); // This should be last
m_PluginManager->ReloadPluginsNow();
@@ -122,7 +129,7 @@ void cRoot::Start()
delete m_FurnaceRecipe; m_FurnaceRecipe = 0;
delete m_RecipeChecker; m_RecipeChecker = 0;
delete m_GroupManager; m_GroupManager = 0;
- delete m_World; m_World = 0;
+ UnloadWorlds();
//delete HeartBeat; HeartBeat = 0;
delete m_Server; m_Server = 0;
}
@@ -130,6 +137,73 @@ void cRoot::Start()
delete m_Log; m_Log = 0;
}
+void cRoot::LoadWorlds()
+{
+ cIniFile IniFile("settings.ini"); IniFile.ReadFile();
+
+ // First get the default world
+ std::string DefaultWorldName = IniFile.GetValue("Worlds", "DefaultWorld", "world");
+ m_pState->pDefaultWorld = new cWorld( DefaultWorldName.c_str() );
+ m_pState->pDefaultWorld->InitializeSpawn();
+ m_pState->WorldsByName[ DefaultWorldName ] = m_pState->pDefaultWorld;
+
+ // Then load the other worlds
+ unsigned int KeyNum = IniFile.FindKey("Worlds");
+ unsigned int NumWorlds = IniFile.GetNumValues( KeyNum );
+ if( NumWorlds > 0 )
+ {
+ for(unsigned int i = 0; i < NumWorlds; i++)
+ {
+ std::string ValueName = IniFile.GetValueName(KeyNum, i );
+ if( ValueName.compare("World") == 0 )
+ {
+ std::string WorldName = IniFile.GetValue(KeyNum, i );
+ if( WorldName.size() > 0 )
+ {
+ cWorld* NewWorld = new cWorld( WorldName.c_str() );
+ NewWorld->InitializeSpawn();
+ m_pState->WorldsByName[ WorldName ] = NewWorld;
+ }
+ }
+ }
+ }
+}
+
+void cRoot::UnloadWorlds()
+{
+ for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr )
+ {
+ delete itr->second;
+ }
+ m_pState->WorldsByName.clear();
+}
+
+cWorld* cRoot::GetWorld()
+{
+ return GetDefaultWorld();
+}
+
+cWorld* cRoot::GetDefaultWorld()
+{
+ return m_pState->pDefaultWorld;
+}
+
+cWorld* cRoot::GetWorld( const char* a_WorldName )
+{
+ WorldMap::iterator itr = m_pState->WorldsByName.find( a_WorldName );
+ if( itr != m_pState->WorldsByName.end() )
+ return itr->second;
+ return 0;
+}
+
+void cRoot::TickWorlds( float a_Dt )
+{
+ for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr )
+ {
+ itr->second->Tick( a_Dt );
+ }
+}
+
void cRoot::ServerCommand( const char* a_Cmd )
{
//LOG("Command: %s", a_Cmd );