📄 player.h
字号:
F32 min,max;
F32 delta;
};
ParticleEmitter *mSplashEmitter[PlayerData::NUM_SPLASH_EMITTERS];
F32 mBubbleEmitterTime;
/// Client interpolation/warp data
struct StateDelta {
Move move; ///< Last move from server
F32 dt; ///< Last interpolation time
/// @name Interpolation data
/// @{
Point3F pos;
Point3F rot;
Point3F head;
VectorF posVec;
VectorF rotVec;
VectorF headVec;
/// @}
/// @name Warp data
/// @{
S32 warpTicks;
Point3F warpOffset;
Point3F rotOffset;
/// @}
};
StateDelta delta; ///< Used for interpolation on the client. @see StateDelta
S32 mPredictionCount; ///< Number of ticks to predict
// Current pos, vel etc.
Point3F mHead; ///< Head rotation, uses only x & z
Point3F mRot; ///< Body rotation, uses only z
VectorF mVelocity; ///< Velocity
Point3F mAnchorPoint; ///< Pos compression anchor
static F32 mGravity; ///< Gravity
S32 mImpactSound;
S32 mMountPending; ///< mMountPending suppresses tickDelay countdown so players will sit until
///< their mount, or another animation, comes through (or 13 seconds elapses).
#ifdef TGE_RPG /// TGE_Move
Point3F m_ptOriginBak; /// 上次产生的人物位置,用来进行SelfBlock设置
F32 m_fRunRate; ///跑步速度与步行速度比例
F32 m_fMoveRate; ///移动百分比
F32 m_fMoveSpeed; ///移动速度
#endif
/// Main player state
enum ActionState {
NullState,
/// TGE_PlayerAnim
// MoveState,
WalkState,
RunState,
RecoverState,
NumStateBits = 3
};
ActionState mState; ///< What is the player doing? @see ActionState
bool mFalling; ///< Falling in mid-air?
S32 mJumpDelay; ///< Delay till next jump
S32 mContactTimer; ///< Ticks since last contact
Point3F mJumpSurfaceNormal; ///< Normal of the surface the player last jumped on
U32 mJumpSurfaceLastContact; ///< How long it's been since the player landed (ticks)
F32 mWeaponBackFraction; ///< Amount to slide the weapon back (if it's up against something)
AUDIOHANDLE mMoveBubbleHandle; ///< Audio handle for moving bubbles
AUDIOHANDLE mWaterBreathHandle; ///< Audio handle for underwater breath
SimObjectPtr<ShapeBase> mControlObject; ///< Controlling object
/// @name Animation threads & data
/// @{
struct ActionAnimation {
U32 action;
TSThread* thread;
S32 delayTicks; // before picking another.
bool forward;
bool firstPerson;
bool waitForEnd;
bool holdAtEnd;
bool animateOnServer;
bool atEnd;
} mActionAnimation;
struct ArmAnimation {
U32 action;
TSThread* thread;
} mArmAnimation;
TSThread* mArmThread;
TSThread* mHeadVThread;
TSThread* mHeadHThread;
TSThread* mRecoilThread;
static Range mArmRange;
static Range mHeadVRange;
static Range mHeadHRange;
/// @}
bool mInMissionArea; ///< Are we in the mission area?
//
U32 mRecoverTicks; ///< same as recoverTicks in the player datablock
U32 mReversePending;
bool inLiquid; ///< Are we in liquid?
//
PlayerData* mDataBlock; ///< MMmmmmm...datablock...
Point3F mLastPos; ///< Holds the last position for physics updates
Point3F mLastWaterPos; ///< Same as mLastPos, but for water
struct ContactInfo {
bool contacted, jump, run;
VectorF contactNormal;
void clear() {contacted=jump=run=false; contactNormal.set(1,1,1);}
ContactInfo() {clear();}
} mContactInfo;
struct Death {
F32 lastPos;
Point3F posAdd;
VectorF rotate;
VectorF curNormal;
F32 curSink;
void clear() {dMemset(this, 0, sizeof(*this)); initFall();}
VectorF getPosAdd() {VectorF ret(posAdd); posAdd.set(0,0,0); return ret;}
bool haveVelocity() {return posAdd.x != 0 || posAdd.y != 0;}
void initFall() {curNormal.set(0,0,1); curSink = 0;}
Death() {clear();}
MatrixF* fallToGround(F32 adjust, const Point3F& pos, F32 zrot, F32 boxRad);
} mDeath;
// New collision
public:
OrthoBoxConvex mConvex;
Box3F mWorkingQueryBox;
protected:
void setState(ActionState state, U32 ticks=0);
void updateState();
///Update the movement
void updateMove(const Move *move);
///Interpolate movement
bool updatePos(const F32 travelTime = TickSec);
///Update head animation
void updateLookAnimation();
///Update other animations
void updateAnimation(F32 dt);
void updateAnimationTree(bool firstPerson);
bool step(Point3F *pos,F32 *maxStep,F32 time);
///See if the player is still in the mission area
void checkMissionArea();
virtual bool setArmThread(U32 action);
virtual void setActionThread(U32 action,bool forward,bool hold = false,bool wait = false,bool fsp = false, bool forceSet = false);
virtual void updateActionThread();
virtual void pickActionAnimation();
void onUnmount(ShapeBase* obj,S32 node);
void setPosition(const Point3F& pos,const Point3F& viewRot);
void setRenderPosition(const Point3F& pos,const Point3F& viewRot,F32 dt=-1);
void findContact(bool* run,bool* jump,VectorF* contactNormal);
virtual void onImageRecoil(U32 imageSlot,ShapeBaseImageData::StateData::RecoilState);
virtual void updateDamageLevel();
virtual void updateDamageState();
/// Set which client is controlling this player
void setControllingClient(GameConnection* client);
void calcClassRenderData();
/// Render the mounted image, usually the weapon
void renderMountedImage(SceneState* state, ShapeImageRenderImage* image);
/// Render the player
void renderImage(SceneState *state, SceneRenderImage *image);
/// Play a footstep sound
void playFootstepSound(bool triggeredLeft, S32 sound);
/// Play an impact sound
void playImpactSound();
/// Are we in the process of dying?
bool inDeathAnim();
F32 deathDelta(Point3F &delta);
void updateDeathOffsets();
bool inSittingAnim();
/// @name Water
/// @{
void updateSplash(); ///< Update the splash effect
void updateFroth( F32 dt ); ///< Update any froth
void updateWaterSounds( F32 dt ); ///< Update water sounds
bool pointInWater( Point3F &point ); ///< Tests to see if a point is in water
void createSplash( Point3F &pos, F32 speed ); ///< Creates a splash
bool collidingWithWater( Point3F &waterHeight ); ///< Are we collising with water?
/// @}
public:
DECLARE_CONOBJECT(Player);
Player();
~Player();
static void consoleInit();
/// @name Transforms
/// Transforms are all in object space
/// @{
void setTransform(const MatrixF &mat);
void getEyeTransform(MatrixF* mat);
void getRenderEyeTransform(MatrixF* mat);
void getCameraParameters(F32 *min, F32 *max, Point3F *offset, MatrixF *rot);
void getMuzzleTransform(U32 imageSlot,MatrixF* mat);
void getRenderMuzzleTransform(U32 imageSlot,MatrixF* mat);
/// @}
#ifdef TGE_RPG /// TGE_Move
inline void setMoveRate(F32 fRate) {m_fMoveRate = fRate;}
inline void setMoveSpeed(F32 fSpeed) {m_fMoveSpeed = fSpeed;} //移动速度
inline void setRunRate(F32 fRate) {m_fRunRate = fRate;} //移动速度
#endif
Point3F getVelocity() const;
void setVelocity(const VectorF& vel);
/// Apply an impulse at the given point, with magnitude/direction of vec
void applyImpulse(const Point3F& pos,const VectorF& vec);
/// Get the rotation of the player
const Point3F& getRotation() { return mRot; }
/// Get the rotation of the head of the player
const Point3F& getHeadRotation() { return mHead; }
void getDamageLocation(const Point3F& in_rPos, const char *&out_rpVert, const char *&out_rpQuad);
bool canJump(); ///< Can the player jump?
bool haveContact() {return !mContactTimer;} ///< Is it in contact with something
void getMuzzlePointAI(U32 imageSlot, Point3F* point);
/// duh
float getMaxForwardVelocity() { return (mDataBlock != NULL ? mDataBlock->maxForwardSpeed : 0); }
virtual bool isDisplacable() const;
virtual Point3F getMomentum() const;
virtual void setMomentum(const Point3F &momentum);
virtual F32 getMass() const;
virtual bool displaceObject(const Point3F& displaceVector);
virtual bool getAIMove(Move*);
bool checkDismountPosition(const MatrixF& oldPos, const MatrixF& newPos); ///< Is it safe to dismount here?
//
bool onAdd();
void onRemove();
bool onNewDataBlock(GameBaseData* dptr);
void onScaleChanged();
Box3F mScaledBox;
// Animation
const char* getStateName();
bool setActionThread(const char* sequence,bool hold,bool wait,bool fsp = false);
bool setArmThread(const char* sequence);
// Object control
void setControlObject(ShapeBase *obj);
ShapeBase* getControlObject();
//
void updateWorkingCollisionSet();
void processTick(const Move *move);
void interpolateTick(F32 delta);
void advanceTime(F32 dt);
bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
bool buildPolyList(AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere);
void buildConvex(const Box3F& box, Convex* convex);
bool isControlObject();
void onCameraScopeQuery(NetConnection *cr, CameraScopeQuery *);
void writePacketData(GameConnection *conn, BitStream *stream);
void readPacketData (GameConnection *conn, BitStream *stream);
U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream);
void unpackUpdate(NetConnection *conn, BitStream *stream);
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -