debris.h
Classes:
class
class
Detailed Description
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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 26// Copyright (C) 2015 Faust Logic, Inc. 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 28 29#ifndef _DEBRIS_H_ 30#define _DEBRIS_H_ 31 32#ifndef __RESOURCE_H__ 33#include "core/resource.h" 34#endif 35#ifndef _GAMEBASE_H_ 36#include "T3D/gameBase/gameBase.h" 37#endif 38 39class ParticleEmitterData; 40class ParticleEmitter; 41class ExplosionData; 42class TSPartInstance; 43class TSShapeInstance; 44class TSShape; 45 46//************************************************************************** 47// Debris Data 48//************************************************************************** 49struct DebrisData : public GameBaseData 50{ 51 typedef GameBaseData Parent; 52 53 //----------------------------------------------------------------------- 54 // Data Decs 55 //----------------------------------------------------------------------- 56 enum DebrisDataConst 57 { 58 DDC_NUM_EMITTERS = 2, 59 }; 60 61 62 //----------------------------------------------------------------------- 63 // Debris datablock 64 //----------------------------------------------------------------------- 65 F32 velocity; 66 F32 velocityVariance; 67 F32 friction; 68 F32 elasticity; 69 F32 lifetime; 70 F32 lifetimeVariance; 71 S32 numBounces; 72 S32 bounceVariance; 73 F32 minSpinSpeed; 74 F32 maxSpinSpeed; 75 bool explodeOnMaxBounce; // explodes after it has bounced max times 76 bool staticOnMaxBounce; // becomes static after bounced max times 77 bool snapOnMaxBounce; // snap into a "resting" position on last bounce 78 bool fade; 79 bool useRadiusMass; // use mass calculations based on radius 80 F32 baseRadius; // radius at which the standard elasticity and friction apply 81 F32 gravModifier; // how much gravity affects debris 82 F32 terminalVelocity; // max velocity magnitude 83 bool ignoreWater; 84 85 const char* shapeName; 86 Resource<TSShape> shape; 87 88 StringTableEntry textureName; 89 90 91 S32 explosionId; 92 ExplosionData * explosion; 93 ParticleEmitterData* emitterList[DDC_NUM_EMITTERS]; 94 S32 emitterIDList[DDC_NUM_EMITTERS]; 95 96 DebrisData(); 97 98 bool onAdd(); 99 bool preload( bool server, String &errorStr ); 100 static void initPersistFields(); 101 void packData(BitStream* stream); 102 void unpackData(BitStream* stream); 103 104 DECLARE_CONOBJECT(DebrisData); 105 106public: 107 /*C*/ DebrisData(const DebrisData&, bool = false); 108 /*D*/ ~DebrisData(); 109 DebrisData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0); 110 virtual void onPerformSubstitutions(); 111 virtual bool allowSubstitutions() const { return true; } 112}; 113 114//************************************************************************** 115// Debris 116//************************************************************************** 117class Debris : public GameBase 118{ 119 typedef GameBase Parent; 120 121private: 122 S32 mNumBounces; 123 F32 mSize; 124 Point3F mLastPos; 125 Point3F mVelocity; 126 F32 mLifetime; 127 DebrisData * mDataBlock; 128 F32 mElapsedTime; 129 TSShapeInstance * mShape; 130 TSPartInstance * mPart; 131 MatrixF mInitialTrans; 132 F32 mXRotSpeed; 133 F32 mZRotSpeed; 134 Point3F mRotAngles; 135 F32 mRadius; 136 bool mStatic; 137 F32 mElasticity; 138 F32 mFriction; 139 140 SimObjectPtr<ParticleEmitter> mEmitterList[ DebrisData::DDC_NUM_EMITTERS ]; 141 142 /// Bounce the debris - returns true if debris bounces. 143 bool bounce( const Point3F &nextPos, F32 dt ); 144 145 /// Compute state of debris as if it hasn't collided with anything. 146 void computeNewState( Point3F &newPos, Point3F &newVel, F32 dt ); 147 148 void explode(); 149 void rotate( F32 dt ); 150 151protected: 152 virtual void processTick(const Move* move); 153 virtual void advanceTime( F32 dt ); 154 void prepRenderImage(SceneRenderState *state); 155 void prepBatchRender(SceneRenderState *state); 156 157 158 bool onAdd(); 159 void onRemove(); 160 void updateEmitters( Point3F &pos, Point3F &vel, U32 ms ); 161 162public: 163 164 Debris(); 165 ~Debris(); 166 167 static void initPersistFields(); 168 169 bool onNewDataBlock( GameBaseData *dptr, bool reload ); 170 171 void init( const Point3F &position, const Point3F &velocity ); 172 void setLifetime( F32 lifetime ){ mLifetime = lifetime; } 173 void setPartInstance( TSPartInstance *part ){ mPart = part; } 174 void setSize( F32 size ); 175 void setVelocity( const Point3F &vel ){ mVelocity = vel; } 176 void setRotAngles( const Point3F &angles ){ mRotAngles = angles; } 177 178 DECLARE_CONOBJECT(Debris); 179 180private: 181 SimObject* ss_object; 182 S32 ss_index; 183public: 184 void setSubstitutionData(SimObject* obj, S32 idx=0) { ss_object = obj; ss_index = idx; } 185}; 186 187 188 189 190#endif 191