#include <eNetGameObject.h>
Public Member Functions | |
virtual bool | ActionOnQuit () |
virtual void | ActionOnDelete () |
virtual void | InitAfterCreation () |
eNetGameObject (eGrid *grid, const eCoord &pos, const eCoord &dir, ePlayerNetID *p, bool autodelete=false) | |
eNetGameObject (nMessage &m) | |
virtual void | DoRemoveFromGame () |
called on RemoveFromGame() after OnRemoveFromGame(). Do not call base class implementation of this function, don't expect to get called from subclasses. | |
virtual void | WriteCreate (nMessage &m) |
virtual void | WriteSync (nMessage &m) |
virtual void | ReadSync (nMessage &m) |
virtual bool | ClearToTransmit (int user) const |
virtual bool | SyncIsNew (nMessage &m) |
virtual void | AddRef () |
adds a reference | |
virtual void | Release () |
removes a reference | |
virtual void | SendControl (REAL time, uActionPlayer *Act, REAL x) |
virtual void | ReceiveControl (REAL time, uActionPlayer *Act, REAL x) |
virtual bool | Timestep (REAL currentTime) |
ePlayerNetID * | Player () const |
void | clientside_action () |
virtual REAL | Lag () const |
expected average network latency | |
virtual REAL | LagThreshold () const |
tolerated network latency variation | |
Protected Member Functions | |
tCHECKED_PTR (ePlayerNetID) player | |
virtual void | ReceiveControlNet (nMessage &m) |
virtual | ~eNetGameObject () |
void | SetPlayer (ePlayerNetID *player) |
virtual nMachine & | DoGetMachine () const |
returns the machine this object belongs to | |
Protected Attributes | |
REAL | lastClientsideAction |
REAL | lastAttemptedSyncTime |
REAL | pingOverflow |
REAL | laggometer |
the actual best estimate for lag | |
REAL | laggometerSmooth |
the lag, smoothed over time | |
Private Member Functions | |
void | MyInitAfterCreation () |
Friends | |
class | ePlayerNetID |
Definition at line 41 of file eNetGameObject.h.
eNetGameObject::~eNetGameObject | ( | ) | [protected, virtual] |
Definition at line 129 of file eNetGameObject.cpp.
References NULL.
00129 { 00130 if (player){ 00131 #ifdef DEBUG 00132 //con << "Player " << ePlayer->name << " controls no object.\n"; 00133 #endif 00134 if (player->object==this){ 00135 player->object=NULL; 00136 } 00137 } 00138 }
eNetGameObject::eNetGameObject | ( | eGrid * | grid, | |
const eCoord & | pos, | |||
const eCoord & | dir, | |||
ePlayerNetID * | p, | |||
bool | autodelete = false | |||
) |
Definition at line 85 of file eNetGameObject.cpp.
References lastClientsideAction, MyInitAfterCreation(), nCLIENT, nNetObject::RequestSync(), and sn_GetNetState().
00087 :eGameObject(grid, pos,dir,NULL,autodelete), 00088 nNetObject(p->Owner()),player(p){ 00089 lastClientsideAction=0; 00090 if (sn_GetNetState()!=nCLIENT) 00091 RequestSync(); 00092 MyInitAfterCreation(); 00093 }
eNetGameObject::eNetGameObject | ( | nMessage & | m | ) |
Definition at line 97 of file eNetGameObject.cpp.
References eGameObject::autodelete, laggometer, laggometerSmooth, lastClientsideAction, nNetObject::Object(), pingOverflow, nMessage::Read(), and tASSERT.
00098 :eGameObject(eGrid::CurrentGrid(), eCoord(0,0), eCoord(0,0), NULL), 00099 nNetObject(m){ 00100 tASSERT(grid); 00101 00102 lastClientsideAction=0; 00103 unsigned short pid; 00104 m.Read(pid); 00105 player=static_cast<ePlayerNetID *>(Object(pid)); 00106 m.Read(pid); 00107 autodelete=pid; 00108 00109 laggometerSmooth=laggometer=0; 00110 00111 pingOverflow=0; 00112 }
void eNetGameObject::MyInitAfterCreation | ( | void | ) | [private] |
Reimplemented in gCycle, and gCycleMovement.
Definition at line 69 of file eNetGameObject.cpp.
References clientside_action(), laggometer, laggometerSmooth, and pingOverflow.
Referenced by eNetGameObject(), and InitAfterCreation().
00069 { 00070 laggometer=laggometerSmooth=0; 00071 00072 if (player){ 00073 player->ControlObject(this); 00074 } 00075 clientside_action(); 00076 00077 pingOverflow=0; 00078 }
eNetGameObject::tCHECKED_PTR | ( | ePlayerNetID | ) | [protected] |
void eNetGameObject::ReceiveControlNet | ( | nMessage & | m | ) | [protected, virtual] |
Reimplemented from nNetObject.
Definition at line 169 of file eNetGameObject.cpp.
References eGameObject::Act(), con, uActionPlayer::Find(), Lag(), MAX_PING_OVERFLOW, pingOverflow, nMessage::Read(), REAL, ReceiveControl(), se_GameTime(), sn_pingCharityServer, and x.
00169 { 00170 REAL time; 00171 unsigned short act_id; 00172 REAL x; 00173 00174 m >> time; 00175 m.Read(act_id); 00176 m >> x; 00177 00178 REAL backdate=Lag();//sn_ping[m.SenderID()]*.5; 00179 if (backdate>sn_pingCharityServer*.001) 00180 backdate=sn_pingCharityServer*.001; 00181 00182 REAL mintime=se_GameTime()-backdate*1.5-.1; 00183 if (time<mintime){ 00184 con << "mintime\n"; 00185 REAL pov_needed=mintime-time; 00186 if (pov_needed+pingOverflow > MAX_PING_OVERFLOW*backdate){ 00187 pov_needed = MAX_PING_OVERFLOW*backdate-pingOverflow; 00188 con << "Mintime\n"; 00189 } 00190 if (pov_needed<0) 00191 pov_needed=0; 00192 00193 time=mintime-pov_needed; 00194 pingOverflow+=pov_needed; 00195 } 00196 00197 if (time>se_GameTime()+1) 00198 time=se_GameTime()+1; 00199 00200 uActionPlayer *Act=uActionPlayer::Find(act_id); 00201 00202 ReceiveControl(time,Act,x); 00203 }
void eNetGameObject::SetPlayer | ( | ePlayerNetID * | player | ) | [protected] |
Definition at line 206 of file eNetGameObject.cpp.
References laggometer, laggometerSmooth, nCLIENT, nNetObject::Owner(), se_GetPing(), sn_GetNetState(), and tASSERT.
Referenced by gCycleMovement::CopyFrom().
00207 { 00208 tASSERT( !a_player || Owner() == player->Owner() ); 00209 player = a_player; 00210 if ( laggometerSmooth == 0 && sn_GetNetState() != nCLIENT ) 00211 laggometerSmooth = laggometer = se_GetPing( player ); 00212 }
nMachine & eNetGameObject::DoGetMachine | ( | void | ) | const [protected, virtual] |
returns the machine this object belongs to
Reimplemented from nNetObject.
Definition at line 378 of file eNetGameObject.cpp.
References nNetObject::DoGetMachine(), nNetObject::GetMachine(), and Player().
00379 { 00380 if ( Player() ) 00381 return Player()->GetMachine(); 00382 else 00383 return nNetObject::DoGetMachine(); 00384 }
virtual bool eNetGameObject::ActionOnQuit | ( | ) | [inline, virtual] |
Reimplemented from nNetObject.
Reimplemented in gCycle.
Definition at line 64 of file eNetGameObject.h.
Referenced by _wrap_ENetGameObject_action_on_quit().
virtual void eNetGameObject::ActionOnDelete | ( | ) | [inline, virtual] |
Reimplemented from nNetObject.
Definition at line 69 of file eNetGameObject.h.
References eGameObject::RemoveFromGame().
00069 { 00070 RemoveFromGame(); 00071 }
void eNetGameObject::InitAfterCreation | ( | void | ) | [virtual] |
Reimplemented from nNetObject.
Reimplemented in gCycle, and gCycleMovement.
Definition at line 80 of file eNetGameObject.cpp.
References nNetObject::InitAfterCreation(), and MyInitAfterCreation().
Referenced by gCycleMovement::InitAfterCreation().
00080 { 00081 nNetObject::InitAfterCreation(); 00082 MyInitAfterCreation(); 00083 }
void eNetGameObject::DoRemoveFromGame | ( | ) | [virtual] |
called on RemoveFromGame() after OnRemoveFromGame(). Do not call base class implementation of this function, don't expect to get called from subclasses.
Reimplemented from eGameObject.
Definition at line 114 of file eNetGameObject.cpp.
References NULL, and eGameObject::team.
00114 { 00115 // let the object get deleted on exit if nobody else is interested 00116 tControlledPTR< eNetGameObject > bounce; 00117 if ( this->GetRefcount() >= 0 ) 00118 bounce = this; 00119 00120 // unregister from player 00121 if ( player && this == player->object ) 00122 { 00123 player->object = NULL; 00124 } 00125 00126 team = NULL; 00127 }
void eNetGameObject::WriteCreate | ( | nMessage & | m | ) | [virtual] |
Reimplemented from nNetObject.
Reimplemented in gCycle, gZone, zShape, zShapeCircle, zShapePolygon, and zZone.
Definition at line 238 of file eNetGameObject.cpp.
References eGameObject::autodelete, nMessage::Write(), and nNetObject::WriteCreate().
Referenced by zZone::WriteCreate(), zShape::WriteCreate(), gZone::WriteCreate(), and gCycle::WriteCreate().
00238 { 00239 nNetObject::WriteCreate(m); 00240 m.Write(player->ID()); 00241 m.Write(autodelete); 00242 }
void eNetGameObject::WriteSync | ( | nMessage & | m | ) | [virtual] |
Reimplemented from nNetObject.
Reimplemented in gCycle, gZone, zShape, zShapeCircle, and zZone.
Definition at line 244 of file eNetGameObject.cpp.
References eGameObject::Direction(), eGameObject::lastTime, eGameObject::Position(), and nNetObject::WriteSync().
Referenced by zZone::WriteSync(), and gZone::WriteSync().
00244 { 00245 nNetObject::WriteSync(m); 00246 //con << lastTime << '\n'; 00247 m << lastTime; 00248 m << Direction(); 00249 m << Position(); 00250 }
void eNetGameObject::ReadSync | ( | nMessage & | m | ) | [virtual] |
Reimplemented from nNetObject.
Reimplemented in gCycle, gZone, zShape, zShapeCircle, and zZone.
Definition at line 252 of file eNetGameObject.cpp.
References eGameObject::dir, eGameObject::lastTime, eGameObject::pos, and nNetObject::ReadSync().
Referenced by zZone::ReadSync(), and gZone::ReadSync().
00252 { 00253 nNetObject::ReadSync(m); 00254 m >> lastTime; 00255 m >> dir; 00256 00257 m >> pos; 00258 }
bool eNetGameObject::ClearToTransmit | ( | int | user | ) | const [virtual] |
Reimplemented from nNetObject.
Definition at line 265 of file eNetGameObject.cpp.
References nNetObject::ClearToTransmit(), con, nNetObject::DoDebugPrint(), nNetObject::ID(), eTransferInhibitor::no_transfer(), and st_Breakpoint().
00265 { 00266 #ifdef DEBUG 00267 if (nNetObject::DoDebugPrint()) 00268 { 00269 if (eTransferInhibitor::no_transfer(user)) 00270 { 00271 con << "Not transfering eNetGameObject " << ID() 00272 << " for user " << user << " because of some obscure reason.\n"; 00273 st_Breakpoint(); 00274 eTransferInhibitor::no_transfer(user); 00275 } 00276 else if (!player) 00277 con << "Not transfering eNetGameObject " << ID() 00278 << " for user " << user << " because it has no player!\n"; 00279 else if (!player->HasBeenTransmitted(user)) 00280 { 00281 tString s; 00282 s << "No transfering eNetGameObject " << ID() 00283 << " for user " << user << " because "; 00284 player->PrintName(s); 00285 s << " has not been transmitted.\n"; 00286 con << s; 00287 } 00288 } 00289 #endif 00290 00291 00292 return 00293 nNetObject::ClearToTransmit(user) && 00294 !eTransferInhibitor::no_transfer(user) && 00295 (!player || 00296 player->HasBeenTransmitted(user)); 00297 }
bool eNetGameObject::SyncIsNew | ( | nMessage & | m | ) | [virtual] |
Reimplemented from nNetObject.
Reimplemented in gCycle.
Definition at line 142 of file eNetGameObject.cpp.
References con, eCoord, lastAttemptedSyncTime, lastClientsideAction, nNetObject::Owner(), sn_myNetID, and nNetObject::SyncIsNew().
Referenced by gCycle::SyncIsNew().
00142 { 00143 bool ret=nNetObject::SyncIsNew(m); 00144 m >> lastAttemptedSyncTime; 00145 00146 #ifdef DEBUG 00147 if (Owner()==::sn_myNetID && lastAttemptedSyncTime>lastClientsideAction+100){ 00148 con << "Warning! time overflow!\n"; 00149 } 00150 #endif 00151 00152 eCoord dummy; 00153 m >> dummy; 00154 m >> dummy; 00155 return (ret); // && lastAttemptedSyncTime>lastClientsideAction); // test for time no longer needed 00156 }
void eNetGameObject::AddRef | ( | void | ) | [virtual] |
adds a reference
Implements eGameObject.
Reimplemented in gCycleMovement.
Definition at line 158 of file eNetGameObject.cpp.
References nNetObject::AddRef().
Referenced by gCycleMovement::AddRef().
00159 { 00160 nNetObject::AddRef(); 00161 }
void eNetGameObject::Release | ( | ) | [virtual] |
removes a reference
Implements eGameObject.
Definition at line 163 of file eNetGameObject.cpp.
References nNetObject::Release().
00164 { 00165 nNetObject::Release(); 00166 }
void eNetGameObject::SendControl | ( | REAL | time, | |
uActionPlayer * | Act, | |||
REAL | x | |||
) | [virtual] |
Definition at line 214 of file eNetGameObject.cpp.
References nMessage::BroadCast(), uAction::ID(), nCLIENT, nNetObject::NewControlMessage(), nNetObject::Owner(), sn_GetNetState(), sn_myNetID, and nMessage::Write().
00214 { 00215 if (sn_GetNetState()==nCLIENT && Owner()==::sn_myNetID){ 00216 //con << "sending control at " << time << "\n"; 00217 nMessage *m=NewControlMessage(); 00218 *m << time; 00219 m->Write(Act->ID()); 00220 *m << x; 00221 m->BroadCast(); 00222 } 00223 }
void eNetGameObject::ReceiveControl | ( | REAL | time, | |
uActionPlayer * | Act, | |||
REAL | x | |||
) | [virtual] |
Reimplemented in gCycle.
Definition at line 225 of file eNetGameObject.cpp.
References nCLIENT, nNetObject::RequestSync(), sn_GetNetState(), and tERR_ERROR.
Referenced by ReceiveControlNet().
00225 { 00226 #ifdef DEBUG 00227 if (sn_GetNetState()==nCLIENT) 00228 tERR_ERROR("rec_cont should not be called client-side!"); 00229 #endif 00230 00231 // after control is received, we better sync this object with 00232 // the clients: 00233 00234 RequestSync(); 00235 }
bool eNetGameObject::Timestep | ( | REAL | currentTime | ) | [virtual] |
Reimplemented from eGameObject.
Reimplemented in gCycle, gCycleMovement, gZone, gBaseZoneHack, and zZone.
Definition at line 299 of file eNetGameObject.cpp.
References laggometer, laggometerSmooth, eGameObject::lastTime, nSERVER, nSTANDALONE, nNetObject::Owner(), PING_OVERFLOW_TS, pingOverflow, REAL, se_GetPing(), sn_GetNetState(), and sn_myNetID.
Referenced by gCycleMovement::TimestepCore().
00299 { 00300 // calculate new sr_laggometer 00301 if (sn_GetNetState() == nSTANDALONE){ 00302 laggometerSmooth=0; 00303 return false; 00304 } 00305 00306 REAL animts=(currentTime-lastTime); 00307 if (animts<0) 00308 animts=0; 00309 00310 if (sn_GetNetState() == nSERVER || Owner() == ::sn_myNetID || 00311 ( player && laggometer <= 0 ) ) 00312 { 00313 // calculate laggometer from ping 00314 laggometer = se_GetPing( player ); 00315 } 00316 00317 // legitimate, but does not look good: 00318 // if ( laggometerSmooth <= 0 ) 00319 // laggometerSmooth = laggometer; 00320 00321 laggometerSmooth=(laggometerSmooth+laggometer*animts)/(1 + animts); 00322 lastTime=currentTime; 00323 00324 // Update ping overflow 00325 pingOverflow/=(1+animts*PING_OVERFLOW_TS); 00326 00327 return false; 00328 }
ePlayerNetID* eNetGameObject::Player | ( | ) | const [inline] |
Definition at line 99 of file eNetGameObject.h.
Referenced by gEnemyInfluence::AddWall(), gCycleMovement::CopyFrom(), gDestination::CopyFrom(), gAIPlayer::CycleBlocksWay(), DoGetMachine(), gCycleMovement::DoTurn(), gCycle::DoTurn(), gAISensor::gAISensor(), zZone::InteractWith(), gZone::InteractWith(), zShapePolygon::isInteracting(), zShapeCircle::isInteracting(), zValidatorAllButTeamOwner::isValid(), zValidatorAllButOwner::isValid(), zValidatorOwnerTeam::isValid(), zValidatorOwner::isValid(), gCycle::KillAt(), gCycleMovement::MyInitAfterCreation(), gCycle::MyInitAfterCreation(), new_destination_handler(), gBaseZoneHack::OnEnter(), gDeathZoneHack::OnEnter(), gWinZoneHack::OnEnter(), gCycle::OnNotifyNewDestination(), gCycle::OnRoundEnd(), gCycle::PassEdge(), zSelectorAnotherNotTeammateDead::select(), zSelectorAnotherTeammateDead::select(), zSelectorAnother::select(), zSelectorAllButSelf::select(), zSelectorTeam::select(), zSelectorTeammate::select(), zSelectorSelf::select(), cCockpit::SetCycle(), sg_HoleScore(), sg_TopologyPoliceCheck(), sg_TopologyPoliceKill(), gBaseZoneHack::Timestep(), gCycleMovement::Timestep(), gCycle::Timestep(), gCamera::Timestep(), and gCycleMovement::TimestepCore().
void eNetGameObject::clientside_action | ( | ) | [inline] |
Definition at line 101 of file eNetGameObject.h.
References lastClientsideAction, and eGameObject::lastTime.
Referenced by gCycle::DoTurn(), MyInitAfterCreation(), and gCycle::SyncEnemy().
00101 {lastClientsideAction=lastTime;}
REAL eNetGameObject::Lag | ( | ) | const [virtual] |
expected average network latency
Reimplemented from eGameObject.
Definition at line 330 of file eNetGameObject.cpp.
References laggometerSmooth.
Referenced by new_destination_handler(), gCycle::OnNotifyNewDestination(), gCycle::PassEdge(), ReceiveControlNet(), gCycle::Render(), gCycleMovement::Timestep(), and gCycleMovement::TimestepCore().
00330 { 00331 return laggometerSmooth; 00332 }
REAL eNetGameObject::LagThreshold | ( | ) | const [virtual] |
tolerated network latency variation
Reimplemented from eGameObject.
Definition at line 334 of file eNetGameObject.cpp.
References nSERVER, nNetObject::Owner(), sn_GetNetState(), and eLag::Threshold().
Referenced by gCycleMovement::TimestepCore().
00334 { 00335 // ask the lag compensation framework 00336 if ( sn_GetNetState() != nSERVER ) 00337 return 0; 00338 if ( Owner() == 0 ) 00339 return 0; 00340 return eLag::Threshold(); 00341 }
friend class ePlayerNetID [friend] |
REAL eNetGameObject::lastClientsideAction [protected] |
Definition at line 46 of file eNetGameObject.h.
Referenced by clientside_action(), eNetGameObject(), and SyncIsNew().
REAL eNetGameObject::lastAttemptedSyncTime [protected] |
REAL eNetGameObject::pingOverflow [protected] |
Definition at line 48 of file eNetGameObject.h.
Referenced by eNetGameObject(), MyInitAfterCreation(), ReceiveControlNet(), and Timestep().
REAL eNetGameObject::laggometer [protected] |
the actual best estimate for lag
Definition at line 52 of file eNetGameObject.h.
Referenced by eNetGameObject(), MyInitAfterCreation(), SetPlayer(), gCycle::SyncEnemy(), and Timestep().
REAL eNetGameObject::laggometerSmooth [protected] |
the lag, smoothed over time
Definition at line 53 of file eNetGameObject.h.
Referenced by eNetGameObject(), Lag(), MyInitAfterCreation(), SetPlayer(), gCycle::SyncEnemy(), and Timestep().