1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 17:49:55 +00:00
openmw-tes3mp/apps/openmw/mwvr/realisticcombat.hpp

116 lines
3.7 KiB
C++
Raw Normal View History

2020-03-15 14:31:38 +00:00
#ifndef MWVR_REALISTICCOMBAT_H
#define MWVR_REALISTICCOMBAT_H
#include <components/esm/loadweap.hpp>
#include "../mwbase/world.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/class.hpp"
#include "vrenvironment.hpp"
#include "vrsession.hpp"
2021-05-20 20:40:48 +00:00
#include "vrtracking.hpp"
2020-03-15 14:31:38 +00:00
namespace MWVR {
namespace RealisticCombat {
2020-06-28 09:33:01 +00:00
/// Enum describing the current state of the MWVR::RealisticCombat::StateMachine
enum SwingState
{
SwingState_Ready,
SwingState_Launch,
SwingState_Swing,
SwingState_Impact,
SwingState_Cooldown,
};
2020-03-15 14:31:38 +00:00
2020-06-28 09:33:01 +00:00
/////////////////////////////////////////////////////////////////////
/// \brief State machine for "realistic" combat in openmw vr
///
/// \sa SwingState
///
/// Initial state: Ready.
///
/// State Ready: Ready to initiate a new attack.
/// State Launch: Player has begun swinging his weapon.
/// State Swing: Currently swinging weapon.
/// State Impact: Contact made, weapon still swinging.
/// State Cooldown: Swing completed, wait a minimum period before next.
///
/// Transition rules:
/// Ready -> Launch: When the minimum velocity of swing is achieved.
/// Launch -> Ready: When the minimum velocity of swing is lost before minimum distance was swung.
/// Launch -> Swing: When minimum distance is swung.
/// - Play Swish sound
/// Swing -> Impact: When minimum velocity is lost, or when a hit is detected.
/// - Register hit based on max velocity observed in swing state
/// Impact -> Cooldown: When velocity returns below minimum.
/// Cooldown -> Ready: When the minimum period has passed since entering Cooldown state
///
///
2021-05-20 20:40:48 +00:00
struct StateMachine : public VRTrackingListener
{
2020-06-28 09:33:01 +00:00
public:
2021-05-20 20:40:48 +00:00
StateMachine(MWWorld::Ptr ptr, VRPath trackingPath);
2020-06-28 09:33:01 +00:00
void update(float dt, bool enabled);
MWWorld::Ptr ptr() { return mPtr; }
2020-03-15 14:31:38 +00:00
2020-06-28 09:33:01 +00:00
protected:
2021-05-20 20:40:48 +00:00
void onTrackingUpdated(VRTrackingSource& source, DisplayTime predictedDisplayTime) override;
bool canSwing();
2020-03-23 22:32:47 +00:00
void playSwish();
void reset();
2020-03-15 14:31:38 +00:00
void transition(SwingState newState);
2020-03-15 14:31:38 +00:00
void update_cooldownState();
void transition_cooldownToReady();
2020-03-23 22:32:47 +00:00
void update_readyState();
void transition_readyToLaunch();
void update_launchState();
void transition_launchToReady();
void transition_launchToSwing();
2020-03-15 14:31:38 +00:00
void update_swingState();
void transition_swingingToImpact();
2020-03-15 14:31:38 +00:00
void update_impactState();
void transition_impactToCooldown();
2020-06-28 09:33:01 +00:00
private:
MWWorld::Ptr mPtr;
const float mMinVelocity;
const float mMaxVelocity;
float mVelocity = 0.f;
float mMaxSwingVelocity = 0.f;
SwingState mState = SwingState_Ready;
int mSwingType = -1;
float mStrength = 0.f;
float mThrustVelocity{ 0.f };
float mSlashChopVelocity{ 0.f };
float mSideVelocity{ 0.f };
float mMinimumPeriod{ .25f };
float mTimeSinceEnteredState = { 0.f };
float mMovementSinceEnteredState = { 0.f };
bool mEnabled = false;
2021-05-20 20:40:48 +00:00
osg::Vec3 mPreviousPosition{ 0.f,0.f,0.f };
VRTrackingPose mTrackingInput = VRTrackingPose();
VRPath mTrackingPath = 0;
};
2020-03-15 14:31:38 +00:00
}
}
2020-03-15 14:31:38 +00:00
#endif