src/engine/eGameObject.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_GAMEOBJECT_H
00029 #define ArmageTron_GAMEOBJECT_H
00030 
00031 //#include "uInput.h"
00032 #include "tList.h"
00033 // #include "eGrid.h"
00034 #include "eCoord.h"
00035 #include "tSafePTR.h"
00036 
00037 class eGrid;
00038 class uActionPlayer;
00039 class eTeam;
00040 class eWall;
00041 class eCamera;
00042 
00043 // a generic object for the game (cycles,explosions, particles,
00044 // maybe AI opponents..)
00045 class eGameObject{
00046     friend class eFace;
00047     friend class eCamera;
00048     friend class eSensor;
00049     friend class eGrid;
00050     friend class ePlayerNetID;
00051 
00052     // a list of all active gameobjects
00053     int id;
00054 #define GO ((eGameObject *)NULL)
00055 #define GO_I ((int *)NULL)
00056 
00057     // small wrapper of TimestepThis doing preparation and cleanup work
00058     static void TimestepThisWrapper(eGrid * grid, REAL currentTime, eGameObject *t, REAL minTimestep);
00059 
00060 protected:
00061     // does a timestep and all interactions for this gameobject,
00062     // divided in many small steps
00063     static bool TimestepThis(REAL currentTime,eGameObject *t);
00064 
00065     // tells game objects how far they are allowed to exeed the given simulation time
00066     static REAL MaxSimulateAhead();
00067 
00068     // a list of all eGameObjects that are interesting to watch
00069     int interestingID;
00070     int inactiveID;
00071 
00072     // shall s_Timestep delete a eGameObject requesting destruction
00073     // completely (autodelete=1) or should it just be removed from the list
00074     // (autodelete=0) ?
00075     // (the latter may be useful if there exists other pointers to
00076     // the object)
00077 
00078 
00079     bool autodelete;
00080     REAL lastTime;          // the time it was last updated
00081     REAL deathTime;          // the time the thing died
00082 
00083     eCoord pos;               // current position,
00084     eCoord dir;               // direction
00085     REAL  z;                                                                    // and height (currently unused)
00086 
00087     tJUST_CONTROLLED_PTR< eTeam > team;                                                 // the team we belong to
00088 
00089     tJUST_CONTROLLED_PTR<eFace> currentFace;  // the eFace pos it is currently
00090     tCHECKED_PTR(eGrid) grid;         // the game grid we are on
00091 
00092     // entry and deletion in the list of all eGameObjects
00093 public:
00095     static REAL GetMaxLazyLag();
00097     static void SetMaxLazyLag( REAL lag );
00098 
00099     eTeam* Team() const { return team; }
00100 
00101     static uActionPlayer se_turnLeft,se_turnRight;
00102 
00103     eGrid* Grid()        const { return grid;        }
00104     eFace* CurrentFace() const { return currentFace; }
00105 
00106     virtual void AddRef()  = 0;          
00107     virtual void Release() = 0;         
00108 
00109     void AddToList();
00110     void RemoveFromList();
00111     void RemoveFromListsAll();
00112     void RemoveFromGame(); 
00113 
00114 protected:
00115     virtual void OnRemoveFromGame(); 
00116 private:
00117     virtual void DoRemoveFromGame(); 
00118 public:
00119 
00120     int GOID() const {return id;}
00121     REAL LastTime() const {return lastTime;}
00122     virtual REAL NextInterestingTime() const {return lastTime;} 
00123 
00124     eGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface, bool autodelete=1);
00125     virtual ~eGameObject();
00126 
00127     virtual eCoord Position()const{return pos;}
00128     virtual eCoord Direction()const{return dir;}
00129     virtual eCoord LastDirection()const{return dir;}
00130     virtual REAL DeathTime()const{return deathTime;}
00131     virtual REAL  Speed()const{return 20;}
00132 
00133     // position after FPS dependant extrapolation
00134     virtual eCoord PredictPosition() const {return pos;}
00135 
00136     // makes two gameObjects interact:
00137     virtual void InteractWith( eGameObject *target,REAL time,int recursion=1 );
00138 
00139     // what happens if we pass eWall w? (at position e->p[0]*a + e->p[1]*(1-a) )
00140     virtual void PassEdge( const eWall *w,REAL time,REAL a,int recursion=1 );
00141 
00142     // what length multiplicator does driving along the given wall get when it is the given distance away?
00143     virtual REAL PathfindingModifier( const eWall *w ) const { return 1 ;}
00144 
00145     // moves the object from pos to dest during the timeinterval
00146     // [startTime,endTime] and issues all eWall-crossing tEvents
00147     void Move( const eCoord &dest, REAL startTime, REAL endTime, bool useTempWalls = true );
00148 
00149     // finds the eFace we are in
00150     void FindCurrentFace();
00151 
00152     // simulates behaviour up to currentTime:
00153     virtual bool Timestep(REAL currentTime);
00154     // return value: shall this object be destroyed?
00155 
00156     virtual bool EdgeIsDangerous(const eWall *w, REAL time, REAL a) const{
00157         return w;
00158     }
00159 
00162     virtual void OnRoundBegin();
00163 
00165     virtual void OnRoundEnd();
00166 
00168     virtual void Kill();
00169 
00171     virtual bool Alive() const {return false;}
00172 
00174     virtual void Render(const eCamera *cam);
00175 
00176     // draws it to the screen in two dimensions using OpenGL (ie. for the HUD map)
00177     virtual void Render2D(tCoord scale) const;
00178 
00180     virtual bool RendersAlpha() const;
00181 
00182     // draws the cockpit or whatever is seen from the interior
00183     // in fixed perspective, called before the main rendering
00184     virtual bool RenderCockpitFixedBefore(bool primary=true);
00185     // return value: draw everything else?
00186 
00187     // the same purpose, but called after main rendering
00188     virtual void RenderCockpitFixedAfter(bool primary=true);
00189 
00190     // virtual perspective
00191     virtual void RenderCockpitVirtual(bool primary=false);
00192 
00193     //sound output
00194     //virtual void SoundMix(unsigned char *dest,unsigned int len,
00195     //                      int viewer,REAL rvol,REAL lvol){};
00196 
00197     // internal camera
00198     virtual eCoord CamDir()  const {return dir;}
00199     virtual REAL  CamRise()  const {return 0;}
00200     virtual eCoord CamPos()  const {return pos;}
00201     virtual REAL  CamZ()     const {return z;}
00202     virtual eCoord  CamTop() const {return eCoord(0,0);}
00203 
00204     // sr_laggometer
00205     virtual REAL Lag() const{return 0;}          
00206     virtual REAL LagThreshold() const{return 0;} 
00207 
00208 #ifdef POWERPAK_DEB
00209     virtual void PPDisplay();
00210 #endif
00211 
00212     // Receives control from ePlayer
00213     virtual bool Act(uActionPlayer *Act,REAL x);
00214 
00215     // does a timestep and all interactions for every gameobject
00216     static void s_Timestep(eGrid *grid, REAL currentTime, REAL minTimestep);
00217 
00218     // displays everything:
00219     static void RenderAll(eGrid *grid, const eCamera *cam);
00220     static void PPDisplayAll();
00221 
00222     // kills everything:
00223     static void DeleteAll(eGrid *grid);
00224 };
00225 
00226 // game object to be created on the heap
00227 class eReferencableGameObject: public eGameObject, public tReferencable< eReferencableGameObject >
00228 {
00229 public:
00230     eReferencableGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface, bool autodelete=1);
00231 
00232     // real reference counting
00233     virtual void AddRef();          
00234     virtual void Release();         
00235 
00236 private:
00237     virtual void DoRemoveFromGame(); 
00238 };
00239 
00240 // game object of temporary lifetime on the stack. Don't dynamically allocate this.
00241 class eStackGameObject: public eGameObject
00242 {
00243 public:
00244     eStackGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface);
00245 
00246     // dummy reference counting
00247     virtual void AddRef();          
00248     virtual void Release();         
00249 
00250 private:
00251     virtual void DoRemoveFromGame(); 
00252 };
00253 
00255 class eDeath
00256 {
00257 public:
00258     eDeath(){};   
00259     ~eDeath(){};  
00260 };
00261 
00262 #endif

Generated on Sat Mar 15 22:55:44 2008 for Armagetron Advanced by  doxygen 1.5.4