mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 09:23:52 +00:00
replaced old movement input system
This commit is contained in:
parent
3cd1088695
commit
f773cf27cb
3 changed files with 100 additions and 106 deletions
|
@ -41,27 +41,25 @@ namespace MWInput
|
||||||
|
|
||||||
A_MoveLeft, // Move player left / right
|
A_MoveLeft, // Move player left / right
|
||||||
A_MoveRight,
|
A_MoveRight,
|
||||||
A_MoveUp, // Move up / down
|
|
||||||
A_MoveDown,
|
|
||||||
A_MoveForward, // Forward / Backward
|
A_MoveForward, // Forward / Backward
|
||||||
A_MoveBackward,
|
A_MoveBackward,
|
||||||
|
|
||||||
A_Activate,
|
A_Activate,
|
||||||
|
|
||||||
A_Use, //Use weapon, spell, etc.
|
A_Use, //Use weapon, spell, etc.
|
||||||
A_Jump,
|
A_Jump,
|
||||||
A_AutoMove, //Toggle Auto-move forward
|
A_AutoMove, //Toggle Auto-move forward
|
||||||
A_Rest, //Rest
|
A_Rest, //Rest
|
||||||
A_Journal, //Journal
|
A_Journal, //Journal
|
||||||
A_Weapon, //Draw/Sheath weapon
|
A_Weapon, //Draw/Sheath weapon
|
||||||
A_Spell, //Ready/Unready Casting
|
A_Spell, //Ready/Unready Casting
|
||||||
A_AlwaysRun, //Toggle Always Run
|
A_AlwaysRun, //Toggle Always Run
|
||||||
A_CycleSpellLeft, //cycling through spells
|
A_CycleSpellLeft, //cycling through spells
|
||||||
A_CycleSpellRight,
|
A_CycleSpellRight,
|
||||||
A_CycleWeaponLeft,//Cycling through weapons
|
A_CycleWeaponLeft,//Cycling through weapons
|
||||||
A_CycleWeaponRight,
|
A_CycleWeaponRight,
|
||||||
A_ToggleSneak, //Toggles Sneak, add Push-Sneak later
|
A_ToggleSneak, //Toggles Sneak, add Push-Sneak later
|
||||||
A_ToggleWalk, //Toggle Walking/Running
|
A_ToggleWalk, //Toggle Walking/Running
|
||||||
|
|
||||||
A_QuickSave,
|
A_QuickSave,
|
||||||
A_QuickLoad,
|
A_QuickLoad,
|
||||||
|
@ -143,24 +141,19 @@ namespace MWInput
|
||||||
|
|
||||||
void toggleAutoMove()
|
void toggleAutoMove()
|
||||||
{
|
{
|
||||||
if (player.getAutoMove() == false)
|
player.setAutoMove (!player.getAutoMove());
|
||||||
{
|
|
||||||
player.setAutoMove(true);
|
|
||||||
} else {
|
|
||||||
player.setAutoMove(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleWalking()
|
void toggleWalking()
|
||||||
{
|
{
|
||||||
player.setisWalking(true);
|
player.toggleRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit program now button (which is disabled in GUI mode)
|
// Exit program now button (which is disabled in GUI mode)
|
||||||
void exitNow()
|
void exitNow()
|
||||||
{
|
{
|
||||||
if(!windows.isGuiMode())
|
if(!windows.isGuiMode())
|
||||||
exit.exitNow();
|
exit.exitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -262,73 +255,54 @@ namespace MWInput
|
||||||
poller.bind(A_MoveRight, KC_D);
|
poller.bind(A_MoveRight, KC_D);
|
||||||
poller.bind(A_MoveForward, KC_W);
|
poller.bind(A_MoveForward, KC_W);
|
||||||
poller.bind(A_MoveBackward, KC_S);
|
poller.bind(A_MoveBackward, KC_S);
|
||||||
|
|
||||||
// Use shift and ctrl for up and down
|
|
||||||
poller.bind(A_MoveUp, KC_LSHIFT);
|
|
||||||
poller.bind(A_MoveDown, KC_LCONTROL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: Used to check for movement keys
|
//NOTE: Used to check for movement keys
|
||||||
bool frameStarted(const Ogre::FrameEvent &evt)
|
bool frameStarted(const Ogre::FrameEvent &evt)
|
||||||
{
|
{
|
||||||
// Tell OIS to handle all input events
|
// Tell OIS to handle all input events
|
||||||
input.capture();
|
input.capture();
|
||||||
|
|
||||||
// Update windows/gui as a result of input events
|
// Update windows/gui as a result of input events
|
||||||
// For instance this could mean opening a new window/dialog,
|
// For instance this could mean opening a new window/dialog,
|
||||||
// by doing this after the input events are handled we
|
// by doing this after the input events are handled we
|
||||||
// ensure that window/gui changes appear quickly while
|
// ensure that window/gui changes appear quickly while
|
||||||
// avoiding that window/gui changes does not happen in
|
// avoiding that window/gui changes does not happen in
|
||||||
// event callbacks (which may crash)
|
// event callbacks (which may crash)
|
||||||
windows.update();
|
windows.update();
|
||||||
|
|
||||||
// Disable movement in Gui mode
|
// Disable movement in Gui mode
|
||||||
if(windows.isGuiMode()) return true;
|
if (windows.isGuiMode()) return true;
|
||||||
|
|
||||||
float speed = 300 * evt.timeSinceLastFrame; //placeholder player speed?
|
// Configure player movement according to keyboard input. Actual movement will
|
||||||
//float TESTwalkSpeed = 100 * evt.timeSinceLastFrame; //How about another?
|
// be done in the physics system.
|
||||||
|
if (poller.isDown(A_MoveLeft))
|
||||||
|
{
|
||||||
|
player.setAutoMove (false);
|
||||||
|
player.setLeftRight (1);
|
||||||
|
}
|
||||||
|
else if (poller.isDown(A_MoveRight))
|
||||||
|
{
|
||||||
|
player.setAutoMove (false);
|
||||||
|
player.setLeftRight (-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.setLeftRight (0);
|
||||||
|
|
||||||
float moveX = 0, moveY = 0, moveZ = 0;
|
if (poller.isDown(A_MoveForward))
|
||||||
|
{
|
||||||
|
player.setAutoMove (false);
|
||||||
|
player.setForwardBackward (1);
|
||||||
|
}
|
||||||
|
else if (poller.isDown(A_MoveBackward))
|
||||||
|
{
|
||||||
|
player.setAutoMove (false);
|
||||||
|
player.setForwardBackward (-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.setForwardBackward (0);
|
||||||
|
|
||||||
//execute Automove - condition checked in function
|
return true;
|
||||||
player.executeAutoMove((float)evt.timeSinceLastFrame); //or since last frame?
|
|
||||||
|
|
||||||
//Poll and execute movement keys - will disable automove if pressed.
|
|
||||||
if(poller.isDown(A_MoveLeft))
|
|
||||||
{
|
|
||||||
player.setAutoMove(false);
|
|
||||||
moveX -= speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(poller.isDown(A_MoveRight))
|
|
||||||
{
|
|
||||||
player.setAutoMove(false);
|
|
||||||
moveX += speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(poller.isDown(A_MoveForward))
|
|
||||||
{
|
|
||||||
player.setAutoMove(false);
|
|
||||||
moveZ -= speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(poller.isDown(A_MoveBackward))
|
|
||||||
{
|
|
||||||
player.setAutoMove(false);
|
|
||||||
moveZ += speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: These should be enabled for floating modes (like
|
|
||||||
// swimming and levitation) and disabled for everything else.
|
|
||||||
if(poller.isDown(A_MoveUp)) moveY += speed;
|
|
||||||
if(poller.isDown(A_MoveDown)) moveY -= speed;
|
|
||||||
|
|
||||||
if(moveX != 0 || moveY != 0 || moveZ != 0)
|
|
||||||
player.moveRel(moveX, moveY, moveZ);
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch between gui modes. Besides controlling the Gui windows
|
// Switch between gui modes. Besides controlling the Gui windows
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
#include "../mwrender/player.hpp"
|
#include "../mwrender/player.hpp"
|
||||||
|
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
#include "class.hpp"
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) :
|
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) :
|
||||||
mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0), mCollisionMode (true)
|
mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0), mCollisionMode (true),
|
||||||
|
mAutoMove (false), mForwardBackward (0)
|
||||||
{
|
{
|
||||||
mPlayer.base = player;
|
mPlayer.base = player;
|
||||||
mName = player->name;
|
mName = player->name;
|
||||||
|
@ -16,8 +18,6 @@ namespace MWWorld
|
||||||
mRace = player->race;
|
mRace = player->race;
|
||||||
mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0;
|
mPlayer.ref.pos.pos[0] = mPlayer.ref.pos.pos[1] = mPlayer.ref.pos.pos[2] = 0;
|
||||||
mClass = new ESM::Class (*world.getStore().classes.find (player->cls));
|
mClass = new ESM::Class (*world.getStore().classes.find (player->cls));
|
||||||
mAutoMove = false;
|
|
||||||
misWalking = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
|
@ -64,4 +64,45 @@ namespace MWWorld
|
||||||
mClass = new_class;
|
mClass = new_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setAutoMove (bool enable)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr ptr = getPlayer();
|
||||||
|
|
||||||
|
mAutoMove = enable;
|
||||||
|
|
||||||
|
int value = mForwardBackward;
|
||||||
|
|
||||||
|
if (mAutoMove)
|
||||||
|
value = 1;
|
||||||
|
|
||||||
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mForwardBackward = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::setLeftRight (int value)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr ptr = getPlayer();
|
||||||
|
|
||||||
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mLeftRight = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::setForwardBackward (int value)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr ptr = getPlayer();
|
||||||
|
|
||||||
|
mForwardBackward = value;
|
||||||
|
|
||||||
|
if (mAutoMove)
|
||||||
|
value = 1;
|
||||||
|
|
||||||
|
MWWorld::Class::get (ptr).getMovementSettings (ptr).mForwardBackward = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::toggleRunning()
|
||||||
|
{
|
||||||
|
MWWorld::Ptr ptr = getPlayer();
|
||||||
|
|
||||||
|
bool running = MWWorld::Class::get (ptr).getStance (ptr, MWWorld::Class::Run, true);
|
||||||
|
|
||||||
|
MWWorld::Class::get (ptr).setStance (ptr, MWWorld::Class::Run, !running);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,8 @@ namespace MWWorld
|
||||||
std::string mBirthsign;
|
std::string mBirthsign;
|
||||||
ESM::Class *mClass;
|
ESM::Class *mClass;
|
||||||
bool mCollisionMode;
|
bool mCollisionMode;
|
||||||
|
|
||||||
bool mAutoMove;
|
bool mAutoMove;
|
||||||
bool misWalking;//Testing...
|
int mForwardBackward;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -117,33 +116,13 @@ namespace MWWorld
|
||||||
return mAutoMove;
|
return mAutoMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAutoMove(bool setMe)
|
void setAutoMove (bool enable);
|
||||||
{
|
|
||||||
mAutoMove = setMe;
|
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: we don't have speed being calculated yet, so for now this function only requires a frame duration.
|
void setLeftRight (int value);
|
||||||
/// <param name="duration">float value representing time since last call</param>
|
|
||||||
void executeAutoMove(float duration)
|
|
||||||
{
|
|
||||||
float X_Val = 0.0f;
|
|
||||||
float Y_Val = 0.0f;
|
|
||||||
float Z_Val = 300.0f * duration * -1.0f;
|
|
||||||
if (mAutoMove == true)
|
|
||||||
{
|
|
||||||
moveRel(X_Val, Y_Val, Z_Val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getisWalking()
|
void setForwardBackward (int value);
|
||||||
{
|
|
||||||
return misWalking;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setisWalking(bool setMe)
|
void toggleRunning();
|
||||||
{
|
|
||||||
misWalking = setMe;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue