trigger.h

Engine/source/T3D/trigger.h

More...

Classes:

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   bool              mTripOnce;
 88   bool              mTripped;
 89   S32               mTrippedBy;
 90
 91   String            mTripCondition;
 92   String            mEnterCommand;
 93   String            mLeaveCommand;
 94   String            mTickCommand;
 95
 96   static const U32 CMD_SIZE = 1024;
 97
 98   void onUnmount(SceneObject* obj,S32 node);
 99
100  protected:
101   
102   enum TriggerUpdateBits
103   {
104      TransformMask = Parent::NextFreeMask << 0,
105      PolyMask      = Parent::NextFreeMask << 1,
106      EnterCmdMask  = Parent::NextFreeMask << 2,
107      LeaveCmdMask  = Parent::NextFreeMask << 3,
108      TickCmdMask   = Parent::NextFreeMask << 4,
109      NextFreeMask  = Parent::NextFreeMask << 5,
110   };
111
112   static bool smRenderTriggers;
113   bool testObject(GameBase* enter);
114   bool testTrippable();
115   bool testCondition();
116   bool evalCmD(String*);
117   void processTick(const Move *move);
118   void interpolateTick(F32 delta);
119
120   void buildConvex(const Box3F& box, Convex* convex);
121
122   static bool setEnterCmd(void *object, const char *index, const char *data);
123   static bool setLeaveCmd(void *object, const char *index, const char *data);
124   static bool setTickCmd(void *object, const char *index, const char *data);
125  public:
126   Trigger();
127   ~Trigger();
128
129   // SimObject
130   DECLARE_CONOBJECT(Trigger);
131
132   DECLARE_CALLBACK( void, onAdd, ( U32 objectId ) );
133   DECLARE_CALLBACK( void, onRemove, ( U32 objectId ) );
134
135   static void consoleInit();
136   static void initPersistFields();
137   void testObjects();
138   bool onAdd();
139   void onRemove();
140   void onDeleteNotify(SimObject*);
141   void inspectPostApply();
142
143   // NetObject
144   U32  packUpdate  (NetConnection *conn, U32 mask, BitStream* stream);
145   void unpackUpdate(NetConnection *conn,           BitStream* stream);
146
147   // SceneObject
148   void setTransform(const MatrixF &mat);
149   void prepRenderImage( SceneRenderState* state );
150
151   // GameBase
152   bool onNewDataBlock( GameBaseData *dptr, bool reload );
153
154   // Trigger
155   void setTriggerPolyhedron(const Polyhedron&);
156
157   virtual void potentialEnterObject(GameBase*);
158   U32       getNumTriggeringObjects() const;
159   GameBase* getObject(const U32);   
160   const Vector<GameBase*>& getObjects() const { return mObjects; }
161
162   void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
163
164   bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
165};
166
167inline U32 Trigger::getNumTriggeringObjects() const
168{
169   return mObjects.size();
170}
171
172inline GameBase* Trigger::getObject(const U32 index)
173{
174   AssertFatal(index < getNumTriggeringObjects(), "Error, out of range object index");
175
176   return mObjects[index];
177}
178
179#endif // _H_TRIGGER
180
181