processList.h

Engine/source/T3D/gameBase/processList.h

More...

Classes:

class

List of ProcessObjects.

Public Defines

define
TickMs() 32
define
TickSec() (() / 1000.0f)

Public Typedefs

PostTickSignal 
PreTickSignal 

Detailed Description

Public Defines

TickMs() 32
TickSec() (() / 1000.0f)

Public Typedefs

typedef Signal< void(SimTime)> PostTickSignal 
typedef Signal< void()> PreTickSignal 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _PROCESSLIST_H_
 25#define _PROCESSLIST_H_
 26
 27#ifndef _SIM_H_
 28#include "console/sim.h"
 29#endif
 30#ifndef _TSIGNAL_H_
 31#include "core/util/tSignal.h"
 32#endif
 33
 34//----------------------------------------------------------------------------
 35
 36#define TickMs      32
 37#define TickSec     (F32(TickMs) / 1000.0f)
 38
 39//----------------------------------------------------------------------------
 40
 41class GameConnection;
 42struct Move;
 43
 44
 45class ProcessObject
 46{
 47   
 48public:
 49
 50   ProcessObject();
 51   virtual ~ProcessObject() { removeFromProcessList(); }
 52
 53   /// Removes this object from the tick-processing list
 54   void removeFromProcessList() { plUnlink(); }   
 55
 56   /// Set the status of tick processing.
 57   ///
 58   /// Set true to receive processTick, advanceTime, and interpolateTick calls.
 59   ///
 60   /// @see processTick
 61   /// @param   t   If true, tick processing is enabled.
 62   virtual void setProcessTick( bool t ) { mProcessTick = t; }
 63
 64   /// Returns true if this object processes ticks.
 65   bool isTicking() const { return mProcessTick; }
 66
 67   /// This is really implemented in GameBase and is only here to avoid
 68   /// casts within ProcessList.
 69   virtual GameConnection* getControllingClient() { return NULL; }   
 70
 71   /// This is really implemented in GameBase and is only here to avoid
 72   /// casts within ProcessList.
 73   virtual U32 getPacketDataChecksum( GameConnection *conn ) { return -1; }
 74
 75   /// Force this object to process after some other object.
 76   ///
 77   /// For example, a player mounted to a vehicle would want to process after 
 78   /// the vehicle to prevent a visible 'lagging' from occurring when the 
 79   /// vehicle moves. So the player would be set to processAfter(theVehicle).
 80   ///
 81   /// @param   obj   Object to process after
 82   virtual void processAfter( ProcessObject *obj ) {}
 83  
 84   /// Clears the effects of a call to processAfter()
 85   virtual void clearProcessAfter() {}
 86
 87   /// Returns the object that this processes after.
 88   ///
 89   /// @see processAfter
 90   virtual ProcessObject* getAfterObject() const { return NULL; }
 91
 92   /// Processes a move event and updates object state once every 32 milliseconds.
 93   ///
 94   /// This takes place both on the client and server, every 32 milliseconds (1 tick).
 95   ///
 96   /// @see    ProcessList
 97   /// @param  move   Move event corresponding to this tick, or NULL.
 98   virtual void processTick( const Move *move ) {}
 99
100   /// Interpolates between tick events.  This takes place on the CLIENT ONLY.
101   ///
102   /// @param   delta   Time since last call to interpolate
103   virtual void interpolateTick( F32 delta ) {}
104
105   /// Advances simulation time for animations. This is called every frame.
106   ///
107   /// @param   dt   Time since last advance call
108   virtual void advanceTime( F32 dt ) {}
109   
110   /// Allow object to modify the Move before it is ticked or sent to the server.
111   /// This is only called for the control object on the client-side.
112   virtual void preprocessMove( Move *move ) {}
113
114//protected:
115
116   struct Link
117   {
118      ProcessObject *next;
119      ProcessObject *prev;
120   };
121
122   // Processing interface
123   void plUnlink();
124   void plLinkAfter(ProcessObject*);
125   void plLinkBefore(ProcessObject*);
126   void plJoin(ProcessObject*);
127
128   U32 mProcessTag;                       // Tag used during sort
129   U32 mOrderGUID;                        // UID for keeping order synced (e.g., across network or runs of sim)
130   Link mProcessLink;                     // Ordered process queue
131
132   bool mProcessTick;
133
134   bool mIsGameBase;
135};
136
137//----------------------------------------------------------------------------
138
139typedef Signal<void()> PreTickSignal;
140typedef Signal<void(SimTime)> PostTickSignal;
141class GameBase;
142
143/// List of ProcessObjects.
144class ProcessList
145{
146public:
147
148   ProcessList();
149   virtual ~ProcessList() {}
150
151   void markDirty()  { mDirty = true; }
152   bool isDirty()  { return mDirty; }   
153
154   SimTime getLastTime() { return mLastTime; }
155   F32 getLastDelta() { return mLastDelta; }
156   F32 getLastInterpDelta() { return mLastDelta / F32(TickMs); }
157   U32 getTotalTicks() { return mTotalTicks; }
158   void dumpToConsole();
159
160   PreTickSignal& preTickSignal() { return mPreTick; }
161   PostTickSignal& postTickSignal() { return mPostTick; }
162   
163   virtual void addObject( ProcessObject *obj );
164   
165   /// Returns true if a tick was processed.
166   virtual bool advanceTime( SimTime timeDelta );
167
168protected:
169 
170   void orderList();
171   GameBase* getGameBase( ProcessObject *obj );
172
173   virtual void advanceObjects();
174   virtual void onAdvanceObjects() { advanceObjects(); }
175   virtual void onPreTickObject( ProcessObject* ) {}
176   virtual void onTickObject( ProcessObject* ) {}   
177
178protected:
179
180   ProcessObject mHead;
181
182   U32 mCurrentTag;
183   bool mDirty;
184
185   U32 mTotalTicks;
186   SimTime mLastTick;
187   SimTime mLastTime;
188   F32 mLastDelta;
189
190   PreTickSignal mPreTick;
191   PostTickSignal mPostTick;
192};
193
194#endif // _PROCESSLIST_H_
195