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