mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 18:39:40 +00:00
commit
354f904a24
5 changed files with 46 additions and 47 deletions
|
@ -213,8 +213,7 @@ namespace MWGui
|
||||||
map->setNeedMouseFocus(false);
|
map->setNeedMouseFocus(false);
|
||||||
fog->setNeedMouseFocus(false);
|
fog->setNeedMouseFocus(false);
|
||||||
|
|
||||||
mMapWidgets.push_back(map);
|
mMaps.emplace_back(map, fog);
|
||||||
mFogWidgets.push_back(fog);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,36 +233,37 @@ namespace MWGui
|
||||||
|
|
||||||
void LocalMapBase::applyFogOfWar()
|
void LocalMapBase::applyFogOfWar()
|
||||||
{
|
{
|
||||||
TextureVector fogTextures;
|
|
||||||
for (int mx=0; mx<mNumCells; ++mx)
|
for (int mx=0; mx<mNumCells; ++mx)
|
||||||
{
|
{
|
||||||
for (int my=0; my<mNumCells; ++my)
|
for (int my=0; my<mNumCells; ++my)
|
||||||
{
|
{
|
||||||
int x = mCurX + (mx - mCellDistance);
|
int x = mCurX + (mx - mCellDistance);
|
||||||
int y = mCurY + (-1*(my - mCellDistance));
|
int y = mCurY + (-1*(my - mCellDistance));
|
||||||
MyGUI::ImageBox* fog = mFogWidgets[my + mNumCells*mx];
|
|
||||||
|
MapEntry& entry = mMaps[my + mNumCells*mx];
|
||||||
|
MyGUI::ImageBox* fog = entry.mFogWidget;
|
||||||
|
|
||||||
if (!mFogOfWarToggled || !mFogOfWarEnabled)
|
if (!mFogOfWarToggled || !mFogOfWarEnabled)
|
||||||
{
|
{
|
||||||
fog->setImageTexture("");
|
fog->setImageTexture("");
|
||||||
|
entry.mFogTexture.reset();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> tex = mLocalMapRender->getFogOfWarTexture(x, y);
|
osg::ref_ptr<osg::Texture2D> tex = mLocalMapRender->getFogOfWarTexture(x, y);
|
||||||
if (tex)
|
if (tex)
|
||||||
{
|
{
|
||||||
std::shared_ptr<MyGUI::ITexture> myguitex (new osgMyGUI::OSGTexture(tex));
|
entry.mFogTexture.reset(new osgMyGUI::OSGTexture(tex));
|
||||||
fog->setRenderItemTexture(myguitex.get());
|
fog->setRenderItemTexture(entry.mFogTexture.get());
|
||||||
fog->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 1.f, 1.f, 0.f));
|
fog->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 1.f, 1.f, 0.f));
|
||||||
fogTextures.push_back(myguitex);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
fog->setImageTexture("black");
|
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();
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,6 @@ namespace MWGui
|
||||||
applyFogOfWar();
|
applyFogOfWar();
|
||||||
|
|
||||||
// Update the map textures
|
// Update the map textures
|
||||||
TextureVector textures;
|
|
||||||
for (int mx=0; mx<mNumCells; ++mx)
|
for (int mx=0; mx<mNumCells; ++mx)
|
||||||
{
|
{
|
||||||
for (int my=0; my<mNumCells; ++my)
|
for (int my=0; my<mNumCells; ++my)
|
||||||
|
@ -377,21 +376,23 @@ namespace MWGui
|
||||||
int mapX = x + (mx - mCellDistance);
|
int mapX = x + (mx - mCellDistance);
|
||||||
int mapY = y + (-1*(my - mCellDistance));
|
int mapY = y + (-1*(my - mCellDistance));
|
||||||
|
|
||||||
MyGUI::ImageBox* box = mMapWidgets[my + mNumCells*mx];
|
MapEntry& entry = mMaps[my + mNumCells*mx];
|
||||||
|
MyGUI::ImageBox* box = entry.mMapWidget;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> texture = mLocalMapRender->getMapTexture(mapX, mapY);
|
osg::ref_ptr<osg::Texture2D> texture = mLocalMapRender->getMapTexture(mapX, mapY);
|
||||||
if (texture)
|
if (texture)
|
||||||
{
|
{
|
||||||
std::shared_ptr<MyGUI::ITexture> guiTex (new osgMyGUI::OSGTexture(texture));
|
entry.mMapTexture.reset(new osgMyGUI::OSGTexture(texture));
|
||||||
textures.push_back(guiTex);
|
box->setRenderItemTexture(entry.mMapTexture.get());
|
||||||
box->setRenderItemTexture(guiTex.get());
|
|
||||||
box->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
box->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
box->setRenderItemTexture(nullptr);
|
box->setRenderItemTexture(nullptr);
|
||||||
|
entry.mMapTexture.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mMapTextures.swap(textures);
|
|
||||||
|
|
||||||
// Delay the door markers update until scripts have been given a chance to run.
|
// 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.
|
// If we don't do this, door markers that should be disabled will still appear on the map.
|
||||||
|
@ -837,22 +838,13 @@ namespace MWGui
|
||||||
|
|
||||||
void MapWindow::cellExplored(int x, int y)
|
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)
|
void MapWindow::onFrame(float dt)
|
||||||
{
|
{
|
||||||
LocalMapBase::onFrame(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);
|
NoDrop::onFrame(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1055,8 +1047,8 @@ namespace MWGui
|
||||||
NoDrop::setAlpha(alpha);
|
NoDrop::setAlpha(alpha);
|
||||||
// can't allow showing map with partial transparency, as the fog of war will also go transparent
|
// 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
|
// and reveal parts of the map you shouldn't be able to see
|
||||||
for (MyGUI::ImageBox* widget : mMapWidgets)
|
for (MapEntry& entry : mMaps)
|
||||||
widget->setVisible(alpha == 1);
|
entry.mMapWidget->setVisible(alpha == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWindow::customMarkerCreated(MyGUI::Widget *marker)
|
void MapWindow::customMarkerCreated(MyGUI::Widget *marker)
|
||||||
|
|
|
@ -126,12 +126,17 @@ namespace MWGui
|
||||||
// Stores markers that were placed by a player. May be shared between multiple map views.
|
// Stores markers that were placed by a player. May be shared between multiple map views.
|
||||||
CustomMarkerCollection& mCustomMarkers;
|
CustomMarkerCollection& mCustomMarkers;
|
||||||
|
|
||||||
std::vector<MyGUI::ImageBox*> mMapWidgets;
|
struct MapEntry
|
||||||
std::vector<MyGUI::ImageBox*> mFogWidgets;
|
{
|
||||||
|
MapEntry(MyGUI::ImageBox* mapWidget, MyGUI::ImageBox* fogWidget)
|
||||||
|
: mMapWidget(mapWidget), mFogWidget(fogWidget) {}
|
||||||
|
|
||||||
typedef std::vector<std::shared_ptr<MyGUI::ITexture> > TextureVector;
|
MyGUI::ImageBox* mMapWidget;
|
||||||
TextureVector mMapTextures;
|
MyGUI::ImageBox* mFogWidget;
|
||||||
TextureVector mFogTextures;
|
std::shared_ptr<MyGUI::ITexture> mMapTexture;
|
||||||
|
std::shared_ptr<MyGUI::ITexture> mFogTexture;
|
||||||
|
};
|
||||||
|
std::vector<MapEntry> mMaps;
|
||||||
|
|
||||||
// Keep track of created marker widgets, just to easily remove them later.
|
// Keep track of created marker widgets, just to easily remove them later.
|
||||||
std::vector<MyGUI::Widget*> mDoorMarkerWidgets;
|
std::vector<MyGUI::Widget*> mDoorMarkerWidgets;
|
||||||
|
@ -261,10 +266,6 @@ namespace MWGui
|
||||||
typedef std::pair<int, int> CellId;
|
typedef std::pair<int, int> CellId;
|
||||||
std::set<CellId> mMarkers;
|
std::set<CellId> 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<CellId> mQueuedToExplore;
|
|
||||||
|
|
||||||
MyGUI::Button* mEventBoxGlobal;
|
MyGUI::Button* mEventBoxGlobal;
|
||||||
MyGUI::Button* mEventBoxLocal;
|
MyGUI::Button* mEventBoxLocal;
|
||||||
|
|
||||||
|
|
|
@ -1027,9 +1027,6 @@ namespace MWGui
|
||||||
|
|
||||||
updateMap();
|
updateMap();
|
||||||
|
|
||||||
if (!mMap->isVisible())
|
|
||||||
mMap->onFrame(frameDuration);
|
|
||||||
|
|
||||||
mHud->onFrame(frameDuration);
|
mHud->onFrame(frameDuration);
|
||||||
|
|
||||||
mDebugWindow->onFrame(frameDuration);
|
mDebugWindow->onFrame(frameDuration);
|
||||||
|
|
|
@ -293,7 +293,7 @@ namespace MWRender
|
||||||
camera->setViewMatrix(osg::Matrix::identity());
|
camera->setViewMatrix(osg::Matrix::identity());
|
||||||
camera->setProjectionMatrix(osg::Matrix::identity());
|
camera->setProjectionMatrix(osg::Matrix::identity());
|
||||||
camera->setProjectionResizePolicy(osg::Camera::FIXED);
|
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
|
y = mHeight - y - height; // convert top-left origin to bottom-left
|
||||||
camera->setViewport(x, y, width, height);
|
camera->setViewport(x, y, width, height);
|
||||||
|
|
||||||
|
|
|
@ -613,7 +613,8 @@ void LocalMap::updatePlayer (const osg::Vec3f& position, const osg::Quat& orient
|
||||||
if (!segment.mFogOfWarImage || !segment.mMapTexture)
|
if (!segment.mFogOfWarImage || !segment.mMapTexture)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
unsigned char* data = segment.mFogOfWarImage->data();
|
uint32_t* data = (uint32_t*)segment.mFogOfWarImage->data();
|
||||||
|
bool changed = false;
|
||||||
for (int texV = 0; texV<sFogOfWarResolution; ++texV)
|
for (int texV = 0; texV<sFogOfWarResolution; ++texV)
|
||||||
{
|
{
|
||||||
for (int texU = 0; texU<sFogOfWarResolution; ++texU)
|
for (int texU = 0; texU<sFogOfWarResolution; ++texU)
|
||||||
|
@ -625,14 +626,22 @@ void LocalMap::updatePlayer (const osg::Vec3f& position, const osg::Quat& orient
|
||||||
uint8_t alpha = (clr >> 24);
|
uint8_t alpha = (clr >> 24);
|
||||||
|
|
||||||
alpha = std::min( alpha, (uint8_t) (std::max(0.f, std::min(1.f, (sqrDist/sqrExploreRadius)))*255) );
|
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;
|
if (changed)
|
||||||
segment.mFogOfWarImage->dirty();
|
{
|
||||||
|
segment.mHasFogState = true;
|
||||||
|
segment.mFogOfWarImage->dirty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue