mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-24 04:11:50 -04:00
Update cell local map on different neighbour cells
This commit is contained in:
parent
2d25ffeb89
commit
ab0a460a6f
@ -177,28 +177,28 @@ void LocalMap::setupRenderToTexture(int segment_x, int segment_y, float left, fl
|
|||||||
|
|
||||||
void LocalMap::requestMap(const MWWorld::CellStore* cell)
|
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);
|
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)
|
void LocalMap::addCell(MWWorld::CellStore *cell)
|
||||||
{
|
{
|
||||||
if (cell->isExterior())
|
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)
|
void LocalMap::removeExteriorCell(int x, int y)
|
||||||
@ -210,7 +210,9 @@ void LocalMap::removeCell(MWWorld::CellStore *cell)
|
|||||||
{
|
{
|
||||||
saveFogOfWar(cell);
|
saveFogOfWar(cell);
|
||||||
|
|
||||||
if (!cell->isExterior())
|
if (cell->isExterior())
|
||||||
|
mExteriorSegments.erase({ cell->getCell()->getGridX(), cell->getCell()->getGridY() });
|
||||||
|
else
|
||||||
mInteriorSegments.clear();
|
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;
|
mInterior = false;
|
||||||
|
|
||||||
@ -260,18 +262,16 @@ void LocalMap::requestExteriorMap(const MWWorld::CellStore* cell)
|
|||||||
float zmin = bound.center().z() - bound.radius();
|
float zmin = bound.center().z() - bound.radius();
|
||||||
float zmax = bound.center().z() + bound.radius();
|
float zmax = bound.center().z() + bound.radius();
|
||||||
|
|
||||||
setupRenderToTexture(cell->getCell()->getGridX(), cell->getCell()->getGridY(),
|
setupRenderToTexture(x, y, x * mMapWorldSize + mMapWorldSize / 2.f, y * mMapWorldSize + mMapWorldSize / 2.f,
|
||||||
x * mMapWorldSize + mMapWorldSize / 2.f, y * mMapWorldSize + mMapWorldSize / 2.f,
|
|
||||||
osg::Vec3d(0, 1, 0), zmin, zmax);
|
osg::Vec3d(0, 1, 0), zmin, zmax);
|
||||||
|
|
||||||
MapSegment& segment = mExteriorSegments[std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY())];
|
if (segment.mFogOfWarImage != nullptr)
|
||||||
if (!segment.mFogOfWarImage)
|
return;
|
||||||
{
|
|
||||||
if (cell->getFog())
|
if (cell->getFog())
|
||||||
segment.loadFogOfWar(cell->getFog()->mFogTextures.back());
|
segment.loadFogOfWar(cell->getFog()->mFogTextures.back());
|
||||||
else
|
else
|
||||||
segment.initFogOfWar();
|
segment.initFogOfWar();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalMap::requestInteriorMap(const MWWorld::CellStore* cell)
|
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()
|
std::uint8_t LocalMap::getExteriorNeighbourFlags(int cellX, int cellY) const
|
||||||
: mHasFogState(false)
|
|
||||||
{
|
{
|
||||||
|
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()
|
void LocalMap::MapSegment::createFogOfWarTexture()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef GAME_RENDER_LOCALMAP_H
|
#ifndef GAME_RENDER_LOCALMAP_H
|
||||||
#define GAME_RENDER_LOCALMAP_H
|
#define GAME_RENDER_LOCALMAP_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -105,23 +106,30 @@ namespace MWRender
|
|||||||
typedef std::set<std::pair<int, int> > Grid;
|
typedef std::set<std::pair<int, int> > Grid;
|
||||||
Grid mCurrentGrid;
|
Grid mCurrentGrid;
|
||||||
|
|
||||||
|
enum NeighbourCellFlag : std::uint8_t
|
||||||
|
{
|
||||||
|
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
|
struct MapSegment
|
||||||
{
|
{
|
||||||
MapSegment();
|
|
||||||
~MapSegment() = default;
|
|
||||||
|
|
||||||
void initFogOfWar();
|
void initFogOfWar();
|
||||||
void loadFogOfWar(const ESM::FogTexture& fog);
|
void loadFogOfWar(const ESM::FogTexture& fog);
|
||||||
void saveFogOfWar(ESM::FogTexture& fog) const;
|
void saveFogOfWar(ESM::FogTexture& fog) const;
|
||||||
void createFogOfWarTexture();
|
void createFogOfWarTexture();
|
||||||
|
|
||||||
|
std::uint8_t mLastRenderNeighbourFlags = 0;
|
||||||
|
bool mHasFogState = false;
|
||||||
osg::ref_ptr<osg::Texture2D> mMapTexture;
|
osg::ref_ptr<osg::Texture2D> mMapTexture;
|
||||||
osg::ref_ptr<osg::Texture2D> mFogOfWarTexture;
|
osg::ref_ptr<osg::Texture2D> mFogOfWarTexture;
|
||||||
osg::ref_ptr<osg::Image> mFogOfWarImage;
|
osg::ref_ptr<osg::Image> mFogOfWarImage;
|
||||||
|
|
||||||
bool needUpdate = true;
|
|
||||||
|
|
||||||
bool mHasFogState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::pair<int, int>, MapSegment> SegmentMap;
|
typedef std::map<std::pair<int, int>, MapSegment> SegmentMap;
|
||||||
@ -141,13 +149,15 @@ namespace MWRender
|
|||||||
float mAngle;
|
float mAngle;
|
||||||
const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle);
|
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 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);
|
void setupRenderToTexture(int segment_x, int segment_y, float left, float top, const osg::Vec3d& upVector, float zmin, float zmax);
|
||||||
|
|
||||||
bool mInterior;
|
bool mInterior;
|
||||||
osg::BoundingBox mBounds;
|
osg::BoundingBox mBounds;
|
||||||
|
|
||||||
|
std::uint8_t getExteriorNeighbourFlags(int cellX, int cellY) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user