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
StarSystem Class Reference

#include <star_system_generic.h>

Inheritance diagram for StarSystem:
GameStarSystem

Classes

struct  StarXML
 Starsystem XML Struct For use with XML loading. More...
 
struct  Statistics
 

Public Member Functions

 StarSystem ()
 
 StarSystem (const char *filename, const Vector &centroid=Vector(0, 0, 0), const float timeofyear=0)
 
virtual ~StarSystem ()
 
void SetZone (unsigned int zonenum)
 
unsigned int GetZone ()
 
virtual void AddMissileToQueue (class MissileEffect *)
 
virtual void UpdateMissiles ()
 
void UpdateUnitPhysics (bool firstframe)
 
void RequestPhysics (Unit *un, unsigned int queue)
 Requeues the unit so that it is simulated ASAP. More...
 
virtual void activateLightMap (int stage=1)
 
virtual TexturegetLightMap ()
 
virtual unsigned int numTerrain ()
 activates the light map texture More...
 
virtual unsigned int numContTerrain ()
 
virtual void Draw (bool DrawCockpit=true)
 Draws a frame of action, interpolating between physics frames. More...
 
void Update (float priority, bool executeDirector)
 update a simulation atom ExecuteDirector must be false if star system is just loaded before mission is loaded More...
 
void Update (float priority)
 
virtual void SwapIn ()
 re-enables the included lights and terrains More...
 
virtual void SwapOut ()
 Disables included lights and terrains. More...
 
virtual TerraingetTerrain (unsigned int which)
 
virtual ContinuousTerraingetContTerrain (unsigned int which)
 
virtual BackgroundgetBackground ()
 
virtual ClickListgetClickList ()
 
unsigned int getCurrentSimFrame () const
 Gets the current simulation frame. More...
 
void ExecuteUnitAI ()
 
std::string getFileName () const
 
std::string getName ()
 
UnitCollectiongetUnitList ()
 Loads the star system from an XML file. More...
 
UnitCollectiongravitationalUnits ()
 
UnitnextSignificantUnit ()
 
void AddUnit (Unit *unit)
 
bool RemoveUnit (Unit *unit)
 Removes from draw list. More...
 
bool JumpTo (Unit *unit, Unit *jumppoint, const std::string &system, bool force=false, bool save_coordinates=false)
 
virtual void VolitalizeJumpAnimation (const int ani)
 
virtual void DoJumpingComeSightAndSound (Unit *un)
 
virtual int DoJumpingLeaveSightAndSound (Unit *un)
 
virtual void createBackground (StarSystem::StarXML *xml)
 

Static Public Member Functions

static void beginElement (void *userData, const XML_Char *name, const XML_Char **atts)
 
static void endElement (void *userData, const XML_Char *name)
 
static void ProcessPendingJumps ()
 

Public Attributes

struct StarSystem::Statistics stats
 
std::multimap< Unit *, Unit * > last_collisions
 
class CollideTablecollidetable
 
CollideMapcollidemap [2]
 
class bolt_drawbolts
 

Protected Types

enum  PHYSICS_STAGE { MISSION_SIMULATION, PROCESS_UNIT, PHY_NUM }
 Physics is divided into 3 stages spread over 3 frames. More...
 

Protected Member Functions

void LoadXML (const char *, const Vector &centroid, const float timeofyear)
 
void beginElement (const std::string &name, const AttributeList &attributes)
 
void endElement (const std::string &name)
 
void AddStarsystemToUniverse (const std::string &filename)
 The Light Map corresponding for the BP for spheremapping. More...
 
void RemoveStarsystemFromUniverse ()
 

Protected Attributes

struct StarSystem::StarXMLxml
 
enum StarSystem::PHYSICS_STAGE current_stage
 
std::vector< Terrain * > terrains
 Stars, planets, etc. Orbital mechanics precalculated. More...
 
std::vector< ContinuousTerrain * > contterrains
 
UnitCollection drawList
 Everything to be drawn. Folded missiles in here oneday. More...
 
UnitCollection GravitationalUnits
 
UnitCollection physics_buffer [SIM_QUEUE_SIZE+1]
 
unsigned int current_sim_location
 
unsigned char no_collision_time
 Objects subject to global gravitron physics (disabled) More...
 
char * name
 system name More...
 
std::string filename
 
un_iter sigIter
 
double time
 to track the next given physics frame More...
 
Starsstars
 The background associated with this system. More...
 
int lightcontext
 
std::vector< class
MissileEffect * > 
dischargedMissiles
 
unsigned int zone
 

Friends

class Universe
 

Detailed Description

Definition at line 53 of file star_system_generic.h.

Member Enumeration Documentation

enum StarSystem::PHYSICS_STAGE
protected

Physics is divided into 3 stages spread over 3 frames.

Enumerator
MISSION_SIMULATION 
PROCESS_UNIT 
PHY_NUM 

Definition at line 113 of file star_system_generic.h.

Constructor & Destructor Documentation

StarSystem::StarSystem ( )

adds to jumping table;

Definition at line 73 of file star_system_generic.cpp.

References bolts, collidemap, collidetable, UnitCollection::createIterator(), current_sim_location, current_stage, drawList, MISSION_SIMULATION, name, no_collision_time, sigIter, stars, time, Unit::UNIT_BOLT, Unit::UNIT_ONLY, and zone.

Referenced by Universe::GenerateStarSystem().

74 {
75  stars = NULL;
76  bolts = NULL;
77  collidetable = NULL;
80 
81  no_collision_time = 0; //(int)(1+2.000/SIMULATION_ATOM);
83  name = NULL;
85  time = 0;
86  zone = 0;
88  this->current_sim_location = 0;
89 }
StarSystem::StarSystem ( const char *  filename,
const Vector centroid = Vector( 0, 0, 0 ),
const float  timeofyear = 0 
)
StarSystem::~StarSystem ( )
virtual

