trigger.h
Classes:
class
class
Public Functions
DefineConsoleType(TypeTriggerPolyhedron , Polyhedron )
Detailed Description
Public Functions
DefineConsoleType(TypeTriggerPolyhedron , Polyhedron )
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 _H_TRIGGER 25#define _H_TRIGGER 26 27#ifndef _GAMEBASE_H_ 28#include "T3D/gameBase/gameBase.h" 29#endif 30#ifndef _MBOX_H_ 31#include "math/mBox.h" 32#endif 33#ifndef _EARLYOUTPOLYLIST_H_ 34#include "collision/earlyOutPolyList.h" 35#endif 36#ifndef _MPOLYHEDRON_H_ 37#include "math/mPolyhedron.h" 38#endif 39 40class Convex; 41class PhysicsBody; 42class Trigger; 43 44DefineConsoleType( TypeTriggerPolyhedron, Polyhedron ) 45 46 47struct TriggerData: public GameBaseData { 48 typedef GameBaseData Parent; 49 50 public: 51 S32 tickPeriodMS; 52 bool isClientSide; 53 54 TriggerData(); 55 56 DECLARE_CONOBJECT(TriggerData); 57 58 DECLARE_CALLBACK( void, onEnterTrigger, ( Trigger* trigger, GameBase* obj ) ); 59 DECLARE_CALLBACK( void, onTickTrigger, ( Trigger* trigger ) ); 60 DECLARE_CALLBACK( void, onLeaveTrigger, ( Trigger* trigger, GameBase* obj ) ); 61 62 bool onAdd(); 63 static void initPersistFields(); 64 virtual void packData (BitStream* stream); 65 virtual void unpackData(BitStream* stream); 66}; 67 68class Trigger : public GameBase 69{ 70 typedef GameBase Parent; 71 72 /// Trigger polyhedron with *outward* facing normals and CCW ordered 73 /// vertices. 74 Polyhedron mTriggerPolyhedron; 75 76 EarlyOutPolyList mClippedList; 77 Vector<GameBase*> mObjects; 78 79 PhysicsBody *mPhysicsRep; 80 81 TriggerData* mDataBlock; 82 83 U32 mLastThink; 84 U32 mCurrTick; 85 Convex *mConvexList; 86 87 String mEnterCommand; 88 String mLeaveCommand; 89 String mTickCommand; 90 91 static const U32 CMD_SIZE = 1024; 92 93 protected: 94 95 enum TriggerUpdateBits 96 { 97 TransformMask = Parent::NextFreeMask << 0, 98 PolyMask = Parent::NextFreeMask << 1, 99 EnterCmdMask = Parent::NextFreeMask << 2, 100 LeaveCmdMask = Parent::NextFreeMask << 3, 101 TickCmdMask = Parent::NextFreeMask << 4, 102 NextFreeMask = Parent::NextFreeMask << 5, 103 }; 104 105 static bool smRenderTriggers; 106 bool testObject(GameBase* enter); 107 void processTick(const Move *move); 108 109 void buildConvex(const Box3F& box, Convex* convex); 110 111 static bool setEnterCmd(void *object, const char *index, const char *data); 112 static bool setLeaveCmd(void *object, const char *index, const char *data); 113 static bool setTickCmd(void *object, const char *index, const char *data); 114 115 public: 116 Trigger(); 117 ~Trigger(); 118 119 // SimObject 120 DECLARE_CONOBJECT(Trigger); 121 122 DECLARE_CALLBACK( void, onAdd, ( U32 objectId ) ); 123 DECLARE_CALLBACK( void, onRemove, ( U32 objectId ) ); 124 125 static void consoleInit(); 126 static void initPersistFields(); 127 bool onAdd(); 128 void onRemove(); 129 void onDeleteNotify(SimObject*); 130 void inspectPostApply(); 131 132 // NetObject 133 U32 packUpdate (NetConnection *conn, U32 mask, BitStream* stream); 134 void unpackUpdate(NetConnection *conn, BitStream* stream); 135 136 // SceneObject 137 void setTransform(const MatrixF &mat); 138 void prepRenderImage( SceneRenderState* state ); 139 140 // GameBase 141 bool onNewDataBlock( GameBaseData *dptr, bool reload ); 142 143 // Trigger 144 void setTriggerPolyhedron(const Polyhedron&); 145 146 virtual void potentialEnterObject(GameBase*); 147 U32 getNumTriggeringObjects() const; 148 GameBase* getObject(const U32); 149 const Vector<GameBase*>& getObjects() const { return mObjects; } 150 151 void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat ); 152 153 bool castRay(const Point3F &start, const Point3F &end, RayInfo* info); 154}; 155 156inline U32 Trigger::getNumTriggeringObjects() const 157{ 158 return mObjects.size(); 159} 160 161inline GameBase* Trigger::getObject(const U32 index) 162{ 163 AssertFatal(index < getNumTriggeringObjects(), "Error, out of range object index"); 164 165 return mObjects[index]; 166} 167 168#endif // _H_TRIGGER 169 170
