Refactor: InputManager no longer depends on Engine

openmw-38
scrawl 9 years ago
parent 1402a16702
commit 05498ad592

@ -483,8 +483,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
else
gameControllerdb = ""; //if it doesn't exist, pass in an empty string
// FIXME: shouldn't depend on Engine
MWInput::InputManager* input = new MWInput::InputManager (mWindow, mViewer, *this, keybinderUser, keybinderUserExists, gameControllerdb, mGrab);
MWInput::InputManager* input = new MWInput::InputManager (mWindow, mViewer, mScreenCaptureHandler, keybinderUser, keybinderUserExists, gameControllerdb, mGrab);
mEnvironment.setInputManager (input);
std::string myguiResources = (mResDir / "mygui").string();
@ -717,41 +716,6 @@ void OMW::Engine::go()
std::cout << "Quitting peacefully." << std::endl;
}
void OMW::Engine::activate()
{
if (mEnvironment.getWindowManager()->isGuiMode())
return;
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
const MWMechanics::NpcStats &playerStats = player.getClass().getNpcStats(player);
if (playerStats.isParalyzed() || playerStats.getKnockedDown())
return;
MWWorld::Ptr ptr = mEnvironment.getWorld()->getFacedObject();
if (ptr.isEmpty())
return;
if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
return;
if (ptr.getClass().isActor())
{
MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);
if (stats.getAiSequence().isInCombat() && !stats.isDead())
return;
}
mEnvironment.getWorld()->activate(ptr, mEnvironment.getWorld()->getPlayerPtr());
}
void OMW::Engine::screenshot()
{
mScreenCaptureHandler->setFramesToCapture(1);
mScreenCaptureHandler->captureNextFrame(*mViewer);
}
void OMW::Engine::setCompileAll (bool all)
{
mCompileAll = all;

@ -169,12 +169,6 @@ namespace OMW
/// Initialise and enter main loop.
void go();
/// Activate the focussed object.
void activate();
/// Write screenshot to file.
void screenshot();
/// Compile all scripts (excludign dialogue scripts) at startup?
void setCompileAll (bool all);

@ -4,6 +4,8 @@
#include <boost/lexical_cast.hpp>
#include <osgViewer/ViewerEventHandlers>
#include <MyGUI_InputManager.h>
#include <MyGUI_RenderManager.h>
#include <MyGUI_Widget.h>
@ -15,12 +17,11 @@
#include <components/sdlutil/sdlinputwrapper.hpp>
#include <components/sdlutil/sdlvideowrapper.hpp>
#include "../engine.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/statemanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/class.hpp"
@ -37,15 +38,15 @@ namespace MWInput
InputManager::InputManager(
SDL_Window* window,
osg::ref_ptr<osgViewer::Viewer> viewer,
OMW::Engine& engine,
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
const std::string& userFile, bool userFileExists,
const std::string& controllerBindingsFile, bool grab)
: mWindow(window)
, mWindowVisible(true)
, mViewer(viewer)
, mScreenCaptureHandler(screenCaptureHandler)
, mJoystickLastUsed(false)
, mPlayer(NULL)
, mEngine(engine)
, mInputManager(NULL)
, mVideoWrapper(NULL)
, mUserFile(userFile)
@ -952,7 +953,8 @@ namespace MWInput
void InputManager::screenshot()
{
mEngine.screenshot();
mScreenCaptureHandler->setFramesToCapture(1);
mScreenCaptureHandler->captureNextFrame(*mViewer);
MWBase::Environment::get().getWindowManager()->messageBox ("Screenshot saved");
}
@ -1058,7 +1060,7 @@ namespace MWInput
void InputManager::activate()
{
if (mControlSwitch["playercontrols"])
mEngine.activate();
mPlayer->activate();
}
void InputManager::toggleAutoMove()

@ -25,11 +25,6 @@ namespace MWBase
class WindowManager;
}
namespace OMW
{
class Engine;
}
namespace ICS
{
class InputControlSystem;
@ -54,6 +49,7 @@ namespace SDLUtil
namespace osgViewer
{
class Viewer;
class ScreenCaptureHandler;
}
struct SDL_Window;
@ -77,7 +73,7 @@ namespace MWInput
InputManager(
SDL_Window* window,
osg::ref_ptr<osgViewer::Viewer> viewer,
OMW::Engine& engine,
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
const std::string& userFile, bool userFileExists,
const std::string& controllerBindingsFile, bool grab);
@ -157,10 +153,10 @@ namespace MWInput
SDL_Window* mWindow;
bool mWindowVisible;
osg::ref_ptr<osgViewer::Viewer> mViewer;
osg::ref_ptr<osgViewer::ScreenCaptureHandler> mScreenCaptureHandler;
bool mJoystickLastUsed;
MWWorld::Player* mPlayer;
OMW::Engine& mEngine;
ICS::InputControlSystem* mInputBinder;

@ -205,6 +205,35 @@ namespace MWWorld
return ptr.getClass().getNpcStats(ptr).getDrawState();
}
void Player::activate()
{
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
return;
MWWorld::Ptr player = getPlayer();
const MWMechanics::NpcStats &playerStats = player.getClass().getNpcStats(player);
if (playerStats.isParalyzed() || playerStats.getKnockedDown())
return;
MWWorld::Ptr toActivate = MWBase::Environment::get().getWorld()->getFacedObject();
if (toActivate.isEmpty())
return;
if (toActivate.getClass().getName(toActivate) == "") // objects without name presented to user can never be activated
return;
if (toActivate.getClass().isActor())
{
MWMechanics::CreatureStats &stats = toActivate.getClass().getCreatureStats(toActivate);
if (stats.getAiSequence().isInCombat() && !stats.isDead())
return;
}
MWBase::Environment::get().getWorld()->activate(toActivate, player);
}
bool Player::wasTeleported() const
{
return mTeleported;

@ -82,6 +82,9 @@ namespace MWWorld
void setDrawState (MWMechanics::DrawState_ state);
MWMechanics::DrawState_ getDrawState(); /// \todo constness
/// Activate the object under the crosshair, if any
void activate();
bool getAutoMove() const;
void setAutoMove (bool enable);

Loading…
Cancel
Save