Definition at line 117 of file star_system_generic.cpp.

References _Universe, Universe::activeStarSystem(), ClientServerSetLightContext(), collidemap, collidetable, UnitCollection::createIterator(), drawList, fprintf, getFileName(), Universe::getNumActiveStarSystem(), Unit::Kill(), lightcontext, name, Universe::popActiveStarSystem(), Universe::pushActiveStarSystem(), RemoveStarsystemFromUniverse(), SwapIn(), SwapOut(), Unit::UNIT_BOLT, and Unit::UNIT_ONLY.

118 {
123  delete[] name;
124  Unit *unit;
125  for (un_iter iter = drawList.createIterator(); (unit = *iter); ++iter)
126  unit->Kill( false );
127  //if the next line goes ANYWHERE else Vega Strike will CRASH!!!!!
128  //DO NOT MOVE THIS LINE! IT MUST STAY
129  if (collidetable) delete collidetable;
131  vector< StarSystem* >activ;
132  while ( _Universe->getNumActiveStarSystem() ) {
133  if (_Universe->activeStarSystem() != this)
134  activ.push_back( _Universe->activeStarSystem() );
135  else
136  fprintf( stderr, "Avoided fatal error in deleting star system %s\n", getFileName().c_str() );
138  }
139  while ( activ.size() ) {
140  _Universe->pushActiveStarSystem( activ.back() );
141  activ.pop_back();
142  }
146  delete collidemap[Unit::UNIT_ONLY];
147  delete collidemap[Unit::UNIT_BOLT];
148 }

Member Function Documentation

virtual void StarSystem::activateLightMap ( int  stage = 1)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 163 of file star_system_generic.h.

Referenced by GameUniverse::activateLightMap(), and RestoreFirstPassState().

163 {}
void StarSystem::AddMissileToQueue ( class MissileEffect me)
virtual

Definition at line 67 of file missile_generic.cpp.

References dischargedMissiles.

Referenced by Missile::Discharge(), and GameUnit< UnitType >::Explode().

68 {
69  dischargedMissiles.push_back( me );
70 }
void StarSystem::AddStarsystemToUniverse ( const std::string &  filename)
protected

The Light Map corresponding for the BP for spheremapping.

Definition at line 775 of file star_system_generic.cpp.

References Hashtable< KEY, VALUE, SIZ >::Put().

Referenced by GameStarSystem::GameStarSystem(), and StarSystem().

776 {
777  star_system_table.Put( mname, this );
778 }
void StarSystem::AddUnit ( Unit unit)

returns xy sorted bounding spheres of all units in current view Adds to draw list

Definition at line 230 of file star_system_generic.cpp.

References Unit::activeStarSystem, StarSystem::Statistics::AddUnit(), ASTEROIDPTR, UnitFactory::broadcastUnit(), StarSystem::Statistics::CheckVitals(), UnitCollection::createIterator(), current_sim_location, drawList, VSRandom::genrand_int32(), FactionUtil::GetNeutralFaction(), UnitUtil::getPhysicsPriority(), GetZone(), gravitationalUnits(), i, int, Unit::isJumppoint(), Unit::isPlanet(), Unit::isUnit(), physics_buffer, UnitCollection::prepend(), SIM_QUEUE_SIZE, Unit::specInterdiction, stats, StarSystem::Statistics::system_faction, and vsrandom.

Referenced by ZoneMgr::addClient(), NetClient::AddClientObject(), AddUnitToSystem(), buyShip(), Mission::call_unit_launch(), StarSystem::Statistics::CheckVitals(), createObjects(), Unit::EjectCargo(), LoadMission(), LoadXML(), Mount::PhysicsAlignedFire(), NetClient::Respawn(), Unit::TransferUnitToSystem(), and Cockpit::Update().

231 {
233  stats.CheckVitals( this );
234  if (unit->specInterdiction > 0 || unit->isPlanet() || unit->isJumppoint() || unit->isUnit() == ASTEROIDPTR) {
235  Unit *un;
236  bool found = false;
238  (un = *i) != NULL;
239  ++i)
240  if (un == unit) {
241  found = true;
242  break;
243  }
244  if (!found)
245  gravitationalUnits().prepend( unit );
246  }
247  drawList.prepend( unit );
248  unit->activeStarSystem = this; //otherwise set at next physics frame...
250  unsigned int priority = UnitUtil::getPhysicsPriority( unit );
251  //Do we need the +1 here or not - need to look at when current_sim_location is changed relative to this function
252  //and relative to this function, when the bucket is processed...
253  unsigned int tmp = 1+( (unsigned int) vsrandom.genrand_int32() )%priority;
254  this->physics_buffer[(this->current_sim_location+tmp)%SIM_QUEUE_SIZE].prepend( unit );
255  stats.AddUnit( unit );
256 }
void StarSystem::beginElement ( const std::string &  name,
const AttributeList attributes 
)
protected

Referenced by LoadXML().

void StarSystem::beginElement ( void *  userData,
const XML_Char *  name,
const XML_Char **  atts 
)
static

Definition at line 209 of file star_system_generic.cpp.

210 {
211  ( (StarSystem*) userData )->beginElement( name, AttributeList( atts ) );
212 }
virtual void StarSystem::createBackground ( StarSystem::StarXML xml)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 242 of file star_system_generic.h.

Referenced by LoadXML().

