1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:53:52 +00:00
openmw-tes3mp/apps/openmw/mwrender/localmap.hpp

149 lines
4.6 KiB
C++
Raw Normal View History

#ifndef GAME_RENDER_LOCALMAP_H
#define GAME_RENDER_LOCALMAP_H
2015-05-26 14:40:44 +00:00
#include <set>
#include <vector>
#include <map>
#include <osg/BoundingBox>
#include <osg/Quat>
#include <osg/ref_ptr>
namespace MWWorld
{
class CellStore;
}
namespace ESM
{
struct FogTexture;
}
2015-05-26 14:40:44 +00:00
namespace osgViewer
{
2015-05-26 14:40:44 +00:00
class Viewer;
}
2012-04-02 17:37:24 +00:00
2015-05-26 14:40:44 +00:00
namespace osg
{
class Texture2D;
class Camera;
class Group;
class Node;
}
namespace MWRender
{
///
/// \brief Local map rendering
///
2015-05-23 21:10:53 +00:00
class LocalMap
{
public:
2015-05-26 14:40:44 +00:00
LocalMap(osgViewer::Viewer* viewer);
2012-03-14 16:44:19 +00:00
~LocalMap();
/**
* Clear all savegame-specific data (i.e. fog of war textures)
*/
void clear();
2015-05-26 14:40:44 +00:00
void requestMap (std::set<MWWorld::CellStore*> cells);
void removeCell (MWWorld::CellStore* cell);
osg::ref_ptr<osg::Texture2D> getMapTexture (bool interior, int x, int y);
void markForRemoval(osg::Camera* cam);
/**
2015-05-26 14:40:44 +00: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 14:40:44 +00:00
void cleanupCameras();
2012-03-14 13:51:58 +00:00
/**
2015-05-26 14:40:44 +00:00
* Set the position & direction of the player, and returns the position in map space through the reference parameters.
2012-03-14 13:51:58 +00: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 14:40:44 +00: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 13:51:58 +00: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 15:30:34 +00:00
/**
* Get the interior map texture index and normalized position
* on this texture, given a world position
2012-08-28 15:30:34 +00:00
*/
2015-05-26 14:40:44 +00:00
void worldToInteriorMapPosition (osg::Vec2f pos, float& nX, float& nY, int& x, int& y);
2015-05-26 14:40:44 +00:00
osg::Vec2f interiorMapToWorldPosition (float nX, float nY, int x, int y);
2012-08-28 15:30:34 +00:00
/**
* Check if a given position is explored by the player (i.e. not obscured by fog of war)
*/
bool isPositionExplored (float nX, float nY, int x, int y, bool interior);
private:
2015-05-26 14:40:44 +00:00
osg::ref_ptr<osgViewer::Viewer> mViewer;
osg::ref_ptr<osg::Group> mRoot;
osg::ref_ptr<osg::Node> mSceneRoot;
typedef std::vector< osg::ref_ptr<osg::Camera> > CameraVector;
CameraVector mActiveCameras;
CameraVector mCamerasPendingRemoval;
typedef std::map<std::pair<int, int>, osg::ref_ptr<osg::Texture2D> > TextureMap;
TextureMap mTextures;
int mMapResolution;
2012-03-18 19:44:56 +00:00
// the dynamic texture is a bottleneck, so don't set this too high
static const int sFogOfWarResolution = 32;
// frames to skip before rendering fog of war
static const int sFogOfWarSkip = 2;
// size of a map segment (for exteriors, 1 cell)
2015-05-26 14:40:44 +00:00
float mMapWorldSize;
2012-04-02 17:37:24 +00:00
float mAngle;
2015-05-26 16:10:31 +00:00
const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle);
2012-04-02 17:37:24 +00:00
2015-05-26 14:40:44 +00:00
void requestExteriorMap(MWWorld::CellStore* cell);
void requestInteriorMap(MWWorld::CellStore* cell);
osg::ref_ptr<osg::Camera> createOrthographicCamera(float left, float top, float width, float height, const osg::Vec3d& upVector, float zmin, float zmax);
void setupRenderToTexture(osg::ref_ptr<osg::Camera> camera, int x, int y);
2012-03-14 13:51:58 +00:00
// Creates a fog of war texture and initializes it to full black
2015-05-26 14:40:44 +00:00
//void createFogOfWar(const std::string& texturePrefix);
// Loads a fog of war texture from its ESM struct
2015-05-26 14:40:44 +00:00
//void loadFogOfWar(const std::string& texturePrefix, ESM::FogTexture& esm); // FogTexture not const because MemoryDataStream doesn't accept it
// A buffer for the "fog of war" textures of the current cell.
// Both interior and exterior maps are possibly divided into multiple textures.
2015-05-26 14:40:44 +00:00
//std::map <std::string, std::vector<Ogre::uint32> > mBuffers;
2012-03-14 16:44:19 +00:00
// The render texture we will use to create the map images
2015-05-26 14:40:44 +00:00
//Ogre::TexturePtr mRenderTexture;
//Ogre::RenderTarget* mRenderTarget;
2012-03-14 16:44:19 +00:00
bool mInterior;
2015-05-26 14:40:44 +00:00
osg::BoundingBox mBounds;
//std::string mInteriorName;
};
}
#endif