processList.h
Engine/source/T3D/gameBase/processList.h
Classes:
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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 26// Copyright (C) 2015 Faust Logic, Inc. 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 28 29#ifndef _PROCESSLIST_H_ 30#define _PROCESSLIST_H_ 31 32#ifndef _SIM_H_ 33#include "console/sim.h" 34#endif 35#ifndef _TSIGNAL_H_ 36#include "core/util/tSignal.h" 37#endif 38 39//---------------------------------------------------------------------------- 40 41#define TickMs 32 42#define TickSec (F32(TickMs) / 1000.0f) 43 44//---------------------------------------------------------------------------- 45 46class GameConnection; 47struct Move; 48 49 50class ProcessObject 51{ 52 53public: 54 55 ProcessObject(); 56 virtual ~ProcessObject() { removeFromProcessList(); } 57 58 /// Removes this object from the tick-processing list 59 void removeFromProcessList() { plUnlink(); } 60 61 /// Set the status of tick processing. 62 /// 63 /// Set true to receive processTick, advanceTime, and interpolateTick calls. 64 /// 65 /// @see processTick 66 /// @param t If true, tick processing is enabled. 67 virtual void setProcessTick( bool t ) { mProcessTick = t; } 68 69 /// Returns true if this object processes ticks. 70 bool isTicking() const { return mProcessTick; } 71 72 /// This is really implemented in GameBase and is only here to avoid 73 /// casts within ProcessList. 74 virtual GameConnection* getControllingClient() { return NULL; } 75 76 /// This is really implemented in GameBase and is only here to avoid 77 /// casts within ProcessList. 78 virtual U32 getPacketDataChecksum( GameConnection *conn ) { return -1; } 79 80 /// Force this object to process after some other object. 81 /// 82 /// For example, a player mounted to a vehicle would want to process after 83 /// the vehicle to prevent a visible 'lagging' from occurring when the 84 /// vehicle moves. So the player would be set to processAfter(theVehicle). 85 /// 86 /// @param obj Object to process after 87 virtual void processAfter( ProcessObject *obj ) {} 88 89 /// Clears the effects of a call to processAfter() 90 virtual void clearProcessAfter() {} 91 92 /// Returns the object that this processes after. 93 /// 94 /// @see processAfter 95 virtual ProcessObject* getAfterObject() const { return NULL; } 96 97 /// Processes a move event and updates object state once every 32 milliseconds. 98 /// 99 /// This takes place both on the client and server, every 32 milliseconds (1 tick). 100 /// 101 /// @see ProcessList 102 /// @param move Move event corresponding to this tick, or NULL. 103 virtual void processTick( const Move *move ) {} 104 105 /// Interpolates between tick events. This takes place on the CLIENT ONLY. 106 /// 107 /// @param delta Time since last call to interpolate 108 virtual void interpolateTick( F32 delta ) {} 109 110 /// Advances simulation time for animations. This is called every frame. 111 /// 112 /// @param dt Time since last advance call 113 virtual void advanceTime( F32 dt ) {} 114 115 /// Allow object to modify the Move before it is ticked or sent to the server. 116 /// This is only called for the control object on the client-side. 117 virtual void preprocessMove( Move *move ) {} 118 119//protected: 120 121 struct Link 122 { 123 ProcessObject *next; 124 ProcessObject *prev; 125 }; 126 127 // Processing interface 128 void plUnlink(); 129 void plLinkAfter(ProcessObject*); 130 void plLinkBefore(ProcessObject*); 131 void plJoin(ProcessObject*); 132 133 U32 mProcessTag; // Tag used during sort 134 U32 mOrderGUID; // UID for keeping order synced (e.g., across network or runs of sim) 135 Link mProcessLink; // Ordered process queue 136 137 bool mProcessTick; 138 139 bool mIsGameBase; 140}; 141 142//---------------------------------------------------------------------------- 143 144typedef Signal<void()> PreTickSignal; 145typedef Signal<void(SimTime)> PostTickSignal; 146class GameBase; 147 148/// List of ProcessObjects. 149class ProcessList 150{ 151public: 152 153 ProcessList(); 154 virtual ~ProcessList() {} 155 156 void markDirty() { mDirty = true; } 157 bool isDirty() { return mDirty; } 158 159 SimTime getLastTime() { return mLastTime; } 160 F32 getLastDelta() { return mLastDelta; } 161 F32 getLastInterpDelta() { return mLastDelta / F32(TickMs); } 162 U32 getTotalTicks() { return mTotalTicks; } 163 void dumpToConsole(); 164 165 PreTickSignal& preTickSignal() { return mPreTick; } 166 PostTickSignal& postTickSignal() { return mPostTick; } 167 168 virtual void addObject( ProcessObject *obj ); 169 170 /// Returns true if a tick was processed. 171 virtual bool advanceTime( SimTime timeDelta ); 172 173protected: 174 175 void orderList(); 176 GameBase* getGameBase( ProcessObject *obj ); 177 178 virtual void advanceObjects(); 179 virtual void onAdvanceObjects() { advanceObjects(); } 180 virtual void onPreTickObject( ProcessObject* ) {} 181 virtual void onTickObject( ProcessObject* ) {} 182 183protected: 184 185 ProcessObject mHead; 186 187 U32 mCurrentTag; 188 bool mDirty; 189 190 U32 mTotalTicks; 191 SimTime mLastTick; 192 SimTime mLastTime; 193 F32 mLastDelta; 194 195 PreTickSignal mPreTick; 196 PostTickSignal mPostTick; 197 // JTF: still needed? 198public: 199 ProcessObject* findNearestToEnd(Vector<ProcessObject*>& objs) const; 200}; 201 202#endif // _PROCESSLIST_H_ 203