From 3878a12ed31961e77ad94607c164ac08fe541043 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 6 Sep 2021 00:40:13 +0200 Subject: [PATCH] Delay cell grid change until scene update This allows proper profiling. Changing cell grid is not a part of physics system, it's a part of world system. --- apps/openmw/mwworld/scene.cpp | 14 +++++++++++++- apps/openmw/mwworld/scene.hpp | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 1cb80389ce..07a613db4a 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -296,6 +296,13 @@ namespace MWWorld void Scene::update (float duration, bool paused) { + if (mChangeCellGridRequest.has_value()) + { + changeCellGrid(mChangeCellGridRequest->mPosition, mChangeCellGridRequest->mCell.x(), + mChangeCellGridRequest->mCell.y(), mChangeCellGridRequest->mChangeEvent); + mChangeCellGridRequest.reset(); + } + mPreloader->updateCache(mRendering.getReferenceTime()); preloadCells(duration); @@ -515,7 +522,12 @@ namespace MWWorld osg::Vec2i newCell = getNewGridCenter(pos, &mCurrentGridCenter); if (newCell != mCurrentGridCenter) - changeCellGrid(pos, newCell.x(), newCell.y()); + requestChangeCellGrid(pos, newCell); + } + + void Scene::requestChangeCellGrid(const osg::Vec3f &position, const osg::Vec2i& cell, bool changeEvent) + { + mChangeCellGridRequest = ChangeCellGridRequest {position, cell, changeEvent}; } void Scene::changeCellGrid (const osg::Vec3f &pos, int playerCellX, int playerCellY, bool changeEvent) diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index c0b6f5ae46..464088f223 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -74,6 +75,12 @@ namespace MWWorld using CellStoreCollection = std::set; private: + struct ChangeCellGridRequest + { + osg::Vec3f mPosition; + osg::Vec2i mCell; + bool mChangeEvent; + }; CellStore* mCurrentCell; // the cell the player is in CellStoreCollection mActiveCells; @@ -99,12 +106,16 @@ namespace MWWorld std::vector> mWorkItems; + std::optional mChangeCellGridRequest; + void insertCell(CellStore &cell, Loading::Listener* loadingListener); osg::Vec2i mCurrentGridCenter; // Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center void changeCellGrid (const osg::Vec3f &pos, int playerCellX, int playerCellY, bool changeEvent = true); + void requestChangeCellGrid(const osg::Vec3f &position, const osg::Vec2i& cell, bool changeEvent = true); + typedef std::pair PositionCellGrid; void preloadCells(float dt); @@ -131,7 +142,7 @@ namespace MWWorld void playerMoved (const osg::Vec3f& pos); - void changePlayerCell (CellStore* newCell, const ESM::Position& position, bool adjustPlayerPos); + void changePlayerCell(CellStore* newCell, const ESM::Position& position, bool adjustPlayerPos); CellStore *getCurrentCell();