242 {}
virtual void StarSystem::DoJumpingComeSightAndSound ( Unit un)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 236 of file star_system_generic.h.

Referenced by ProcessPendingJumps().

236 {}
virtual int StarSystem::DoJumpingLeaveSightAndSound ( Unit un)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 237 of file star_system_generic.h.

Referenced by JumpTo().

238  {
239  return -1;
240  }
virtual void StarSystem::Draw ( bool  DrawCockpit = true)
inlinevirtual

Draws a frame of action, interpolating between physics frames.

Reimplemented in GameStarSystem.

Definition at line 178 of file star_system_generic.h.

Referenced by GameUniverse::StartDraw().

178 {}
void StarSystem::endElement ( const std::string &  name)
protected

Referenced by LoadXML().

void StarSystem::endElement ( void *  userData,
const XML_Char *  name 
)
static

Definition at line 214 of file star_system_generic.cpp.

215 {
216  ( (StarSystem*) userData )->endElement( name );
217 }
void StarSystem::ExecuteUnitAI ( )

Definition at line 300 of file star_system_generic.cpp.

References Unit::ExecuteAI(), getUnitList(), and Unit::ResetThreatLevel().

301 {
302  try {
303  Unit *unit = NULL;
304  for (un_iter iter = getUnitList().createIterator(); (unit = *iter); ++iter) {
305  unit->ExecuteAI();
306  unit->ResetThreatLevel();
307  }
308  }
309  catch (const boost::python::error_already_set) {
310  if ( PyErr_Occurred() ) {
311  PyErr_Print();
312  PyErr_Clear();
313  fflush( stderr );
314  fflush( stdout );
315  } throw;
316  }
317 }
virtual Background* StarSystem::getBackground ( )
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 195 of file star_system_generic.h.

Referenced by CockpitKeys::Inside(), NetClient::Respawn(), and Cockpit::Update().

196  {
197  return NULL;
198  }
virtual ClickList* StarSystem::getClickList ( )
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 199 of file star_system_generic.h.

Referenced by createObjects().

200  {
201  return NULL;
202  }
virtual ContinuousTerrain* StarSystem::getContTerrain ( unsigned int  which)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 191 of file star_system_generic.h.

Referenced by createObjects().

192  {
193  return NULL;
194  }
unsigned int StarSystem::getCurrentSimFrame ( ) const
inline

Gets the current simulation frame.

Definition at line 204 of file star_system_generic.h.

References current_sim_location.

Referenced by GameStarSystem::Draw(), GameUnit< UnitType >::Draw(), UnitDrawer::draw(), Unit::UpdatePhysics(), and Unit::UpdateSubunitPhysics().

205  {
206  return current_sim_location;
207  }
virtual Texture* StarSystem::getLightMap ( )
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 164 of file star_system_generic.h.

Referenced by GameUniverse::getLightMap().

165  {
166  return NULL;
167  }
string StarSystem::getName ( )

Definition at line 225 of file star_system_generic.cpp.

References name.

Referenced by ZoneMgr::displayStats(), NavigationSystem::DrawSystem(), and Universe::getStarSystem().

226 {
227  return string( name );
228 }
virtual Terrain* StarSystem::getTerrain ( unsigned int  which)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 187 of file star_system_generic.h.

Referenced by createObjects().

188  {
189  return NULL;
190  }
unsigned int StarSystem::GetZone ( )
inline

Definition at line 153 of file star_system_generic.h.

References zone.

Referenced by ZoneMgr::addClient(), AddUnit(), ZoneMgr::broadcast(), NetServer::sendMessage(), and NetServer::sendNewUnitQueue().

154  {
155  //short fix
156  return this->zone;
157  }
UnitCollection& StarSystem::gravitationalUnits ( )
inline
bool StarSystem::JumpTo ( Unit unit,
Unit jumppoint,
const std::string &  system,
bool  force = false,
bool  save_coordinates = false 
)

Definition at line 927 of file star_system_generic.cpp.

References _Universe, Universe::AccessCockpit(), ActivateAnimation(), Universe::activeStarSystem(), ComputeJumpPointArrival(), Unit::UnitJump::delay, Unit::DockedOrDocking(), DoJumpingLeaveSightAndSound(), Unit::UnitJump::drive, filename, Universe::GenerateStarSystem(), Hashtable< KEY, VALUE, SIZ >::Get(), Universe::getActiveStarSystem(), getFileName(), Unit::GetJumpStatus(), Unit::GetSerial(), isJumping(), Universe::isPlayerStarship(), Unit::jump, NetClient::jumpRequest(), Network, Cockpit::OnJumpBegin(), pendingjump, Unit::Position(), QVector, Vector, and VSFileSystem::vs_fprintf().

Referenced by Unit::jumpReactToCollision(), UnitUtil::JumpTo(), TentativeJumpTo(), Unit::UpdatePhysics(), and WarpPursuit().

