diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index 1cc6eca2ab..dc21680af4 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -41,27 +41,25 @@ namespace MWInput A_MoveLeft, // Move player left / right A_MoveRight, - A_MoveUp, // Move up / down - A_MoveDown, A_MoveForward, // Forward / Backward A_MoveBackward, A_Activate, - A_Use, //Use weapon, spell, etc. + A_Use, //Use weapon, spell, etc. A_Jump, - A_AutoMove, //Toggle Auto-move forward - A_Rest, //Rest - A_Journal, //Journal - A_Weapon, //Draw/Sheath weapon - A_Spell, //Ready/Unready Casting - A_AlwaysRun, //Toggle Always Run + A_AutoMove, //Toggle Auto-move forward + A_Rest, //Rest + A_Journal, //Journal + A_Weapon, //Draw/Sheath weapon + A_Spell, //Ready/Unready Casting + A_AlwaysRun, //Toggle Always Run A_CycleSpellLeft, //cycling through spells A_CycleSpellRight, A_CycleWeaponLeft,//Cycling through weapons A_CycleWeaponRight, - A_ToggleSneak, //Toggles Sneak, add Push-Sneak later - A_ToggleWalk, //Toggle Walking/Running + A_ToggleSneak, //Toggles Sneak, add Push-Sneak later + A_ToggleWalk, //Toggle Walking/Running A_QuickSave, A_QuickLoad, @@ -143,24 +141,19 @@ namespace MWInput void toggleAutoMove() { - if (player.getAutoMove() == false) - { - player.setAutoMove(true); - } else { - player.setAutoMove(false); - } + player.setAutoMove (!player.getAutoMove()); } void toggleWalking() { - player.setisWalking(true); + player.toggleRunning(); } // Exit program now button (which is disabled in GUI mode) void exitNow() { - if(!windows.isGuiMode()) - exit.exitNow(); + if(!windows.isGuiMode()) + exit.exitNow(); } public: @@ -262,73 +255,54 @@ namespace MWInput poller.bind(A_MoveRight, KC_D); poller.bind(A_MoveForward, KC_W); 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 bool frameStarted(const Ogre::FrameEvent &evt) { - // Tell OIS to handle all input events - input.capture(); + // Tell OIS to handle all input events + input.capture(); - // Update windows/gui as a result of input events - // For instance this could mean opening a new window/dialog, - // by doing this after the input events are handled we - // ensure that window/gui changes appear quickly while - // avoiding that window/gui changes does not happen in - // event callbacks (which may crash) - windows.update(); + // Update windows/gui as a result of input events + // For instance this could mean opening a new window/dialog, + // by doing this after the input events are handled we + // ensure that window/gui changes appear quickly while + // avoiding that window/gui changes does not happen in + // event callbacks (which may crash) + windows.update(); - // Disable movement in Gui mode - if(windows.isGuiMode()) return true; + // Disable movement in Gui mode + if (windows.isGuiMode()) return true; - float speed = 300 * evt.timeSinceLastFrame; //placeholder player speed? - //float TESTwalkSpeed = 100 * evt.timeSinceLastFrame; //How about another? + // Configure player movement according to keyboard input. Actual movement will + // 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 - 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; + return true; } // Switch between gui modes. Besides controlling the Gui windows diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index b0805269dd..bdfc32c72f 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -4,11 +4,13 @@ #include "../mwrender/player.hpp" #include "world.hpp" +#include "class.hpp" namespace MWWorld { 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; mName = player->name; @@ -16,8 +18,6 @@ namespace MWWorld mRace = player->race; 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)); - mAutoMove = false; - misWalking = false; } Player::~Player() @@ -64,4 +64,45 @@ namespace MWWorld 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); + } } diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 5174c2d33d..1b28baf9b9 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -30,9 +30,8 @@ namespace MWWorld std::string mBirthsign; ESM::Class *mClass; bool mCollisionMode; - bool mAutoMove; - bool misWalking;//Testing... + int mForwardBackward; public: @@ -117,33 +116,13 @@ namespace MWWorld return mAutoMove; } - void setAutoMove(bool setMe) - { - mAutoMove = setMe; - } + void setAutoMove (bool enable); -//NOTE: we don't have speed being calculated yet, so for now this function only requires a frame duration. -/// float value representing time since last call - 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); - } - } + void setLeftRight (int value); - bool getisWalking() - { - return misWalking; - } + void setForwardBackward (int value); - void setisWalking(bool setMe) - { - misWalking = setMe; - } + void toggleRunning(); }; } #endif