Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GameUniverse Class Reference

#include <universe.h>

Inheritance diagram for GameUniverse:
Universe

Public Member Functions

StarSystemGenerateStarSystem (const char *file, const char *jumpback, Vector origin)
 A list of all factions. More...
 
void WriteSaveGame (bool auto_save)
 
void SetupCockpits (std::vector< std::string >players)
 
void activateLightMap (int stage=1)
 
TexturegetLightMap ()
 
 GameUniverse (int argc, char **argv, const char *galaxy)
 inits graphics with args More...
 
 GameUniverse ()
 
void Init (int argc, char **argv, const char *galaxy)
 
 ~GameUniverse ()
 
void StartGFX ()
 Loads Defaults in Graphics Drivers. More...
 
class StarSystemInit (string systemfile, const Vector &centroid=Vector(0, 0, 0), const string planetname=string())
 Should load the Universe data file. Now just inits system with test.xml. More...
 
void StartDraw ()
 Begins a scene. More...
 
void Loop (void main_loop())
 Runs the main loop. More...
 
void SelectCamera (int cam)
 Wrapper function for Star System. More...
 
CameraAccessCamera (int num)
 Accessor to cockpit. More...
 
CameraAccessCamera ()
 Wrapper function for star system. More...
 
CameraAccessHudCamera ()
 Returns the current hud cam. More...
 
void SetViewport ()
 Wrapper function for star system. More...
 
- Public Member Functions inherited from Universe
void netLock (bool enable)
 A list of all factions. More...
 
bool netLocked ()
 
bool isServer ()
 
CockpitisPlayerStarship (const Unit *fighter)
 
CockpitisPlayerStarshipVoid (const void *pointercompare)
 
int whichPlayerStarship (const Unit *fighter)
 
CockpitAccessCockpit ()
 
CockpitAccessCockpit (int i)
 
unsigned int CurrentCockpit ()
 
void SetActiveCockpit (int whichcockpit)
 
void SetActiveCockpit (Cockpit *which)
 
CockpitcreateCockpit (std::string player)
 
void getJumpPath (const std::string &from, const std::string &to, std::vector< std::string > &path) const
 
const std::vector< std::string > & getAdjacentStarSystems (const std::string &ss) const
 
std::string getGalaxyProperty (const std::string &sys, const std::string &prop)
 
std::string getGalaxyPropertyDefault (const std::string &sys, const std::string &prop, const std::string def="")
 
GalaxyXML::GalaxygetGalaxy ()
 
bool StillExists (StarSystem *ss)
 
void setActiveStarSystem (StarSystem *ss)
 
void pushActiveStarSystem (StarSystem *ss)
 
void popActiveStarSystem ()
 
void clearAllSystems ()
 
StarSystemgetActiveStarSystem (unsigned int size)
 
unsigned int getNumActiveStarSystem ()
 
void LoadStarSystem (StarSystem *ss)
 
void UnloadStarSystem (StarSystem *ss)
 
void Generate1 (const char *file, const char *jumpback)
 
void Generate2 (StarSystem *ss)
 
void LoadFactionXML (const char *factfile)
 Loads and parses factions. More...
 
 Universe ()
 inits graphics with args More...
 
 Universe (int argc, char **argv, const char *galaxy, bool server=false)
 
void Init (const char *gal)
 
virtual ~Universe ()
 
void Update ()
 
StarSystemactiveStarSystem ()
 returns active star system More...
 
unsigned int numPlayers ()
 Wrapper function for Star System. More...
 
StarSystemgetStarSystem (string name)
 Wrapper function for Star System. More...
 
StarSystemscriptStarSystem ()
 
bool setScriptSystem (string name)
 
int StarSystemIndex (StarSystem *ss)
 

Protected Member Functions

void StartGL ()
 init proc More...
 

Protected Attributes

Camera hud_camera
 The users cockpit. More...
 
- Protected Attributes inherited from Universe
std::auto_ptr< GalaxyXML::Galaxygalaxy
 
unsigned int current_cockpit
 The users cockpit. More...
 
std::vector< Cockpit * > cockpit
 
std::vector< StarSystem * > active_star_system
 a generic camera facing the HUD More...
 
StarSystemscript_system
 
bool is_server
 
bool network_lock
 

Friends

void bootstrap_main_loop ()
 

Additional Inherited Members

- Public Attributes inherited from Universe
StarDate current_stardate
 
std::vector< StarSystem * > star_system
 

Detailed Description

Class GameUniverse Deals with universal constants. It is a global, accessed from anywhere as _Universe-> Universe may be queried for Relationships, the current star system rendering is taking place in etc. It acts as a wrapper to the active Star System. Additionally it handles beginning and ending the main loop. And starting and ending graphics. (incl the task of wiping temp lights) Deprecated: loaded dynamic gldrv module

Definition at line 39 of file universe.h.

Constructor & Destructor Documentation

GameUniverse::GameUniverse ( int  argc,
char **  argv,
const char *  galaxy 
)

inits graphics with args

Definition at line 100 of file universe.cpp.

References Init(), and Universe::is_server.

101 {
102  this->Init( argc, argv, galaxy );
103  is_server = false;
104 }
GameUniverse::GameUniverse ( )

Definition at line 106 of file universe.cpp.

106  : Universe()
107 {}
GameUniverse::~GameUniverse ( )

Definition at line 109 of file universe.cpp.

References DeInitInput(), and GFXShutdown().

110 {
111  DeInitInput();
112  GFXShutdown();
113 }

Member Function Documentation

Camera* GameUniverse::AccessCamera ( int  num)
inlinevirtual

Accessor to cockpit.

Wrapper function for Star System

Reimplemented from Universe.

Definition at line 84 of file universe.h.

References Cockpit::AccessCamera(), and Universe::AccessCockpit().

85  {
86  return AccessCockpit()->AccessCamera( num );
87  }
Camera* GameUniverse::AccessCamera ( )
inlinevirtual

Wrapper function for star system.

Reimplemented from Universe.

Definition at line 89 of file universe.h.

References Cockpit::AccessCamera(), and Universe::AccessCockpit().

Referenced by StartDraw().

90  {
91  return AccessCockpit()->AccessCamera();
92  }
Camera* GameUniverse::AccessHudCamera ( )
inlinevirtual

Returns the current hud cam.

Reimplemented from Universe.

Definition at line 94 of file universe.h.

References hud_camera.

95  {
96  return &hud_camera;
97  }
void GameUniverse::activateLightMap ( int  stage = 1)
virtual

Reimplemented from Universe.

Definition at line 127 of file universe.cpp.

References StarSystem::activateLightMap(), and Universe::getActiveStarSystem().

128 {
129  getActiveStarSystem( 0 )->activateLightMap( stage );
130 }
StarSystem * GameUniverse::GenerateStarSystem ( const char *  file,
const char *  jumpback,
Vector  origin 
)
virtual

A list of all factions.

Reimplemented from Universe.

Definition at line 357 of file universe.cpp.

References Universe::Generate1(), Universe::Generate2(), and GetLoadedStarSystem().

358 {
359  StarSystem *tmpcache;
360  if ( ( tmpcache = GetLoadedStarSystem( file ) ) )
361  return tmpcache;
362  this->Generate1( file, jumpback );
363  StarSystem *ss = new GameStarSystem( file, center );
364  this->Generate2( ss );
365  return ss;
366 }
Texture * GameUniverse::getLightMap ( )
virtual

Reimplemented from Universe.

Definition at line 132 of file universe.cpp.

References Universe::getActiveStarSystem(), and StarSystem::getLightMap().

133 {
134  return getActiveStarSystem( 0 )->getLightMap();
135 }
void GameUniverse::Init ( int  argc,
char **  argv,
const char *  galaxy 
)

Definition at line 75 of file universe.cpp.

References bootstrap_first_loop(), Universe::current_cockpit, GFXInit(), hud_camera, Universe::Init(), InitInput(), pwd, and StartGFX().

Referenced by GameUniverse().

76 {
77  current_cockpit = 0;
78  //Select drivers
79 #if defined (__APPLE__)
80  //get the current working directory so when glut trashes it we can restore.
81  char pwd[MAXPATHLEN];
82  getcwd( pwd, MAXPATHLEN );
83 #endif
84  GFXInit( argc, argv );
85 #if defined (__APPLE__)
86  //Restore it
87  chdir( pwd );
88 #endif
89  StartGFX();
90  InitInput();
91 
92  hud_camera = Camera();
93 
94  //Hasten splash screen loading, to cover up lengthy universe initialization
96 
97  this->Universe::Init( galaxy );
98 }
StarSystem * GameUniverse::Init ( string  systemfile,
const Vector centroid = Vector( 0, 0, 0 ),
const string  planetname = string() 
)
virtual

Should load the Universe data file. Now just inits system with test.xml.

