1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Global map base layer

This commit is contained in:
scrawl 2015-05-16 14:48:20 +02:00
parent bec9abd319
commit 75ace9f8b5
5 changed files with 60 additions and 69 deletions

View File

@ -22,10 +22,10 @@ source_group(game FILES ${GAME} ${GAME_HEADER})
add_openmw_dir (mwrender
actors objects renderingmanager animation sky npcanimation vismask
creatureanimation effectmanager util renderinginterface pathgrid rendermode
bulletdebugdraw
bulletdebugdraw globalmap
# camera
# localmap occlusionquery water shadows
# characterpreview globalmap ripplesimulation refraction
# characterpreview ripplesimulation refraction
# terrainstorage weaponanimation
)

View File

@ -1,8 +1,9 @@
#include "mapwindow.hpp"
#include <OgreSceneNode.h>
#include <OgreVector2.h>
#include <osg/Texture2D>
#include <MyGUI_ScrollView.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_RenderManager.h>
@ -14,6 +15,7 @@
#include <components/esm/globalmap.hpp>
#include <components/settings/settings.hpp>
#include <components/myguiplatform/myguitexture.hpp>
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
@ -559,6 +561,7 @@ namespace MWGui
: WindowPinnableBase("openmw_map_window.layout")
, NoDrop(drag, mMainWidget)
, LocalMapBase(customMarkers)
, mGlobalMapTexture(NULL)
, mGlobal(false)
, mGlobalMap(0)
//, mGlobalMapRender(0)
@ -708,19 +711,23 @@ namespace MWGui
void MapWindow::renderGlobalMap(Loading::Listener* loadingListener)
{
#if 0
mGlobalMapRender = new MWRender::GlobalMap("");
mGlobalMapRender = new MWRender::GlobalMap();
mGlobalMapRender->render(loadingListener);
mGlobalMap->setCanvasSize (mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
mGlobalMapImage->setSize(mGlobalMapRender->getWidth(), mGlobalMapRender->getHeight());
mGlobalMapImage->setImageTexture("GlobalMap.png");
mGlobalMapOverlay->setImageTexture("GlobalMapOverlay");
#endif
mGlobalMapTexture = new osgMyGUI::OSGTexture(mGlobalMapRender->getBaseTexture());
mGlobalMapImage->setRenderItemTexture(mGlobalMapTexture);
mGlobalMapImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
//mGlobalMapOverlay->setImageTexture("GlobalMapOverlay");
}
MapWindow::~MapWindow()
{
//delete mGlobalMapRender;
delete mGlobalMapTexture;
delete mGlobalMapRender;
}
void MapWindow::setCellName(const std::string& cellName)
@ -730,7 +737,6 @@ namespace MWGui
void MapWindow::addVisitedLocation(const std::string& name, int x, int y)
{
#if 0
CellId cell;
cell.first = x;
cell.second = y;
@ -757,7 +763,6 @@ namespace MWGui
markerWidget->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
markerWidget->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
}
#endif
}
void MapWindow::cellExplored(int x, int y)
@ -769,12 +774,11 @@ namespace MWGui
{
LocalMapBase::onFrame(dt);
#if 0
for (std::vector<CellId>::iterator it = mQueuedToExplore.begin(); it != mQueuedToExplore.end(); ++it)
{
mGlobalMapRender->exploreCell(it->first, it->second);
}
#endif
mQueuedToExplore.clear();
NoDrop::onFrame(dt);
@ -831,14 +835,12 @@ namespace MWGui
void MapWindow::globalMapUpdatePlayer ()
{
#if 0
// For interiors, position is set by WindowManager via setGlobalMapPlayerPosition
if (MWBase::Environment::get().getWorld ()->isCellExterior ())
{
Ogre::Vector3 pos = MWBase::Environment::get().getWorld ()->getPlayerPtr().getRefData ().getBaseNode ()->_getDerivedPosition ();
setGlobalMapPlayerPosition(pos.x, pos.y);
osg::Vec3f pos = MWBase::Environment::get().getWorld ()->getPlayerPtr().getRefData().getPosition().asVec3();
setGlobalMapPlayerPosition(pos.x(), pos.y());
}
#endif
}
void MapWindow::notifyPlayerUpdate ()
@ -848,7 +850,6 @@ namespace MWGui
void MapWindow::setGlobalMapPlayerPosition(float worldX, float worldY)
{
#if 0
float x, y;
mGlobalMapRender->worldPosToImageSpace (worldX, worldY, x, y);
x *= mGlobalMapRender->getWidth();
@ -860,7 +861,6 @@ namespace MWGui
MyGUI::IntSize viewsize = mGlobalMap->getSize();
MyGUI::IntPoint viewoffs(static_cast<int>(viewsize.width * 0.5f - x), static_cast<int>(viewsize.height *0.5 - y));
mGlobalMap->setViewOffset(viewoffs);
#endif
}
void MapWindow::setGlobalMapPlayerDir(const float x, const float y)
@ -876,7 +876,7 @@ namespace MWGui
{
mMarkers.clear();
//mGlobalMapRender->clear();
mGlobalMapRender->clear();
mChanged = true;
while (mEventBoxGlobal->getChildCount())
@ -885,7 +885,6 @@ namespace MWGui
void MapWindow::write(ESM::ESMWriter &writer, Loading::Listener& progress)
{
#if 0
ESM::GlobalMap map;
mGlobalMapRender->write(map);
@ -894,12 +893,10 @@ namespace MWGui
writer.startRecord(ESM::REC_GMAP);
map.save(writer);
writer.endRecord(ESM::REC_GMAP);
#endif
}
void MapWindow::readRecord(ESM::ESMReader &reader, uint32_t type)
{
#if 0
if (type == ESM::REC_GMAP)
{
ESM::GlobalMap map;
@ -914,7 +911,6 @@ namespace MWGui
addVisitedLocation(cell->mName, it->first, it->second);
}
}
#endif
}
void MapWindow::setAlpha(float alpha)

View File

@ -195,6 +195,7 @@ namespace MWGui
void globalMapUpdatePlayer();
MyGUI::ScrollView* mGlobalMap;
MyGUI::ITexture* mGlobalMapTexture;
MyGUI::ImageBox* mGlobalMapImage;
MyGUI::ImageBox* mGlobalMapOverlay;
MyGUI::ImageBox* mPlayerArrowLocal;
@ -216,7 +217,7 @@ namespace MWGui
MyGUI::Button* mEventBoxGlobal;
MyGUI::Button* mEventBoxLocal;
//MWRender::GlobalMap* mGlobalMapRender;
MWRender::GlobalMap* mGlobalMapRender;
EditNoteDialog mEditNoteDialog;
ESM::CustomMarker mEditingMarker;

View File

@ -1,14 +1,9 @@
#include "globalmap.hpp"
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <climits>
#include <OgreImage.h>
#include <OgreTextureManager.h>
#include <OgreColourValue.h>
#include <OgreHardwareVertexBuffer.h>
#include <OgreRoot.h>
#include <OgreHardwarePixelBuffer.h>
#include <osg/Image>
#include <osg/Texture2D>
#include <components/loadinglistener/loadinglistener.hpp>
#include <components/settings/settings.hpp>
@ -23,9 +18,8 @@
namespace MWRender
{
GlobalMap::GlobalMap(const std::string &cacheDir)
: mCacheDir(cacheDir)
, mMinX(0), mMaxX(0)
GlobalMap::GlobalMap()
: mMinX(0), mMaxX(0)
, mMinY(0), mMaxY(0)
, mWidth(0)
, mHeight(0)
@ -35,13 +29,10 @@ namespace MWRender
GlobalMap::~GlobalMap()
{
Ogre::TextureManager::getSingleton().remove(mOverlayTexture->getName());
}
void GlobalMap::render (Loading::Listener* loadingListener)
{
Ogre::TexturePtr tex;
const MWWorld::ESMStore &esmStore =
MWBase::Environment::get().getWorld()->getStore();
@ -67,7 +58,9 @@ namespace MWRender
loadingListener->setProgressRange((mMaxX-mMinX+1) * (mMaxY-mMinY+1));
loadingListener->setProgress(0);
std::vector<Ogre::uchar> data (mWidth * mHeight * 3);
osg::ref_ptr<osg::Image> image = new osg::Image;
image->allocateImage(mWidth, mHeight, 1, GL_RGB, GL_UNSIGNED_BYTE);
unsigned char* data = image->data();
for (int x = mMinX; x <= mMaxX; ++x)
{
@ -139,16 +132,8 @@ namespace MWRender
}
}
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size()));
tex = Ogre::TextureManager::getSingleton ().createManual ("GlobalMap.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_B8G8R8, Ogre::TU_STATIC);
tex->loadRawData(stream, mWidth, mHeight, Ogre::PF_B8G8R8);
tex->load();
mOverlayTexture = Ogre::TextureManager::getSingleton().createManual("GlobalMapOverlay", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_A8B8G8R8, Ogre::TU_DYNAMIC, this);
mBaseTexture = new osg::Texture2D;
mBaseTexture->setImage(image);
clear();
@ -172,13 +157,14 @@ namespace MWRender
void GlobalMap::exploreCell(int cellX, int cellY)
{
float originX = static_cast<float>((cellX - mMinX) * mCellSize);
//float originX = static_cast<float>((cellX - mMinX) * mCellSize);
// NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
float originY = static_cast<float>(mHeight - (cellY + 1 - mMinY) * mCellSize);
//float originY = static_cast<float>(mHeight - (cellY + 1 - mMinY) * mCellSize);
if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
return;
/*
Ogre::TexturePtr localMapTexture = Ogre::TextureManager::getSingleton().getByName("Cell_"
+ boost::lexical_cast<std::string>(cellX) + "_" + boost::lexical_cast<std::string>(cellY));
@ -208,24 +194,19 @@ namespace MWRender
mOverlayImage.setColourAt(backup.getColourAt(x, y, 0), static_cast<size_t>(originX + x), static_cast<size_t>(originY + y), 0);
}
}
*/
}
void GlobalMap::clear()
{
/*
Ogre::uchar* buffer = OGRE_ALLOC_T(Ogre::uchar, mWidth * mHeight * 4, Ogre::MEMCATEGORY_GENERAL);
memset(buffer, 0, mWidth * mHeight * 4);
mOverlayImage.loadDynamicImage(&buffer[0], mWidth, mHeight, 1, Ogre::PF_A8B8G8R8, true); // pass ownership of buffer to image
mOverlayTexture->load();
}
void GlobalMap::loadResource(Ogre::Resource *resource)
{
Ogre::Texture* tex = static_cast<Ogre::Texture*>(resource);
Ogre::ConstImagePtrList list;
list.push_back(&mOverlayImage);
tex->_loadImages(list);
*/
}
void GlobalMap::write(ESM::GlobalMap& map)
@ -235,9 +216,11 @@ namespace MWRender
map.mBounds.mMinY = mMinY;
map.mBounds.mMaxY = mMaxY;
/*
Ogre::DataStreamPtr encoded = mOverlayImage.encode("png");
map.mImageData.resize(encoded->size());
encoded->read(&map.mImageData[0], encoded->size());
*/
}
void GlobalMap::read(ESM::GlobalMap& map)
@ -253,6 +236,7 @@ namespace MWRender
|| bounds.mMinY > bounds.mMaxY)
throw std::runtime_error("invalid map bounds");
/*
Ogre::Image image;
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&map.mImageData[0], map.mImageData.size()));
image.load(stream, "png");
@ -309,5 +293,11 @@ namespace MWRender
mOverlayTexture->convertToImage(mOverlayImage);
Ogre::TextureManager::getSingleton().remove("@temp");
*/
}
osg::ref_ptr<osg::Texture2D> GlobalMap::getBaseTexture()
{
return mBaseTexture;
}
}

