1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
OpenMW/apps/openmw/mwrender/localmap.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

168 lines
5.0 KiB
C++
Raw Normal View History

#ifndef GAME_RENDER_LOCALMAP_H
#define GAME_RENDER_LOCALMAP_H
#include <cstdint>
2015-05-26 16:40:44 +02:00
#include <map>
#include <set>
#include <vector>
#include <osg/BoundingBox>
#include <osg/Quat>
#include <osg/ref_ptr>
namespace MWWorld
{
class CellStore;
}
namespace ESM
{
struct FogTexture;
}
2015-05-26 16:40:44 +02:00
namespace osg
{
class Texture2D;
class Image;
2015-05-26 16:40:44 +02:00
class Camera;
class Group;
class Node;
}
namespace MWRender
{
class LocalMapRenderToTexture;
///
/// \brief Local map rendering
///
2015-05-23 23:10:53 +02:00
class LocalMap
{
public:
LocalMap(osg::Group* root);
2012-03-14 17:44:19 +01:00
~LocalMap();
/**
* Clear all savegame-specific data (i.e. fog of war textures)
*/
void clear();
/**
* Request a map render for the given cell. Render textures will be immediately created and can be retrieved
* with the getMapTexture function.
*/
void requestMap(const MWWorld::CellStore* cell);
void addCell(MWWorld::CellStore* cell);
void removeExteriorCell(int x, int y);
2015-05-26 16:40:44 +02:00
void removeCell(MWWorld::CellStore* cell);
osg::ref_ptr<osg::Texture2D> getMapTexture(int x, int y);
2015-05-26 16:40:44 +02:00
osg::ref_ptr<osg::Texture2D> getFogOfWarTexture(int x, int y);
/**
2015-05-26 16:40:44 +02:00
* Removes cameras that have already been rendered. Should be called every frame to ensure that
* we do not render the same map more than once. Note, this cleanup is difficult to implement in an
* automated fashion, since we can't alter the scene graph structure from within an update callback.
*/
2015-05-26 16:40:44 +02:00
void cleanupCameras();
2012-03-14 14:51:58 +01:00
/**
2015-05-26 16:40:44 +02:00
* Set the position & direction of the player, and returns the position in map space through the reference
* parameters.
2012-03-14 14:51:58 +01:00
* @remarks This is used to draw a "fog of war" effect
* to hide areas on the map the player has not discovered yet.
*/
2015-05-26 16:40:44 +02:00
void updatePlayer(const osg::Vec3f& position, const osg::Quat& orientation, float& u, float& v, int& x, int& y,
osg::Vec3f& direction);
2012-03-14 14:51:58 +01:00
/**
* Save the fog of war for this cell to its CellStore.
* @remarks This should be called when unloading a cell, and for all active cells prior to saving the game.
*/
void saveFogOfWar(MWWorld::CellStore* cell);
2012-08-28 17:30:34 +02:00
/**
* Get the interior map texture index and normalized position on this texture, given a world position
2012-08-28 17:30:34 +02:00
*/
2015-05-26 16:40:44 +02:00
void worldToInteriorMapPosition(osg::Vec2f pos, float& nX, float& nY, int& x, int& y);
2015-05-26 16:40:44 +02:00
osg::Vec2f interiorMapToWorldPosition(float nX, float nY, int x, int y);
2012-08-28 17:30:34 +02:00
/**
* Check if a given position is explored by the player (i.e. not obscured by fog of war)
*/
2016-01-07 00:45:12 +01:00
bool isPositionExplored(float nX, float nY, int x, int y);
2012-08-28 17:30:34 +02:00
2015-05-29 01:49:52 +02:00
osg::Group* getRoot();
private:
2015-05-26 16:40:44 +02:00
osg::ref_ptr<osg::Group> mRoot;
osg::ref_ptr<osg::Node> mSceneRoot;
typedef std::vector<osg::ref_ptr<LocalMapRenderToTexture>> RTTVector;
RTTVector mLocalMapRTTs;
2015-05-26 16:40:44 +02:00
typedef std::set<std::pair<int, int>> Grid;
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
{
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;
};
typedef std::map<std::pair<int, int>, MapSegment> SegmentMap;
SegmentMap mExteriorSegments;
SegmentMap mInteriorSegments;
2015-05-26 16:40:44 +02:00
int mMapResolution;
2012-03-18 20:44:56 +01:00
// the dynamic texture is a bottleneck, so don't set this too high
static const int sFogOfWarResolution = 32;
2012-03-18 20:44:56 +01:00
// size of a map segment (for exteriors, 1 cell)
2015-05-26 16:40:44 +02:00
float mMapWorldSize;
int mCellDistance;
2012-04-02 19:37:24 +02:00
float mAngle;
2015-05-26 18:10:31 +02:00
const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle);
2012-04-02 19:37:24 +02:00
2023-05-10 20:13:47 +02:00
void requestExteriorMap(const MWWorld::CellStore* cell, MapSegment& segment);
void requestInteriorMap(const MWWorld::CellStore* cell);
2015-05-26 16:40:44 +02:00
void setupRenderToTexture(
int segment_x, int segment_y, float left, float top, const osg::Vec3d& upVector, float zmin, float zmax);
2012-03-14 14:51:58 +01:00
2012-03-14 17:44:19 +01:00
bool mInterior;
2015-05-26 16:40:44 +02:00
osg::BoundingBox mBounds;
std::uint8_t getExteriorNeighbourFlags(int cellX, int cellY) const;
};
}
#endif