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

#include <vdu.h>

Inheritance diagram for VDU:
VSSprite

Public Types

enum  VDU_MODE {
  TARGET =0x1, NAV =0x2, OBJECTIVES =0x4, COMM =0x8,
  WEAPON =0x10, DAMAGE =0x20, SHIELD =0x40, MANIFEST =0x80,
  TARGETMANIFEST =0x100, VIEW =0x200, MSG =0x400, SCANNING =0x800,
  NETWORK =0x1000, WEBCAM =0x2000
}
 Alert! To add a mode must change const array on the bottom. VIEW must remain LAST. More...
 

Public Member Functions

void ReceivedTargetData ()
 
bool staticable () const
 
unsigned int getMode () const
 
 VDU (const char *file, TextPlane *textp, unsigned short modes, short rows, short cols, float *MaxArmor, float *maxhull)
 
void Draw (GameCockpit *parentcp, Unit *parent, const GFXColor &c)
 Draws the entire VDU, all data, etc. More...
 
void SwitchMode (Unit *parent)
 Changes the mode of the current VDU to another legal mode. More...
 
void SetViewingStyle (VIEWSTYLE vm)
 
void Scroll (int howmuch)
 
bool SetCommAnimation (Animation *ani, Unit *unit, bool force)
 
UnitGetCommunicating ()
 
bool CheckCommAnimation (Unit *un) const
 
- Public Member Functions inherited from VSSprite
 VSSprite (const char *file, enum FILTER texturefilter=BILINEAR, GFXBOOL force=GFXFALSE)
 
 VSSprite (Texture *surface, float xcenter, float ycenter, float width, float height, float s=0.f, float t=0.f, bool isAnimation=false)
 
 VSSprite (const VSSprite &source)
 
 ~VSSprite ()
 
bool LoadSuccess () const
 
void Draw ()
 
void DrawHere (Vector &ll, Vector &lr, Vector &ur, Vector &ul)
 
void Rotate (const float &rad)
 
void SetRotation (const float &rot)
 
void GetRotation (float &rot)
 
void ReadTexture (VSFileSystem::VSFile *f)
 
void GetST (float &s, float &t)
 
void SetST (const float s, const float t)
 
void SetTime (double newtime)
 
void SetPosition (const float &x1, const float &y1)
 
void GetPosition (float &x1, float &y1)
 
void SetSize (float s1, float s2)
 
void GetSize (float &x1, float &y1)
 
void SetTimeSource (SharedPtr< Audio::Source > source)
 
void ClearTimeSource ()
 
bool Done () const
 
void Reset ()
 
SharedPtr< Audio::SourceGetTimeSource () const
 
TexturegetTexture ()
 
const TexturegetTexture () const
 

Public Attributes

int scrolloffset
 

Detailed Description

Definition at line 21 of file vdu.h.

Member Enumeration Documentation

Alert! To add a mode must change const array on the bottom. VIEW must remain LAST.

Enumerator
TARGET 
NAV 
OBJECTIVES 
COMM 
WEAPON 
DAMAGE 
SHIELD 
MANIFEST 
TARGETMANIFEST 
VIEW 
MSG 
SCANNING 
NETWORK 
WEBCAM 

Definition at line 81 of file vdu.h.

82  {
83  TARGET=0x1, NAV=0x2, OBJECTIVES=0x4, COMM=0x8, WEAPON=0x10, DAMAGE=0x20, SHIELD=0x40, MANIFEST=0x80,
84  TARGETMANIFEST=0x100, VIEW=0x200, MSG=0x400, SCANNING=0x800, NETWORK=0x1000, WEBCAM=0x2000
85  };

Constructor & Destructor Documentation

VDU::VDU ( const char *  file,
TextPlane textp,
unsigned short  modes,
short  rows,
short  cols,
float MaxArmor,
float maxhull 
)

Definition at line 187 of file vdu.cpp.

References _Universe, CP_TARGET, MSG, Network, Universe::numPlayers(), SwitchMode(), and VIEW.

188  : VSSprite( file )
189  , tp( textp )
190  , posmodes( modes )
191  , rows( rwws )
192  , cols( clls )
193  , scrolloffset( 0 )
194 {
195  thismode.push_back( MSG );
196  if (_Universe->numPlayers() > 1)
197  posmodes &= (~VIEW);
198  comm_ani = NULL;
199  viewStyle = CP_TARGET;
200  StartArmor = ma;
201  maxhull = mh;
202  if (Network != NULL)
203  got_target_info = false;
204  else
205  got_target_info = true;
206  SwitchMode( NULL );
207 
208  //printf("\nVDU rows=%d,col=%d\n",rows,cols);
209  //cout << "vdu" << endl;
210 }

Member Function Documentation

bool VDU::CheckCommAnimation ( Unit un) const

Definition at line 2032 of file vdu.cpp.

References AnimatedTexture::Done().

2033 {
2034  if (comm_ani && comm_ani->Done() == false)
2035  if (communicating == un || communicating == NULL)
2036  return true;
2037  return false;
2038 }
void VDU::Draw ( GameCockpit parentcp,
Unit parent,
const GFXColor c 
)

Draws the entire VDU, all data, etc.

Definition at line 1806 of file vdu.cpp.

References _Universe, Universe::AccessCamera(), GameCockpit::autoMessage, GameCockpit::autoMessageTime, TextPlane::bgcol, TextPlane::col, COMM, Universe::current_stardate, DAMAGE, AnimatedTexture::Done(), VSSprite::Draw(), TextPlane::Draw(), TextPlane::GetCharSize(), Unit::GetComputerData(), StarDate::GetFullTrekDate(), UniverseUtil::GetGameTime(), NetClient::getLag(), Camera::GetNebula(), VSSprite::GetPosition(), VSSprite::GetSize(), UnitContainer::GetUnit(), VegaConfig::getVariable(), GFXBlendMode(), GFXDisable(), GFXEnable(), int, INVSRCALPHA, LIGHTING, MangleString, MANIFEST, MSG, NAV, Unit::Computer::NavPoint, Network, NETWORK, OBJECTIVES, XMLSupport::parse_float(), Unit::Position(), SCANNING, TextPlane::SetPos(), TextPlane::SetSize(), UnitContainer::SetUnit(), SHIELD, SRCALPHA, retString128::str, TARGET, Unit::Computer::target, TARGETMANIFEST, TEXTURE0, TEXTURE1, Unit::ToLocalCoordinates(), VIEW, vs_config, WEAPON, Universe::whichPlayerStarship(), x, and y.