928 {
929  if ( ( un->DockedOrDocking()&(~Unit::DOCKING_UNITS) ) != 0 )
930  return false;
931  if (Network == NULL || force) {
932  if (un->jump.drive >= 0)
933  un->jump.drive = -1;
934 #ifdef JUMP_DEBUG
935  VSFileSystem::vs_fprintf( stderr, "jumping to %s. ", system.c_str() );
936 #endif
937  StarSystem *ss = star_system_table.Get( system );
938  std::string ssys( system+".system" );
939  if (!ss)
940  ss = star_system_table.Get( ssys );
941  bool justloaded = false;
942  if (!ss) {
943  justloaded = true;
944  ss = _Universe->GenerateStarSystem( ssys.c_str(), filename.c_str(), Vector( 0, 0, 0 ) );
945  //NETFIXME: Do we want to generate the system if an AI unit jumps?
946  }
947  if ( ss && !isJumping( pendingjump, un ) ) {
948 #ifdef JUMP_DEBUG
949  VSFileSystem::vs_fprintf( stderr, "Pushing back to pending queue!\n" );
950 #endif
951  bool dosightandsound = ( ( this == _Universe->getActiveStarSystem( 0 ) ) || _Universe->isPlayerStarship( un ) );
952  int ani = -1;
953  if (dosightandsound)
956  pendingjump.push_back( new unorigdest( un, jumppoint, this, ss, un->GetJumpStatus().delay, ani, justloaded,
957  save_coordinates ? ComputeJumpPointArrival( un->Position(), this->getFileName(),
958  system ) : QVector( 0, 0, 0 ) ) );
959  } else {
960 #ifdef JUMP_DEBUG
961  VSFileSystem::vs_fprintf( stderr, "Failed to retrieve!\n" );
962 #endif
963  return false;
964  }
965  if (jumppoint)
966  ActivateAnimation( jumppoint );
967  } else
968  //Networking mode
969  if (jumppoint) {
970  Network->jumpRequest( system, jumppoint->GetSerial() );
971  }
972  return true;
973 }
void StarSystem::LoadXML ( const char *  filename,
const Vector centroid,
const float  timeofyear 
)
protected

Definition at line 1498 of file star_system_xml.cpp.

References AddUnit(), Planet::PlanetIterator::advance(), StarSystem::StarXML::backgroundColor, StarSystem::StarXML::backgroundDegamma, StarSystem::StarXML::backgroundname, beginElement(), createBackground(), StarSystem::StarXML::ct, endElement(), f, StarSystem::StarXML::fade, accountXML::file, filename, vs_options::game_speed_affects_autogen_systems, VSFileSystem::GetCorrectStarSysPath(), GetNumNearStarsScale(), GetNumStarsScale(), GetStarSpreadScale(), StarSystem::StarXML::moons, StarSystem::StarXML::numnearstars, StarSystem::StarXML::numstars, VSFileSystem::Ok, StarSystem::StarXML::parentterrain, PLANETPTR, vs_options::reflectivity, StarSystem::StarXML::reflectivity, StarSystem::StarXML::scale, vs_options::star_system_scale, StarSystem::StarXML::starsp, StarSystem::StarXML::systemcentroid, VSFileSystem::SystemFile, StarSystem::StarXML::timeofyear, StarSystem::StarXML::unitlevel, VSFileSystem::vs_dprintf(), and xml.

Referenced by GameStarSystem::GameStarSystem(), and StarSystem().

1499 {
1500  using namespace StarXML;
1501  bool autogenerated = false;
1502  this->filename = filename;
1503  string file = VSFileSystem::GetCorrectStarSysPath( filename, autogenerated );
1504  if ( file.empty() )
1505  file = filename;
1507  autogenerated = false;
1508  VSFile f;
1509  VSError err;
1510  //if (file.length()) {
1511  err = f.OpenReadOnly( file, SystemFile );
1512  if (err > Ok) {
1513  printf( "StarSystem: file not found %s\n", file.c_str() );
1514  return;
1515  }
1516  xml = new StarXML;
1517  xml->scale = 1;
1518  xml->fade = autogenerated;
1520  xml->parentterrain = NULL;
1521  xml->ct = NULL;
1522  xml->systemcentroid = centroid;
1527  xml->backgroundname = string( "cube" );
1528  xml->backgroundColor = GFXColor(1.0,1.0,1.0,1.0);
1529  xml->backgroundDegamma = false;
1531  xml->unitlevel = 0;
1532  XML_Parser parser = XML_ParserCreate( NULL );
1533  XML_SetUserData( parser, this );
1534  XML_SetElementHandler( parser, &StarSystem::beginElement, &StarSystem::endElement );
1535  {
1536  string fcontents = f.ReadFull();
1537  VSFileSystem::vs_dprintf( 2, "Contents of star system:\n%s\n", fcontents.c_str() );
1538  XML_Parse( parser, (fcontents).c_str(), f.Size(), 1 );
1539  }
1540  f.Close();
1541  XML_ParserFree( parser );
1542  unsigned int i;
1543  for (i = 0; i < xml->moons.size(); ++i) {
1544  if (xml->moons[i]->isUnit() == PLANETPTR) {
1545  Unit *un = NULL;
1546  for ( Planet::PlanetIterator iter( (Planet*) xml->moons[i] ); (un = *iter); iter.advance() )
1547  AddUnit( un );
1548  } else {
1549  AddUnit( xml->moons[i] );
1550  }
1551  }
1552  createBackground( xml );
1553  delete xml;
1554 }
Unit * StarSystem::nextSignificantUnit ( )

Definition at line 654 of file star_system_generic.cpp.

References sigIter.

655 {
656  return(*sigIter);
657 }
virtual unsigned int StarSystem::numContTerrain ( )
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 173 of file star_system_generic.h.

Referenced by createObjects().

174  {
175  return 0;
176  }
virtual unsigned int StarSystem::numTerrain ( )
inlinevirtual

activates the light map texture

Reimplemented in GameStarSystem.

Definition at line 169 of file star_system_generic.h.

Referenced by createObjects().

170  {
171  return 0;
172  }
void StarSystem::ProcessPendingJumps ( )
static

Definition at line 804 of file star_system_generic.cpp.

