Interactions between LuaManager and other parts of OpenMW

dont-compose-content
Petr Mikheev 4 years ago
parent f2d0a702e9
commit 914e604e06

@ -6,6 +6,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/player.hpp"
@ -58,6 +59,9 @@ namespace MWInput
if (!input->controlsDisabled() && !consumed)
mBindingsManager->keyPressed(arg);
if (!consumed)
MWBase::Environment::get().getLuaManager()->keyPressed(arg);
input->setJoystickLastUsed(false);
}

@ -24,6 +24,7 @@
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/statemanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwmechanics/aibreathe.hpp"
@ -2009,6 +2010,25 @@ namespace MWMechanics
return; // for now abort update of the old cell when cell changes by teleportation magic effect
// a better solution might be to apply cell changes at the end of the frame
}
bool controlledFromLua;
{
const MWBase::LuaManager::ActorControls* luaControls =
MWBase::Environment::get().getLuaManager()->getActorControls(iter->first);
controlledFromLua = luaControls && luaControls->controlledFromLua;
if (controlledFromLua && isConscious(iter->first))
{
Movement& mov = iter->first.getClass().getMovementSettings(iter->first);
mov.mPosition[0] = luaControls->sideMovement;
mov.mPosition[1] = luaControls->movement;
mov.mPosition[2] = luaControls->jump ? 1 : 0;
mov.mRotation[0] = mov.mRotation[1] = 0;
mov.mRotation[2] = luaControls->turn;
mov.mSpeedFactor = osg::Vec2(luaControls->movement, luaControls->sideMovement).length();
CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first);
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, luaControls->run);
}
}
if (aiActive && inProcessingRange)
{
if (engageCombatTimerStatus == Misc::TimerStatus::Elapsed)
@ -2062,7 +2082,7 @@ namespace MWMechanics
if (iter->first != player)
{
CreatureStats &stats = iter->first.getClass().getCreatureStats(iter->first);
if (isConscious(iter->first))
if (isConscious(iter->first) && !controlledFromLua)
{
stats.getAiSequence().execute(iter->first, *ctrl, duration);
updateGreetingState(iter->first, *iter->second, timerUpdateHello > 0);
@ -2071,7 +2091,7 @@ namespace MWMechanics
}
}
}
else if (aiActive && iter->first != player && isConscious(iter->first))
else if (aiActive && iter->first != player && isConscious(iter->first) && !controlledFromLua)
{
CreatureStats &stats = iter->first.getClass().getCreatureStats(iter->first);
stats.getAiSequence().execute(iter->first, *ctrl, duration, /*outOfRange*/true);

@ -27,6 +27,7 @@
#include "../mwbase/scriptmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/class.hpp"
@ -59,6 +60,7 @@ void MWState::StateManager::cleanup (bool force)
MWMechanics::CreatureStats::cleanup();
}
MWBase::Environment::get().getLuaManager()->clear();
}
std::map<int, int> MWState::StateManager::buildContentFileIndexMap (const ESM::ESMReader& reader)
@ -146,7 +148,7 @@ void MWState::StateManager::newGame (bool bypass)
{
Log(Debug::Info) << "Starting a new game";
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addStartup();
MWBase::Environment::get().getLuaManager()->newGameStarted();
MWBase::Environment::get().getWorld()->startNewGame (bypass);
mState = State_Running;

@ -25,6 +25,7 @@
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwrender/renderingmanager.hpp"
#include "../mwrender/landmanager.hpp"
@ -138,6 +139,8 @@ namespace
if (!physics.getObject(ptr))
ptr.getClass().insertObject (ptr, model, rotation, physics);
MWBase::Environment::get().getLuaManager()->objectAddedToScene(ptr);
}
void addObject(const MWWorld::Ptr& ptr, const MWPhysics::PhysicsSystem& physics, DetourNavigator::Navigator& navigator)
@ -385,6 +388,7 @@ namespace MWWorld
mRendering.removeActorPath(ptr);
mPhysics->remove(ptr);
}
MWBase::Environment::get().getLuaManager()->objectRemovedFromScene(ptr);
}
const auto cellX = cell->getCell()->getGridX();
@ -1006,6 +1010,7 @@ namespace MWWorld
{
MWBase::Environment::get().getMechanicsManager()->remove (ptr);
MWBase::Environment::get().getSoundManager()->stopSound3D (ptr);
MWBase::Environment::get().getLuaManager()->objectRemovedFromScene(ptr);
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
if (const auto object = mPhysics->getObject(ptr))
{

@ -36,6 +36,7 @@
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
@ -2483,12 +2484,14 @@ namespace MWWorld
mNavigator->removeAgent(getPathfindingHalfExtents(getPlayerConstPtr()));
mPhysics->remove(getPlayerPtr());
mRendering->removePlayer(getPlayerPtr());
MWBase::Environment::get().getLuaManager()->objectRemovedFromScene(getPlayerPtr());
mPlayer->set(player);
}
Ptr ptr = mPlayer->getPlayer();
mRendering->setupPlayer(ptr);
MWBase::Environment::get().getLuaManager()->setupPlayer(ptr);
}
void World::renderPlayer()

Loading…
Cancel
Save