#include <galaxy.h>
Inheritance diagram for Galaxy:


Public Member Functions | |
| Galaxy (void) | |
| ~Galaxy (void) | |
| void | Reset (void) |
| const bool | IsLoaded (void) |
Protected Member Functions | |
| virtual long | Run (void *) |
| const bool | evMessage (const UserMessage &msg) |
Private Member Functions | |
| void | Load (const string fname) |
Private Attributes | |
| string | filename |
| SDL_mutex * | mutex |
|
|
Definition at line 3 of file galaxy.cpp. References mutex.
|
|
|
Definition at line 10 of file galaxy.cpp. References mutex, and Reset().
|
|
|
Definition at line 114 of file galaxy.cpp. References filename, Cfg::GetCfg(), Cfg::Handler::GetCfgString(), itoa(), Load(), LOAD_GALAXY, mutex, Reset(), SAVE_GALAXY, and Thread::Start().
00115 {
00116 Cfg::Handler &h = Cfg::GetCfg();
00117
00118 if( msg.SubMessage() == SAVE_GALAXY )
00119 {
00120 char temp[10];
00121 filename = h.GetCfgString( "SavedGames" , itoa( (int)msg.Data() , temp , 10 ) ) + ".glx";
00122
00123 Start( mutex );
00124 return true;
00125 }
00126 else if( msg.SubMessage() == LOAD_GALAXY )
00127 {
00128 Reset();
00129 char temp[10];
00130 filename = h.GetCfgString( "SavedGames" , itoa( (int)msg.Data() , temp , 10 ) );
00131 Load( filename + ".glx" );
00132 return true;
00133 }
00134 return false;
00135 }
|
|
|
Definition at line 34 of file galaxy.h. References filename. Referenced by LoadGalaxyData::Run().
00034 { return !filename.empty(); }
|
|
|
Definition at line 52 of file galaxy.cpp. References Planet::atmPressure, Planet::deuterium, Planet::energy, Planet::fauna, Planet::flora, Cfg::GetCfg(), Cfg::Handler::GetCfgInt(), Parameters::GetDenomination(), GetGalaxy(), Planet::gravity, Planet::humidity, Planet::humidityTerraformedDelta, icstring, Planet::lithium, mutex, Planet::ore, Planet::pressureTerraformedDelta, Planet::soil, Planet::sunEnergy, Planet::surfaceTemperature, Planet::surfaceTemperatureTerraformedDelta, and Planet::water. Referenced by evMessage().
00053 {
00054 SDL_mutexP( mutex );
00055
00056 ifstream inf( fname.c_str() , ios::in );
00057 if( inf.good() && !inf.fail() )
00058 {
00059 Cfg::Handler &h = Cfg::GetCfg( "@Generator" );
00060
00061 const int gw = h.GetCfgInt( "Galaxy-coord" , "playW" );
00062 const int gh = h.GetCfgInt( "Galaxy-coord" , "playH" );
00063 char buffer[4096];
00064 inf.getline( buffer , sizeof( buffer ) , '~' );
00065 inf.getline( buffer , sizeof( buffer ) , '~' );
00066 while( !inf.eof() )
00067 {
00068 icstring ics = buffer;
00069 ics = Rsrc::GetList( ics );
00070 const string StarName = Rsrc::GetStr( ics );
00071 const string StraNameDescr = Rsrc::GetStr( ics );
00072 XPoint p;
00073 p.x = Rsrc::GetInt( ics );
00074 p.y = Rsrc::GetInt( ics );
00075 const int StarType = Rsrc::GetInt( ics );
00076 const int StarSize = Rsrc::GetInt( ics );
00077 const int nrPlanet = Rsrc::GetInt( ics );
00078
00079 StarSystem *ss = new StarSystem( StarName , StraNameDescr , Parameters::GetDenomination( p , StarType , StarSize , nrPlanet , gw , gh ) , StarType , StarSize );
00080 static_cast<XPoint &>( *ss ) = p;
00081 while( !ics.empty() )
00082 {
00083 icstring str = Rsrc::GetList( ics );
00084 const int PlanetNo = Rsrc::GetInt( str );
00085 const int Size = Rsrc::GetInt( str );
00086 const int Type = Rsrc::GetInt( str );
00087 Planet *pl = new Planet( ss , ss->GetPlanetName( PlanetNo ) , Type , Size , PlanetNo );
00088 pl->ore = Rsrc::GetInt( str );
00089 pl->energy = Rsrc::GetInt( str );
00090 pl->soil = Rsrc::GetInt( str );
00091 pl->fauna = Rsrc::GetInt( str );
00092 pl->flora = Rsrc::GetInt( str );
00093 pl->lithium = Rsrc::GetInt( str );
00094 pl->deuterium= Rsrc::GetInt( str );
00095 pl->humidity = Rsrc::GetDbl( str );
00096 pl->surfaceTemperature = Rsrc::GetDbl( str );
00097 pl->gravity = Rsrc::GetDbl( str );
00098 pl->atmPressure = Rsrc::GetDbl( str );
00099 pl->sunEnergy = Rsrc::GetDbl( str );
00100 pl->water = Rsrc::GetDbl( str );
00101 pl->humidityTerraformedDelta = Rsrc::GetDbl( str );
00102 pl->surfaceTemperatureTerraformedDelta = Rsrc::GetDbl( str );
00103 pl->pressureTerraformedDelta= Rsrc::GetDbl( str );
00104 ss->push_back( pl );
00105 }
00106 GetGalaxy().push_back( ss );
00107
00108 inf.getline( buffer , sizeof( buffer ) , '~' );
00109 }
00110 }
00111 SDL_mutexV( mutex );
00112 }
|
|
|
Definition at line 20 of file galaxy.cpp. References Planet::allPlanets, filename, mutex, Colony::ResetAllColonies(), and Parameters::species. Referenced by Parameters::CreateGalaxy(), evMessage(), ~Galaxy(), and MainGame::~MainGame().
00021 {
00022 SDL_mutexP( mutex );
00023 filename = "";
00024
00025 for( vector<StarSystem *>::iterator it = begin() ; it != end() ; ++it )
00026 delete (*it);
00027 clear();
00028 Colony::ResetAllColonies();
00029 Planet::allPlanets.clear();
00030 Parameters::species.clear();
00031 SDL_mutexV( mutex );
00032 }
|
|
|
Reimplemented from Thread. Definition at line 34 of file galaxy.cpp. References Thread::arg, filename, and StarSystem::Save().
00035 {
00036 SDL_mutexP( (SDL_mutex *)arg );
00037
00038 ofstream of( filename.c_str() , ios::out );
00039 if( of.good() && !of.fail() )
00040 {
00041 of << "//tFormat of the file as followed:\n"
00042 << "//\t( \"<StarName>\" \"<StarName Description>\" <coord x> <coord-y> <Type> <size> <nrPlanets>\n"
00043 << "//\t\tfor each planet:\n"
00044 << "//\t\t( <planetNo> <size> <type> <ore> <energy> <soil> <fauna> <flora> <lithium> <deuterium> <humidity> <surface-temperature> <gravity> <atmPressure> <sunEnergy> <water> <humidityTerraformedDelta> <surfaceTemperatureTerraformedDelta> <pressureTerraformedDelta> )\n"
00045 << "//\t)~\n";
00046 for_each( begin() , end() , bind2nd( mem_fun( &StarSystem::Save ) , &of ) );
00047 }
00048
00049 return SDL_mutexV( (SDL_mutex *)arg );
00050 }
|
|
|
Definition at line 23 of file galaxy.h. Referenced by evMessage(), IsLoaded(), Reset(), and Run(). |
|
|
Definition at line 24 of file galaxy.h. Referenced by evMessage(), Galaxy(), Load(), Reset(), and ~Galaxy(). |
1.3.3