References _Universe, Universe::AccessCockpit(), Universe::activeStarSystem(), Unit::activeStarSystem, Unit::DecreaseWarpEnergy(), DoJumpingComeSightAndSound(), NetClient::downloadZoneInfo(), GetElapsedTime(), VegaConfig::getVariable(), NetClient::inGame(), Universe::isPlayerStarship(), Unit::LocalPosition(), Network, Cockpit::OnJumpEnd(), XMLSupport::parse_bool(), pendingjump, QVector, Universe::setActiveStarSystem(), Unit::SetCurPosition(), SetShieldZero(), Unit::SetVelocity(), SIMULATION_ATOM, speed, Universe::StillExists(), time, Unit::TransferUnitToSystem(), NetClient::unreadyToJump(), Vector, VolitalizeJumpAnimation(), vs_config, VSFileSystem::vs_fprintf(), and Universe::whichPlayerStarship().

Referenced by NetServer::start(), and GameUniverse::StartDraw().

805 {
806  for (unsigned int kk = 0; kk < pendingjump.size(); ++kk) {
807  Unit *un = pendingjump[kk]->un.GetUnit();
808  if (pendingjump[kk]->delay >= 0) {
809  Unit *jp = pendingjump[kk]->jumppoint.GetUnit();
810  if (un && jp) {
811  QVector delta = ( jp->LocalPosition()-un->LocalPosition() );
812  float dist = delta.Magnitude();
813  if (pendingjump[kk]->delay > 0) {
814  float speed = dist/pendingjump[kk]->delay;
815  bool player = (_Universe->isPlayerStarship( un ) != NULL);
816  if (dist > 10 && player) {
817  if (un->activeStarSystem == pendingjump[kk]->orig)
818  un->SetCurPosition( un->LocalPosition()+SIMULATION_ATOM*delta*(speed/dist) );
819  } else if (!player) {
820  un->SetVelocity( Vector( 0, 0, 0 ) );
821  }
822  static bool setshieldzero =
823  XMLSupport::parse_bool( vs_config->getVariable( "physics", "jump_disables_shields", "true" ) );
824  if (setshieldzero)
825  SetShieldZero( un );
826  }
827  }
828  double time = GetElapsedTime();
829  if (time > 1)
830  time = 1;
831  pendingjump[kk]->delay -= time;
832  continue;
833  } else {
834 #ifdef JUMP_DEBUG
835  VSFileSystem::vs_fprintf( stderr, "Volitalizing pending jump animation.\n" );
836 #endif
838  }
839  int playernum = _Universe->whichPlayerStarship( un );
840  //In non-networking mode or in networking mode or a netplayer wants to jump and is ready or a non-player jump
841  if ( Network == NULL || playernum < 0 || ( Network != NULL && playernum >= 0 && Network[playernum].readyToJump() ) ) {
842  Unit *un = pendingjump[kk]->un.GetUnit();
843  StarSystem *savedStarSystem = _Universe->activeStarSystem();
844  //Download client descriptions of the new zone (has to be blocking)
845  if (Network != NULL)
846  Network[playernum].downloadZoneInfo();
847  if ( un == NULL || !_Universe->StillExists( pendingjump[kk]->dest )
848  || !_Universe->StillExists( pendingjump[kk]->orig ) ) {
849 #ifdef JUMP_DEBUG
850  VSFileSystem::vs_fprintf( stderr, "Adez Mon! Unit destroyed during jump!\n" );
851 #endif
852  delete pendingjump[kk];
853  pendingjump.erase( pendingjump.begin()+kk );
854  --kk;
855  continue;
856  }
857  bool dosightandsound = ( (pendingjump[kk]->dest == savedStarSystem) || _Universe->isPlayerStarship( un ) );
859  if ( un->TransferUnitToSystem( kk, savedStarSystem, dosightandsound ) )
860  un->DecreaseWarpEnergy( false, 1.0f );
861  if (dosightandsound)
864  delete pendingjump[kk];
865  pendingjump.erase( pendingjump.begin()+kk );
866  --kk;
867  _Universe->setActiveStarSystem( savedStarSystem );
868  //In networking mode we tell the server we want to go back in game
869  if (Network != NULL) {
870  //Find the corresponding networked player
871  if (playernum >= 0) {
872  Network[playernum].inGame();
873  Network[playernum].unreadyToJump();
874  }
875  }
876  }
877  }
878 }
void StarSystem::RemoveStarsystemFromUniverse ( )
protected
bool StarSystem::RemoveUnit ( Unit unit)

Removes from draw list.

Definition at line 258 of file star_system_generic.cpp.

References collidemap, UnitCollection::createIterator(), drawList, CollideArray::erase(), gravitationalUnits(), i, is_null(), Unit::location, Unit::NUM_COLLIDE_MAPS, physics_buffer, StarSystem::Statistics::RemoveUnit(), set_null(), SIM_QUEUE_SIZE, and stats.

Referenced by ZoneMgr::removeClient().

259 {
260  for (unsigned int locind = 0; locind < Unit::NUM_COLLIDE_MAPS; ++locind)
261  if ( !is_null( un->location[locind] ) ) {
262  collidemap[locind]->erase( un->location[locind] );
263  set_null( un->location[locind] );
264  }
265  bool removed2 = false;
266  Unit *unit;
267  for (un_iter iter = gravitationalUnits().createIterator(); (unit = *iter); ++iter)
268  if (unit == un) {
269  iter.remove();
270  removed2 = true;
271  break; //Shouldn't be in there twice
272  }
273  //NOTE: not sure why if(1) was here, but safemode removed it
274  bool removed = false;
275  if (1) {
276  for (un_iter iter = drawList.createIterator(); (unit = *iter); ++iter)
277  if (unit == un) {
278  iter.remove();
279  removed = true;
280  break;
281  }
282  }
283  if (removed) {
284  for (unsigned int i = 0; i <= SIM_QUEUE_SIZE; ++i) {
285  Unit *unit;
286  for (un_iter iter = physics_buffer[i].createIterator(); (unit = *iter); ++iter)
287  if (unit == un) {
288  iter.remove();
289  removed = true;
290  //terminate outer loop
291  i = SIM_QUEUE_SIZE+1;
292  break;
293  }
294  }
295  stats.RemoveUnit( un );
296  }
297  return removed;
298 }
void StarSystem::RequestPhysics ( Unit un,
unsigned int  queue 
)

