From 319022d962197b73f09d47418ff29ede2f6dcc2d Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 23 Mar 2012 15:24:39 +0100 Subject: [PATCH 01/23] speed up dialogue start-up. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 91785819f..451c49b1e 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -531,6 +531,13 @@ namespace MWDialogue mChoice = -1; mIsInChoice = false; mCompilerContext.setExtensions (&extensions); + mDialogueMap.clear(); + actorKnownTopics.clear(); + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) + { + mDialogueMap[it->first] = it->second; + } } void DialogueManager::addTopic(std::string topic) @@ -566,13 +573,7 @@ namespace MWDialogue mActor = actor; - mDialogueMap.clear(); actorKnownTopics.clear(); - ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; - for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) - { - mDialogueMap[it->first] = it->second; - } //initialise the GUI mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); @@ -585,6 +586,7 @@ namespace MWDialogue //greeting bool greetingFound = false; //ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) { ESM::Dialogue ndialogue = it->second; From 4249d2c53699fe42fdc9da3553a7ac5fc9403b90 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 28 Mar 2012 03:15:10 +0200 Subject: [PATCH 02/23] add getNorthVector method --- apps/openmw/mwworld/world.cpp | 16 ++++++++++++++++ apps/openmw/mwworld/world.hpp | 3 +++ 2 files changed, 19 insertions(+) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index a636ce288..a1d582491 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -701,6 +701,7 @@ namespace MWWorld void World::update (float duration) { + getNorthVector(mWorldScene->getCurrentCell()); mWorldScene->update (duration); mWeatherManager->update (duration); @@ -754,4 +755,19 @@ namespace MWWorld { return mRendering->getFader(); } + + Ogre::Vector2 World::getNorthVector(Ptr::CellStore* cell) + { + ESMS::CellRefList statics = cell->statics; + ESMS::LiveCellRef* ref = statics.find("northmarker"); + if (!ref) + { + std::cout << "No north marker found." << std::endl; + return Vector2(0, 1); + } + Ogre::SceneNode* node = ref->mData.getBaseNode(); + Vector3 dir = -node->_getDerivedOrientation().zAxis(); + Vector2 d = Vector2(dir.x, dir.z); + return d; + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 71cca3545..2607c3830 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -129,6 +129,9 @@ namespace MWWorld bool isCellExterior() const; bool isCellQuasiExterior() const; + Ogre::Vector2 getNorthVector(Ptr::CellStore* cell); + ///< get north vector (OGRE coordinates) for given interior cell + Globals::Data& getGlobalVariable (const std::string& name); Globals::Data getGlobalVariable (const std::string& name) const; From 37e6db69d83a82892be8463b36daea5926b131cc Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 29 Mar 2012 17:07:59 +0200 Subject: [PATCH 03/23] fix --- apps/openmw/mwworld/world.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index a1d582491..5c661b4a2 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -766,7 +766,7 @@ namespace MWWorld return Vector2(0, 1); } Ogre::SceneNode* node = ref->mData.getBaseNode(); - Vector3 dir = -node->_getDerivedOrientation().zAxis(); + Vector3 dir = node->_getDerivedOrientation().yAxis(); Vector2 d = Vector2(dir.x, dir.z); return d; } From 35f40b99adb5cd6b04499b5c78f8909eccad27a4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 29 Mar 2012 18:10:01 +0200 Subject: [PATCH 04/23] remove the bounding box hack, not needed because calculation is correct now --- apps/openmw/mwrender/localmap.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index ed218dc97..2c0a4e76b 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -65,9 +65,6 @@ void LocalMap::saveFogOfWar(MWWorld::Ptr::CellStore* cell) { Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); Vector2 max(mBounds.getMaximum().x, mBounds.getMaximum().z); - /// \todo why is this workaround needed? - min *= 1.3; - max *= 1.3; Vector2 length = max-min; // divide into segments @@ -108,10 +105,6 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, Vector2 min(bounds.getMinimum().x, bounds.getMinimum().z); Vector2 max(bounds.getMaximum().x, bounds.getMaximum().z); - /// \todo why is this workaround needed? - min *= 1.3; - max *= 1.3; - Vector2 length = max-min; Vector2 center(bounds.getCenter().x, bounds.getCenter().z); @@ -243,7 +236,6 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& else { Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); - min *= 1.3; x = std::ceil((pos.x - min.x)/sSize)-1; y = std::ceil((pos.y - min.y)/sSize)-1; @@ -264,7 +256,6 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& else { Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); - min *= 1.3; u = (pos.x - min.x - sSize*x)/sSize; v = (pos.y - min.y - sSize*y)/sSize; From 01ecf3e0be726f028bd662f89c2b26177c169a3d Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 29 Mar 2012 18:16:11 +0200 Subject: [PATCH 05/23] attempt at rotation (BROKEN) --- apps/openmw/mwrender/localmap.cpp | 16 +++++++++++++--- apps/openmw/mwrender/localmap.hpp | 2 ++ apps/openmw/mwworld/world.cpp | 4 ---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 2c0a4e76b..47b8171a5 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -2,6 +2,7 @@ #include "renderingmanager.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" #include "../mwgui/window_manager.hpp" #include @@ -14,12 +15,17 @@ LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWWorld::Environment* en { mRendering = rend; mEnvironment = env; - + + mCameraRotNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode(); + mCameraNode = mCameraRotNode->createChildSceneNode(); + mCellCamera = mRendering->getScene()->createCamera("CellCamera"); mCellCamera->setProjectionType(PT_ORTHOGRAPHIC); // look down -y const float sqrt0pt5 = 0.707106781; mCellCamera->setOrientation(Quaternion(sqrt0pt5, -sqrt0pt5, 0, 0)); + + mCameraNode->attachObject(mCellCamera); } LocalMap::~LocalMap() @@ -100,11 +106,15 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, { mInterior = true; mBounds = bounds; - + Vector2 z(bounds.getMaximum().y, bounds.getMinimum().y); Vector2 min(bounds.getMinimum().x, bounds.getMinimum().z); Vector2 max(bounds.getMaximum().x, bounds.getMaximum().z); + const Vector2& north = mEnvironment->mWorld->getNorthVector(cell); + Radian angle(std::atan2(north.x, north.y)); + mCameraRotNode->setOrientation(Quaternion(Math::Cos(angle/2.f), 0, Math::Sin(angle/2.f), 0)); + Vector2 length = max-min; Vector2 center(bounds.getCenter().x, bounds.getCenter().z); @@ -141,7 +151,7 @@ void LocalMap::render(const float x, const float y, // make everything visible mRendering->getScene()->setAmbientLight(ColourValue(1,1,1)); - mCellCamera->setPosition(Vector3(x, zhigh+100000, y)); + mCameraNode->setPosition(Vector3(x, zhigh+100000, y)); //mCellCamera->setFarClipDistance( (zhigh-zlow) * 1.1 ); mCellCamera->setFarClipDistance(0); // infinite diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index efbccf884..42603885a 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -73,6 +73,8 @@ namespace MWRender static const int sSize = 8192; Ogre::Camera* mCellCamera; + Ogre::SceneNode* mCameraNode; + Ogre::SceneNode* mCameraRotNode; void render(const float x, const float y, const float zlow, const float zhigh, diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 5c661b4a2..24d055c35 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -701,7 +701,6 @@ namespace MWWorld void World::update (float duration) { - getNorthVector(mWorldScene->getCurrentCell()); mWorldScene->update (duration); mWeatherManager->update (duration); @@ -761,10 +760,7 @@ namespace MWWorld ESMS::CellRefList statics = cell->statics; ESMS::LiveCellRef* ref = statics.find("northmarker"); if (!ref) - { - std::cout << "No north marker found." << std::endl; return Vector2(0, 1); - } Ogre::SceneNode* node = ref->mData.getBaseNode(); Vector3 dir = node->_getDerivedOrientation().yAxis(); Vector2 d = Vector2(dir.x, dir.z); From 0c2317ce9d7f9fb2877605301d53785dc3b472ac Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 29 Mar 2012 19:20:09 +0200 Subject: [PATCH 06/23] player arrow works again --- apps/openmw/mwrender/localmap.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 47b8171a5..ef21e2658 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -11,7 +11,8 @@ using namespace MWRender; using namespace Ogre; -LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWWorld::Environment* env) +LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWWorld::Environment* env) : + mInterior(false), mCellX(0), mCellY(0) { mRendering = rend; mEnvironment = env; @@ -93,6 +94,8 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell) { mInterior = false; + mCameraRotNode->setOrientation(Quaternion::IDENTITY); + std::string name = "Cell_"+coordStr(cell->cell->data.gridX, cell->cell->data.gridY); int x = cell->cell->data.gridX; @@ -235,7 +238,12 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& // retrieve the x,y grid coordinates the player is in int x,y; - Vector2 pos(position.x, position.z); + Vector3 _pos(position.x, 0, position.z); + _pos = mCameraRotNode->convertWorldToLocalPosition(_pos); + Vector2 pos(_pos.x, _pos.z); + + Vector3 playerdirection = mCameraRotNode->convertWorldToLocalPosition(direction); + if (!mInterior) { x = std::ceil(pos.x / sSize)-1; @@ -273,7 +281,7 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& texName = mInteriorName + "_" + coordStr(x,y); } mEnvironment->mWindowManager->setPlayerPos(u, v); - mEnvironment->mWindowManager->setPlayerDir(direction.x, -direction.z); + mEnvironment->mWindowManager->setPlayerDir(playerdirection.x, -playerdirection.z); // explore radius (squared) const float sqrExploreRadius = 0.01 * sFogOfWarResolution*sFogOfWarResolution; From 8d224f009fc34957572d4c8a3a8695936856197a Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 29 Mar 2012 19:45:19 +0200 Subject: [PATCH 07/23] toggleFogOfWar script command --- apps/openmw/mwgui/layouts.cpp | 35 ++++++++++++++++++++------ apps/openmw/mwgui/layouts.hpp | 5 ++++ apps/openmw/mwgui/window_manager.cpp | 6 +++++ apps/openmw/mwgui/window_manager.hpp | 2 ++ apps/openmw/mwrender/localmap.cpp | 1 - apps/openmw/mwscript/docs/vmformat.txt | 3 ++- apps/openmw/mwscript/guiextensions.cpp | 19 ++++++++++++++ 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index de74214ee..223c072b7 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/layouts.cpp @@ -278,6 +278,7 @@ LocalMapBase::LocalMapBase() : mCurX(0) , mCurY(0) , mInterior(false) + , mFogOfWar(true) , mLocalMap(NULL) , mPrefix() , mChanged(true) @@ -297,6 +298,32 @@ void LocalMapBase::setCellPrefix(const std::string& prefix) mChanged = true; } +void LocalMapBase::toggleFogOfWar() +{ + mFogOfWar = !mFogOfWar; + applyFogOfWar(); +} + +void LocalMapBase::applyFogOfWar() +{ + for (int mx=0; mx<3; ++mx) + { + for (int my=0; my<3; ++my) + { + std::string name = "Map_" + boost::lexical_cast(mx) + "_" + + boost::lexical_cast(my); + std::string image = mPrefix+"_"+ boost::lexical_cast(mCurX + (mx-1)) + "_" + + boost::lexical_cast(mCurY + (mInterior ? (my-1) : -1*(my-1))); + MyGUI::ImageBox* fog; + mLayout->getWidget(fog, name+"_fog"); + fog->setImageTexture(mFogOfWar ? + ((MyGUI::RenderManager::getInstance().getTexture(image+"_fog") != 0) ? image+"_fog" + : "black.png" ) + : ""); + } + } +} + void LocalMapBase::setActiveCell(const int x, const int y, bool interior) { if (x==mCurX && y==mCurY && mInterior==interior && !mChanged) return; // don't do anything if we're still in the same cell @@ -312,23 +339,17 @@ void LocalMapBase::setActiveCell(const int x, const int y, bool interior) MyGUI::ImageBox* box; mLayout->getWidget(box, name); - MyGUI::ImageBox* fog; - mLayout->getWidget(fog, name+"_fog"); if (MyGUI::RenderManager::getInstance().getTexture(image) != 0) box->setImageTexture(image); else box->setImageTexture("black.png"); - - if (MyGUI::RenderManager::getInstance().getTexture(image+"_fog") != 0) - fog->setImageTexture(image+"_fog"); - else - fog->setImageTexture("black.png"); } } mInterior = interior; mCurX = x; mCurY = y; mChanged = false; + applyFogOfWar(); } diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index 614479ccc..6719e967c 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -40,12 +40,17 @@ namespace MWGui void setCellPrefix(const std::string& prefix); void setActiveCell(const int x, const int y, bool interior=false); + void toggleFogOfWar(); + protected: int mCurX, mCurY; bool mInterior; MyGUI::ScrollView* mLocalMap; std::string mPrefix; bool mChanged; + bool mFogOfWar; + + void applyFogOfWar(); OEngine::GUI::Layout* mLayout; }; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index a04e2dcb8..e7aa7690f 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -469,3 +469,9 @@ void WindowManager::setPlayerDir(const float x, const float y) map->setPlayerDir(x,y); hud->setPlayerDir(x,y); } + +void WindowManager::toggleFogOfWar() +{ + map->toggleFogOfWar(); + hud->toggleFogOfWar(); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 582f438e8..204774f5f 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -156,6 +156,8 @@ namespace MWGui void changeCell(MWWorld::Ptr::CellStore* cell); ///< change the active cell void setPlayerPos(const float x, const float y); ///< set player position in map space void setPlayerDir(const float x, const float y); ///< set player view direction in map space + + void toggleFogOfWar(); void setInteriorMapTexture(const int x, const int y); ///< set the index of the map texture that should be used (for interiors) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index ef21e2658..803899110 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -269,7 +269,6 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& u = std::abs((pos.x - (sSize*x))/sSize); v = 1-std::abs((pos.y + (sSize*y))/sSize); texName = "Cell_"+coordStr(x,y); - } else { diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index eab5bf846..d7e81531d 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -123,4 +123,5 @@ op 0x200013d: FadeOut op 0x200013e: FadeTo op 0x200013f: GetCurrentWeather op 0x2000140: ChangeWeather -opcodes 0x2000141-0x3ffffff unused +op 0x2000145: ToggleFogOfWar (tfow) +opcodes 0x2000146-0x3ffffff unused diff --git a/apps/openmw/mwscript/guiextensions.cpp b/apps/openmw/mwscript/guiextensions.cpp index 484c0d3ab..426378efc 100644 --- a/apps/openmw/mwscript/guiextensions.cpp +++ b/apps/openmw/mwscript/guiextensions.cpp @@ -67,6 +67,19 @@ namespace MWScript } }; + class OpToggleFogOfWar : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getEnvironment().mWindowManager->toggleFogOfWar(); + } + }; + const int opcodeEnableBirthMenu = 0x200000e; const int opcodeEnableClassMenu = 0x200000f; const int opcodeEnableNameMenu = 0x2000010; @@ -79,6 +92,7 @@ namespace MWScript const int opcodeEnableRest = 0x2000017; const int opcodeShowRestMenu = 0x2000018; const int opcodeGetButtonPressed = 0x2000137; + const int opcodeToggleFogOfWar = 0x2000145; void registerExtensions (Compiler::Extensions& extensions) { @@ -100,6 +114,9 @@ namespace MWScript extensions.registerInstruction ("showrestmenu", "", opcodeShowRestMenu); extensions.registerFunction ("getbuttonpressed", 'l', "", opcodeGetButtonPressed); + + extensions.registerInstruction ("togglefogofwar", "", opcodeToggleFogOfWar); + extensions.registerInstruction ("tfow", "", opcodeToggleFogOfWar); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -135,6 +152,8 @@ namespace MWScript new OpShowDialogue (MWGui::GM_Rest)); interpreter.installSegment5 (opcodeGetButtonPressed, new OpGetButtonPressed); + + interpreter.installSegment5 (opcodeToggleFogOfWar, new OpToggleFogOfWar); } } } From fc5cd703bb189d774a1d843d44e508772389a1c7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 30 Mar 2012 16:34:36 +0200 Subject: [PATCH 08/23] maps are now rendered with correct rotation, however for interiors the arrow is wrong --- apps/openmw/mwrender/localmap.cpp | 37 +++++++++++++++++------ apps/openmw/mwrender/localmap.hpp | 5 +-- apps/openmw/mwrender/renderingmanager.cpp | 2 +- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 803899110..063b25301 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -17,7 +17,8 @@ LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWWorld::Environment* en mRendering = rend; mEnvironment = env; - mCameraRotNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode(); + mCameraPosNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode(); + mCameraRotNode = mCameraPosNode->createChildSceneNode(); mCameraNode = mCameraRotNode->createChildSceneNode(); mCellCamera = mRendering->getScene()->createCamera("CellCamera"); @@ -101,6 +102,8 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell) int x = cell->cell->data.gridX; int y = cell->cell->data.gridY; + mCameraPosNode->setPosition(Vector3(0,0,0)); + render((x+0.5)*sSize, (-y-0.5)*sSize, -10000, 10000, sSize, sSize, name); } @@ -110,17 +113,26 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, mInterior = true; mBounds = bounds; - Vector2 z(bounds.getMaximum().y, bounds.getMinimum().y); - Vector2 min(bounds.getMinimum().x, bounds.getMinimum().z); - Vector2 max(bounds.getMaximum().x, bounds.getMaximum().z); + Vector2 z(mBounds.getMaximum().y, mBounds.getMinimum().y); const Vector2& north = mEnvironment->mWorld->getNorthVector(cell); - Radian angle(std::atan2(north.x, north.y)); + Radian angle(std::atan2(-north.x, -north.y)); mCameraRotNode->setOrientation(Quaternion(Math::Cos(angle/2.f), 0, Math::Sin(angle/2.f), 0)); - Vector2 length = max-min; + mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::NEAR_LEFT_BOTTOM))); + mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::FAR_LEFT_BOTTOM))); + mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::NEAR_RIGHT_BOTTOM))); + mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::FAR_RIGHT_BOTTOM))); + Vector2 center(bounds.getCenter().x, bounds.getCenter().z); + Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); + Vector2 max(mBounds.getMaximum().x, mBounds.getMaximum().z); + + Vector2 length = max-min; + + mCameraPosNode->setPosition(Vector3(center.x, 0, center.y)); + // divide into segments const int segsX = std::ceil( length.x / sSize ); const int segsY = std::ceil( length.y / sSize ); @@ -134,7 +146,7 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, Vector2 start = min + Vector2(sSize*x,sSize*y); Vector2 newcenter = start + 4096; - render(newcenter.x, newcenter.y, z.y, z.x, sSize, sSize, + render(newcenter.x - center.x, newcenter.y - center.y, z.y, z.x, sSize, sSize, cell->cell->name + "_" + coordStr(x,y)); } } @@ -227,7 +239,7 @@ void LocalMap::render(const float x, const float y, mRendering->getScene()->setFog(FOG_LINEAR, clr, 0, fStart, fEnd); } -void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& direction) +void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaternion& orientation) { if (sFogOfWarSkip != 0) { @@ -240,9 +252,13 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& int x,y; Vector3 _pos(position.x, 0, position.z); _pos = mCameraRotNode->convertWorldToLocalPosition(_pos); + + //if (mInterior) + /// \todo + Vector2 pos(_pos.x, _pos.z); - Vector3 playerdirection = mCameraRotNode->convertWorldToLocalPosition(direction); + Vector3 playerdirection = -mCameraRotNode->convertWorldToLocalOrientation(orientation).zAxis(); if (!mInterior) { @@ -279,6 +295,9 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& texName = mInteriorName + "_" + coordStr(x,y); } + + //std::cout << " x,y " << x << ", " << y << " u,v " << u << "," << v << std::endl; + mEnvironment->mWindowManager->setPlayerPos(u, v); mEnvironment->mWindowManager->setPlayerDir(playerdirection.x, -playerdirection.z); diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index 42603885a..cb294a656 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -44,9 +44,9 @@ namespace MWRender * @remarks This is used to draw a "fog of war" effect * to hide areas on the map the player has not discovered yet. * @param position (OGRE coordinates) - * @param view direction (OGRE coordinates) + * @param camera orientation (OGRE coordinates) */ - void updatePlayer (const Ogre::Vector3& position, const Ogre::Vector3& direction); + void updatePlayer (const Ogre::Vector3& position, const Ogre::Quaternion& orientation); /** * Save the fog of war for the current cell to disk. @@ -74,6 +74,7 @@ namespace MWRender Ogre::Camera* mCellCamera; Ogre::SceneNode* mCameraNode; + Ogre::SceneNode* mCameraPosNode; Ogre::SceneNode* mCameraRotNode; void render(const float x, const float y, diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index c947b67f5..5df93ab32 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -171,7 +171,7 @@ void RenderingManager::update (float duration){ mRendering.update(duration); - mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealDirection() ); + mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealOrientation() ); checkUnderwater(); } From ff85006e7159aa808c23bd02f9fb83d24b277da0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 30 Mar 2012 18:38:33 +0200 Subject: [PATCH 09/23] added untested interface --- components/CMakeLists.txt | 4 ++ components/settings/settings.cpp | 64 ++++++++++++++++++++++++++++++++ components/settings/settings.hpp | 35 +++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 components/settings/settings.cpp create mode 100644 components/settings/settings.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index c95efb37d..b48c50640 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -2,6 +2,10 @@ project (Components) # source files +add_component_dir (settings + settings + ) + add_component_dir (bsa bsa_archive bsa_file ) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp new file mode 100644 index 000000000..157de0b4d --- /dev/null +++ b/components/settings/settings.cpp @@ -0,0 +1,64 @@ +#include "settings.hpp" + +#include + +#include +#include + +using namespace Settings; + +Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile(); +Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile(); + +void Manager::load(const std::string& file) +{ + mFile.load(file); +} + +void Manager::loadDefault(const std::string& file) +{ + mDefaultFile.load(file); +} + +void Manager::save(const std::string& file) +{ + std::fstream fout(file.c_str(), std::ios::out); + + Ogre::ConfigFile::SectionIterator seci = mFile.getSectionIterator(); + + while (seci.hasMoreElements()) + { + Ogre::String sectionName = seci.peekNextKey(); + + if (sectionName.length() > 0) + fout << '\n' << '[' << seci.peekNextKey() << ']' << '\n'; + + Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); + Ogre::ConfigFile::SettingsMultiMap::iterator i; + for (i = settings->begin(); i != settings->end(); ++i) + { + fout << i->first.c_str() << '=' << i->second.c_str() << '\n'; + } + } +} + +const std::string Manager::getString (const std::string& setting, const std::string& category) +{ + std::string defaultval = mDefaultFile.getSetting(setting, category); + return mFile.getSetting(setting, category, defaultval); +} + +const float Manager::getFloat (const std::string& setting, const std::string& category) +{ + return Ogre::StringConverter::parseReal( getString(setting, category) ); +} + +const int Manager::getInt (const std::string& setting, const std::string& category) +{ + return Ogre::StringConverter::parseInt( getString(setting, category) ); +} + +const bool Manager::getBool (const std::string& setting, const std::string& category) +{ + return Ogre::StringConverter::parseBool( getString(setting, category) ); +} diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp new file mode 100644 index 000000000..ae6f1a9de --- /dev/null +++ b/components/settings/settings.hpp @@ -0,0 +1,35 @@ +#ifndef _COMPONENTS_SETTINGS_H +#define _COMPONENTS_SETTINGS_H + +#include + +namespace Settings +{ + + /// + /// \brief Settings management (can change during runtime) + /// + class Manager + { + public: + static Ogre::ConfigFile mFile; + static Ogre::ConfigFile mDefaultFile; + + void loadDefault (const std::string& file); + ///< load file as the default settings (can be overridden by user settings) + + void load (const std::string& file); + ///< load file as user settings + + void save (const std::string& file); + ///< save to file + + static const int getInt (const std::string& setting, const std::string& category); + static const float getFloat (const std::string& setting, const std::string& category); + static const std::string getString (const std::string& setting, const std::string& category); + static const bool getBool (const std::string& setting, const std::string& category); + }; + +} + +#endif // _COMPONENTS_SETTINGS_H From 82429d69316ae8c12c6633d414aadbfec2e694f4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 31 Mar 2012 13:35:40 +0200 Subject: [PATCH 10/23] finished interface --- components/settings/settings.cpp | 42 +++++++++++++++++++++++++++++--- components/settings/settings.hpp | 14 ++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 157de0b4d..500d3c6e6 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -10,17 +10,22 @@ using namespace Settings; Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile(); Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile(); -void Manager::load(const std::string& file) +void Manager::loadUser (const std::string& file) { mFile.load(file); } -void Manager::loadDefault(const std::string& file) +void Manager::loadDefault (const std::string& file) { mDefaultFile.load(file); } -void Manager::save(const std::string& file) +void Manager::copyDefaultToUserSettings () +{ + mFile = mDefaultFile; +} + +void Manager::saveUser(const std::string& file) { std::fstream fout(file.c_str(), std::ios::out); @@ -39,6 +44,8 @@ void Manager::save(const std::string& file) { fout << i->first.c_str() << '=' << i->second.c_str() << '\n'; } + + seci.getNext(); } } @@ -62,3 +69,32 @@ const bool Manager::getBool (const std::string& setting, const std::string& cate { return Ogre::StringConverter::parseBool( getString(setting, category) ); } + +void Manager::setString (const std::string& setting, const std::string& category, const std::string& value) +{ + Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); + while (it.hasMoreElements()) + { + Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); + + if ((*i).first == setting) + (*i).second = value; + + it.getNext(); + } +} + +void Manager::setInt (const std::string& setting, const std::string& category, const int value) +{ + setString(setting, category, Ogre::StringConverter::toString(value)); +} + +void Manager::setFloat (const std::string& setting, const std::string& category, const float value) +{ + setString(setting, category, Ogre::StringConverter::toString(value)); +} + +void Manager::setBool (const std::string& setting, const std::string& category, const bool value) +{ + setString(setting, category, Ogre::StringConverter::toString(value)); +} diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index ae6f1a9de..46f8139c4 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -18,16 +18,24 @@ namespace Settings void loadDefault (const std::string& file); ///< load file as the default settings (can be overridden by user settings) - void load (const std::string& file); + void copyDefaultToUserSettings (); + ///< copy the default settings to the user settings (useful when there are no user settings yet) + + void loadUser (const std::string& file); ///< load file as user settings - void save (const std::string& file); - ///< save to file + void saveUser (const std::string& file); + ///< save user settings to file static const int getInt (const std::string& setting, const std::string& category); static const float getFloat (const std::string& setting, const std::string& category); static const std::string getString (const std::string& setting, const std::string& category); static const bool getBool (const std::string& setting, const std::string& category); + + static void setInt (const std::string& setting, const std::string& category, const int value); + static void setFloat (const std::string& setting, const std::string& category, const float value); + static void setString (const std::string& setting, const std::string& category, const std::string& value); + static void setBool (const std::string& setting, const std::string& category, const bool value); }; } From 308df7caa8806f344a7e32f02b9b1114b433b791 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 1 Apr 2012 16:26:42 +0200 Subject: [PATCH 11/23] add method for keeping track of settings that changed --- components/settings/settings.cpp | 13 ++++++++++++- components/settings/settings.hpp | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 500d3c6e6..463230bc7 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -9,6 +9,7 @@ using namespace Settings; Ogre::ConfigFile Manager::mFile = Ogre::ConfigFile(); Ogre::ConfigFile Manager::mDefaultFile = Ogre::ConfigFile(); +SettingCategoryVector Manager::mChangedSettings = SettingCategoryVector(); void Manager::loadUser (const std::string& file) { @@ -77,8 +78,11 @@ void Manager::setString (const std::string& setting, const std::string& category { Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); - if ((*i).first == setting) + if ((*i).first == setting && (*i).second != value) + { + mChangedSettings.push_back(std::make_pair(setting, category)); (*i).second = value; + } it.getNext(); } @@ -98,3 +102,10 @@ void Manager::setBool (const std::string& setting, const std::string& category, { setString(setting, category, Ogre::StringConverter::toString(value)); } + +const SettingCategoryVector Manager::apply() +{ + SettingCategoryVector vec = mChangedSettings; + mChangedSettings.clear(); + return vec; +} diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index 46f8139c4..98fad605e 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -5,6 +5,7 @@ namespace Settings { + typedef std::vector< std::pair > SettingCategoryVector; /// /// \brief Settings management (can change during runtime) @@ -12,9 +13,13 @@ namespace Settings class Manager { public: + static Ogre::ConfigFile mFile; static Ogre::ConfigFile mDefaultFile; + static SettingCategoryVector mChangedSettings; + ///< tracks all the settings that were changed since the last apply() call + void loadDefault (const std::string& file); ///< load file as the default settings (can be overridden by user settings) @@ -27,6 +32,9 @@ namespace Settings void saveUser (const std::string& file); ///< save user settings to file + const SettingCategoryVector apply(); + ///< returns the list of changed settings and then clears it + static const int getInt (const std::string& setting, const std::string& category); static const float getFloat (const std::string& setting, const std::string& category); static const std::string getString (const std::string& setting, const std::string& category); From 6091a0504db624f10e605a1bf3a22345c9399fe6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 1 Apr 2012 16:59:35 +0200 Subject: [PATCH 12/23] first settings test (config file has to be created manually) --- apps/openmw/engine.cpp | 12 ++ components/nifogre/ogre_nif_loader.cpp | 241 ++++++++++++------------- components/settings/settings.cpp | 3 + components/settings/settings.hpp | 1 - 4 files changed, 135 insertions(+), 122 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 38050e53b..294fcf492 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -313,6 +314,17 @@ void OMW::Engine::go() { boost::filesystem::create_directories(configPath); } + + Settings::Manager settings; + + //settings.loadDefault(defaultsettingspath); + + const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg"; + if (boost::filesystem::exists(settingspath)) + settings.loadUser(settingspath); + else + settings.copyDefaultToUserSettings(); + mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), mCfgMgr.getLogPath().string(), diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 2ab6ae621..7fa45815f 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -25,6 +25,7 @@ #include "ogre_nif_loader.hpp" +#include typedef unsigned char ubyte; @@ -299,138 +300,136 @@ void NIFLoader::createMaterial(const String &name, material->setSelfIllumination(emissive.array[0], emissive.array[1], emissive.array[2]); material->setShininess(glossiness); - // Create shader for the material - // vertex - HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton(); - - HighLevelGpuProgramPtr vertex; - if (mgr.getByName("main_vp").isNull()) + if (Settings::Manager::getBool("shaders", "Objects")) { - vertex = mgr.createProgram("main_vp", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - "cg", GPT_VERTEX_PROGRAM); - vertex->setParameter("profiles", "vs_4_0 vs_2_x vp40 arbvp1"); - vertex->setParameter("entry_point", "main_vp"); - StringUtil::StrStreamType outStream; - outStream << - "void main_vp( \n" - " float4 position : POSITION, \n" - " float4 normal : NORMAL, \n" - " float4 colour : COLOR, \n" - " in float2 uv : TEXCOORD0, \n" - " out float2 oUV : TEXCOORD0, \n" - " out float4 oPosition : POSITION, \n" - " out float4 oPositionObjSpace : TEXCOORD1, \n" - " out float4 oNormal : TEXCOORD2, \n" - " out float oFogValue : TEXCOORD3, \n" - " out float4 oVertexColour : TEXCOORD4, \n" - " uniform float4 fogParams, \n" - " uniform float4x4 worldViewProj \n" - ") \n" - "{ \n" - " oVertexColour = colour; \n" - " oUV = uv; \n" - " oNormal = normal; \n" - " oPosition = mul( worldViewProj, position ); \n" - " oFogValue = saturate((oPosition.z - fogParams.y) * fogParams.w); \n" - " oPositionObjSpace = position; \n" - "}"; - vertex->setSource(outStream.str()); - vertex->load(); - vertex->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); - vertex->getDefaultParameters()->setNamedAutoConstant("fogParams", GpuProgramParameters::ACT_FOG_PARAMS); - } - else - vertex = mgr.getByName("main_vp"); - material->getTechnique(0)->getPass(0)->setVertexProgram(vertex->getName()); - - // the number of lights to support. - // when rendering an object, OGRE automatically picks the lights that are - // closest to the object being rendered. unfortunately this mechanism does - // not work perfectly for objects batched together (they will all use the same - // lights). to work around this, we are simply pushing the maximum number - // of lights here in order to minimize disappearing lights. - float num_lights; - if (GpuProgramManager::getSingleton().isSyntaxSupported("fp40") || - GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0")) - num_lights = 8 /* 32 */; - else - num_lights = 8; + // Create shader for the material + // vertex + HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton(); - // fragment - HighLevelGpuProgramPtr fragment; - if (mgr.getByName("main_fp").isNull()) - { - fragment = mgr.createProgram("main_fp", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - "cg", GPT_FRAGMENT_PROGRAM); - fragment->setParameter("profiles", "ps_4_0 ps_2_x fp40 arbfp1"); - fragment->setParameter("entry_point", "main_fp"); - StringUtil::StrStreamType outStream; - outStream << - "void main_fp( \n" - " in float2 uv : TEXCOORD0, \n" - " out float4 oColor : COLOR, \n" - " uniform sampler2D texture : TEXUNIT0, \n" - " float4 positionObjSpace : TEXCOORD1, \n" - " float4 normal : TEXCOORD2, \n" - " float fogValue : TEXCOORD3, \n" - " float4 vertexColour : TEXCOORD4, \n" - " uniform float4 fogColour, \n"; - - for (int i=0; isetParameter("profiles", "vs_4_0 vs_2_x vp40 arbvp1"); + vertex->setParameter("entry_point", "main_vp"); + StringUtil::StrStreamType outStream; outStream << - " uniform float4 lightDiffuse"<setSource(outStream.str()); + vertex->load(); + vertex->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); + vertex->getDefaultParameters()->setNamedAutoConstant("fogParams", GpuProgramParameters::ACT_FOG_PARAMS); } - outStream << - " uniform float4 lightAmbient, \n" - " uniform float4 ambient, \n" - " uniform float4 diffuse, \n" - " uniform float4 emissive \n" - ") \n" - "{ \n" - " float4 tex = tex2D(texture, uv); \n" - " float d; \n" - " float attn; \n" - " float3 lightColour = float3(0, 0, 0); \n"; - - for (int i=0; igetTechnique(0)->getPass(0)->setVertexProgram(vertex->getName()); + + // the number of lights to support. + // when rendering an object, OGRE automatically picks the lights that are + // closest to the object being rendered. unfortunately this mechanism does + // not work perfectly for objects batched together (they will all use the same + // lights). to work around this, we are simply pushing the maximum number + // of lights here in order to minimize disappearing lights. + int num_lights = Settings::Manager::getInt("num lights", "Objects"); + + // fragment + HighLevelGpuProgramPtr fragment; + if (mgr.getByName("main_fp").isNull()) { + fragment = mgr.createProgram("main_fp", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + "cg", GPT_FRAGMENT_PROGRAM); + fragment->setParameter("profiles", "ps_4_0 ps_2_x fp40 arbfp1"); + fragment->setParameter("entry_point", "main_fp"); + StringUtil::StrStreamType outStream; + outStream << + "void main_fp( \n" + " in float2 uv : TEXCOORD0, \n" + " out float4 oColor : COLOR, \n" + " uniform sampler2D texture : TEXUNIT0, \n" + " float4 positionObjSpace : TEXCOORD1, \n" + " float4 normal : TEXCOORD2, \n" + " float fogValue : TEXCOORD3, \n" + " float4 vertexColour : TEXCOORD4, \n" + " uniform float4 fogColour, \n"; + + for (int i=0; isetSource(outStream.str()); - fragment->load(); - - for (int i=0; igetDefaultParameters()->setNamedAutoConstant("lightPositionObjSpace"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, i); - fragment->getDefaultParameters()->setNamedAutoConstant("lightDiffuse"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, i); - fragment->getDefaultParameters()->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); + " lightColour.xyz += lit(dot(normalize(lightDir"<setSource(outStream.str()); + fragment->load(); + + for (int i=0; igetDefaultParameters()->setNamedAutoConstant("lightPositionObjSpace"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, i); + fragment->getDefaultParameters()->setNamedAutoConstant("lightDiffuse"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, i); + fragment->getDefaultParameters()->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); + } + fragment->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); + fragment->getDefaultParameters()->setNamedAutoConstant("diffuse", GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR); + fragment->getDefaultParameters()->setNamedAutoConstant("ambient", GpuProgramParameters::ACT_SURFACE_AMBIENT_COLOUR); + fragment->getDefaultParameters()->setNamedAutoConstant("lightAmbient", GpuProgramParameters::ACT_AMBIENT_LIGHT_COLOUR); + fragment->getDefaultParameters()->setNamedAutoConstant("fogColour", GpuProgramParameters::ACT_FOG_COLOUR); } - fragment->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR); - fragment->getDefaultParameters()->setNamedAutoConstant("diffuse", GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR); - fragment->getDefaultParameters()->setNamedAutoConstant("ambient", GpuProgramParameters::ACT_SURFACE_AMBIENT_COLOUR); - fragment->getDefaultParameters()->setNamedAutoConstant("lightAmbient", GpuProgramParameters::ACT_AMBIENT_LIGHT_COLOUR); - fragment->getDefaultParameters()->setNamedAutoConstant("fogColour", GpuProgramParameters::ACT_FOG_COLOUR); + else + fragment = mgr.getByName("main_fp"); + material->getTechnique(0)->getPass(0)->setFragmentProgram(fragment->getName()); } - else - fragment = mgr.getByName("main_fp"); - material->getTechnique(0)->getPass(0)->setFragmentProgram(fragment->getName()); } // Takes a name and adds a unique part to it. This is just used to diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 463230bc7..f2b7823e3 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -73,6 +73,7 @@ const bool Manager::getBool (const std::string& setting, const std::string& cate void Manager::setString (const std::string& setting, const std::string& category, const std::string& value) { + bool found=false; Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); while (it.hasMoreElements()) { @@ -82,10 +83,12 @@ void Manager::setString (const std::string& setting, const std::string& category { mChangedSettings.push_back(std::make_pair(setting, category)); (*i).second = value; + found = true; } it.getNext(); } + assert(found && "Attempting to change a non-existing setting"); } void Manager::setInt (const std::string& setting, const std::string& category, const int value) diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index 98fad605e..368b5e692 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -13,7 +13,6 @@ namespace Settings class Manager { public: - static Ogre::ConfigFile mFile; static Ogre::ConfigFile mDefaultFile; From f4bbcb48a6de3a5d505004571c627a68b8b28d71 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 1 Apr 2012 17:14:49 +0200 Subject: [PATCH 13/23] settings-default.cfg --- CMakeLists.txt | 4 ++++ apps/openmw/engine.cpp | 11 +++++++++-- files/settings-default.cfg | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 files/settings-default.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f007dbcc..9c2f5a29a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,6 +214,9 @@ endif (APPLE) # Other files +configure_file(${OpenMW_SOURCE_DIR}/files/settings-default.cfg + "${OpenMW_BINARY_DIR}/settings-default.cfg") + configure_file(${OpenMW_SOURCE_DIR}/files/openmw.cfg.local "${OpenMW_BINARY_DIR}/openmw.cfg") configure_file(${OpenMW_SOURCE_DIR}/files/openmw.cfg @@ -288,6 +291,7 @@ if(DPKG_PROGRAM) INSTALL(FILES "${OpenMW_SOURCE_DIR}/apps/launcher/resources/images/openmw.png" DESTINATION "share/pixmaps/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") #Install global configuration files + INSTALL(FILES "${OpenMW_BINARY_DIR}/settings-default.cfg" DESTINATION "../etc/openmw/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "../etc/openmw/" RENAME "openmw.cfg" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") INSTALL(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "../etc/openmw/" PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT "openmw") diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 294fcf492..166c9c16b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -315,9 +315,16 @@ void OMW::Engine::go() boost::filesystem::create_directories(configPath); } + // Create the settings manager and load default and user settings file Settings::Manager settings; - - //settings.loadDefault(defaultsettingspath); + const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg"; + const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg"; + + // prefer local + if (boost::filesystem::exists(localdefault)) + settings.loadDefault(localdefault); + else if (boost::filesystem::exists(globaldefault)) + settings.loadDefault(globaldefault); const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg"; if (boost::filesystem::exists(settingspath)) diff --git a/files/settings-default.cfg b/files/settings-default.cfg new file mode 100644 index 000000000..7a35b7102 --- /dev/null +++ b/files/settings-default.cfg @@ -0,0 +1,3 @@ +[Objects] +shaders = true +num lights = 8 From 7b3adb27a3eb88752681f47fc4622d80f191fd4f Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 1 Apr 2012 18:48:37 +0200 Subject: [PATCH 14/23] backend changes, terrain num lights setting --- apps/openmw/engine.cpp | 3 + apps/openmw/mwrender/terrainmaterial.cpp | 40 ++++-------- components/settings/settings.cpp | 79 +++++++++++++++++++----- components/settings/settings.hpp | 11 +++- files/settings-default.cfg | 3 + 5 files changed, 91 insertions(+), 45 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 166c9c16b..849ccbe2e 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -426,6 +426,9 @@ void OMW::Engine::go() // Start the main rendering loop mOgre->start(); + // Save user settings + settings.saveUser(settingspath); + std::cout << "Quitting peacefully.\n"; } diff --git a/apps/openmw/mwrender/terrainmaterial.cpp b/apps/openmw/mwrender/terrainmaterial.cpp index 67ebf45af..922ea2280 100644 --- a/apps/openmw/mwrender/terrainmaterial.cpp +++ b/apps/openmw/mwrender/terrainmaterial.cpp @@ -36,7 +36,7 @@ THE SOFTWARE. #include "OgreHardwarePixelBuffer.h" #include "OgreShadowCameraSetupPSSM.h" -#define POINTLIGHTS +#include namespace Ogre { @@ -220,22 +220,10 @@ namespace Ogre } - int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const - { - #ifndef POINTLIGHTS - return 1; - #else - // number of supported lights depends on the number of available constant registers, - // which in turn depends on the shader profile used - if (GpuProgramManager::getSingleton().isSyntaxSupported("ps_3_0") - || GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0") - || GpuProgramManager::getSingleton().isSyntaxSupported("fp40") - ) - return 32; - else - return 8; - #endif - } + int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const + { + return Settings::Manager::getInt("num lights", "Terrain"); + } //--------------------------------------------------------------------- MaterialPtr TerrainMaterialGeneratorB::SM2Profile::generate(const Terrain* terrain) { @@ -565,7 +553,8 @@ namespace Ogre { params->setNamedAutoConstant("lightPosObjSpace"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, i); params->setNamedAutoConstant("lightDiffuseColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, i); - params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); + if (prof->getNumberOfLightsSupported() > 1) + params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); //params->setNamedAutoConstant("lightSpecularColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR, i); } @@ -980,10 +969,9 @@ namespace Ogre //"uniform float3 lightSpecularColour"<getNumberOfLightsSupported() > 1) + outStream << + "uniform float4 lightAttenuation"<getNumberOfLightsSupported() > 1) + outStream << "float d; \n" "float attn; \n"; - #endif outStream << " eyeDir = normalize(eyeDir); \n"; @@ -1144,13 +1131,12 @@ namespace Ogre outStream << " float3 halfAngle"<getNumberOfLightsSupported() > 1) outStream << // pre-multiply light color with attenuation factor "d = length( lightDir"<begin(); i != settings->end(); ++i) { - fout << i->first.c_str() << '=' << i->second.c_str() << '\n'; + fout << i->first.c_str() << " = " << i->second.c_str() << '\n'; } - seci.getNext(); + CategorySettingValueMap::iterator it = mNewSettings.begin(); + while (it != mNewSettings.end()) + { + if (it->first.first == sectionName) + { + fout << it->first.second << " = " << it->second << '\n'; + mNewSettings.erase(it++); + } + else + ++it; + } + } + + std::string category = ""; + for (CategorySettingValueMap::iterator it = mNewSettings.begin(); + it != mNewSettings.end(); ++it) + { + if (category != it->first.first) + { + category = it->first.first; + fout << '\n' << '[' << category << ']' << '\n'; + } + fout << it->first.second << " = " << it->second << '\n'; } } const std::string Manager::getString (const std::string& setting, const std::string& category) { + if (mNewSettings.find(std::make_pair(category, setting)) != mNewSettings.end()) + return mNewSettings[std::make_pair(category, setting)]; + std::string defaultval = mDefaultFile.getSetting(setting, category); return mFile.getSetting(setting, category, defaultval); } @@ -73,22 +99,45 @@ const bool Manager::getBool (const std::string& setting, const std::string& cate void Manager::setString (const std::string& setting, const std::string& category, const std::string& value) { + CategorySetting s = std::make_pair(category, setting); + bool found=false; - Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); - while (it.hasMoreElements()) + try { - Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); - - if ((*i).first == setting && (*i).second != value) + Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); + while (it.hasMoreElements()) { - mChangedSettings.push_back(std::make_pair(setting, category)); - (*i).second = value; - found = true; + Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); + + if ((*i).first == setting) + { + if ((*i).second != value) + { + mChangedSettings.push_back(std::make_pair(category, setting)); + (*i).second = value; + } + found = true; + } + + it.getNext(); } + } + catch (Ogre::Exception&) + {} - it.getNext(); + if (!found) + { + if (mNewSettings.find(s) != mNewSettings.end()) + { + if (mNewSettings[s] != value) + { + mChangedSettings.push_back(std::make_pair(category, setting)); + mNewSettings[s] = value; + } + } + else + mNewSettings[s] = value; } - assert(found && "Attempting to change a non-existing setting"); } void Manager::setInt (const std::string& setting, const std::string& category, const int value) @@ -106,9 +155,9 @@ void Manager::setBool (const std::string& setting, const std::string& category, setString(setting, category, Ogre::StringConverter::toString(value)); } -const SettingCategoryVector Manager::apply() +const CategorySettingVector Manager::apply() { - SettingCategoryVector vec = mChangedSettings; + CategorySettingVector vec = mChangedSettings; mChangedSettings.clear(); return vec; } diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index 368b5e692..f670ea1dd 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -5,7 +5,9 @@ namespace Settings { - typedef std::vector< std::pair > SettingCategoryVector; + typedef std::pair < std::string, std::string > CategorySetting; + typedef std::vector< std::pair > CategorySettingVector; + typedef std::map < CategorySetting, std::string > CategorySettingValueMap; /// /// \brief Settings management (can change during runtime) @@ -16,9 +18,12 @@ namespace Settings static Ogre::ConfigFile mFile; static Ogre::ConfigFile mDefaultFile; - static SettingCategoryVector mChangedSettings; + static CategorySettingVector mChangedSettings; ///< tracks all the settings that were changed since the last apply() call + static CategorySettingValueMap mNewSettings; + ///< tracks all the settings that are in the default file, but not in user file yet + void loadDefault (const std::string& file); ///< load file as the default settings (can be overridden by user settings) @@ -31,7 +36,7 @@ namespace Settings void saveUser (const std::string& file); ///< save user settings to file - const SettingCategoryVector apply(); + static const CategorySettingVector apply(); ///< returns the list of changed settings and then clears it static const int getInt (const std::string& setting, const std::string& category); diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 7a35b7102..1a6b9b328 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1,3 +1,6 @@ [Objects] shaders = true num lights = 8 + +[Terrain] +num lights = 8 From 5accca385ce148bb56545e0d9fbb0037665be3b3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 13:47:25 +0200 Subject: [PATCH 15/23] fix crash on exit when no user settings exist --- apps/openmw/engine.cpp | 9 ++++++--- components/settings/settings.cpp | 5 ----- components/settings/settings.hpp | 3 --- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 849ccbe2e..25c0c60bd 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -315,7 +315,7 @@ void OMW::Engine::go() boost::filesystem::create_directories(configPath); } - // Create the settings manager and load default and user settings file + // Create the settings manager and load default settings file Settings::Manager settings; const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg"; const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg"; @@ -326,11 +326,14 @@ void OMW::Engine::go() else if (boost::filesystem::exists(globaldefault)) settings.loadDefault(globaldefault); + // load user settings if they exist, otherwise just load the default settings as user settings const std::string settingspath = mCfgMgr.getUserPath().string() + "/settings.cfg"; if (boost::filesystem::exists(settingspath)) settings.loadUser(settingspath); - else - settings.copyDefaultToUserSettings(); + else if (boost::filesystem::exists(localdefault)) + settings.loadUser(localdefault); + else if (boost::filesystem::exists(globaldefault)) + settings.loadUser(globaldefault); mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index d94e06678..28201eda2 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -22,11 +22,6 @@ void Manager::loadDefault (const std::string& file) mDefaultFile.load(file); } -void Manager::copyDefaultToUserSettings () -{ - mFile = mDefaultFile; -} - void Manager::saveUser(const std::string& file) { std::fstream fout(file.c_str(), std::ios::out); diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index f670ea1dd..e9858eb94 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -27,9 +27,6 @@ namespace Settings void loadDefault (const std::string& file); ///< load file as the default settings (can be overridden by user settings) - void copyDefaultToUserSettings (); - ///< copy the default settings to the user settings (useful when there are no user settings yet) - void loadUser (const std::string& file); ///< load file as user settings From 1445ae992db1b4fde52330b0a498a2b616836c41 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 14:24:16 +0200 Subject: [PATCH 16/23] adding a setting to disable static geometry --- apps/openmw/mwrender/objects.cpp | 3 ++- files/settings-default.cfg | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 94ccb6e97..eb79581aa 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -3,6 +3,7 @@ #include #include +#include using namespace MWRender; @@ -113,7 +114,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) bounds.scale(insert->getScale()); mBounds[ptr.getCell()].merge(bounds); - if(!mIsStatic) + if(!mIsStatic || !Settings::Manager::getBool("use static geometry", "Objects")) { insert->attachObject(ent); diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 1a6b9b328..bf471e111 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1,6 +1,7 @@ [Objects] shaders = true num lights = 8 +use static geometry = true [Terrain] num lights = 8 From e5cc9adbb02938809938f3ea8a0fe222372d82af Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 15:30:29 +0200 Subject: [PATCH 17/23] added settings for rendering distance of small objects --- apps/openmw/mwrender/objects.cpp | 12 +++++------- files/settings-default.cfg | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index eb79581aa..dd211f8e9 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -89,18 +89,16 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) NifOgre::NIFLoader::load(mesh); Ogre::Entity *ent = mRenderer.getScene()->createEntity(mesh); -/* + Ogre::Vector3 extents = ent->getBoundingBox().getSize(); extents *= insert->getScale(); -// float size = std::max(std::max(extents.x, extents.y), extents.z); + float size = std::max(std::max(extents.x, extents.y), extents.z); - bool small = (size < 250); /// \todo config value + bool small = (size < Settings::Manager::getInt("small object size", "Objects")) && Settings::Manager::getBool("limit small object distance", "Objects"); // do not fade out doors. that will cause holes and look stupid if (ptr.getTypeName().find("Door") != std::string::npos) small = false; -*/ - const bool small = false; if (mBounds.find(ptr.getCell()) == mBounds.end()) mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL; @@ -118,7 +116,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) { insert->attachObject(ent); - ent->setRenderingDistance(small ? 2500 : 0); /// \todo config value + ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Objects") : 0); /// \todo config value } else { @@ -132,7 +130,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); mStaticGeometrySmall[ptr.getCell()] = sg; - sg->setRenderingDistance(2500); /// \todo config value + sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Objects")); /// \todo config value } else sg = mStaticGeometrySmall[ptr.getCell()]; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index bf471e111..1e8be450e 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1,7 +1,24 @@ [Objects] + shaders = true + +# Max. number of lights that affect objects. Setting to 1 will only reflect sunlight +# Note: has no effect when shaders are turned off num lights = 8 + +# Use static geometry for static objects. Improves rendering speed. use static geometry = true +# Limit the rendering distance of small objects +limit small object distance = false + +# Size below which an object is considered as small +small object size = 250 + +# Rendering distance for small objects +small object distance = 3500 + [Terrain] + +# Max. number of lights that affect the terrain. Setting to 1 will only reflect sunlight num lights = 8 From fd662f937a7b6fe2d5db70eb6a2fa5bc5a929728 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 15:51:48 +0200 Subject: [PATCH 18/23] add settings for viewing distance and fog --- apps/openmw/mwrender/objects.cpp | 6 +++--- apps/openmw/mwrender/renderingmanager.cpp | 13 +++++-------- files/settings-default.cfg | 11 +++++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index dd211f8e9..bf83e5c83 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -94,7 +94,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) extents *= insert->getScale(); float size = std::max(std::max(extents.x, extents.y), extents.z); - bool small = (size < Settings::Manager::getInt("small object size", "Objects")) && Settings::Manager::getBool("limit small object distance", "Objects"); + bool small = (size < Settings::Manager::getInt("small object size", "View distance")) && Settings::Manager::getBool("limit small object distance", "Objects"); // do not fade out doors. that will cause holes and look stupid if (ptr.getTypeName().find("Door") != std::string::npos) @@ -116,7 +116,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) { insert->attachObject(ent); - ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Objects") : 0); /// \todo config value + ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "View distance") : 0); /// \todo config value } else { @@ -130,7 +130,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); mStaticGeometrySmall[ptr.getCell()] = sg; - sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Objects")); /// \todo config value + sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "View distance")); /// \todo config value } else sg = mStaticGeometrySmall[ptr.getCell()]; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 688b97a2e..7f4b1ec39 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -12,6 +12,7 @@ #include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone #include "../mwworld/ptr.hpp" #include +#include using namespace MWRender; @@ -273,18 +274,14 @@ void RenderingManager::configureFog(ESMS::CellStore &mCell) void RenderingManager::configureFog(const float density, const Ogre::ColourValue& colour) { - /// \todo make the viewing distance and fog start/end configurable + float max = Settings::Manager::getFloat("max viewing distance", "Viewing distance"); - // right now we load 3x3 cells, so the maximum viewing distance we - // can allow (to prevent objects suddenly popping up) equals: - // 8192 * 0.69 - // ^ cell size ^ minimum density value used (clear weather) - float low = 5652.48 / density / 2.f; - float high = 5652.48 / density; + float low = max / (density) * Settings::Manager::getFloat("fog start factor", "Viewing distance"); + float high = max / (density) * Settings::Manager::getFloat("fog end factor", "Viewing distance"); mRendering.getScene()->setFog (FOG_LINEAR, colour, 0, low, high); - mRendering.getCamera()->setFarClipDistance ( high ); + mRendering.getCamera()->setFarClipDistance ( max / density ); mRendering.getViewport()->setBackgroundColour (colour); } diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 1e8be450e..345977922 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -9,6 +9,8 @@ num lights = 8 # Use static geometry for static objects. Improves rendering speed. use static geometry = true +[Viewing distance] + # Limit the rendering distance of small objects limit small object distance = false @@ -18,6 +20,15 @@ small object size = 250 # Rendering distance for small objects small object distance = 3500 +# Max viewing distance at clear weather conditions +max viewing distance = 5600 + +# Distance at which fog starts (proportional to viewing distance) +fog start factor = 0.5 + +# Distance at which fog ends (proportional to viewing distance) +fog end factor = 1.0 + [Terrain] # Max. number of lights that affect the terrain. Setting to 1 will only reflect sunlight From 00cc45c5371913d2d4965ffc065e43c10c74042e Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 16:10:54 +0200 Subject: [PATCH 19/23] FPS is now a setting instead of commandline option --- apps/openmw/engine.cpp | 2 ++ apps/openmw/main.cpp | 4 ---- files/settings-default.cfg | 8 ++++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 1722be675..cfcf9f76b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -343,6 +343,8 @@ void OMW::Engine::go() else if (boost::filesystem::exists(globaldefault)) settings.loadUser(globaldefault); + mFpsLevel = settings.getInt("fps", "HUD"); + mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), mCfgMgr.getLogPath().string(), diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index cd1e0e26e..a5e5c99e6 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -92,9 +92,6 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("plugin", bpo::value()->default_value(StringsVector(), "") ->multitoken(), "plugin file(s)") - ("fps", boost::program_options::value()->implicit_value(1) - ->default_value(0), "fps counter detail (0 = off, 1 = fps counter, 2 = full detail)") - ("anim-verbose", boost::program_options::value()->implicit_value(true) ->default_value(false), "output animation indices files") @@ -225,7 +222,6 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setNewGame(variables["new-game"].as()); // other settings - engine.showFPS(variables["fps"].as()); engine.setDebugMode(variables["debug"].as()); engine.setSoundUsage(!variables["nosound"].as()); engine.setScriptsVerbosity(variables["script-verbose"].as()); diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 345977922..6372a31c1 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1,3 +1,11 @@ +[HUD] + +# FPS counter +# 0: not visible +# 1: basic FPS display +# 2: advanced FPS display (batches, triangles) +fps = 0 + [Objects] shaders = true From 5f2a674d939f326a41ae9ee6c71f32cdc8136077 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 16:14:39 +0200 Subject: [PATCH 20/23] fixed a typo --- apps/openmw/mwrender/objects.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index bf83e5c83..f52953692 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -94,7 +94,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) extents *= insert->getScale(); float size = std::max(std::max(extents.x, extents.y), extents.z); - bool small = (size < Settings::Manager::getInt("small object size", "View distance")) && Settings::Manager::getBool("limit small object distance", "Objects"); + bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) && Settings::Manager::getBool("limit small object distance", "Objects"); // do not fade out doors. that will cause holes and look stupid if (ptr.getTypeName().find("Door") != std::string::npos) @@ -116,7 +116,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) { insert->attachObject(ent); - ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "View distance") : 0); /// \todo config value + ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0); /// \todo config value } else { @@ -130,7 +130,7 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); mStaticGeometrySmall[ptr.getCell()] = sg; - sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "View distance")); /// \todo config value + sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Viewing distance")); /// \todo config value } else sg = mStaticGeometrySmall[ptr.getCell()]; From 342464530de5f88da0a6728e6ad2f8a99ff08e00 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 19:37:24 +0200 Subject: [PATCH 21/23] rotated map working --- apps/openmw/mwrender/localmap.cpp | 35 ++++++++++++++--------- apps/openmw/mwrender/localmap.hpp | 8 +++++- apps/openmw/mwrender/objects.cpp | 32 +++++++++++++++++++++ apps/openmw/mwrender/objects.hpp | 4 +++ apps/openmw/mwrender/renderingmanager.cpp | 12 +++++++- apps/openmw/mwrender/renderingmanager.hpp | 3 ++ 6 files changed, 79 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 063b25301..e88557f20 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -11,10 +11,11 @@ using namespace MWRender; using namespace Ogre; -LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWWorld::Environment* env) : +LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWRender::RenderingManager* rendering, MWWorld::Environment* env) : mInterior(false), mCellX(0), mCellY(0) { mRendering = rend; + mRenderingManager = rendering; mEnvironment = env; mCameraPosNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode(); @@ -35,6 +36,12 @@ LocalMap::~LocalMap() deleteBuffers(); } +const Ogre::Vector2 LocalMap::rotatePoint(const Ogre::Vector2& p, const Ogre::Vector2& c, const float angle) +{ + return Vector2( Math::Cos(angle) * (p.x - c.x) - Math::Sin(angle) * (p.y - c.y) + c.x, + Math::Sin(angle) * (p.x - c.x) + Math::Cos(angle) * (p.y - c.y) + c.y); +} + void LocalMap::deleteBuffers() { mBuffers.clear(); @@ -117,6 +124,7 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, const Vector2& north = mEnvironment->mWorld->getNorthVector(cell); Radian angle(std::atan2(-north.x, -north.y)); + mAngle = angle.valueRadians(); mCameraRotNode->setOrientation(Quaternion(Math::Cos(angle/2.f), 0, Math::Sin(angle/2.f), 0)); mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::NEAR_LEFT_BOTTOM))); @@ -124,7 +132,9 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::NEAR_RIGHT_BOTTOM))); mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::FAR_RIGHT_BOTTOM))); - Vector2 center(bounds.getCenter().x, bounds.getCenter().z); + mBounds.scale(Vector3(2,2,2)); + + Vector2 center(mBounds.getCenter().x, mBounds.getCenter().z); Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); Vector2 max(mBounds.getMaximum().x, mBounds.getMaximum().z); @@ -165,6 +175,7 @@ void LocalMap::render(const float x, const float y, // make everything visible mRendering->getScene()->setAmbientLight(ColourValue(1,1,1)); + mRenderingManager->disableLights(); mCameraNode->setPosition(Vector3(x, zhigh+100000, y)); //mCellCamera->setFarClipDistance( (zhigh-zlow) * 1.1 ); @@ -233,7 +244,8 @@ void LocalMap::render(const float x, const float y, //rtt->writeContentsToFile("./" + texture + ".jpg"); } } - + + mRenderingManager->enableLights(); // re-enable fog mRendering->getScene()->setFog(FOG_LINEAR, clr, 0, fStart, fEnd); @@ -251,15 +263,18 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaterni // retrieve the x,y grid coordinates the player is in int x,y; Vector3 _pos(position.x, 0, position.z); - _pos = mCameraRotNode->convertWorldToLocalPosition(_pos); + Vector2 pos(_pos.x, _pos.z); - //if (mInterior) - /// \todo + if (mInterior) + { + pos = rotatePoint(pos, Vector2(mBounds.getCenter().x, mBounds.getCenter().z), mAngle); + } - Vector2 pos(_pos.x, _pos.z); Vector3 playerdirection = -mCameraRotNode->convertWorldToLocalOrientation(orientation).zAxis(); + Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); + if (!mInterior) { x = std::ceil(pos.x / sSize)-1; @@ -269,8 +284,6 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaterni } else { - Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); - x = std::ceil((pos.x - min.x)/sSize)-1; y = std::ceil((pos.y - min.y)/sSize)-1; @@ -288,16 +301,12 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaterni } else { - Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().z); - u = (pos.x - min.x - sSize*x)/sSize; v = (pos.y - min.y - sSize*y)/sSize; texName = mInteriorName + "_" + coordStr(x,y); } - //std::cout << " x,y " << x << ", " << y << " u,v " << u << "," << v << std::endl; - mEnvironment->mWindowManager->setPlayerPos(u, v); mEnvironment->mWindowManager->setPlayerDir(playerdirection.x, -playerdirection.z); diff --git a/apps/openmw/mwrender/localmap.hpp b/apps/openmw/mwrender/localmap.hpp index cb294a656..95685167c 100644 --- a/apps/openmw/mwrender/localmap.hpp +++ b/apps/openmw/mwrender/localmap.hpp @@ -12,13 +12,15 @@ namespace MWWorld namespace MWRender { + class RenderingManager; + /// /// \brief Local map rendering /// class LocalMap { public: - LocalMap(OEngine::Render::OgreRenderer*, MWWorld::Environment* env); + LocalMap(OEngine::Render::OgreRenderer*, MWRender::RenderingManager* rendering, MWWorld::Environment* env); ~LocalMap(); /** @@ -58,6 +60,7 @@ namespace MWRender private: OEngine::Render::OgreRenderer* mRendering; + MWRender::RenderingManager* mRenderingManager; MWWorld::Environment* mEnvironment; // 1024*1024 pixels for a cell @@ -77,6 +80,9 @@ namespace MWRender Ogre::SceneNode* mCameraPosNode; Ogre::SceneNode* mCameraRotNode; + float mAngle; + const Ogre::Vector2 rotatePoint(const Ogre::Vector2& p, const Ogre::Vector2& c, const float angle); + void render(const float x, const float y, const float zlow, const float zhigh, const float xw, const float yw, diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 94ccb6e97..05b7e3b0b 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -169,6 +169,7 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f assert(insert); Ogre::Light *light = mRenderer.getScene()->createLight(); light->setDiffuseColour (r, g, b); + mLights.push_back(light->getName()); float cval=0.0f, lval=0.0f, qval=0.0f; @@ -274,3 +275,34 @@ Ogre::AxisAlignedBox Objects::getDimensions(MWWorld::Ptr::CellStore* cell) { return mBounds[cell]; } + +void Objects::enableLights() +{ + std::vector::iterator it = mLights.begin(); + while (it != mLights.end()) + { + if (mMwRoot->getCreator()->hasLight(*it)) + { + mMwRoot->getCreator()->getLight(*it)->setVisible(true); + ++it; + } + else + it = mLights.erase(it); + } +} + +void Objects::disableLights() +{ + std::vector::iterator it = mLights.begin(); + while (it != mLights.end()) + { + if (mMwRoot->getCreator()->hasLight(*it)) + { + mMwRoot->getCreator()->getLight(*it)->setVisible(false); + ++it; + } + else + it = mLights.erase(it); + } +} + diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 265de875b..5911aa4cc 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -16,6 +16,7 @@ class Objects{ std::map mStaticGeometry; std::map mStaticGeometrySmall; std::map mBounds; + std::vector mLights; Ogre::SceneNode* mMwRoot; bool mIsStatic; static int uniqueID; @@ -44,6 +45,9 @@ public: void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); + void enableLights(); + void disableLights(); + Ogre::AxisAlignedBox getDimensions(MWWorld::Ptr::CellStore*); ///< get a bounding box that encloses all objects in the specified cell diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 18675203c..92e6d9edd 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -64,7 +64,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const mSun = 0; mDebugging = new Debugging(mMwRoot, environment, engine); - mLocalMap = new MWRender::LocalMap(&mRendering, &environment); + mLocalMap = new MWRender::LocalMap(&mRendering, this, &environment); } RenderingManager::~RenderingManager () @@ -411,4 +411,14 @@ void RenderingManager::preCellChange(MWWorld::Ptr::CellStore* cell) mLocalMap->saveFogOfWar(cell); } +void RenderingManager::disableLights() +{ + mObjects.disableLights(); +} + +void RenderingManager::enableLights() +{ + mObjects.enableLights(); +} + } // namespace diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 81907a938..ff9cd168e 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -109,6 +109,9 @@ class RenderingManager: private RenderingInterface { void sunEnable(); void sunDisable(); + void disableLights(); + void enableLights(); + bool occlusionQuerySupported() { return mOcclusionQuery->supported(); }; OcclusionQuery* getOcclusionQuery() { return mOcclusionQuery; }; From d4a2bdfa3d33263481a82b0a3e28b98613bd5c30 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 2 Apr 2012 20:46:42 +0200 Subject: [PATCH 22/23] fix crash when hardware occlusion queries unsupporetd --- apps/openmw/mwrender/sky.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 2fdf9b2cd..781f7abd5 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -746,6 +746,7 @@ void SkyManager::setGlare(const float glare) Vector3 SkyManager::getRealSunPos() { + if (!mCreated) return Vector3(0,0,0); return mSun->getNode()->_getDerivedPosition(); } From 51e33cc090d8bf3c0cd4d28506861509959b0942 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 3 Apr 2012 15:34:13 +0200 Subject: [PATCH 23/23] fixed map of some interiors --- apps/openmw/mwrender/localmap.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index e88557f20..6a94551de 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -127,12 +127,24 @@ void LocalMap::requestMap(MWWorld::Ptr::CellStore* cell, mAngle = angle.valueRadians(); mCameraRotNode->setOrientation(Quaternion(Math::Cos(angle/2.f), 0, Math::Sin(angle/2.f), 0)); - mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::NEAR_LEFT_BOTTOM))); - mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::FAR_LEFT_BOTTOM))); - mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::NEAR_RIGHT_BOTTOM))); - mBounds.merge(mCameraRotNode->convertWorldToLocalPosition(bounds.getCorner(AxisAlignedBox::FAR_RIGHT_BOTTOM))); - - mBounds.scale(Vector3(2,2,2)); + // rotate the cell and merge the rotated corners to the bounding box + Vector2 _center(bounds.getCenter().x, bounds.getCenter().z); + Vector3 _c1 = bounds.getCorner(AxisAlignedBox::NEAR_LEFT_BOTTOM); + Vector3 _c2 = bounds.getCorner(AxisAlignedBox::FAR_LEFT_BOTTOM); + Vector3 _c3 = bounds.getCorner(AxisAlignedBox::NEAR_RIGHT_BOTTOM); + Vector3 _c4 = bounds.getCorner(AxisAlignedBox::FAR_RIGHT_BOTTOM); + Vector2 c1(_c1.x, _c1.z); + Vector2 c2(_c2.x, _c2.z); + Vector2 c3(_c3.x, _c3.z); + Vector2 c4(_c4.x, _c4.z); + c1 = rotatePoint(c1, _center, mAngle); + c2 = rotatePoint(c2, _center, mAngle); + c3 = rotatePoint(c3, _center, mAngle); + c4 = rotatePoint(c4, _center, mAngle); + mBounds.merge(Vector3(c1.x, 0, c1.y)); + mBounds.merge(Vector3(c2.x, 0, c2.y)); + mBounds.merge(Vector3(c3.x, 0, c3.y)); + mBounds.merge(Vector3(c4.x, 0, c4.y)); Vector2 center(mBounds.getCenter().x, mBounds.getCenter().z);