1 //************************************************************************** 2 //** 3 //** ## ## ## ## ## #### #### ### ### 4 //** ## ## ## ## ## ## ## ## ## ## #### #### 5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## 6 //** ## ## ######## ## ## ## ## ## ## ## ### ## 7 //** ### ## ## ### ## ## ## ## ## ## 8 //** # ## ## # #### #### ## ## 9 //** 10 //** $Id: p_thinker.h 4110 2009-11-13 21:54:07Z dj_jl $ 11 //** 12 //** Copyright (C) 1999-2006 Jānis Legzdiņš 13 //** 14 //** This program is free software; you can redistribute it and/or 15 //** modify it under the terms of the GNU General Public License 16 //** as published by the Free Software Foundation; either version 2 17 //** of the License, or (at your option) any later version. 18 //** 19 //** This program is distributed in the hope that it will be useful, 20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 //** GNU General Public License for more details. 23 //** 24 //************************************************************************** 25 26 enum 27 { 28 ROLE_None, 29 ROLE_DumbProxy, 30 ROLE_Authority 31 }; 32 33 // Type of the sound origin, used for origin IDs when playing sounds. 34 enum 35 { 36 SNDORG_Entity, 37 SNDORG_Sector, 38 SNDORG_PolyObj, 39 }; 40 41 // 42 // VThinker 43 // 44 // Doubly linked list of actors and other special elements of a level. 45 // 46 class VThinker : public VGameObject 47 { 48 DECLARE_CLASS(VThinker, VGameObject, 0) 49 50 VLevel* XLevel; // Level object. 51 VLevelInfo* Level; // Level info object. 52 53 VThinker* Prev; 54 VThinker* Next; 55 56 vuint8 Role; 57 vuint8 RemoteRole; 58 59 enum 60 { 61 TF_AlwaysRelevant = 0x00000001, 62 TF_NetInitial = 0x00000002, 63 TF_NetOwner = 0x00000004, 64 }; 65 vuint32 ThinkerFlags; 66 67 static int FIndex_Tick; 68 69 VThinker(); 70 71 // VObject interface 72 void Destroy(); 73 void Serialise(VStream&); 74 75 // VThinker interface 76 virtual void Tick(float); 77 virtual void DestroyThinker(); 78 virtual void AddedToLevel(); 79 virtual void RemovedFromLevel(); 80 81 void StartSound(const TVec&, vint32, vint32, vint32, float, float, bool); 82 void StopSound(vint32, vint32); 83 void StartSoundSequence(const TVec&, vint32, VName, vint32); 84 void AddSoundSequenceChoice(vint32, VName); 85 void StopSoundSequence(vint32); 86 87 void BroadcastPrint(const char*); 88 void BroadcastPrintf(const char*, ...); 89 void BroadcastCentrePrint(const char*); 90 void BroadcastCentrePrintf(const char*, ...); 91 92 DECLARE_FUNCTION(Spawn) DECLARE_FUNCTION(Destroy)93 DECLARE_FUNCTION(Destroy) 94 95 // Print functions 96 DECLARE_FUNCTION(bprint) 97 98 DECLARE_FUNCTION(AllocDlight) 99 DECLARE_FUNCTION(NewParticle) 100 DECLARE_FUNCTION(GetAmbientSound) 101 102 // Iterators 103 DECLARE_FUNCTION(AllThinkers) 104 DECLARE_FUNCTION(AllActivePlayers) 105 DECLARE_FUNCTION(PathTraverse) 106 DECLARE_FUNCTION(RadiusThings) 107 108 void eventClientTick(float DeltaTime) 109 { 110 P_PASS_SELF; 111 P_PASS_FLOAT(DeltaTime); 112 EV_RET_VOID(NAME_ClientTick); 113 } 114 }; 115 116 template <class T> class TThinkerIterator 117 { 118 private: 119 VThinker* Th; GetNext()120 void GetNext() 121 { 122 while (Th && (!Th->IsA(T::StaticClass()) || 123 (Th->GetFlags() & _OF_DelayedDestroy))) 124 { 125 Th = Th->Next; 126 } 127 } 128 public: TThinkerIterator(const VLevel * Level)129 TThinkerIterator(const VLevel* Level) 130 { 131 Th = Level->ThinkerHead; 132 GetNext(); 133 } 134 operator bool() 135 { 136 return Th != NULL; 137 } 138 void operator ++() 139 { 140 if (Th) 141 { 142 Th = Th->Next; 143 GetNext(); 144 } 145 } 146 T* operator ->() 147 { 148 return (T*)Th; 149 } 150 T* operator *() 151 { 152 return (T*)Th; 153 } 154 }; 155