Update cell local map on different neighbour cells

backport_gl_clamp_removal
elsid 1 year ago
parent 2d25ffeb89
commit ab0a460a6f
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -177,28 +177,28 @@ void LocalMap::setupRenderToTexture(int segment_x, int segment_y, float left, fl
void LocalMap::requestMap(const MWWorld::CellStore* cell)
{
if (cell->isExterior())
if (!cell->isExterior())
{
int cellX = cell->getCell()->getGridX();
int cellY = cell->getCell()->getGridY();
MapSegment& segment = mExteriorSegments[std::make_pair(cellX, cellY)];
if (!segment.needUpdate)
return;
else
{
requestExteriorMap(cell);
segment.needUpdate = false;
}
}
else
requestInteriorMap(cell);
return;
}
int cellX = cell->getCell()->getGridX();
int cellY = cell->getCell()->getGridY();
MapSegment& segment = mExteriorSegments[std::make_pair(cellX, cellY)];
const std::uint8_t neighbourFlags = getExteriorNeighbourFlags(cellX, cellY);
if ((segment.mLastRenderNeighbourFlags & neighbourFlags) == neighbourFlags)
return;
requestExteriorMap(cell, segment);
segment.mLastRenderNeighbourFlags = neighbourFlags;
}
void LocalMap::addCell(MWWorld::CellStore *cell)
{
if (cell->isExterior())
mExteriorSegments[std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY())].needUpdate = true;
mExteriorSegments.emplace(
std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY()), MapSegment{});
}
void LocalMap::removeExteriorCell(int x, int y)
@ -210,7 +210,9 @@ void LocalMap::removeCell(MWWorld::CellStore *cell)
{
saveFogOfWar(cell);
if (!cell->isExterior())
if (cell->isExterior())
mExteriorSegments.erase({ cell->getCell()->getGridX(), cell->getCell()->getGridY() });
else
mInteriorSegments.clear();
}
@ -249,7 +251,7 @@ void LocalMap::cleanupCameras()
}
}
void LocalMap::requestExteriorMap(const MWWorld::CellStore* cell)
void LocalMap::requestExteriorMap(const MWWorld::CellStore* cell, MapSegment& segment)
{
mInterior = false;
@ -260,18 +262,16 @@ void LocalMap::requestExteriorMap(const MWWorld::CellStore* cell)
float zmin = bound.center().z() - bound.radius();
float zmax = bound.center().z() + bound.radius();
setupRenderToTexture(cell->getCell()->getGridX(), cell->getCell()->getGridY(),
x * mMapWorldSize + mMapWorldSize / 2.f, y * mMapWorldSize + mMapWorldSize / 2.f,
setupRenderToTexture(x, y, x * mMapWorldSize + mMapWorldSize / 2.f, y * mMapWorldSize + mMapWorldSize / 2.f,
osg::Vec3d(0, 1, 0), zmin, zmax);
MapSegment& segment = mExteriorSegments[std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY())];
if (!segment.mFogOfWarImage)
{
if (cell->getFog())
segment.loadFogOfWar(cell->getFog()->mFogTextures.back());
else
segment.initFogOfWar();
}
if (segment.mFogOfWarImage != nullptr)
return;
if (cell->getFog())
segment.loadFogOfWar(cell->getFog()->mFogTextures.back());
else
segment.initFogOfWar();
}
void LocalMap::requestInteriorMap(const MWWorld::CellStore* cell)
@ -561,9 +561,23 @@ void LocalMap::updatePlayer (const osg::Vec3f& position, const osg::Quat& orient
}
}
LocalMap::MapSegment::MapSegment()
: mHasFogState(false)
std::uint8_t LocalMap::getExteriorNeighbourFlags(int cellX, int cellY) const
{
constexpr std::tuple<NeighbourCellFlag, int, int> flags[] = {
{ NeighbourCellTopLeft, -1, -1 },
{ NeighbourCellTopCenter, 0, -1 },
{ NeighbourCellTopRight, 1, -1 },
{ NeighbourCellMiddleLeft, -1, 0 },
{ NeighbourCellMiddleRight, 1, 0 },
{ NeighbourCellBottomLeft, -1, 1 },
{ NeighbourCellBottomCenter, 0, 1 },
{ NeighbourCellBottomRight, 1, 1 },
};
std::uint8_t result = 0;
for (const auto& [flag, dx, dy] : flags)
if (mExteriorSegments.contains({cellX + dx, cellY + dy}))
result |= flag;
return result;
}
void LocalMap::MapSegment::createFogOfWarTexture()

@ -1,6 +1,7 @@
#ifndef GAME_RENDER_LOCALMAP_H
#define GAME_RENDER_LOCALMAP_H
#include <cstdint>
#include <set>
#include <vector>
#include <map>
@ -105,23 +106,30 @@ namespace MWRender
typedef std::set<std::pair<int, int> > Grid;
Grid mCurrentGrid;
struct MapSegment
enum NeighbourCellFlag : std::uint8_t
{
MapSegment();
~MapSegment() = default;
NeighbourCellTopLeft = 1,
NeighbourCellTopCenter = 1 << 1,
NeighbourCellTopRight = 1 << 2,
NeighbourCellMiddleLeft = 1 << 3,
NeighbourCellMiddleRight = 1 << 4,
NeighbourCellBottomLeft = 1 << 5,
NeighbourCellBottomCenter = 1 << 6,
NeighbourCellBottomRight = 1 << 7,
};
struct MapSegment
{
void initFogOfWar();
void loadFogOfWar(const ESM::FogTexture& fog);
void saveFogOfWar(ESM::FogTexture& fog) const;
void createFogOfWarTexture();
std::uint8_t mLastRenderNeighbourFlags = 0;
bool mHasFogState = false;
osg::ref_ptr<osg::Texture2D> mMapTexture;
osg::ref_ptr<osg::Texture2D> mFogOfWarTexture;
osg::ref_ptr<osg::Image> mFogOfWarImage;
bool needUpdate = true;
bool mHasFogState;
};
typedef std::map<std::pair<int, int>, MapSegment> SegmentMap;
@ -141,13 +149,15 @@ namespace MWRender
float mAngle;
const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle);
void requestExteriorMap(const MWWorld::CellStore* cell);
void requestExteriorMap(const MWWorld::CellStore* cell, MapSegment& segment);
void requestInteriorMap(const MWWorld::CellStore* cell);
void setupRenderToTexture(int segment_x, int segment_y, float left, float top, const osg::Vec3d& upVector, float zmin, float zmax);
bool mInterior;
osg::BoundingBox mBounds;
std::uint8_t getExteriorNeighbourFlags(int cellX, int cellY) const;
};
}

Loading…
Cancel
Save