Public Functions
DefineEnumType(ItemLightType )
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 _ITEM_H_
25#define _ITEM_H_
26
27#ifndef _SHAPEBASE_H_
28 #include "T3D/shapeBase.h"
29#endif
30#ifndef _BOXCONVEX_H_
31 #include "collision/boxConvex.h"
32#endif
33#ifndef _DYNAMIC_CONSOLETYPES_H_
34 #include "console/dynamicTypes.h"
35#endif
36
37
38class PhysicsBody;
39
40
41//----------------------------------------------------------------------------
42
43struct ItemData: public ShapeBaseData {
44 typedef ShapeBaseData Parent;
45
46 F32 friction;
47 F32 elasticity;
48
49 bool sticky;
50 F32 gravityMod;
51 F32 maxVelocity;
52
53 bool lightOnlyStatic;
54 S32 lightType;
55 ColorF lightColor;
56 S32 lightTime;
57 F32 lightRadius;
58
59 bool simpleServerCollision;
60
61 ItemData();
62 DECLARE_CONOBJECT(ItemData);
63 static void initPersistFields();
64 virtual void packData(BitStream* stream);
65 virtual void unpackData(BitStream* stream);
66};
67
68
69//----------------------------------------------------------------------------
70
71class Item: public ShapeBase
72{
73 protected:
74 typedef ShapeBase Parent;
75
76 enum MaskBits {
77 HiddenMask = Parent::NextFreeMask,
78 ThrowSrcMask = Parent::NextFreeMask << 1,
79 PositionMask = Parent::NextFreeMask << 2,
80 RotationMask = Parent::NextFreeMask << 3,
81 NextFreeMask = Parent::NextFreeMask << 4
82 };
83
84 // Client interpolation data
85 struct StateDelta {
86 Point3F pos;
87 VectorF posVec;
88 S32 warpTicks;
89 Point3F warpOffset;
90 F32 dt;
91 };
92 StateDelta delta;
93
94 // Static attributes
95 ItemData* mDataBlock;
96 static F32 mGravity;
97 bool mStatic;
98 bool mRotate;
99
100 //
101 VectorF mVelocity;
102 bool mAtRest;
103
104 S32 mAtRestCounter;
105 static const S32 csmAtRestTimer;
106
107 bool mInLiquid;
108
109 ShapeBase* mCollisionObject;
110 U32 mCollisionTimeout;
111
112 PhysicsBody *mPhysicsRep;
113
114 bool mSubclassItemHandlesScene; ///< A subclass of Item will handle all of the adding to the scene
115
116 protected:
117 DECLARE_CALLBACK( void, onStickyCollision, ( const char* objID ));
118 DECLARE_CALLBACK( void, onEnterLiquid, ( const char* objID, F32 waterCoverage, const char* liquidType ));
119 DECLARE_CALLBACK( void, onLeaveLiquid, ( const char* objID, const char* liquidType ));
120
121 public:
122
123 void registerLights(LightManager * lightManager, bool lightingScene);
124 enum LightType
125 {
126 NoLight = 0,
127 ConstantLight,
128 PulsingLight,
129
130 NumLightTypes,
131 };
132
133 private:
134 S32 mDropTime;
135 LightInfo* mLight;
136
137 public:
138
139 Point3F mStickyCollisionPos;
140 Point3F mStickyCollisionNormal;
141
142 //
143 private:
144 OrthoBoxConvex mConvex;
145 Box3F mWorkingQueryBox;
146
147 void updateVelocity(const F32 dt);
148 void updatePos(const U32 mask, const F32 dt);
149 void updateWorkingCollisionSet(const U32 mask, const F32 dt);
150 bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere);
151 void buildConvex(const Box3F& box, Convex* convex);
152 void onDeleteNotify(SimObject*);
153
154 static bool _setStatic(void *object, const char *index, const char *data);
155 static bool _setRotate(void *object, const char *index, const char *data);
156
157 protected:
158 void _updatePhysics();
159 void prepRenderImage(SceneRenderState *state);
160 void advanceTime(F32 dt);
161
162 public:
163 DECLARE_CONOBJECT(Item);
164
165
166 Item();
167 ~Item();
168 static void initPersistFields();
169 static void consoleInit();
170
171 bool onAdd();
172 void onRemove();
173 bool onNewDataBlock( GameBaseData *dptr, bool reload );
174
175 bool isStatic() { return mStatic; }
176 bool isAtRest() { return mAtRest; }
177 bool isRotating() { return mRotate; }
178 Point3F getVelocity() const;
179 void setVelocity(const VectorF& vel);
180 void applyImpulse(const Point3F& pos,const VectorF& vec);
181 void setCollisionTimeout(ShapeBase* obj);
182 ShapeBase* getCollisionObject() { return mCollisionObject; };
183
184 void processTick(const Move *move);
185 void interpolateTick(F32 delta);
186 virtual void setTransform(const MatrixF &mat);
187
188 U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
189 void unpackUpdate(NetConnection *conn, BitStream *stream);
190};
191
192typedef Item::LightType ItemLightType;
193DefineEnumType( ItemLightType );
194
195#endif
196