1807 {
1808  tp->col = color;
1809  GFXDisable( LIGHTING );
1811  GFXEnable( TEXTURE0 );
1812  GFXDisable( TEXTURE1 );
1813  VSSprite::Draw();
1814  //glDisable( GL_ALPHA_TEST);
1815  if (!parent)
1816  return;
1817  //configure text plane;
1818  float x, y;
1819  float h, w;
1820  GetSize( w, h );
1821 
1822  static float width_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_width", "0" ) );
1823  static float height_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_height", "0" ) );
1824  w = w-width_factor;
1825  h = h+height_factor;
1826 
1827  GetPosition( x, y );
1828  //tp->SetCharSize (fabs(w/cols),fabs(h/rows));
1829  float csx, csy;
1830  tp->GetCharSize( csx, csy );
1831  //This was as below:
1832  //cols = abs( (int) ceil( w/csx ) );
1833  //rows = abs( (int) ceil( h/csy ) );
1834  //I'm changing it to as below, which avoids abs blues with visual studio, and is
1835  //also faster, as computing the abs of a float amounts to setting the sign bit;
1836  //though I'm less than 100% entirely sure of the correctness of the change... --chuck_starchaser
1837  cols = int(fabs(ceil(w/csx)));
1838  rows = int(fabs(ceil(h/csy)));
1839 
1840  Unit *targ;
1841  h = fabs( h/2 );
1842  w = fabs( w/2 );
1843  tp->SetPos( x-w, y+h );
1844  tp->SetSize( x+w, y-h-.5*fabs( w/cols ) );
1845  targ = parent->GetComputerData().target.GetUnit();
1846  if (thismode.back() != COMM && comm_ani != NULL) {
1847  if ( comm_ani->Done() ) {
1848  comm_ani = NULL;
1849  communicating.SetUnit( NULL );
1850  }
1851  }
1852  float delautotime = UniverseUtil::GetGameTime()-parentcp->autoMessageTime;
1853  static float auto_switch_lim =
1854  XMLSupport::parse_float( vs_config->getVariable( "graphics", "auto_message_nav_switch_time_lim", ".15" ) );
1855  if ( (delautotime<auto_switch_lim) && (parentcp->autoMessage.length()!=0) ) {
1856  if ( (thismode.back()!=COMM) && ((posmodes&NAV)!=0) ) {
1857  thismode.back() = NAV;
1858  parentcp->autoMessageTime -= auto_switch_lim*1.125;
1859  }
1860  }
1861  switch ( thismode.back() )
1862  {
1863  case NETWORK:
1864  if (Network != NULL) {
1865  int playernum = _Universe->whichPlayerStarship( parent );
1866  char buf[32];
1867  string str( "Lag: " );
1868  unsigned int lag = Network[playernum].getLag();
1869  memset( buf, 0, 32 );
1870  sprintf( buf, "%.1Lf", (long double) lag );
1871  if (lag < 50)
1872  str += "#00FF00";
1873  else if (lag < 150)
1874  str += "#FFFF00";
1875  else if (lag > 0)
1876  str += "#FF0000";
1877  str += string( buf )+"#000000 ms\n";
1878  if ( Network[playernum].IsNetcommSecured() )
1879  str += "#DD0000";
1880  memset( buf, 0, 32 );
1881  sprintf( buf, "%g", Network[playernum].getCurrentFrequency() );
1882  str += string( buf )+"/";
1883  memset( buf, 0, 32 );
1884  sprintf( buf, "%g", Network[playernum].getSelectedFrequency() );
1885  str += string( buf )+" GHz";
1886  if ( Network[playernum].IsNetcommSecured() )
1887  str += "#000000";
1888  if ( Network[playernum].IsNetcommActive() )
1889  str += " - #0000FFON";
1890  else
1891  str += " - #FF0000OFF";
1892  str += "#000000\n";
1893  str += "SD: "+_Universe->current_stardate.GetFullTrekDate();
1894  static float background_alpha =
1895  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1896  GFXColor tpbg = tp->bgcol;
1897  bool automatte = (0 == tpbg.a);
1898  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1899  tp->Draw( MangleString( str, _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
1900  tp->bgcol = tpbg;
1901  }
1902  break;
1903  case WEBCAM:
1904  if (Network != NULL)
1905  DrawWebcam( parent );
1906  break;
1907  case SCANNING:
1908  if (!got_target_info)
1909  DrawScanningMessage();
1910  /*
1911  * else
1912  * DrawScanner();
1913  */
1914  break;
1915  case TARGET:
1916  if (targ)
1917  DrawTarget( parentcp, parent, targ );
1918  break;
1919  case MANIFEST:
1920  DrawManifest( parent, parent );
1921  break;
1922  case TARGETMANIFEST:
1923  if (targ)
1924  DrawManifest( parent, targ );
1925  break;
1926  case VIEW:
1927  GetPosition( x, y );
1928  GetSize( w, h );
1929  DrawStarSystemAgain( .5*(x-fabs( w/2 )+1), .5*( ( y-fabs( h/2 ) )+1 ), fabs( w/2 ), fabs(
1930  h/2 ), viewStyle, parent, targ );
1931  break;
1932  case NAV:
1933  DrawNav( parentcp, parent, targ, parent->ToLocalCoordinates( parent->GetComputerData().NavPoint-parent->Position().Cast() ) );
1934  break;
1935  case MSG:
1936  DrawMessages( parentcp, targ );
1937  break;
1938  case COMM:
1939  DrawComm();
1940  break;
1941  case DAMAGE:
1942  DrawDamage( parent );
1943  break;
1944  case WEAPON:
1945  DrawWeapon( parent );
1946  break;
1947  case SHIELD:
1948  DrawVDUShield( parent );
1949  break;
1950  case OBJECTIVES:
1951  DrawVDUObjectives( parent );
1952  break;
1953  default:
1954  break; //FIXME --chuck_starchaser; please verify correctness and/or add a errlog or throw
1955  }
1956 }
Unit * VDU::GetCommunicating ( )

Definition at line 1046 of file vdu.cpp.

References AnimatedTexture::Done(), and UnitContainer::GetUnit().

1047 {
1048  if (comm_ani)
1049  if ( !comm_ani->Done() )
1050  return communicating.GetUnit();
1051  return NULL;
1052 }
unsigned int VDU::getMode ( ) const
inline

Definition at line 75 of file vdu.h.

Referenced by staticable().

76  {
77  return thismode.back();
78  }
void VDU::ReceivedTargetData ( )
inline

Definition at line 70 of file vdu.h.

71  {
72  got_target_info = true;
73  }
void VDU::Scroll ( int  howmuch)

Definition at line 371 of file vdu.cpp.

References scrolloffset.

372 {
373  scrolloffset += howmuch;
374 }
bool VDU::SetCommAnimation ( Animation ani,
Unit unit,
bool  force 
)

Definition at line 1027 of file vdu.cpp.

References COMM, AnimatedTexture::Reset(), and UnitContainer::SetUnit().

1028 {
1029  if (comm_ani == NULL || force) {
1030  if (posmodes&COMM) {
1031  if (ani != NULL && comm_ani == NULL)
1032  thismode.push_back( COMM );
1033  else if (comm_ani != NULL && thismode.size() > 1 && ani != NULL)
1034  thismode.back() = COMM;
1035  if (ani) {
1036  comm_ani = ani;
1037  ani->Reset();
1038  }
1039  communicating.SetUnit( un );
1040  return true;
1041  }
1042  }
1043  return false;
1044 }
void VDU::SetViewingStyle ( VIEWSTYLE  vm)

Definition at line 1452 of file vdu.cpp.

1453 {
1454  viewStyle = vs;
1455 }
bool VDU::staticable ( ) const

Definition at line 37 of file vdu.cpp.

References COMM, getMode(), VegaConfig::getVariable(), NAV, XMLSupport::parse_bool(), TARGET, TARGETMANIFEST, VIEW, vs_config, and WEBCAM.

38 {
39  unsigned int thismode = getMode();
40  static bool only_scanner_modes_static =
41  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "only_scanner_modes_static", "true" ) );
42  if (thismode != COMM && thismode != TARGETMANIFEST && thismode != TARGET && thismode != NAV && thismode != VIEW
43  && thismode != WEBCAM && only_scanner_modes_static)
44  return false;
45  return ( posmodes&(posmodes-1) ) != 0; //check not power of two
46 }
void VDU::SwitchMode ( Unit parent)