View File

@ -2,8 +2,14 @@
#define GAME_RENDER_GLOBALMAP_H
#include <string>
#include <vector>
#include <OgreTexture.h>
#include <osg/ref_ptr>
namespace osg
{
class Texture2D;
}
namespace Loading
{
@ -18,10 +24,10 @@ namespace ESM
namespace MWRender
{
class GlobalMap : public Ogre::ManualResourceLoader
class GlobalMap
{
public:
GlobalMap(const std::string& cacheDir);
GlobalMap();
~GlobalMap();
void render(Loading::Listener* loadingListener);
@ -37,23 +43,21 @@ namespace MWRender
void exploreCell (int cellX, int cellY);
virtual void loadResource(Ogre::Resource* resource);
/// Clears the overlay
void clear();
void write (ESM::GlobalMap& map);
void read (ESM::GlobalMap& map);
private:
std::string mCacheDir;
osg::ref_ptr<osg::Texture2D> getBaseTexture();
//osg::ref_ptr<osg::Texture2D> getOverlayTexture();
private:
int mCellSize;
std::vector< std::pair<int,int> > mExploredCells;
Ogre::TexturePtr mOverlayTexture;
Ogre::Image mOverlayImage; // Backup in system memory
osg::ref_ptr<osg::Texture2D> mBaseTexture;
int mWidth;
int mHeight;