1 /* 2 3 ************************************************************************* 4 5 ArmageTron -- Just another Tron Lightcycle Game in 3D. 6 Copyright (C) 2000 Manuel Moos (manuel@moosnet.de) 7 8 ************************************************************************** 9 10 This program is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public License 12 as published by the Free Software Foundation; either version 2 13 of the License, or (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 23 24 *************************************************************************** 25 26 */ 27 28 #ifndef ArmageTron_NETGAME_H 29 #define ArmageTron_NETGAME_H 30 31 #include "nNetObject.h" 32 #include "eGameObject.h" 33 #include "tCallback.h" 34 35 // max ping to equalize; 36 extern int sn_pingCharityServer; 37 38 class ePlayerNetID; 39 40 41 class eNetGameObject:public eGameObject,public nNetObject{ 42 friend class ePlayerNetID; 43 44 void MyInitAfterCreation(); 45 protected: 46 REAL lastClientsideAction; 47 REAL lastAttemptedSyncTime; 48 REAL pingOverflow; 49 50 tCHECKED_PTR(ePlayerNetID) player; // the player controlling this cycle. 51 // NULL means the AI. 52 REAL laggometer; //!< the actual best estimate for lag 53 REAL laggometerSmooth; //!< the lag, smoothed over time 54 55 // used to implement the control functions 56 virtual void ReceiveControlNet(nMessage &m); 57 58 virtual ~eNetGameObject(); 59 60 void SetPlayer(ePlayerNetID* player); 61 62 virtual nMachine & DoGetMachine() const; //!< returns the machine this object belongs to 63 public: ActionOnQuit()64 virtual bool ActionOnQuit(){ 65 // this->Kill(); 66 return false; 67 } 68 ActionOnDelete()69 virtual void ActionOnDelete(){ 70 RemoveFromGame(); 71 } 72 73 virtual void InitAfterCreation(); 74 75 eNetGameObject(eGrid *grid, const eCoord &pos,const eCoord &dir,ePlayerNetID* p,bool autodelete=false); 76 eNetGameObject(nMessage &m); 77 78 virtual void DoRemoveFromGame(); // just remove it from the lists and unregister it 79 80 virtual void WriteCreate(nMessage &m); 81 virtual void WriteSync(nMessage &m); 82 virtual void ReadSync(nMessage &m); 83 //virtual nDescriptor &CreatorDescriptor() const; 84 virtual bool ClearToTransmit(int user) const; 85 virtual bool SyncIsNew(nMessage &m); 86 87 virtual void AddRef(); //!< adds a reference 88 virtual void Release(); //!< removes a reference 89 90 // control functions: (were once part of nNetObject.h) 91 virtual void SendControl(REAL time,uActionPlayer *Act,REAL x); 92 // is called on the client whenever a control key is pressed. This 93 // sends a message to the server, who will call 94 virtual void ReceiveControl(REAL time,uActionPlayer *Act,REAL x); 95 // on his instance of the nNetObject. 96 97 virtual bool Timestep(REAL currentTime); 98 Player()99 ePlayerNetID *Player()const{return player;} 100 clientside_action()101 void clientside_action(){lastClientsideAction=lastTime;} 102 103 virtual REAL Lag() const; 104 virtual REAL LagThreshold() const; 105 }; 106 107 nMessage &operator << (nMessage &m, const eCoord &x); 108 nMessage &operator >> (nMessage &m, eCoord &x); 109 110 class eTransferInhibitor: public tCallbackOr{ 111 static int user; 112 public: User()113 static int User(){return user;} 114 115 eTransferInhibitor(BOOLRETFUNC *f); 116 static bool no_transfer(int user); 117 }; 118 119 #endif 120 121