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 LinearColorF 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 mDelta;
93
94 // Static attributes
95 ItemData* mDataBlock;
96 bool mStatic;
97 bool mRotate;
98
99 //
100 VectorF mVelocity;
101 bool mAtRest;
102
103 S32 mAtRestCounter;
104 static const S32 csmAtRestTimer;
105
106 bool mInLiquid;
107
108 ShapeBase* mCollisionObject;
109 U32 mCollisionTimeout;
110
111 PhysicsBody *mPhysicsRep;
112
113 bool mSubclassItemHandlesScene; ///< A subclass of Item will handle all of the adding to the scene
114
115 protected:
116 DECLARE_CALLBACK( void, onStickyCollision, ( const char* objID ));
117 DECLARE_CALLBACK( void, onEnterLiquid, ( const char* objID, F32 waterCoverage, const char* liquidType ));
118 DECLARE_CALLBACK( void, onLeaveLiquid, ( const char* objID, const char* liquidType ));
119
120 public:
121
122 void registerLights(LightManager * lightManager, bool lightingScene);
123 enum LightType
124 {
125 NoLight = 0,
126 ConstantLight,
127 PulsingLight,
128
129 NumLightTypes,
130 };
131
132 private:
133 S32 mDropTime;
134 LightInfo* mLight;
135
136 public:
137
138 Point3F mStickyCollisionPos;
139 Point3F mStickyCollisionNormal;
140
141 //
142 private:
143 OrthoBoxConvex mConvex;
144 Box3F mWorkingQueryBox;
145
146 void updateVelocity(const F32 dt);
147 void updatePos(const U32 mask, const F32 dt);
148 void updateWorkingCollisionSet(const U32 mask, const F32 dt);
149 bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere);
150 void buildConvex(const Box3F& box, Convex* convex);
151 void onDeleteNotify(SimObject*);
152
153 static bool _setStatic(void *object, const char *index, const char *data);
154 static bool _setRotate(void *object, const char *index, const char *data);
155
156 protected:
157 void _updatePhysics();
158 void prepRenderImage(SceneRenderState *state);
159 void advanceTime(F32 dt);
160
161 public:
162 DECLARE_CONOBJECT(Item);
163
164
165 Item();
166 ~Item();
167 static void initPersistFields();
168 static void consoleInit();
169
170 bool onAdd();
171 void onRemove();
172 bool onNewDataBlock( GameBaseData *dptr, bool reload );
173
174 bool isStatic() { return mStatic; }
175 bool isAtRest() { return mAtRest; }
176 bool isRotating() { return mRotate; }
177 Point3F getVelocity() const;
178 void setVelocity(const VectorF& vel);
179 void applyImpulse(const Point3F& pos,const VectorF& vec);
180 void setCollisionTimeout(ShapeBase* obj);
181 ShapeBase* getCollisionObject() { return mCollisionObject; };
182
183 void processTick(const Move *move);
184 void interpolateTick(F32 delta);
185 virtual void setTransform(const MatrixF &mat);
186
187 U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
188 void unpackUpdate(NetConnection *conn, BitStream *stream);
189};
190
191typedef Item::LightType ItemLightType;
192DefineEnumType( ItemLightType );
193
194#endif
195