2014-01-05 17:22:29 +00:00
|
|
|
#ifndef GAME_RENDER_GLOBALMAP_H
|
|
|
|
#define GAME_RENDER_GLOBALMAP_H
|
2012-09-20 11:56:37 +00:00
|
|
|
|
|
|
|
#include <string>
|
2015-05-16 12:48:20 +00:00
|
|
|
#include <vector>
|
2012-09-20 11:56:37 +00:00
|
|
|
|
2015-05-16 12:48:20 +00:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Texture2D;
|
2015-05-28 16:49:24 +00:00
|
|
|
class Image;
|
2015-05-28 23:49:52 +00:00
|
|
|
class Group;
|
|
|
|
class Camera;
|
2015-05-16 12:48:20 +00:00
|
|
|
}
|
2012-11-04 11:13:04 +00:00
|
|
|
|
2013-08-27 13:48:13 +00:00
|
|
|
namespace Loading
|
|
|
|
{
|
|
|
|
class Listener;
|
|
|
|
}
|
|
|
|
|
2014-01-25 17:20:17 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2015-03-06 08:36:42 +00:00
|
|
|
struct GlobalMap;
|
2014-01-25 17:20:17 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 11:56:37 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
|
2015-05-16 12:48:20 +00:00
|
|
|
class GlobalMap
|
2012-09-20 11:56:37 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-05-28 23:49:52 +00:00
|
|
|
GlobalMap(osg::Group* root);
|
2014-08-14 17:01:03 +00:00
|
|
|
~GlobalMap();
|
2012-09-20 11:56:37 +00:00
|
|
|
|
2013-08-27 13:48:13 +00:00
|
|
|
void render(Loading::Listener* loadingListener);
|
2012-09-20 11:56:37 +00:00
|
|
|
|
2014-09-26 10:47:33 +00:00
|
|
|
int getWidth() const { return mWidth; }
|
|
|
|
int getHeight() const { return mHeight; }
|
|
|
|
|
|
|
|
int getCellSize() const { return mCellSize; }
|
2012-09-21 14:26:04 +00:00
|
|
|
|
|
|
|
void worldPosToImageSpace(float x, float z, float& imageX, float& imageY);
|
|
|
|
|
|
|
|
void cellTopLeftCornerToImageSpace(int x, int y, float& imageX, float& imageY);
|
|
|
|
|
2015-05-28 23:49:52 +00:00
|
|
|
void exploreCell (int cellX, int cellY, osg::ref_ptr<osg::Texture2D> localMapTexture);
|
2012-11-04 11:13:04 +00:00
|
|
|
|
2014-01-25 12:34:56 +00:00
|
|
|
/// Clears the overlay
|
|
|
|
void clear();
|
|
|
|
|
2015-05-28 23:49:52 +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.
|
|
|
|
*/
|
|
|
|
void cleanupCameras();
|
|
|
|
|
2016-08-15 16:11:36 +00:00
|
|
|
void removeCamera(osg::Camera* cam);
|
|
|
|
|
2015-05-28 23:49:52 +00:00
|
|
|
/**
|
|
|
|
* Mark a camera for cleanup in the next update. For internal use only.
|
|
|
|
*/
|
|
|
|
void markForRemoval(osg::Camera* camera);
|
|
|
|
|
2014-04-26 11:42:32 +00:00
|
|
|
void write (ESM::GlobalMap& map);
|
|
|
|
void read (ESM::GlobalMap& map);
|
2014-01-25 17:20:17 +00:00
|
|
|
|
2015-05-16 12:48:20 +00:00
|
|
|
osg::ref_ptr<osg::Texture2D> getBaseTexture();
|
2015-05-28 16:49:24 +00:00
|
|
|
osg::ref_ptr<osg::Texture2D> getOverlayTexture();
|
2012-09-21 14:26:04 +00:00
|
|
|
|
2015-05-16 12:48:20 +00:00
|
|
|
private:
|
2015-05-28 23:49:52 +00:00
|
|
|
/**
|
|
|
|
* Request rendering a 2d quad onto mOverlayTexture.
|
2015-11-15 20:32:34 +00:00
|
|
|
* x, y, width and height are the destination coordinates (top-left coordinate origin)
|
2015-05-28 23:49:52 +00:00
|
|
|
* @param cpuCopy copy the resulting render onto mOverlayImage as well?
|
|
|
|
*/
|
|
|
|
void requestOverlayTextureUpdate(int x, int y, int width, int height, osg::ref_ptr<osg::Texture2D> texture, bool clear, bool cpuCopy,
|
|
|
|
float srcLeft = 0.f, float srcTop = 0.f, float srcRight = 1.f, float srcBottom = 1.f);
|
|
|
|
|
2014-09-26 10:47:33 +00:00
|
|
|
int mCellSize;
|
|
|
|
|
2015-05-28 23:49:52 +00:00
|
|
|
osg::ref_ptr<osg::Group> mRoot;
|
|
|
|
|
|
|
|
typedef std::vector<osg::ref_ptr<osg::Camera> > CameraVector;
|
|
|
|
CameraVector mActiveCameras;
|
|
|
|
|
|
|
|
CameraVector mCamerasPendingRemoval;
|
|
|
|
|
|
|
|
struct ImageDest
|
|
|
|
{
|
|
|
|
ImageDest()
|
2015-07-01 01:42:04 +00:00
|
|
|
: mX(0), mY(0)
|
|
|
|
, mFramesUntilDone(3) // wait an extra frame to ensure the draw thread has completed its frame.
|
2015-05-28 23:49:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> mImage;
|
|
|
|
int mX, mY;
|
|
|
|
int mFramesUntilDone;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<ImageDest> ImageDestVector;
|
|
|
|
|
|
|
|
ImageDestVector mPendingImageDest;
|
|
|
|
|
2012-11-04 11:13:04 +00:00
|
|
|
std::vector< std::pair<int,int> > mExploredCells;
|
|
|
|
|
2015-05-16 12:48:20 +00:00
|
|
|
osg::ref_ptr<osg::Texture2D> mBaseTexture;
|
2017-01-02 03:01:04 +00:00
|
|
|
osg::ref_ptr<osg::Texture2D> mAlphaTexture;
|
2015-05-28 23:49:52 +00:00
|
|
|
|
|
|
|
// GPU copy of overlay
|
|
|
|
// Note, uploads are pushed through a Camera, instead of through mOverlayImage
|
2015-05-28 16:49:24 +00:00
|
|
|
osg::ref_ptr<osg::Texture2D> mOverlayTexture;
|
|
|
|
|
2015-05-28 23:49:52 +00:00
|
|
|
// CPU copy of overlay
|
2015-05-28 16:49:24 +00:00
|
|
|
osg::ref_ptr<osg::Image> mOverlayImage;
|
2012-11-04 11:13:04 +00:00
|
|
|
|
2012-09-21 14:26:04 +00:00
|
|
|
int mWidth;
|
|
|
|
int mHeight;
|
|
|
|
|
|
|
|
int mMinX, mMaxX, mMinY, mMaxY;
|
2012-09-20 11:56:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|