From c2176945bd8cdfe8b5c34563e05bac68584585c4 Mon Sep 17 00:00:00 2001 From: bzzt Date: Thu, 28 Feb 2019 09:10:22 +0400 Subject: [PATCH 1/3] Do not use the delayed map cells update --- apps/openmw/mwgui/mapwindow.cpp | 13 ++----------- apps/openmw/mwgui/mapwindow.hpp | 4 ---- apps/openmw/mwgui/windowmanagerimp.cpp | 3 --- apps/openmw/mwrender/globalmap.cpp | 2 +- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index f3bdd4c7d..a6e9c9818 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -837,22 +837,13 @@ namespace MWGui void MapWindow::cellExplored(int x, int y) { - mQueuedToExplore.push_back(std::make_pair(x,y)); + mGlobalMapRender->cleanupCameras(); + mGlobalMapRender->exploreCell(x, y, mLocalMapRender->getMapTexture(x, y)); } void MapWindow::onFrame(float dt) { LocalMapBase::onFrame(dt); - - mGlobalMapRender->cleanupCameras(); - - for (CellId& cellId : mQueuedToExplore) - { - mGlobalMapRender->exploreCell(cellId.first, cellId.second, mLocalMapRender->getMapTexture(cellId.first, cellId.second)); - } - - mQueuedToExplore.clear(); - NoDrop::onFrame(dt); } diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index 3d9ca23d8..033672c7f 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -261,10 +261,6 @@ namespace MWGui typedef std::pair CellId; std::set mMarkers; - // Cells that should be explored in the next frame (i.e. their map revealed on the global map) - // We can't do this immediately, because the map update is not immediate either (see mNeedMapUpdate in scene.cpp) - std::vector mQueuedToExplore; - MyGUI::Button* mEventBoxGlobal; MyGUI::Button* mEventBoxLocal; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index badfa2f3c..abd483a72 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1027,9 +1027,6 @@ namespace MWGui updateMap(); - if (!mMap->isVisible()) - mMap->onFrame(frameDuration); - mHud->onFrame(frameDuration); mDebugWindow->onFrame(frameDuration); diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index 588039639..57137d415 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -293,7 +293,7 @@ namespace MWRender camera->setViewMatrix(osg::Matrix::identity()); camera->setProjectionMatrix(osg::Matrix::identity()); camera->setProjectionResizePolicy(osg::Camera::FIXED); - camera->setRenderOrder(osg::Camera::PRE_RENDER); + camera->setRenderOrder(osg::Camera::PRE_RENDER, 1); // Make sure the global map is rendered after the local map y = mHeight - y - height; // convert top-left origin to bottom-left camera->setViewport(x, y, width, height); From 231e629e66f70dfcf59c9bdd8bb09fcab1ee82e4 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 2/3] Store map widgets and textures in one vector instead of 4 different ones --- apps/openmw/mwgui/mapwindow.cpp | 37 +++++++++++++++++---------------- apps/openmw/mwgui/mapwindow.hpp | 15 ++++++++----- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index a6e9c9818..5f4c9971c 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -213,8 +213,7 @@ namespace MWGui map->setNeedMouseFocus(false); fog->setNeedMouseFocus(false); - mMapWidgets.push_back(map); - mFogWidgets.push_back(fog); + mMaps.emplace_back(map, fog); } } } @@ -234,36 +233,37 @@ namespace MWGui void LocalMapBase::applyFogOfWar() { - TextureVector fogTextures; for (int mx=0; mxsetImageTexture(""); + entry.mFogTexture.reset(); continue; } osg::ref_ptr tex = mLocalMapRender->getFogOfWarTexture(x, y); if (tex) { - std::shared_ptr myguitex (new osgMyGUI::OSGTexture(tex)); - fog->setRenderItemTexture(myguitex.get()); + entry.mFogTexture.reset(new osgMyGUI::OSGTexture(tex)); + fog->setRenderItemTexture(entry.mFogTexture.get()); fog->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 1.f, 1.f, 0.f)); - fogTextures.push_back(myguitex); } else + { fog->setImageTexture("black"); + entry.mFogTexture.reset(); + } } } - // Move the textures we just set into mFogTextures, and move the previous textures into fogTextures, for deletion when this function ends. - // Note, above we need to ensure that all widgets are getting a new texture set, lest we delete textures that are still in use. - mFogTextures.swap(fogTextures); redraw(); } @@ -369,7 +369,6 @@ namespace MWGui applyFogOfWar(); // Update the map textures - TextureVector textures; for (int mx=0; mx texture = mLocalMapRender->getMapTexture(mapX, mapY); if (texture) { - std::shared_ptr guiTex (new osgMyGUI::OSGTexture(texture)); - textures.push_back(guiTex); - box->setRenderItemTexture(guiTex.get()); + entry.mMapTexture.reset(new osgMyGUI::OSGTexture(texture)); + box->setRenderItemTexture(entry.mMapTexture.get()); box->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f)); } else + { box->setRenderItemTexture(nullptr); + entry.mMapTexture.reset(); + } } } - mMapTextures.swap(textures); // Delay the door markers update until scripts have been given a chance to run. // If we don't do this, door markers that should be disabled will still appear on the map. @@ -1046,8 +1047,8 @@ namespace MWGui NoDrop::setAlpha(alpha); // can't allow showing map with partial transparency, as the fog of war will also go transparent // and reveal parts of the map you shouldn't be able to see - for (MyGUI::ImageBox* widget : mMapWidgets) - widget->setVisible(alpha == 1); + for (MapEntry& entry : mMaps) + entry.mMapWidget->setVisible(alpha == 1); } void MapWindow::customMarkerCreated(MyGUI::Widget *marker) diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index 033672c7f..4104a7824 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -126,12 +126,17 @@ namespace MWGui // Stores markers that were placed by a player. May be shared between multiple map views. CustomMarkerCollection& mCustomMarkers; - std::vector mMapWidgets; - std::vector mFogWidgets; + struct MapEntry + { + MapEntry(MyGUI::ImageBox* mapWidget, MyGUI::ImageBox* fogWidget) + : mMapWidget(mapWidget), mFogWidget(fogWidget) {} - typedef std::vector > TextureVector; - TextureVector mMapTextures; - TextureVector mFogTextures; + MyGUI::ImageBox* mMapWidget; + MyGUI::ImageBox* mFogWidget; + std::shared_ptr mMapTexture; + std::shared_ptr mFogTexture; + }; + std::vector mMaps; // Keep track of created marker widgets, just to easily remove them later. std::vector mDoorMarkerWidgets; From 1143985bc7559e5f19d996eeac7a04c4a3edd30d Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 3/3] Do not update map texture if it did not change --- apps/openmw/mwrender/localmap.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 1650dc92c..6c8dfec60 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -613,7 +613,8 @@ void LocalMap::updatePlayer (const osg::Vec3f& position, const osg::Quat& orient if (!segment.mFogOfWarImage || !segment.mMapTexture) continue; - unsigned char* data = segment.mFogOfWarImage->data(); + uint32_t* data = (uint32_t*)segment.mFogOfWarImage->data(); + bool changed = false; for (int texV = 0; texV> 24); alpha = std::min( alpha, (uint8_t) (std::max(0.f, std::min(1.f, (sqrDist/sqrExploreRadius)))*255) ); - *(uint32_t*)data = (uint32_t) (alpha << 24); + uint32_t val = (uint32_t) (alpha << 24); + if ( *data != val) + { + *data = val; + changed = true; + } - data += 4; + ++data; } } - segment.mHasFogState = true; - segment.mFogOfWarImage->dirty(); + if (changed) + { + segment.mHasFogState = true; + segment.mFogOfWarImage->dirty(); + } } } }