mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 16:45:33 +00:00
Unite all viewer traversals.
This commit is contained in:
parent
e59fcf7613
commit
018e790ec0
11 changed files with 56 additions and 35 deletions
|
@ -1023,12 +1023,7 @@ void OMW::Engine::go()
|
|||
}
|
||||
else
|
||||
{
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
|
||||
mEnvironment.getWorld()->updateWindowManager();
|
||||
|
||||
mViewer->renderingTraversals();
|
||||
mEnvironment.getWindowManager()->viewerTraversals(true);
|
||||
|
||||
bool guiActive = mEnvironment.getWindowManager()->isGuiMode();
|
||||
if (!guiActive)
|
||||
|
|
|
@ -350,6 +350,8 @@ namespace MWBase
|
|||
|
||||
virtual void watchActor(const MWWorld::Ptr& ptr) = 0;
|
||||
virtual MWWorld::Ptr getWatchedActor() const = 0;
|
||||
|
||||
virtual void viewerTraversals(bool updateWindowManager) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -407,9 +407,7 @@ namespace MWGui
|
|||
// at the time this function is called we are in the middle of a frame,
|
||||
// so out of order calls are necessary to get a correct frameNumber for the next frame.
|
||||
// refer to the advance() and frame() order in Engine::go()
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
mViewer->renderingTraversals();
|
||||
MWBase::Environment::get().getWindowManager()->viewerTraversals(false);
|
||||
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
|
||||
|
||||
if (mHasCallback)
|
||||
|
|
|
@ -124,6 +124,8 @@
|
|||
#include "../mwvr/vrenvironment.hpp"
|
||||
#include "../mwvr/vrgui.hpp"
|
||||
#include "../mwvr/vrvirtualkeyboard.hpp"
|
||||
#include "../mwvr/vrviewer.hpp"
|
||||
#include "../mwvr/vrsession.hpp"
|
||||
#endif
|
||||
|
||||
namespace MWGui
|
||||
|
@ -770,11 +772,7 @@ namespace MWGui
|
|||
if (!mWindowVisible)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
else
|
||||
{
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
mViewer->renderingTraversals();
|
||||
}
|
||||
viewerTraversals(false);
|
||||
// at the time this function is called we are in the middle of a frame,
|
||||
// so out of order calls are necessary to get a correct frameNumber for the next frame.
|
||||
// refer to the advance() and frame() order in Engine::go()
|
||||
|
@ -1829,9 +1827,7 @@ namespace MWGui
|
|||
if (mVideoWidget->isPaused())
|
||||
mVideoWidget->resume();
|
||||
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
mViewer->renderingTraversals();
|
||||
viewerTraversals(false);
|
||||
}
|
||||
// at the time this function is called we are in the middle of a frame,
|
||||
// so out of order calls are necessary to get a correct frameNumber for the next frame.
|
||||
|
@ -2248,6 +2244,25 @@ namespace MWGui
|
|||
return MyGUI::InputManager::getInstance().injectKeyRelease(key);
|
||||
}
|
||||
|
||||
void WindowManager::viewerTraversals(bool updateWindowManager)
|
||||
{
|
||||
#ifdef USE_OPENXR
|
||||
if (MWBase::Environment::get().getVrMode())
|
||||
MWVR::Environment::get().getSession()->beginFrame();
|
||||
#endif
|
||||
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
if (updateWindowManager)
|
||||
MWBase::Environment::get().getWorld()->updateWindowManager();
|
||||
mViewer->renderingTraversals();
|
||||
|
||||
#ifdef USE_OPENXR
|
||||
if (MWBase::Environment::get().getVrMode())
|
||||
MWVR::Environment::get().getSession()->endFrame();
|
||||
#endif
|
||||
}
|
||||
|
||||
void WindowManager::GuiModeState::update(bool visible)
|
||||
{
|
||||
for (unsigned int i=0; i<mWindows.size(); ++i)
|
||||
|
|
|
@ -389,6 +389,7 @@ namespace MWGui
|
|||
bool injectKeyPress(MyGUI::KeyCode key, unsigned int text, bool repeat=false) override;
|
||||
bool injectKeyRelease(MyGUI::KeyCode key) override;
|
||||
|
||||
void viewerTraversals(bool updateWindowManager) override;
|
||||
private:
|
||||
unsigned int mOldUpdateMask; unsigned int mOldCullMask;
|
||||
|
||||
|
|
|
@ -927,9 +927,7 @@ namespace MWRender
|
|||
|
||||
MWBase::Environment::get().getWindowManager()->getLoadingScreen()->loadingOn(false);
|
||||
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
mViewer->renderingTraversals();
|
||||
MWBase::Environment::get().getWindowManager()->viewerTraversals(false);
|
||||
callback->waitTillDone();
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->getLoadingScreen()->loadingOff();
|
||||
|
@ -969,9 +967,6 @@ namespace MWRender
|
|||
void RenderingManager::screenshotFramebuffer(osg::Image* image, int w, int h)
|
||||
{
|
||||
osg::Camera* camera = mViewer->getCamera();
|
||||
#ifdef USE_OPENXR
|
||||
MWVR::Environment::get().getSession()->beginPhase(MWVR::VRSession::FramePhase::Update);
|
||||
#endif
|
||||
osg::ref_ptr<osg::Drawable> tempDrw = new osg::Drawable;
|
||||
tempDrw->setDrawCallback(new ReadImageFromFramebufferCallback(image, w, h));
|
||||
tempDrw->setCullingActive(false);
|
||||
|
@ -980,9 +975,7 @@ namespace MWRender
|
|||
osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback(mViewer->getFrameStamp()->getFrameNumber()));
|
||||
auto* oldCb = camera->getFinalDrawCallback();
|
||||
camera->setFinalDrawCallback(callback);
|
||||
mViewer->eventTraversal();
|
||||
mViewer->updateTraversal();
|
||||
mViewer->renderingTraversals();
|
||||
MWBase::Environment::get().getWindowManager()->viewerTraversals(false);
|
||||
callback->waitTillDone();
|
||||
// now that we've "used up" the current frame, get a fresh frame number for the next frame() following after the screenshot is completed
|
||||
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
|
||||
|
|
|
@ -394,12 +394,13 @@ namespace MWVR
|
|||
updateActivationIndication();
|
||||
|
||||
MWInput::InputManager::update(dt, disableControls, disableEvents);
|
||||
|
||||
// This is the first update that needs openxr tracking, so i begin the next frame here.
|
||||
auto* session = Environment::get().getSession();
|
||||
if (!session)
|
||||
return;
|
||||
|
||||
session->beginPhase(VRSession::FramePhase::Update);
|
||||
session->beginFrame();
|
||||
|
||||
// The rest of this code assumes the game is running
|
||||
if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame)
|
||||
|
|
|
@ -78,6 +78,26 @@ namespace MWVR
|
|||
}
|
||||
}
|
||||
|
||||
void VRSession::beginFrame()
|
||||
{
|
||||
// Viewer traversals are sometimes entered without first updating the input manager.
|
||||
if (getFrame(FramePhase::Update) == nullptr)
|
||||
{
|
||||
beginPhase(FramePhase::Update);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VRSession::endFrame()
|
||||
{
|
||||
// Make sure we don't continue until the render thread has moved the frame to its next phase.
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
while (getFrame(FramePhase::Update))
|
||||
{
|
||||
mCondition.wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
osg::Matrix VRSession::viewMatrix(osg::Vec3 position, osg::Quat orientation)
|
||||
{
|
||||
position = position * Constants::UnitsPerMeter;
|
||||
|
@ -179,7 +199,7 @@ namespace MWVR
|
|||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
while (getFrame(phase))
|
||||
{
|
||||
//Log(Debug::Verbose) << "Warning: beginPhase called with a frame already in the target phase";
|
||||
Log(Debug::Verbose) << "Warning: beginPhase called with a frame already in the target phase";
|
||||
mCondition.wait(lock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,9 @@ namespace MWVR
|
|||
|
||||
void processChangedSettings(const std::set< std::pair<std::string, std::string> >& changed);
|
||||
|
||||
void beginFrame();
|
||||
void endFrame();
|
||||
|
||||
private:
|
||||
std::mutex mMutex{};
|
||||
std::condition_variable mCondition{};
|
||||
|
|
|
@ -57,12 +57,6 @@ namespace MWVR
|
|||
{
|
||||
}
|
||||
|
||||
void VRViewer::traversals()
|
||||
{
|
||||
mViewer->updateTraversal();
|
||||
mViewer->renderingTraversals();
|
||||
}
|
||||
|
||||
int parseResolution(std::string conf, int recommended, int max)
|
||||
{
|
||||
if (Misc::StringUtils::isNumber(conf))
|
||||
|
|
|
@ -104,7 +104,6 @@ namespace MWVR
|
|||
|
||||
~VRViewer(void);
|
||||
|
||||
void traversals();
|
||||
void swapBuffersCallback(osg::GraphicsContext* gc);
|
||||
void initialDrawCallback(osg::RenderInfo& info);
|
||||
void preDrawCallback(osg::RenderInfo& info);
|
||||
|
|
Loading…
Reference in a new issue