projectile.h
Engine/source/T3D/projectile.h
Classes:
class
Base class for all projectiles.
class
Datablock for projectiles. This class is the base class for all other projectiles.
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 _PROJECTILE_H_ 30#define _PROJECTILE_H_ 31 32#ifndef _GAMEBASE_H_ 33#include "T3D/gameBase/gameBase.h" 34#endif 35#ifndef __RESOURCE_H__ 36#include "core/resource.h" 37#endif 38#ifndef _TSSHAPE_H_ 39#include "ts/tsShape.h" 40#endif 41#ifndef _LIGHTDESCRIPTION_H_ 42#include "T3D/lightDescription.h" 43#endif 44#ifndef _LIGHTINFO_H_ 45#include "lighting/lightInfo.h" 46#endif 47 48 49class ExplosionData; 50class SplashData; 51class ShapeBase; 52class TSShapeInstance; 53class TSThread; 54class PhysicsWorld; 55class DecalData; 56class LightDescription; 57class SFXTrack; 58class SFXSource; 59class ParticleEmitterData; 60class ParticleEmitter; 61class Projectile; 62 63//-------------------------------------------------------------------------- 64/// Datablock for projectiles. This class is the base class for all other projectiles. 65class ProjectileData : public GameBaseData 66{ 67 typedef GameBaseData Parent; 68 69protected: 70 bool onAdd(); 71 72public: 73 // variables set in datablock definition: 74 // Shape related 75 const char* projectileShapeName; 76 77 /// Set to true if it is a billboard and want it to always face the viewer, false otherwise 78 bool faceViewer; 79 Point3F scale; 80 81 82 /// [0,1] scale of how much velocity should be inherited from the parent object 83 F32 velInheritFactor; 84 /// Speed of the projectile when fired 85 F32 muzzleVelocity; 86 87 /// Force imparted on a hit object. 88 F32 impactForce; 89 90 /// Should it arc? 91 bool isBallistic; 92 93 /// How HIGH should it bounce (parallel to normal), [0,1] 94 F32 bounceElasticity; 95 /// How much momentum should be lost when it bounces (perpendicular to normal), [0,1] 96 F32 bounceFriction; 97 98 /// Should this projectile fall/rise different than a default object? 99 F32 gravityMod; 100 101 /// How long the projectile should exist before deleting itself 102 U32 lifetime; // all times are internally represented as ticks 103 /// How long it should not detonate on impact 104 S32 armingDelay; // the values are converted on initialization with 105 S32 fadeDelay; // the IRangeValidatorScaled field validator 106 107 ExplosionData* explosion; 108 S32 explosionId; 109 110 ExplosionData* waterExplosion; // Water Explosion Datablock 111 S32 waterExplosionId; // Water Explosion ID 112 113 SplashData* splash; // Water Splash Datablock 114 S32 splashId; // Water splash ID 115 116 DecalData *decal; // (impact) Decal Datablock 117 S32 decalId; // (impact) Decal ID 118 119 SFXTrack* sound; // Projectile Sound 120 121 LightDescription *lightDesc; 122 S32 lightDescId; 123 124 // variables set on preload: 125 Resource<TSShape> projectileShape; 126 S32 activateSeq; 127 S32 maintainSeq; 128 129 ParticleEmitterData* particleEmitter; 130 S32 particleEmitterId; 131 132 ParticleEmitterData* particleWaterEmitter; 133 S32 particleWaterEmitterId; 134 135 ProjectileData(); 136 137 void packData(BitStream*); 138 void unpackData(BitStream*); 139 bool preload(bool server, String &errorStr); 140 141 static bool setLifetime( void *object, const char *index, const char *data ); 142 static bool setArmingDelay( void *object, const char *index, const char *data ); 143 static bool setFadeDelay( void *object, const char *index, const char *data ); 144 static const char *getScaledValue( void *obj, const char *data); 145 static S32 scaleValue( S32 value, bool down = true ); 146 147 static void initPersistFields(); 148 DECLARE_CONOBJECT(ProjectileData); 149 150 151 DECLARE_CALLBACK( void, onExplode, ( Projectile* proj, Point3F pos, F32 fade ) ); 152 DECLARE_CALLBACK( void, onCollision, ( Projectile* proj, SceneObject* col, F32 fade, Point3F pos, Point3F normal ) ); 153public: 154 ProjectileData(const ProjectileData&, bool = false); 155 virtual bool allowSubstitutions() const { return true; } 156}; 157 158 159//-------------------------------------------------------------------------- 160/// Base class for all projectiles. 161class Projectile : public GameBase, public ISceneLight 162{ 163 typedef GameBase Parent; 164 165 static bool _setInitialPosition( void* object, const char* index, const char* data ); 166 static bool _setInitialVelocity( void* object, const char* index, const char* data ); 167 168public: 169 170 // Initial conditions 171 enum ProjectileConstants { 172 SourceIdTimeoutTicks = 7, // = 231 ms 173 DeleteWaitTime = 500, ///< 500 ms delete timeout (for network transmission delays) 174 ExcessVelDirBits = 7, 175 MaxLivingTicks = 4095, 176 }; 177 enum UpdateMasks { 178 BounceMask = Parent::NextFreeMask, 179 ExplosionMask = Parent::NextFreeMask << 1, 180 NextFreeMask = Parent::NextFreeMask << 2 181 }; 182 183 184 Projectile(); 185 ~Projectile(); 186 187 DECLARE_CONOBJECT(Projectile); 188 189 // SimObject 190 bool onAdd(); 191 void onRemove(); 192 static void initPersistFields(); 193 194 // NetObject 195 F32 getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips); 196 U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream); 197 void unpackUpdate(NetConnection *conn, BitStream *stream); 198 199 // SceneObject 200 Point3F getVelocity() const { return mCurrVelocity; } 201 void processTick( const Move *move ); 202 void advanceTime( F32 dt ); 203 void interpolateTick( F32 delta ); 204 205 // GameBase 206 bool onNewDataBlock( GameBaseData *dptr, bool reload ); 207 208 // Rendering 209 void prepRenderImage( SceneRenderState *state ); 210 void prepBatchRender( SceneRenderState *state ); 211 212 /// Updates velocity and position, and performs collision testing. 213 void simulate( F32 dt ); 214 215 /// What to do once this projectile collides with something 216 virtual void onCollision(const Point3F& p, const Point3F& n, SceneObject*); 217 218 /// What to do when this projectile explodes 219 virtual void explode(const Point3F& p, const Point3F& n, const U32 collideType ); 220 221 bool pointInWater(const Point3F &point); 222 223 void emitParticles(const Point3F&, const Point3F&, const Point3F&, const U32); 224 225 void updateSound(); 226 227 virtual bool calculateImpact( F32 simTime, 228 Point3F &pointOfImpact, 229 F32 &impactTime ); 230 231 void setInitialPosition( const Point3F& pos ); 232 void setInitialVelocity( const Point3F& vel ); 233 234protected: 235 236 static const U32 csmStaticCollisionMask; 237 static const U32 csmDynamicCollisionMask; 238 static const U32 csmDamageableMask; 239 static U32 smProjectileWarpTicks; 240 241 PhysicsWorld *mPhysicsWorld; 242 243 ProjectileData* mDataBlock; 244 245 SimObjectPtr< ParticleEmitter> mParticleEmitter; 246 SimObjectPtr< ParticleEmitter> mParticleWaterEmitter; 247 248 SFXSource* mSound; 249 250 // These two are server-side only 251 Point3F mInitialPosition; 252 Point3F mInitialVelocity; 253 254 Point3F mCurrPosition; 255 Point3F mCurrVelocity; 256 S32 mSourceObjectId; 257 S32 mSourceObjectSlot; 258 259 // Time related variables common to all projectiles, managed by processTick 260 U32 mCurrTick; ///< Current time in ticks 261 SimObjectPtr<ShapeBase> mSourceObject; ///< Actual pointer to the source object, times out after SourceIdTimeoutTicks 262 263 // Rendering related variables 264 TSShapeInstance* mProjectileShape; 265 TSThread* mActivateThread; 266 TSThread* mMaintainThread; 267 268 // ISceneLight 269 virtual void submitLights( LightManager *lm, bool staticLighting ); 270 virtual LightInfo* getLight() { return mLight; } 271 272 LightInfo *mLight; 273 LightState mLightState; 274 275 bool mHasExploded; ///< Prevent rendering, lighting, and duplicate explosions. 276 F32 mFadeValue; ///< set in processTick, interpolation between fadeDelay and lifetime 277 ///< in data block 278 279 // Warping and back delta variables. Only valid on the client 280 // 281 Point3F mWarpStart; 282 Point3F mWarpEnd; 283 U32 mWarpTicksRemaining; 284 285 Point3F mCurrDeltaBase; 286 Point3F mCurrBackDelta; 287 288 Point3F mExplosionPosition; 289 Point3F mExplosionNormal; 290 U32 mCollideHitType; 291public: 292 bool ignoreSourceTimeout; 293 U32 dynamicCollisionMask; 294 U32 staticCollisionMask; 295}; 296 297#endif // _PROJECTILE_H_ 298 299