Changes the mode of the current VDU to another legal mode.

Definition at line 1997 of file vdu.cpp.

References _Universe, CP_CHASE, CP_TARGET, Network, SCANNING, scrolloffset, NetClient::startWebcamTransfer(), NetClient::stopWebcamTransfer(), UpdateViewstyle(), VIEW, and Universe::whichPlayerStarship().

Referenced by VDU().

1998 {
1999  if (!posmodes)
2000  return;
2001  scrolloffset = 0;
2002  //If we switch from SCANNING VDU VIEW_MODE we loose target info
2003  if (thismode.back() == SCANNING && Network != NULL)
2004  got_target_info = false;
2005  //If we switch from WEBCAM VDU VIEW_MODE we stop dlding images
2006  if (thismode.back() == WEBCAM && Network != NULL && parent != NULL) {
2007  int playernum = _Universe->whichPlayerStarship( parent );
2008  Network[playernum].stopWebcamTransfer();
2009  }
2010  if ( thismode.back() == VIEW && viewStyle != CP_CHASE && (thismode.back()&posmodes) ) {
2011  UpdateViewstyle( viewStyle );
2012  } else {
2013  viewStyle = CP_TARGET;
2014  thismode.back() <<= 1;
2015  while ( !(thismode.back()&posmodes) ) {
2016  if (thismode.back() > posmodes)
2017  thismode.back() = 0x1;
2018  else
2019  thismode.back() <<= 1;
2020  }
2021  }
2022  //If we switch to SCANNING MODE we consider we lost target info
2023  if (thismode.back() == SCANNING && Network != NULL)
2024  got_target_info = false;
2025  //If we switch to WEBCAM MODE we start dlding images
2026  if (thismode.back() == WEBCAM && Network != NULL && parent != NULL) {
2027  int playernum = _Universe->whichPlayerStarship( parent );
2028  Network[playernum].startWebcamTransfer();
2029  }
2030 }

Member Data Documentation

int VDU::scrolloffset

Definition at line 79 of file vdu.h.

Referenced by Scroll(), and SwitchMode().


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