~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/engine/eGameObject.h

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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_GAMEOBJECT_H
29
 
#define ArmageTron_GAMEOBJECT_H
30
 
 
31
 
//#include "uInput.h"
32
 
#include "tList.h"
33
 
// #include "eGrid.h"
34
 
#include "eCoord.h"
35
 
#include "tSafePTR.h"
36
 
 
37
 
#include <fstream>
38
 
#include <iostream>
39
 
 
40
 
class eGrid;
41
 
class uActionPlayer;
42
 
class eTeam;
43
 
class eWall;
44
 
class eCamera;
45
 
 
46
 
// a generic object for the game (cycles,explosions, particles,
47
 
// maybe AI opponents..)
48
 
class eGameObject{
49
 
    friend class eFace;
50
 
    friend class eCamera;
51
 
    friend class eSensor;
52
 
    friend class eGrid;
53
 
    friend class ePlayerNetID;
54
 
 
55
 
    // a list of all active gameobjects
56
 
    int id;
57
 
#define GO ((eGameObject *)NULL)
58
 
#define GO_I ((int *)NULL)
59
 
 
60
 
    // small wrapper of TimestepThis doing preparation and cleanup work
61
 
    static void TimestepThisWrapper(eGrid * grid, REAL currentTime, eGameObject *t, REAL minTimestep);
62
 
 
63
 
protected:
64
 
    // does a timestep and all interactions for this gameobject,
65
 
    // divided in many small steps
66
 
    static bool TimestepThis(REAL currentTime,eGameObject *t);
67
 
 
68
 
    // tells game objects how far they are allowed to exeed the given simulation time
69
 
    static REAL MaxSimulateAhead();
70
 
 
71
 
    // a list of all eGameObjects that are interesting to watch
72
 
    int interestingID;
73
 
    int inactiveID;
74
 
 
75
 
    // shall s_Timestep delete a eGameObject requesting destruction
76
 
    // completely (autodelete=1) or should it just be removed from the list
77
 
    // (autodelete=0) ?
78
 
    // (the latter may be useful if there exists other pointers to
79
 
    // the object)
80
 
 
81
 
 
82
 
    bool autodelete;
83
 
    REAL lastTime;          // the time it was last updated
84
 
    REAL deathTime;          // the time the thing died
85
 
 
86
 
    eCoord pos;               // current position,
87
 
    eCoord dir;               // direction
88
 
    REAL  z;                                                                    // and height (currently unused)
89
 
 
90
 
    tJUST_CONTROLLED_PTR< eTeam > team;                                                 // the team we belong to
91
 
 
92
 
    tJUST_CONTROLLED_PTR<eFace> currentFace;  // the eFace pos it is currently
93
 
    tCHECKED_PTR(eGrid) grid;         // the game grid we are on
94
 
 
95
 
    // entry and deletion in the list of all eGameObjects
96
 
public:
97
 
    //! tells game objects what the maximum lag caused by lazy simulation of timesteps is
98
 
    static REAL GetMaxLazyLag();
99
 
    //! sets the value reported by GetMaxLazyLag()
100
 
    static void SetMaxLazyLag( REAL lag );
101
 
 
102
 
    eTeam* Team() const { return team; }
103
 
 
104
 
    static uActionPlayer se_turnLeft,se_turnRight;
105
 
 
106
 
    eGrid* Grid()        const { return grid;        }
107
 
    eFace* CurrentFace() const { return currentFace; }
108
 
 
109
 
    virtual void AddRef()  = 0;          //!< adds a reference
110
 
    virtual void Release() = 0;         //!< removes a reference
111
 
 
112
 
    void AddToList();
113
 
    void RemoveFromList();
114
 
    void RemoveFromListsAll();
115
 
    void RemoveFromGame(); //!< removes the object physically from the game
116
 
 
117
 
protected:
118
 
    virtual void OnRemoveFromGame(); //!< called on RemoveFromGame(). Call base class implementation, too, in your implementation. Must keep the object alive.
119
 
private:
120
 
    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.
121
 
public:
122
 
 
123
 
    int GOID() const {return id;}
124
 
    REAL LastTime() const {return lastTime;}
125
 
    virtual REAL NextInterestingTime() const {return lastTime;} //!< the next time something interesting is going to happen with this object
126
 
 
127
 
    eGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface, bool autodelete=1);
128
 
    virtual ~eGameObject();
129
 
 
130
 
    virtual eCoord Position()const{return pos;}
131
 
    virtual eCoord Direction()const{return dir;}
132
 
    virtual eCoord LastDirection()const{return dir;}
133
 
    virtual REAL DeathTime()const{return deathTime;}
134
 
    virtual REAL  Speed()const{return 20;}
135
 
 
136
 
    // position after FPS dependant extrapolation
137
 
    virtual eCoord PredictPosition() const {return pos;}
138
 
 
139
 
    // makes two gameObjects interact:
140
 
    virtual void InteractWith( eGameObject *target,REAL time,int recursion=1 );
141
 
 
142
 
    // what happens if we pass eWall w? (at position e->p[0]*a + e->p[1]*(1-a) )
143
 
    virtual void PassEdge( const eWall *w,REAL time,REAL a,int recursion=1 );
144
 
 
145
 
    // what length multiplicator does driving along the given wall get when it is the given distance away?
146
 
    virtual REAL PathfindingModifier( const eWall *w ) const { return 1 ;}
147
 
 
148
 
    // moves the object from pos to dest during the timeinterval
149
 
    // [startTime,endTime] and issues all eWall-crossing tEvents
150
 
    void Move( const eCoord &dest, REAL startTime, REAL endTime, bool useTempWalls = true );
151
 
 
152
 
    // finds the eFace we are in
153
 
    void FindCurrentFace();
154
 
 
155
 
    // simulates behaviour up to currentTime:
156
 
    virtual bool Timestep(REAL currentTime);
157
 
    // return value: shall this object be destroyed?
158
 
 
159
 
    virtual bool EdgeIsDangerous(const eWall *w, REAL time, REAL a) const{
160
 
        return w;
161
 
    }
162
 
 
163
 
    //! called when the round begins, after all game objects have been created,
164
 
    //! before the first network sync is sent out.
165
 
    virtual void OnRoundBegin();
166
 
 
167
 
    //! called when the round ends
168
 
    virtual void OnRoundEnd();
169
 
 
170
 
    //! destroys the gameobject (in the game)
171
 
    virtual void Kill();
172
 
 
173
 
    //! tells whether the object is alive
174
 
    virtual bool Alive() const {return false;}
175
 
 
176
 
    //! draws object to the screen using OpenGL
177
 
    virtual void Render(const eCamera *cam);
178
 
 
179
 
    //! draws it in a svg file
180
 
    virtual void DrawSvg(std::ofstream &f);
181
 
 
182
 
    //! returns whether the rendering uses alpha blending (massively, so sorting errors would show)
183
 
    virtual bool RendersAlpha() const;
184
 
 
185
 
    // draws the cockpit or whatever is seen from the interior
186
 
    // in fixed perspective, called before the main rendering
187
 
    virtual bool RenderCockpitFixedBefore(bool primary=true);
188
 
    // return value: draw everything else?
189
 
 
190
 
    // the same purpose, but called after main rendering
191
 
    virtual void RenderCockpitFixedAfter(bool primary=true);
192
 
 
193
 
    // virtual perspective
194
 
    virtual void RenderCockpitVirtual(bool primary=false);
195
 
 
196
 
    //sound output
197
 
    virtual void SoundMix(unsigned char *dest,unsigned int len,
198
 
                          int viewer,REAL rvol,REAL lvol){};
199
 
 
200
 
    // internal camera
201
 
    virtual eCoord CamDir()  const {return dir;}
202
 
    virtual REAL  CamRise()  const {return 0;}
203
 
    virtual eCoord CamPos()  const {return pos;}
204
 
    virtual REAL  CamZ()     const {return z;}
205
 
    virtual eCoord  CamTop() const {return eCoord(0,0);}
206
 
 
207
 
    // sr_laggometer
208
 
    virtual REAL Lag() const{return 0;}          //!< expected average network latency
209
 
    virtual REAL LagThreshold() const{return 0;} //!< tolerated network latency variation
210
 
 
211
 
#ifdef POWERPAK_DEB
212
 
    virtual void PPDisplay();
213
 
#endif
214
 
 
215
 
    // Receives control from ePlayer
216
 
    virtual bool Act(uActionPlayer *Act,REAL x);
217
 
 
218
 
    // does a timestep and all interactions for every gameobject
219
 
    static void s_Timestep(eGrid *grid, REAL currentTime, REAL minTimestep);
220
 
 
221
 
    // displays everything:
222
 
    static void RenderAll(eGrid *grid, const eCamera *cam);
223
 
    static void PPDisplayAll();
224
 
 
225
 
    // kills everything:
226
 
    static void DeleteAll(eGrid *grid);
227
 
};
228
 
 
229
 
// game object to be created on the heap
230
 
class eReferencableGameObject: public eGameObject, public tReferencable< eReferencableGameObject >
231
 
{
232
 
public:
233
 
    eReferencableGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface, bool autodelete=1);
234
 
 
235
 
    // real reference counting
236
 
    virtual void AddRef();          //!< adds a reference
237
 
    virtual void Release();         //!< removes a reference
238
 
 
239
 
private:
240
 
    virtual void DoRemoveFromGame(); //!< called when removed from the game
241
 
};
242
 
 
243
 
// game object of temporary lifetime on the stack. Don't dynamically allocate this.
244
 
class eStackGameObject: public eGameObject
245
 
{
246
 
public:
247
 
    eStackGameObject(eGrid *grid, const eCoord &p,const eCoord &d, eFace *currentface);
248
 
 
249
 
    // dummy reference counting
250
 
    virtual void AddRef();          //!< adds a reference
251
 
    virtual void Release();         //!< removes a reference
252
 
 
253
 
private:
254
 
    virtual void DoRemoveFromGame(); //!< called when removed from the game
255
 
};
256
 
 
257
 
//! Exception to throw when a gameobject dies during movement
258
 
class eDeath
259
 
{
260
 
public:
261
 
    eDeath(){};   //!< constructor
262
 
    ~eDeath(){};  //!< destructor
263
 
};
264
 
 
265
 
#endif