Requeues the unit so that it is simulated ASAP.

Definition at line 484 of file star_system_generic.cpp.

References UnitCollection::createIterator(), current_sim_location, UnitCollection::UnitIterator::moveBefore(), physics_buffer, Unit::predicted_priority, and SIM_QUEUE_SIZE.

485 {
486  Unit *unit = NULL;
487  un_iter iter = this->physics_buffer[queue].createIterator();
488  while ( (unit = *iter) && *iter != un )
489  ++iter;
490  if (unit == un) {
491  un->predicted_priority = 0;
492  unsigned int newloc = (current_sim_location+1)%SIM_QUEUE_SIZE;
493  if (newloc != queue)
494  iter.moveBefore( this->physics_buffer[newloc] );
495  }
496 }
void StarSystem::SetZone ( unsigned int  zonenum)
inline

Definition at line 149 of file star_system_generic.h.

References zone.

Referenced by ZoneMgr::addZone().

150  {
151  this->zone = zonenum;
152  }
virtual void StarSystem::SwapIn ( )
inlinevirtual

re-enables the included lights and terrains

Reimplemented in GameStarSystem.

Definition at line 184 of file star_system_generic.h.

Referenced by GameUniverse::StartDraw(), Cockpit::Update(), and ~StarSystem().

184 {}
virtual void StarSystem::SwapOut ( )
inlinevirtual

Disables included lights and terrains.

Reimplemented in GameStarSystem.

Definition at line 186 of file star_system_generic.h.

Referenced by Universe::Generate2(), GameUnit< UnitType >::TransferUnitToSystem(), Cockpit::Update(), and ~StarSystem().

186 {}
void StarSystem::Update ( float  priority,
bool  executeDirector 
)

update a simulation atom ExecuteDirector must be false if star system is just loaded before mission is loaded

this makes it so systems without players may be simulated less accurately

just be sure to restore this at the end

Definition at line 689 of file star_system_generic.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, Cockpit::activeStarSystem, AUDRefreshSounds(), collidetable, UnitCollection::createIterator(), current_stage, Universe::CurrentCockpit(), drawList, ExecuteDirector(), Universe::getActiveStarSystem(), GetElapsedTime(), getTimeCompression(), i, UnitCollection::UnitIterator::isDone(), UnitUtil::isSignificant(), j, k, MISSION_SIMULATION, Universe::numPlayers(), PHY_NUM, Universe::popActiveStarSystem(), PROCESS_UNIT, Unit::ProcessDeleteQueue(), Universe::pushActiveStarSystem(), queryTime(), run_only_player_starsystem, Universe::SetActiveCockpit(), sigIter, SIMULATION_ATOM, TerrainCollide(), time, Cockpit::Update(), CollideTable::Update(), UpdateAnimatedTexture(), Cockpit::updateAttackers(), UpdateCameraSnds(), UpdateMissiles(), and UpdateUnitPhysics().

Referenced by Universe::Update().

690 {
691  bool firstframe = true;
692  double pythontime = 0;
694  for (unsigned int k = 0; k < _Universe->numPlayers(); ++k)
695  if (_Universe->AccessCockpit( k )->activeStarSystem == this)
696  priority = 1;
697  float normal_simulation_atom = SIMULATION_ATOM;
698  SIMULATION_ATOM /= ( priority/getTimeCompression() );
700  time += GetElapsedTime();
702  //WARNING PERFORMANCE HACK!!!!!
703  if (time > 2*SIMULATION_ATOM)
704  time = 2*SIMULATION_ATOM;
705  double bolttime = 0;
706  if ( time/SIMULATION_ATOM >= (1./PHY_NUM) ) {
707  //Chew up all SIMULATION_ATOMs that have elapsed since last update
708  while ( time/SIMULATION_ATOM >= (1./PHY_NUM) ) {
710  TerrainCollide();
713  double pythonidea = queryTime();
716  if (executeDirector)
717  ExecuteDirector();
718  pythontime = queryTime()-pythonidea;
719  static int dothis = 0;
720  if ( this == _Universe->getActiveStarSystem( 0 ) )
721  if ( (++dothis)%2 == 0 )
723  for (unsigned int i = 0; i < active_missions.size(); ++i)
724  //waste of farkin time
725  active_missions[i]->BriefingUpdate();
727  } else if (current_stage == PROCESS_UNIT) {
728  UpdateUnitPhysics( firstframe );
729  UpdateMissiles(); //do explosions
730  collidetable->Update();
731  if ( this == _Universe->getActiveStarSystem( 0 ) )
733  bolttime = queryTime();
734  bolttime = queryTime()-bolttime;
736  firstframe = false;
737  }
738  time -= (1./PHY_NUM)*SIMULATION_ATOM;
739  }
740  unsigned int i = _Universe->CurrentCockpit();
741  for (unsigned int j = 0; j < _Universe->numPlayers(); ++j)
742  if (_Universe->AccessCockpit( j )->activeStarSystem == this) {
745  if ( _Universe->AccessCockpit( j )->Update() ) {
746  SIMULATION_ATOM = normal_simulation_atom;
749  return;
750  }
751  }
753  }
754  if ( sigIter.isDone() )
756  else
757  ++sigIter;
758  while ( !sigIter.isDone() && !UnitUtil::isSignificant( *sigIter) )
759  ++sigIter;
760  //If it is done, leave it NULL for this frame then.
761  //WARNING cockpit does not get here...
762  SIMULATION_ATOM = normal_simulation_atom;
763  //WARNING cockpit does not get here...
765 }
void StarSystem::Update ( float  priority)

