1 //-----------------------------------------------------------------------------
2 // Copyright (c) 2012 GarageGames, LLC
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to
6 // deal in the Software without restriction, including without limitation the
7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 // sell copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 //-----------------------------------------------------------------------------
23 #include "platform/platform.h"
24 #include "core/dnet.h"
25 #include "core/stream/bitStream.h"
27 #include "math/mMath.h"
28 #include "console/simBase.h"
29 #include "console/console.h"
30 #include "console/consoleTypes.h"
31 #include "console/engineAPI.h"
32 #include "T3D/gameBase/moveManager.h"
33 #include "ts/tsShapeInstance.h"
34 #include "T3D/staticShape.h"
35 #include "math/mathIO.h"
36 #include "sim/netConnection.h"
37 #include "scene/sceneObjectLightingPlugin.h"
39 extern void wireCube(F32 size
,Point3F pos
);
41 static const U32 sgAllowedDynamicTypes
= 0xffffff;
43 //----------------------------------------------------------------------------
45 IMPLEMENT_CO_DATABLOCK_V1(StaticShapeData
);
47 ConsoleDocClass( StaticShapeData
,
48 "@brief The most basic ShapeBaseData derrived shape datablock available in Torque 3D.\n\n"
50 "When it comes to placing 3D objects in the scene, you effectively have two options:\n\n"
51 "1. TSStatic objects\n\n"
52 "2. ShapeBase derived objects\n\n"
54 "Since ShapeBase and ShapeBaseData are not meant to be instantiated in script, you "
55 "will use one of its child classes instead. Several game related objects are derived "
56 "from ShapeBase: Player, Vehicle, Item, and so on.\n\n"
58 "When you need a 3D object with datablock capabilities, you will use an object derived "
59 "from ShapeBase. When you need an object with extremely low overhead, and with no other "
60 "purpose than to be a 3D object in the scene, you will use TSStatic.\n\n"
62 "The most basic child of ShapeBase is StaticShape. It does not introduce any of the "
63 "additional functionality you see in Player, Item, Vehicle or the other game play "
64 "heavy classes. At its core, it is comparable to a TSStatic, but with a datbalock. Having "
65 "a datablock provides a location for common variables as well as having access to "
66 "various ShapeBaseData, GameBaseData and SimDataBlock callbacks.\n\n"
69 "// Create a StaticShape using a datablock\n"
70 "datablock StaticShapeData(BasicShapeData)\n"
72 " shapeFile = \"art/shapes/items/kit/healthkit.dts\";\n"
73 " testVar = \"Simple string, not a stock variable\";\n"
77 " dataBlock = \"BasicShapeData\";\n"
78 " position = \"0.0 0.0 0.0\";\n"
79 " rotation = \"1 0 0 0\";\n"
80 " scale = \"1 1 1\";\n"
85 "@see ShapeBaseData\n"
88 "@ingroup gameObjects\n"
89 "@ingroup Datablocks");
91 StaticShapeData::StaticShapeData()
97 noIndividualDamage
= false;
100 void StaticShapeData::initPersistFields()
102 addField("noIndividualDamage", TypeBool
, Offset(noIndividualDamage
, StaticShapeData
), "Deprecated\n\n @internal");
103 addField("dynamicType", TypeS32
, Offset(dynamicTypeField
, StaticShapeData
),
104 "@brief An integer value which, if speficied, is added to the value retured by getType().\n\n"
105 "This allows you to extend the type mask for a StaticShape that uses this datablock. Type masks "
106 "are used for container queries, etc.");
108 Parent::initPersistFields();
111 void StaticShapeData::packData(BitStream
* stream
)
113 Parent::packData(stream
);
114 stream
->writeFlag(noIndividualDamage
);
115 stream
->write(dynamicTypeField
);
118 void StaticShapeData::unpackData(BitStream
* stream
)
120 Parent::unpackData(stream
);
121 noIndividualDamage
= stream
->readFlag();
122 stream
->read(&dynamicTypeField
);
126 //----------------------------------------------------------------------------
128 IMPLEMENT_CO_NETOBJECT_V1(StaticShape
);
130 ConsoleDocClass( StaticShape
,
131 "@brief The most basic 3D shape with a datablock available in Torque 3D.\n\n"
133 "When it comes to placing 3D objects in the scene, you technically have two options:\n\n"
134 "1. TSStatic objects\n\n"
135 "2. ShapeBase derived objects\n\n"
137 "Since ShapeBase and ShapeBaseData are not meant to be instantiated in script, you "
138 "will use one of its child classes instead. Several game related objects are derived "
139 "from ShapeBase: Player, Vehicle, Item, and so on.\n\n"
141 "When you need a 3D object with datablock capabilities, you will use an object derived "
142 "from ShapeBase. When you need an object with extremely low overhead, and with no other "
143 "purpose than to be a 3D object in the scene, you will use TSStatic.\n\n"
145 "The most basic child of ShapeBase is StaticShape. It does not introduce any of the "
146 "additional functionality you see in Player, Item, Vehicle or the other game play "
147 "heavy classes. At its core, it is comparable to a TSStatic, but with a datbalock. Having "
148 "a datablock provides a location for common variables as well as having access to "
149 "various ShapeBaseData, GameBaseData and SimDataBlock callbacks.\n\n"
152 "// Create a StaticShape using a datablock\n"
153 "datablock StaticShapeData(BasicShapeData)\n"
155 " shapeFile = \"art/shapes/items/kit/healthkit.dts\";\n"
156 " testVar = \"Simple string, not a stock variable\";\n"
158 "new StaticShape()\n"
160 " dataBlock = \"BasicShapeData\";\n"
161 " position = \"0.0 0.0 0.0\";\n"
162 " rotation = \"1 0 0 0\";\n"
163 " scale = \"1 1 1\";\n"
167 "@see StaticShapeData\n"
171 "@ingroup gameObjects\n");
173 StaticShape::StaticShape()
175 mTypeMask
|= StaticShapeObjectType
| StaticObjectType
;
179 StaticShape::~StaticShape()
184 //----------------------------------------------------------------------------
186 void StaticShape::initPersistFields()
188 Parent::initPersistFields();
191 bool StaticShape::onAdd()
193 if(!Parent::onAdd() || !mDataBlock
)
196 // We need to modify our type mask based on what our datablock says...
197 mTypeMask
|= (mDataBlock
->dynamicTypeField
& sgAllowedDynamicTypes
);
201 if (isServerObject())
206 bool StaticShape::onNewDataBlock(GameBaseData
* dptr
, bool reload
)
208 mDataBlock
= dynamic_cast<StaticShapeData
*>(dptr
);
209 if (!mDataBlock
|| !Parent::onNewDataBlock(dptr
, reload
))
212 scriptOnNewDataBlock();
216 void StaticShape::onRemove()
224 //----------------------------------------------------------------------------
226 void StaticShape::processTick(const Move
* move
)
228 Parent::processTick(move
);
231 if (move
&& mDamageState
== Enabled
) {
232 setImageTriggerState(0,move
->trigger
[0]);
233 setImageTriggerState(1,move
->trigger
[1]);
237 void StaticShape::setTransform(const MatrixF
& mat
)
239 Parent::setTransform(mat
);
240 setMaskBits(PositionMask
);
243 void StaticShape::onUnmount(ShapeBase
*,S32
)
245 // Make sure the client get's the final server pos.
246 setMaskBits(PositionMask
);
250 //----------------------------------------------------------------------------
252 U32
StaticShape::packUpdate(NetConnection
*connection
, U32 mask
, BitStream
*bstream
)
254 U32 retMask
= Parent::packUpdate(connection
, mask
, bstream
);
255 if (bstream
->writeFlag(mask
& PositionMask
| ExtendedInfoMask
))
258 // Write the transform (do _not_ use writeAffineTransform. Since this is a static
259 // object, the transform must be RIGHT THE *&)*$&^ ON or it will goof up the
260 // synchronization between the client and the server.
261 mathWrite(*bstream
, mObjToWorld
);
262 mathWrite(*bstream
, mObjScale
);
266 bstream
->writeFlag(mPowered
);
270 retMask
|= mLightPlugin
->packUpdate(this, ExtendedInfoMask
, connection
, mask
, bstream
);
276 void StaticShape::unpackUpdate(NetConnection
*connection
, BitStream
*bstream
)
278 Parent::unpackUpdate(connection
, bstream
);
279 if (bstream
->readFlag())
282 mathRead(*bstream
, &mat
);
283 Parent::setTransform(mat
);
284 Parent::setRenderTransform(mat
);
287 mathRead(*bstream
, &scale
);
292 mPowered
= bstream
->readFlag();
296 mLightPlugin
->unpackUpdate(this, connection
, bstream
);
301 //----------------------------------------------------------------------------
302 // This appears to be legacy T2 stuff
303 // Marked internal, as this is flagged to be deleted
305 DefineConsoleMethod(StaticShape
, setPoweredState
, void, (bool isPowered
), , "(bool isPowered)"
308 if(!object
->isServerObject())
310 object
->setPowered(isPowered
);
313 DefineConsoleMethod(StaticShape
, getPoweredState
, bool, (), , "@internal")
315 if(!object
->isServerObject())
317 return(object
->isPowered());