123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- //-----------------------------------------------------------------------------
- // 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.
- //-----------------------------------------------------------------------------
- #ifndef _FLYINGVEHICLE_H_
- #define _FLYINGVEHICLE_H_
- #ifndef _VEHICLE_H_
- #include "T3D/vehicles/vehicle.h"
- #endif
- #ifndef _CLIPPEDPOLYLIST_H_
- #include "collision/clippedPolyList.h"
- #endif
- class ParticleEmitter;
- class ParticleEmitterData;
- //----------------------------------------------------------------------------
- struct FlyingVehicleData: public VehicleData {
- typedef VehicleData Parent;
- enum Sounds {
- JetSound,
- EngineSound,
- MaxSounds,
- };
- DECLARE_SOUNDASSET_ARRAY(FlyingVehicleData, FlyingSounds, Sounds::MaxSounds);
- DECLARE_ASSET_ARRAY_SETGET(FlyingVehicleData, FlyingSounds);
- enum Jets {
- // These enums index into a static name list.
- ForwardJetEmitter, // Thrust forward
- BackwardJetEmitter, // Thrust backward
- DownwardJetEmitter, // Thrust down
- TrailEmitter, // Contrail
- MaxJetEmitters,
- };
- ParticleEmitterData* jetEmitter[MaxJetEmitters];
- F32 minTrailSpeed;
- //
- F32 maneuveringForce;
- F32 horizontalSurfaceForce;
- F32 verticalSurfaceForce;
- F32 autoInputDamping;
- F32 steeringForce;
- F32 steeringRollForce;
- F32 rollForce;
- F32 autoAngularForce;
- F32 rotationalDrag;
- F32 maxAutoSpeed;
- F32 autoLinearForce;
- F32 hoverHeight;
- F32 createHoverHeight;
- F32 vertThrustMultiple;
- // Initialized in preload
- ClippedPolyList rigidBody;
- F32 maxSpeed;
- enum JetNodes {
- // These enums index into a static name list.
- ForwardJetNode,
- ForwardJetNode1,
- BackwardJetNode,
- BackwardJetNode1,
- DownwardJetNode,
- DownwardJetNode1,
- //
- TrailNode,
- TrailNode1,
- TrailNode2,
- TrailNode3,
- //
- MaxJetNodes,
- MaxDirectionJets = 2,
- ThrustJetStart = ForwardJetNode,
- NumThrustJets = TrailNode,
- MaxTrails = 4,
- };
- static const char *sJetNode[MaxJetNodes];
- S32 jetNode[MaxJetNodes];
- //
- FlyingVehicleData();
- DECLARE_CONOBJECT(FlyingVehicleData);
- static void initPersistFields();
- bool preload(bool server, String &errorStr) override;
- void packData(BitStream* stream) override;
- void unpackData(BitStream* stream) override;
- };
- //----------------------------------------------------------------------------
- class FlyingVehicle: public Vehicle
- {
- typedef Vehicle Parent;
- FlyingVehicleData* mDataBlock;
- SFXSource* mJetSound;
- SFXSource* mEngineSound;
- enum NetMaskBits {
- InitMask = BIT(0),
- HoverHeight = BIT(1)
- };
- bool createHeightOn;
- F32 mCeilingFactor;
- enum ThrustDirection {
- // Enums index into sJetActivationTable
- ThrustForward,
- ThrustBackward,
- ThrustDown,
- NumThrustDirections,
- NumThrustBits = 3
- };
- Point2F mThrust;
- ThrustDirection mThrustDirection;
- // Jet Threads
- enum Jets {
- // These enums index into a static name list.
- BackActivate,
- BackMaintain,
- BottomActivate,
- BottomMaintain,
- JetAnimCount
- };
- static const char* sJetSequence[FlyingVehicle::JetAnimCount];
- TSThread* mJetThread[JetAnimCount];
- S32 mJetSeq[JetAnimCount];
- bool mBackMaintainOn;
- bool mBottomMaintainOn;
- // Jet Particles
- struct JetActivation {
- // Convert thrust direction into nodes & emitters
- S32 node;
- S32 emitter;
- };
- static JetActivation sJetActivation[NumThrustDirections];
- SimObjectPtr<ParticleEmitter> mJetEmitter[FlyingVehicleData::MaxJetNodes];
- //
- bool onNewDataBlock(GameBaseData* dptr,bool reload) override;
- void updateMove(const Move *move) override;
- void updateForces(F32) override;
- // bool collideBody(const MatrixF& mat,Collision* info);
- F32 getHeight();
- // Client sounds & particles
- void updateJet(F32 dt);
- void updateEngineSound(F32 level);
- void updateEmitter(bool active,F32 dt,ParticleEmitterData *emitter,S32 idx,S32 count);
- U32 getCollisionMask() override;
- public:
- DECLARE_CONOBJECT(FlyingVehicle);
- DECLARE_CATEGORY("Actor \t Controllable");
- static void initPersistFields();
- FlyingVehicle();
- ~FlyingVehicle();
- bool onAdd() override;
- void onRemove() override;
- void interpolateTick(F32 dt) override;
- void advanceTime(F32 dt) override;
- void writePacketData(GameConnection *conn, BitStream *stream) override;
- void readPacketData(GameConnection *conn, BitStream *stream) override;
- U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream) override;
- void unpackUpdate(NetConnection *conn, BitStream *stream) override;
- void useCreateHeight(bool val);
- };
- #endif
|