Reimplemented from Universe.

Definition at line 62 of file universe.cpp.

References CacheJumpStar(), Universe::Init(), LoadWeapons(), and VSFileSystem::weapon_list.

63 {
64  static bool js = true;
65  if (js) {
66  js = false;
68  CacheJumpStar( false );
69  }
70  return this->Universe::Init( systemfile, centr, planetname );
71 }
void GameUniverse::Loop ( void   main_loop())
virtual

Runs the main loop.

Reimplemented from Universe.

Definition at line 171 of file universe.cpp.

References GFXLoop(), and main_loop().

172 {
173  GFXLoop( main_loop );
174 }
void GameUniverse::SelectCamera ( int  cam)
inlinevirtual

Wrapper function for Star System.

Reimplemented from Universe.

Definition at line 75 of file universe.h.

References Universe::AccessCockpit(), and Cockpit::SelectCamera().

76  {
77  AccessCockpit()->SelectCamera( cam );
78  }
void GameUniverse::SetupCockpits ( std::vector< std::string >  players)
virtual

Reimplemented from Universe.

Definition at line 117 of file universe.cpp.

References Universe::cockpit, and i.

118 {
119  for (unsigned int i = 0; i < playerNames.size(); ++i) {
120  cockpit.push_back( NULL );
121  int temp = cockpit.size();
122  cockpit.back() = new GameCockpit( "", NULL, playerNames[i] );
123  temp = cockpit.size();
124  }
125 }
void GameUniverse::SetViewport ( )
inlinevirtual

Wrapper function for star system.

Reimplemented from Universe.

Definition at line 99 of file universe.h.

References Universe::AccessCockpit(), and Cockpit::SetViewport().

100  {
102  }
void GameUniverse::StartDraw ( )
virtual

Begins a scene.

Reimplemented from Universe.

Definition at line 266 of file universe.cpp.

References _Universe, AccessCamera(), Universe::AccessCockpit(), Universe::active_star_system, Universe::activeStarSystem(), Cockpit::activeStarSystem, b, CalculateCoords(), Universe::cockpit, vs_options::deleteoldsystems, StarSystem::Draw(), vs_options::garbagecollectfrequency, getmicrosleep(), GFXBeginScene(), GFXEndScene(), h, i, vs_options::InactiveSystemTime, UniverseUtil::isSplashScreenShowing(), micro_sleep, vs_options::numoldsystems, vs_options::NumRunningSystems, PendingJumpsEmpty(), Universe::popActiveStarSystem(), PRESS, ProcessInput(), StarSystem::ProcessPendingJumps(), Universe::pushActiveStarSystem(), rand01(), RefreshGUI(), RESETTIME, Screenshot(), Cockpit::SelectProperCamera(), Universe::SetActiveCockpit(), Camera::SetSubwindow(), SortStarSystems(), Universe::star_system, StarSystem::SwapIn(), Universe::Update(), Camera::UpdateGFX(), UpdateTime(), UpdateTimeCompressionSounds(), VSFileSystem::vs_fprintf(), x, and y.

267 {
268 #ifndef WIN32
269  RESETTIME();
270 #endif
271  GFXBeginScene();
272  size_t i;
273  StarSystem *lastStarSystem = NULL;
274  for (i = 0; i < cockpit.size(); ++i) {
275  SetActiveCockpit( i );
276  float x, y, w, h;
277  CalculateCoords( i, cockpit.size(), x, y, w, h );
278  AccessCamera()->SetSubwindow( x, y, w, h );
279  if (cockpit.size() > 1 && AccessCockpit( i )->activeStarSystem != lastStarSystem) {
280  active_star_system[0]->SwapOut();
281  lastStarSystem = AccessCockpit()->activeStarSystem;
282  active_star_system[0] = lastStarSystem;
283  lastStarSystem->SwapIn();
284  }
286  if (cockpit.size() > 0)
287  AccessCamera()->UpdateGFX();
289  activeStarSystem()->Draw();
290  AccessCamera()->SetSubwindow( 0, 0, 1, 1 );
291  }
292  UpdateTime();
294  _Universe->SetActiveCockpit( ( (int) ( rand01()*cockpit.size() ) )%cockpit.size() );
295  for (i = 0; i < star_system.size() && i < game_options.NumRunningSystems; ++i)
296  star_system[i]->Update( (i == 0) ? 1 : game_options.InactiveSystemTime/i, true );
298  for (i = 0; i < cockpit.size(); ++i) {
299  SetActiveCockpit( i );
301  ProcessInput( i ); //input neesd to be taken care of;
303  }
304  if (screenshotkey) {
305  KBData b;
306  Screenshot( b, PRESS );
307  screenshotkey = false;
308  }
309  GFXEndScene();
310  //so we don't starve the audio thread
312 
313  //remove systems not recently visited?
314  static int sorttime = 0;
316  //don't want to delete something when there is something pending to jump therexo
317  if ( PendingJumpsEmpty() ) {
318  if ( (++sorttime)%game_options.garbagecollectfrequency == 1 ) {
321  if ( std::find( active_star_system.begin(), active_star_system.end(),
322  star_system.back() ) == active_star_system.end() ) {
323  delete star_system.back();
324  star_system.pop_back();
325  } else {
326  VSFileSystem::vs_fprintf( stderr, "error with active star system list\n" );
327  }
328  }
329  }
330  }
331  }
332 }
void GameUniverse::StartGFX ( )

