123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
- // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
- // Copyright (C) 2015 Faust Logic, Inc.
- //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
- #ifndef _PROJECTILE_H_
- #define _PROJECTILE_H_
- #ifndef _GAMEBASE_H_
- #include "T3D/gameBase/gameBase.h"
- #endif
- #ifndef __RESOURCE_H__
- #include "core/resource.h"
- #endif
- #ifndef _TSSHAPE_H_
- #include "ts/tsShape.h"
- #endif
- #ifndef _LIGHTDESCRIPTION_H_
- #include "T3D/lightDescription.h"
- #endif
- #ifndef _LIGHTINFO_H_
- #include "lighting/lightInfo.h"
- #endif
- #include "T3D/assets/SoundAsset.h"
- #include "T3D/assets/ShapeAsset.h"
- class ExplosionData;
- class SplashData;
- class ShapeBase;
- class TSShapeInstance;
- class TSThread;
- class PhysicsWorld;
- class DecalData;
- class LightDescription;
- class SFXTrack;
- class SFXSource;
- class ParticleEmitterData;
- class ParticleEmitter;
- class Projectile;
- //--------------------------------------------------------------------------
- /// Datablock for projectiles. This class is the base class for all other projectiles.
- class ProjectileData : public GameBaseData
- {
- typedef GameBaseData Parent;
- protected:
- bool onAdd();
- public:
- DECLARE_SHAPEASSET(ProjectileData, ProjectileShape, onShapeChanged);
- DECLARE_ASSET_SETGET(ProjectileData, ProjectileShape);
- /// Set to true if it is a billboard and want it to always face the viewer, false otherwise
- bool faceViewer;
- Point3F scale;
- /// [0,1] scale of how much velocity should be inherited from the parent object
- F32 velInheritFactor;
- /// Speed of the projectile when fired
- F32 muzzleVelocity;
- /// Force imparted on a hit object.
- F32 impactForce;
- /// Should it arc?
- bool isBallistic;
- /// How HIGH should it bounce (parallel to normal), [0,1]
- F32 bounceElasticity;
- /// How much momentum should be lost when it bounces (perpendicular to normal), [0,1]
- F32 bounceFriction;
- /// Should this projectile fall/rise different than a default object?
- F32 gravityMod;
- /// How long the projectile should exist before deleting itself
- U32 lifetime; // all times are internally represented as ticks
- /// How long it should not detonate on impact
- S32 armingDelay; // the values are converted on initialization with
- S32 fadeDelay; // the IRangeValidatorScaled field validator
- ExplosionData* explosion;
- S32 explosionId;
- ExplosionData* waterExplosion; // Water Explosion Datablock
- S32 waterExplosionId; // Water Explosion ID
- SplashData* splash; // Water Splash Datablock
- S32 splashId; // Water splash ID
- DecalData *decal; // (impact) Decal Datablock
- S32 decalId; // (impact) Decal ID
- DECLARE_SOUNDASSET(ProjectileData, ProjectileSound);
- DECLARE_ASSET_SETGET(ProjectileData, ProjectileSound);
-
- LightDescription *lightDesc;
- S32 lightDescId;
- // variables set on preload:
- S32 activateSeq;
- S32 maintainSeq;
- ParticleEmitterData* particleEmitter;
- S32 particleEmitterId;
- ParticleEmitterData* particleWaterEmitter;
- S32 particleWaterEmitterId;
- ProjectileData();
- void packData(BitStream*);
- void unpackData(BitStream*);
- bool preload(bool server, String &errorStr);
- static bool setLifetime( void *object, const char *index, const char *data );
- static bool setArmingDelay( void *object, const char *index, const char *data );
- static bool setFadeDelay( void *object, const char *index, const char *data );
- static const char *getScaledValue( void *obj, const char *data);
- static S32 scaleValue( S32 value, bool down = true );
- static void initPersistFields();
- DECLARE_CONOBJECT(ProjectileData);
-
- DECLARE_CALLBACK( void, onExplode, ( Projectile* proj, Point3F pos, F32 fade ) );
- DECLARE_CALLBACK( void, onCollision, ( Projectile* proj, SceneObject* col, F32 fade, Point3F pos, Point3F normal ) );
- public:
- ProjectileData(const ProjectileData&, bool = false);
- virtual bool allowSubstitutions() const { return true; }
- void onShapeChanged() {}
- };
- //--------------------------------------------------------------------------
- /// Base class for all projectiles.
- class Projectile : public GameBase, public ISceneLight
- {
- typedef GameBase Parent;
- static bool _setInitialPosition( void* object, const char* index, const char* data );
- static bool _setInitialVelocity( void* object, const char* index, const char* data );
- public:
- // Initial conditions
- enum ProjectileConstants {
- SourceIdTimeoutTicks = 7, // = 231 ms
- DeleteWaitTime = 500, ///< 500 ms delete timeout (for network transmission delays)
- ExcessVelDirBits = 7,
- MaxLivingTicks = 4095,
- };
- enum UpdateMasks {
- BounceMask = Parent::NextFreeMask,
- ExplosionMask = Parent::NextFreeMask << 1,
- NextFreeMask = Parent::NextFreeMask << 2
- };
-
- Projectile();
- ~Projectile();
- DECLARE_CONOBJECT(Projectile);
- // SimObject
- bool onAdd();
- void onRemove();
- static void initPersistFields();
- // NetObject
- F32 getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips);
- U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
- void unpackUpdate(NetConnection *conn, BitStream *stream);
- // SceneObject
- Point3F getVelocity() const { return mCurrVelocity; }
- void processTick( const Move *move );
- void advanceTime( F32 dt );
- void interpolateTick( F32 delta );
- // GameBase
- bool onNewDataBlock( GameBaseData *dptr, bool reload );
- // Rendering
- void prepRenderImage( SceneRenderState *state );
- void prepBatchRender( SceneRenderState *state );
- /// Updates velocity and position, and performs collision testing.
- void simulate( F32 dt );
- /// What to do once this projectile collides with something
- virtual void onCollision(const Point3F& p, const Point3F& n, SceneObject*);
- /// What to do when this projectile explodes
- virtual void explode(const Point3F& p, const Point3F& n, const U32 collideType );
-
- bool pointInWater(const Point3F &point);
- void emitParticles(const Point3F&, const Point3F&, const Point3F&, const U32);
- void updateSound();
- virtual bool calculateImpact( F32 simTime,
- Point3F &pointOfImpact,
- F32 &impactTime );
- void setInitialPosition( const Point3F& pos );
- void setInitialVelocity( const Point3F& vel );
- protected:
- static const U32 csmStaticCollisionMask;
- static const U32 csmDynamicCollisionMask;
- static const U32 csmDamageableMask;
- static U32 smProjectileWarpTicks;
- PhysicsWorld *mPhysicsWorld;
- ProjectileData* mDataBlock;
- SimObjectPtr< ParticleEmitter > mParticleEmitter;
- SimObjectPtr< ParticleEmitter > mParticleWaterEmitter;
- SFXSource* mSound;
- // These two are server-side only
- Point3F mInitialPosition;
- Point3F mInitialVelocity;
- Point3F mCurrPosition;
- Point3F mCurrVelocity;
- S32 mSourceObjectId;
- S32 mSourceObjectSlot;
- // Time related variables common to all projectiles, managed by processTick
- U32 mCurrTick; ///< Current time in ticks
- SimObjectPtr<ShapeBase> mSourceObject; ///< Actual pointer to the source object, times out after SourceIdTimeoutTicks
- // Rendering related variables
- TSShapeInstance* mProjectileShape;
- TSThread* mActivateThread;
- TSThread* mMaintainThread;
- // ISceneLight
- virtual void submitLights( LightManager *lm, bool staticLighting );
- virtual LightInfo* getLight() { return mLight; }
-
- LightInfo *mLight;
- LightState mLightState;
- bool mHasExploded; ///< Prevent rendering, lighting, and duplicate explosions.
- F32 mFadeValue; ///< set in processTick, interpolation between fadeDelay and lifetime
- ///< in data block
- // Warping and back delta variables. Only valid on the client
- //
- Point3F mWarpStart;
- Point3F mWarpEnd;
- U32 mWarpTicksRemaining;
- Point3F mCurrDeltaBase;
- Point3F mCurrBackDelta;
- Point3F mExplosionPosition;
- Point3F mExplosionNormal;
- U32 mCollideHitType;
- public:
- bool ignoreSourceTimeout;
- U32 dynamicCollisionMask;
- U32 staticCollisionMask;
- };
- #endif // _PROJECTILE_H_
|