Definition at line 659 of file star_system_generic.cpp.

References _Universe, collidetable, UnitCollection::createIterator(), current_stage, drawList, ExecuteDirector(), GetElapsedTime(), MISSION_SIMULATION, PHY_NUM, Universe::popActiveStarSystem(), Unit::ProcessDeleteQueue(), Universe::pushActiveStarSystem(), Unit::SetNebula(), SIMULATION_ATOM, TerrainCollide(), time, CollideTable::Update(), UpdateMissiles(), and UpdateUnitPhysics().

660 {
661  Unit *unit;
662  bool firstframe = true;
663  //No time compression here
664  float normal_simulation_atom = SIMULATION_ATOM;
665  time += GetElapsedTime();
667  if ( time/SIMULATION_ATOM >= (1./PHY_NUM) ) {
668  while ( time/SIMULATION_ATOM >= (1.) ) {
669  //Chew up all SIMULATION_ATOMs that have elapsed since last update
670  ExecuteDirector();
671  TerrainCollide();
674  collidetable->Update();
675  for (un_iter iter = drawList.createIterator(); (unit = *iter); ++iter)
676  unit->SetNebula( NULL );
677  UpdateMissiles(); //do explosions
678  UpdateUnitPhysics( firstframe );
679 
680  firstframe = false;
681  }
683  }
684  SIMULATION_ATOM = normal_simulation_atom;
686 }
void StarSystem::UpdateMissiles ( )
virtual

Definition at line 14 of file missile_generic.cpp.

References UnitCollection::createIterator(), dischargedMissiles, and getUnitList().

Referenced by Update().

15 {
16  //WARNING: This is a big performance problem...
17  //...responsible for many hiccups.
18  //TODO: Make it use the collidemap to only iterate through potential hits...
19  //PROBLEM: The current collidemap does not allow this efficiently (no way of
20  //taking the other unit's rSize() into account).
21  if ( !dischargedMissiles.empty() ) {
22  Unit *un;
23  for (un_iter ui = getUnitList().createIterator();
24  NULL != ( un = (*ui) );
25  ++ui)
26  dischargedMissiles.back()->ApplyDamage( un );
27  delete dischargedMissiles.back();
28  dischargedMissiles.pop_back();
29  }
30 }
void StarSystem::UpdateUnitPhysics ( bool  firstframe)

Definition at line 498 of file star_system_generic.cpp.

References aggfire, StarSystem::Statistics::CheckVitals(), Unit::CollideAll(), collidemap, UnitCollection::createIterator(), Unit::cumulative_transformation, Unit::curr_physical_state, current_sim_location, Unit::ExecuteAI(), CollideArray::flatten(), VSRandom::genrand_int32(), UnitUtil::getPhysicsPriority(), getUnitList(), gravitationalUnits(), identity_matrix(), identity_transformation(), int, last_collisions, Unit::NUM_COLLIDE_MAPS, numprocessed, physics_buffer, physicsframecounter, Unit::predicted_priority, queryTime(), Unit::ResetThreatLevel(), Unit::sim_atom_multiplier, SIM_QUEUE_SIZE, SIMULATION_ATOM, stats, targetpick, theunitcounter, totalprocessed, Unit::UNIT_BOLT, Unit::UNIT_ONLY, Bolt::UpdatePhysics(), Unit::UpdatePhysics(), Vector, and vsrandom.

Referenced by Universe::Generate2(), and Update().

499 {
500  static bool phytoggle = true;
501  static int batchcount = SIM_QUEUE_SIZE-1;
502  double aitime = 0;
503  double phytime = 0;
504  double collidetime = 0;
505  double flattentime = 0;
506  double bolttime = 0;
507  targetpick = 0;
508  aggfire = 0;
509  numprocessed = 0;
510  stats.CheckVitals( this );
511  if (phytoggle) {
512  for (++batchcount; batchcount > 0; --batchcount) {
513  //BELOW COMMENTS ARE NO LONGER IN SYNCH
514  //NOTE: Randomization is necessary to preserve scattering - otherwise, whenever a
515  //unit goes from low-priority to high-priority and back to low-priority, they
516  //get synchronized and start producing peaks.
517  //NOTE2: But... randomization must come only on priority changes. Otherwise, it may
518  //interfere with subunit scheduling. Luckily, all units that make use of subunit
519  //scheduling also require a constant base priority, since otherwise priority changes
520  //will wreak havoc with subunit interpolation. Luckily again, we only need
521  //randomization on priority changes, so we're fine.
522  try {
523  Unit *unit = NULL;
524  for (un_iter iter = physics_buffer[current_sim_location].createIterator(); (unit = *iter); ++iter) {
525  int priority = UnitUtil::getPhysicsPriority( unit );
526  //Doing spreading here and only on priority changes, so as to make AI easier
527  int predprior = unit->predicted_priority;
528  //If the priority has really changed (not an initial scattering, because prediction doesn't match)
529  if (priority != predprior) {
530  if (predprior == 0)
531  //Validate snapshot of current interpolated state (this is a reschedule)
533  //Save priority value as prediction for next scheduling, but don't overwrite yet.
534  predprior = priority;
535  //Scatter, so as to achieve uniform distribution
536  priority = 1+( ( (unsigned int) vsrandom.genrand_int32() )%priority );
537  }
538  float backup = SIMULATION_ATOM;
540  SIMULATION_ATOM *= priority;
541  unit->sim_atom_multiplier = priority;
542  double aa = queryTime();
543  unit->ExecuteAI();
544  double bb = queryTime();
545  unit->ResetThreatLevel();
546  //FIXME "firstframe"-- assume no more than 2 physics updates per frame.
548  0,
549  0 ), priority
550  == 1 ? firstframe : true, &this->gravitationalUnits(), unit );
551  double cc = queryTime();
552  aitime += bb-aa;
553  phytime += cc-bb;
554  SIMULATION_ATOM = backup;
555  unit->predicted_priority = predprior;
556  }
557  }
558  catch (const boost::python::error_already_set) {
559  if ( PyErr_Occurred() ) {
560  PyErr_Print();
561  PyErr_Clear();
562  fflush( stderr );
563  fflush( stdout );
564  } throw;
565  }
566  double c0 = queryTime();
567  Bolt::UpdatePhysics( this );
568  double cc = queryTime();
569  last_collisions.clear();
570  double fl0 = queryTime();
572  if (Unit::NUM_COLLIDE_MAPS > 1)
574  flattentime = queryTime()-fl0;
575  Unit *unit;
576  for (un_iter iter = physics_buffer[current_sim_location].createIterator(); (unit = *iter);) {
577  int priority = unit->sim_atom_multiplier;
578  float backup = SIMULATION_ATOM;
579  SIMULATION_ATOM *= priority;
580  unsigned int newloc = (current_sim_location+priority)%SIM_QUEUE_SIZE;
581  unit->CollideAll();
582  SIMULATION_ATOM = backup;
583  if (newloc == current_sim_location)
584  ++iter;
585  else
586  iter.moveBefore( physics_buffer[newloc] );
587  }
588  double dd = queryTime();
589  collidetime += dd-cc;
590  bolttime += cc-c0;
594  theunitcounter = 0;
595  }
596  } else {
597  Unit *unit = NULL;
598  for (un_iter iter = getUnitList().createIterator(); (unit = *iter); ++iter) {
599  unit->ExecuteAI();
600  last_collisions.clear();
602  0,
603  0 ), firstframe,
604  &this->gravitationalUnits(), unit );
605  unit->CollideAll();
606  }
607  }
608 }
virtual void StarSystem::VolitalizeJumpAnimation ( const int  ani)
inlinevirtual

Reimplemented in GameStarSystem.

Definition at line 235 of file star_system_generic.h.

Referenced by ProcessPendingJumps().

235 {}

Friends And Related Function Documentation

friend class Universe
friend

Definition at line 142 of file star_system_generic.h.

Member Data Documentation

std::vector< ContinuousTerrain* > StarSystem::contterrains
protected
unsigned int StarSystem::current_sim_location
protected
enum StarSystem::PHYSICS_STAGE StarSystem::current_stage
protected
std::vector< class MissileEffect* > StarSystem::dischargedMissiles
protected

Definition at line 144 of file star_system_generic.h.

Referenced by AddMissileToQueue(), and UpdateMissiles().

UnitCollection StarSystem::drawList
protected

Everything to be drawn. Folded missiles in here oneday.

Definition at line 122 of file star_system_generic.h.

Referenced by AddUnit(), GameStarSystem::getClickList(), getUnitList(), RemoveUnit(), StarSystem(), Update(), and ~StarSystem().

std::string StarSystem::filename
protected
UnitCollection StarSystem::GravitationalUnits
protected

Definition at line 123 of file star_system_generic.h.

Referenced by GameStarSystem::Draw(), and gravitationalUnits().

std::multimap< Unit*, Unit* > StarSystem::last_collisions

Definition at line 147 of file star_system_generic.h.

Referenced by Unit::Collide(), and UpdateUnitPhysics().

int StarSystem::lightcontext
protected
char* StarSystem::name
protected
unsigned char StarSystem::no_collision_time
protected

Objects subject to global gravitron physics (disabled)

Definition at line 127 of file star_system_generic.h.

Referenced by GameStarSystem::GameStarSystem(), and StarSystem().

UnitCollection StarSystem::physics_buffer[SIM_QUEUE_SIZE+1]
protected
un_iter StarSystem::sigIter
protected

Definition at line 131 of file star_system_generic.h.

Referenced by nextSignificantUnit(), StarSystem(), and Update().

Stars* StarSystem::stars
protected

The background associated with this system.

The moving, fading stars

Definition at line 137 of file star_system_generic.h.

Referenced by GameStarSystem::createBackground(), GameStarSystem::Draw(), StarSystem(), and GameStarSystem::~GameStarSystem().

struct StarSystem::Statistics StarSystem::stats
std::vector< Terrain* > StarSystem::terrains
protected

Stars, planets, etc. Orbital mechanics precalculated.

Definition at line 119 of file star_system_generic.h.

Referenced by GameStarSystem::getTerrain(), and GameStarSystem::numTerrain().

double StarSystem::time
protected

to track the next given physics frame

Definition at line 133 of file star_system_generic.h.

Referenced by GameStarSystem::Draw(), GameStarSystem::GameStarSystem(), ProcessPendingJumps(), StarSystem(), and Update().

struct StarSystem::StarXML * StarSystem::xml
protected

Referenced by LoadXML().

unsigned int StarSystem::zone
protected

Definition at line 145 of file star_system_generic.h.

Referenced by GetZone(), SetZone(), and StarSystem().


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