Loads Defaults in Graphics Drivers.

Definition at line 137 of file universe.cpp.

References GFXMaterial::aa, GFXMaterial::ab, GFXMaterial::ag, GFXMaterial::ar, GFXMaterial::da, GFXMaterial::db, GFXMaterial::dg, GFXMaterial::dr, GFXMaterial::ea, GFXMaterial::eb, GFXMaterial::eg, GFXMaterial::er, GFXBeginScene(), GFXCreateLightContext(), GFXEndScene(), GFXLightContextAmbient(), GFXSelectMaterial(), GFXSetLightContext(), GFXSetMaterial(), GFXMaterial::power, GFXMaterial::sa, GFXMaterial::sb, GFXMaterial::sg, and GFXMaterial::sr.

Referenced by Init().

138 {
139  GFXBeginScene();
140  GFXMaterial mat;
141  mat.ar = 1.00F;
142  mat.ag = 1.00F;
143  mat.ab = 1.00F;
144  mat.aa = 1.00F;
145 
146  mat.dr = 1.00F;
147  mat.dg = 1.00F;
148  mat.db = 1.00F;
149  mat.da = 1.00F;
150 
151  mat.sr = 1.00F;
152  mat.sg = 1.00F;
153  mat.sb = 1.00F;
154  mat.sa = 1.00F;
155 
156  mat.er = 0.0F;
157  mat.eg = 0.0F;
158  mat.eb = 0.0F;
159  mat.ea = 1.0F;
160  mat.power = 60.0F;
161  unsigned int tmp;
162  GFXSetMaterial( tmp, mat );
163  GFXSelectMaterial( tmp );
164  int ligh;
165  GFXCreateLightContext( ligh );
166  GFXSetLightContext( ligh );
167  GFXLightContextAmbient( GFXColor( 0, 0, 0, 1 ) );
168  GFXEndScene();
169 }
void GameUniverse::StartGL ( )
protected

init proc

void GameUniverse::WriteSaveGame ( bool  auto_save)
virtual

Reimplemented from Universe.

Definition at line 334 of file universe.cpp.

References Universe::AccessCockpit(), Universe::activeStarSystem(), Universe::cockpit, Cockpit::credits, StarSystem::getFileName(), Cockpit::GetParent(), Cockpit::GetUnitFileName(), i, Unit::Position(), Cockpit::savegame, SaveGame::WriteSaveGame(), and Unit::WriteUnit().

335 {
336  for (unsigned int i = 0; i < cockpit.size(); ++i) {
337  if ( AccessCockpit( i ) ) {
338  ::WriteSaveGame( AccessCockpit( i ), auto_save );
339 #if 0
340  if ( AccessCockpit( i )->GetParent() )
341  if (AccessCockpit( i )->GetParent()->GetHull() > 0) {
343  i )->activeStarSystem->getFileName().c_str(),
345  i )->credits, AccessCockpit( i )->GetUnitFileName() );
346  AccessCockpit( i )->GetParent()->WriteUnit( AccessCockpit( i )->GetUnitModifications().c_str() );
347  }
348 
349 #endif
350 
351  }
352  }
353 }

Friends And Related Function Documentation

void bootstrap_main_loop ( )
friend

return to idle func which now should call main_loop mohahahah

Draw Texture

Member Data Documentation

Camera GameUniverse::hud_camera
protected

The users cockpit.

a generic camera facing the HUD

Definition at line 46 of file universe.h.

Referenced by AccessHudCamera(), and Init().


The documentation for this class was generated from the following files: