From 12f7bae526b89aecb024b5f61d2cd77528e5c602 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 7 Apr 2012 18:37:41 +0200 Subject: [PATCH 01/15] added known spells and selected spell to NpcStats --- apps/openmw/mwmechanics/npcstats.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index aeb5f56d5..59bfa2ac0 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -2,6 +2,7 @@ #define GAME_MWMECHANICS_NPCSTATS_H #include +#include #include "stat.hpp" @@ -25,6 +26,9 @@ namespace MWMechanics bool mSneak; bool mCombat; + std::set mKnownSpells; + std::string mSelectedSpell; // can be an empty string (no spell selected) + NpcStats() : mForceRun (false), mForceSneak (false), mRun (false), mSneak (false), mCombat (false) {} }; From c94d6830145dcad282e8c3ac412308746c8692a2 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 7 Apr 2012 18:46:50 +0200 Subject: [PATCH 02/15] fill in initial spell list from NPC record --- apps/openmw/mwclass/npc.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 83a94d27d..2cf4cf41c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -61,6 +61,10 @@ namespace MWClass for (int i=0; i<27; ++i) data->mNpcStats.mSkill[i].setBase (ref->base->npdt52.skills[i]); + for (std::vector::const_iterator iter (ref->base->spells.list.begin()); + iter!=ref->base->spells.list.end(); ++iter) + data->mNpcStats.mKnownSpells.insert (*iter); + // creature stats data->mCreatureStats.mAttributes[0].set (ref->base->npdt52.strength); data->mCreatureStats.mAttributes[1].set (ref->base->npdt52.intelligence); From 944654f2637c68231583c636f064c6308067aa7a Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 9 Apr 2012 15:20:57 +0200 Subject: [PATCH 03/15] image rotating function --- CMakeLists.txt | 1 + libs/openengine/ogre/imagerotate.cpp | 74 ++++++++++++++++++++++++++++ libs/openengine/ogre/imagerotate.hpp | 27 ++++++++++ 3 files changed, 102 insertions(+) create mode 100644 libs/openengine/ogre/imagerotate.cpp create mode 100644 libs/openengine/ogre/imagerotate.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b87e3544..148386432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,7 @@ set(OENGINE_OGRE ${LIBDIR}/openengine/ogre/renderer.cpp ${LIBDIR}/openengine/ogre/mouselook.cpp ${LIBDIR}/openengine/ogre/fader.cpp + ${LIBDIR}/openengine/ogre/imagerotate.cpp ) set(OENGINE_GUI ${LIBDIR}/openengine/gui/events.cpp diff --git a/libs/openengine/ogre/imagerotate.cpp b/libs/openengine/ogre/imagerotate.cpp new file mode 100644 index 000000000..a6304277e --- /dev/null +++ b/libs/openengine/ogre/imagerotate.cpp @@ -0,0 +1,74 @@ +#include "imagerotate.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Ogre; +using namespace OEngine::Render; + +void ImageRotate::rotate(const std::string& sourceImage, const std::string& destImage, const float angle) +{ + Root* root = Ogre::Root::getSingletonPtr(); + + SceneManager* sceneMgr = root->createSceneManager(ST_GENERIC); + Camera* camera = sceneMgr->createCamera("ImageRotateCamera"); + + MaterialPtr material = MaterialManager::getSingleton().create("ImageRotateMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + material->getTechnique(0)->getPass(0)->setLightingEnabled(false); + material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); + TextureUnitState* tus = material->getTechnique(0)->getPass(0)->createTextureUnitState(sourceImage); + Degree deg(angle); + tus->setTextureRotate(Radian(deg.valueRadians())); + tus->setTextureAddressingMode(TextureUnitState::TAM_BORDER); + tus->setTextureBorderColour(ColourValue(0, 0, 0, 0)); + + Rectangle2D* rect = new Rectangle2D(true); + rect->setCorners(-1.0, 1.0, 1.0, -1.0); + rect->setMaterial("ImageRotateMaterial"); + // Render the background before everything else + rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND); + + // Use infinite AAB to always stay visible + AxisAlignedBox aabInf; + aabInf.setInfinite(); + rect->setBoundingBox(aabInf); + + // Attach background to the scene + SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(); + node->attachObject(rect); + + // retrieve image width and height + TexturePtr sourceTexture = TextureManager::getSingleton().getByName(sourceImage); + unsigned int width = sourceTexture->getWidth(); + unsigned int height = sourceTexture->getHeight(); + + TexturePtr destTexture = TextureManager::getSingleton().createManual( + "ImageRotateDestTexture", + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + TEX_TYPE_2D, + width, height, + 0, + PF_R8G8B8, + TU_RENDERTARGET); + + RenderTarget* rtt = destTexture->getBuffer()->getRenderTarget(); + rtt->setAutoUpdated(false); + Viewport* vp = rtt->addViewport(camera); + vp->setOverlaysEnabled(false); + vp->setShadowsEnabled(false); + + rtt->update(); + rtt->writeContentsToFile(destImage); + + // remove all the junk we've created + TextureManager::getSingleton().remove("ImageRotateDestTexture"); + MaterialManager::getSingleton().remove("ImageRotateMaterial"); + root->destroySceneManager(sceneMgr); + delete rect; +} diff --git a/libs/openengine/ogre/imagerotate.hpp b/libs/openengine/ogre/imagerotate.hpp new file mode 100644 index 000000000..85363d71f --- /dev/null +++ b/libs/openengine/ogre/imagerotate.hpp @@ -0,0 +1,27 @@ +#ifndef OENGINE_OGRE_IMAGEROTATE_HPP +#define OENGINE_OGRE_IMAGEROTATE_HPP + +#include + +namespace OEngine +{ +namespace Render +{ + + /// Rotate an image by certain degrees and save as file, uses the GPU + /// Make sure Ogre Root is initialised before calling + class ImageRotate + { + public: + /** + * @param source image (file name - has to exist in an resource group) + * @param destination image (absolute file path) + * @param angle in degrees to turn + */ + static void rotate(const std::string& sourceImage, const std::string& destImage, const float angle); + }; + +} +} + +#endif From 33f360f52f363e67a65b1432a33442d9bfc0a303 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 9 Apr 2012 15:36:51 +0200 Subject: [PATCH 04/15] transparency fix --- libs/openengine/ogre/imagerotate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openengine/ogre/imagerotate.cpp b/libs/openengine/ogre/imagerotate.cpp index a6304277e..166a1d3c6 100644 --- a/libs/openengine/ogre/imagerotate.cpp +++ b/libs/openengine/ogre/imagerotate.cpp @@ -54,7 +54,7 @@ void ImageRotate::rotate(const std::string& sourceImage, const std::string& dest TEX_TYPE_2D, width, height, 0, - PF_R8G8B8, + PF_A8R8G8B8, TU_RENDERTARGET); RenderTarget* rtt = destTexture->getBuffer()->getRenderTarget(); @@ -62,6 +62,8 @@ void ImageRotate::rotate(const std::string& sourceImage, const std::string& dest Viewport* vp = rtt->addViewport(camera); vp->setOverlaysEnabled(false); vp->setShadowsEnabled(false); + vp->setBackgroundColour(ColourValue(0,0,0,0)); + vp->setClearEveryFrame(true, FBT_DEPTH); rtt->update(); rtt->writeContentsToFile(destImage); From 344641e5748d5cb12bcddebd4706a585c73ebbd8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 11 Apr 2012 13:38:17 +0200 Subject: [PATCH 05/15] updated developer list in readme file --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 17806172f..e1c24ab52 100644 --- a/readme.txt +++ b/readme.txt @@ -95,6 +95,7 @@ Allowed options: CREDITS Current Developers: +Aleksandar Jovanov Alexander “Ace” Olofsson athile BrotherBrick From 750d79eaf032ca8bd21f33899853e5a3595e311c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 11 Apr 2012 18:29:36 +0200 Subject: [PATCH 06/15] added spell container class --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwmechanics/spells.cpp | 77 ++++++++++++++++++++++++++++++ apps/openmw/mwmechanics/spells.hpp | 55 +++++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 apps/openmw/mwmechanics/spells.cpp create mode 100644 apps/openmw/mwmechanics/spells.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c31a9d8fd..79f0948f9 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -55,7 +55,7 @@ add_openmw_dir (mwclass ) add_openmw_dir (mwmechanics - mechanicsmanager stat creaturestats magiceffects movement + mechanicsmanager stat creaturestats magiceffects movement spells ) # Main executable diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp new file mode 100644 index 000000000..2b28f0c2f --- /dev/null +++ b/apps/openmw/mwmechanics/spells.cpp @@ -0,0 +1,77 @@ + +#include "spells.hpp" + +#include + +#include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "magiceffects.hpp" + +namespace MWMechanics +{ + void Spells::addSpell (const ESM::Spell *spell, MagicEffects& effects) const + { + for (std::vector::const_iterator iter = spell->effects.list.begin(); + iter!=spell->effects.list.end(); ++iter) + { + EffectParam param; + param.mMagnitude = iter->magnMax; /// \todo calculate magnitude + effects.add (EffectKey (*iter), param); + } + } + + Spells::TIterator Spells::begin (ESM::Spell::SpellType type) const + { + assert (type>=0 && type=0 && typegetStore().spells.find (spellId); + + int type = spell->data.type; + + assert (type>=0 && typegetStore().spells.find (spellId); + + int type = spell->data.type; + + TContainer::iterator iter = std::find (mSpells[type].begin(), mSpells[type].end(), spell); + + if (iter!=mSpells[type].end()) + mSpells[type].erase (iter); + } + + MagicEffects Spells::getMagicEffects (MWWorld::Environment& environment) const + { + MagicEffects effects; + + for (int i=ESM::Spell::ST_Ability; i<=ESM::Spell::ST_Curse; ++i) + for (TIterator iter (begin (static_cast (i))); + iter!=end(static_cast (i)); ++iter) + addSpell (*iter, effects); + + return effects; + } + + void Spells::clear() + { + for (int i=0; i + +#include + +namespace MWWorld +{ + struct Environment; +} + +namespace MWMechanics +{ + class MagicEffects; + + /// \brief Spell list + /// + /// This class manages known spells as well as abilities, powers and permanent negative effects like + /// diseaes. + class Spells + { + public: + + typedef std::vector TContainer; + typedef TContainer::const_iterator TIterator; + + private: + + static const int sTypes = 6; + + std::vector mSpells[sTypes]; + + void addSpell (const ESM::Spell *, MagicEffects& effects) const; + + public: + + TIterator begin (ESM::Spell::SpellType type) const; + + TIterator end (ESM::Spell::SpellType type) const; + + void add (const std::string& spell, MWWorld::Environment& environment); + /// \note Adding a spell that is already listed in *this is a no-op. + + void remove (const std::string& spell, MWWorld::Environment& environment); + + MagicEffects getMagicEffects (MWWorld::Environment& environment) const; + ///< Return sum of magic effects resulting from abilities, blights, deseases and curses. + + void clear(); + ///< Remove all spells of al types. + }; +} + +#endif From e04ccfced0867c27f8ab049096abad91f9a65b09 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 11 Apr 2012 19:03:36 +0200 Subject: [PATCH 07/15] replaced old abilities container in CreatureStats with a Spells object --- apps/openmw/mwmechanics/creaturestats.hpp | 3 +- apps/openmw/mwmechanics/mechanicsmanager.cpp | 55 ++------------------ apps/openmw/mwmechanics/mechanicsmanager.hpp | 2 - 3 files changed, 7 insertions(+), 53 deletions(-) diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index d2edc031d..ab008da9e 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -6,6 +6,7 @@ #include "stat.hpp" #include "magiceffects.hpp" +#include "spells.hpp" namespace MWMechanics { @@ -14,7 +15,7 @@ namespace MWMechanics Stat mAttributes[8]; DynamicStat mDynamic[3]; // health, magicka, fatigue int mLevel; - std::set mAbilities; + Spells mSpells; MagicEffects mMagicEffects; }; } diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 7ed81f785..00453eee5 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -23,7 +23,7 @@ namespace MWMechanics // reset creatureStats.mLevel = player->npdt52.level; - creatureStats.mAbilities.clear(); + creatureStats.mSpells.clear(); creatureStats.mMagicEffects = MagicEffects(); for (int i=0; i<27; ++i) @@ -71,7 +71,7 @@ namespace MWMechanics for (std::vector::const_iterator iter (race->powers.list.begin()); iter!=race->powers.list.end(); ++iter) { - insertSpell (*iter, ptr); + creatureStats.mSpells.add (*iter, mEnvironment); } } @@ -85,7 +85,7 @@ namespace MWMechanics for (std::vector::const_iterator iter (sign->powers.list.begin()); iter!=sign->powers.list.end(); ++iter) { - insertSpell (*iter, ptr); + creatureStats.mSpells.add (*iter, mEnvironment); } } @@ -159,59 +159,14 @@ namespace MWMechanics creatureStats.mDynamic[i].setCurrent (creatureStats.mDynamic[i].getModified()); } - void MechanicsManager::insertSpell (const std::string& id, MWWorld::Ptr& creature) - { - MWMechanics::CreatureStats& creatureStats = - MWWorld::Class::get (creature).getCreatureStats (creature); - - const ESM::Spell *spell = mEnvironment.mWorld->getStore().spells.find (id); - - switch (spell->data.type) - { - case ESM::Spell::ST_Ability: - - if (creatureStats.mAbilities.find (id)==creatureStats.mAbilities.end()) - { - creatureStats.mAbilities.insert (id); - } - - break; - - // TODO ST_SPELL, ST_Blight, ST_Disease, ST_Curse, ST_Power - - default: - - std::cout - << "adding unsupported spell type (" << spell->data.type - << ") to creature: " << id << std::endl; - } - } - void MechanicsManager::adjustMagicEffects (MWWorld::Ptr& creature) { MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (creature).getCreatureStats (creature); - MagicEffects now; + MagicEffects now = creatureStats.mSpells.getMagicEffects (mEnvironment); - for (std::set::const_iterator iter (creatureStats.mAbilities.begin()); - iter!=creatureStats.mAbilities.end(); ++iter) - { - const ESM::Spell *spell = mEnvironment.mWorld->getStore().spells.find (*iter); - - for (std::vector::const_iterator iter = spell->effects.list.begin(); - iter!=spell->effects.list.end(); ++iter) - { - if (iter->range==0) // self - { - EffectParam param; - param.mMagnitude = iter->magnMax; // TODO calculate magnitude - now.add (EffectKey (*iter), param); - } - } - } - - // TODO add effects from other spell types, active spells and equipment + /// \todo add effects from active spells and equipment MagicEffects diff = MagicEffects::diff (creatureStats.mMagicEffects, now); diff --git a/apps/openmw/mwmechanics/mechanicsmanager.hpp b/apps/openmw/mwmechanics/mechanicsmanager.hpp index 2e2192638..8975329dd 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.hpp @@ -37,8 +37,6 @@ namespace MWMechanics ///< build player according to stored class/race/birthsign information. Will /// default to the values of the ESM::NPC object, if no explicit information is given. - void insertSpell (const std::string& id, MWWorld::Ptr& creature); - void adjustMagicEffects (MWWorld::Ptr& creature); public: From 77065390d7de2c09a9972e3fda90c9ed73255644 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 11 Apr 2012 19:40:42 +0200 Subject: [PATCH 08/15] simplifying Spells class --- apps/openmw/mwmechanics/mechanicsmanager.cpp | 4 +- apps/openmw/mwmechanics/spells.cpp | 53 ++++++++------------ apps/openmw/mwmechanics/spells.hpp | 24 +++++---- 3 files changed, 37 insertions(+), 44 deletions(-) diff --git a/apps/openmw/mwmechanics/mechanicsmanager.cpp b/apps/openmw/mwmechanics/mechanicsmanager.cpp index 00453eee5..414faa414 100644 --- a/apps/openmw/mwmechanics/mechanicsmanager.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanager.cpp @@ -71,7 +71,7 @@ namespace MWMechanics for (std::vector::const_iterator iter (race->powers.list.begin()); iter!=race->powers.list.end(); ++iter) { - creatureStats.mSpells.add (*iter, mEnvironment); + creatureStats.mSpells.add (*iter); } } @@ -85,7 +85,7 @@ namespace MWMechanics for (std::vector::const_iterator iter (sign->powers.list.begin()); iter!=sign->powers.list.end(); ++iter) { - creatureStats.mSpells.add (*iter, mEnvironment); + creatureStats.mSpells.add (*iter); } } diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 2b28f0c2f..4e8c6fa5a 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -1,7 +1,7 @@ #include "spells.hpp" -#include +#include #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" @@ -21,57 +21,48 @@ namespace MWMechanics } } - Spells::TIterator Spells::begin (ESM::Spell::SpellType type) const + Spells::TIterator Spells::begin() const { - assert (type>=0 && type=0 && typegetStore().spells.find (spellId); - - int type = spell->data.type; - - assert (type>=0 && typegetStore().spells.find (spellId); + TContainer::iterator iter = std::find (mSpells.begin(), mSpells.end(), spellId); - int type = spell->data.type; - - TContainer::iterator iter = std::find (mSpells[type].begin(), mSpells[type].end(), spell); - - if (iter!=mSpells[type].end()) - mSpells[type].erase (iter); + if (iter!=mSpells.end()) + mSpells.erase (iter); } - MagicEffects Spells::getMagicEffects (MWWorld::Environment& environment) const + MagicEffects Spells::getMagicEffects (const MWWorld::Environment& environment) const { MagicEffects effects; - for (int i=ESM::Spell::ST_Ability; i<=ESM::Spell::ST_Curse; ++i) - for (TIterator iter (begin (static_cast (i))); - iter!=end(static_cast (i)); ++iter) - addSpell (*iter, effects); + for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter) + { + const ESM::Spell *spell = environment.mWorld->getStore().spells.find (*iter); + + if (spell->data.type==ESM::Spell::ST_Ability || spell->data.type==ESM::Spell::ST_Blight || + spell->data.type==ESM::Spell::ST_Disease || spell->data.type==ESM::Spell::ST_Curse) + addSpell (spell, effects); + } return effects; } void Spells::clear() { - for (int i=0; i - #include +#include + +namespace ESM +{ + struct Spell; +} namespace MWWorld { @@ -22,29 +26,27 @@ namespace MWMechanics { public: - typedef std::vector TContainer; + typedef std::vector TContainer; typedef TContainer::const_iterator TIterator; private: - static const int sTypes = 6; - - std::vector mSpells[sTypes]; + std::vector mSpells; void addSpell (const ESM::Spell *, MagicEffects& effects) const; public: - TIterator begin (ESM::Spell::SpellType type) const; + TIterator begin() const; - TIterator end (ESM::Spell::SpellType type) const; + TIterator end() const; - void add (const std::string& spell, MWWorld::Environment& environment); + void add (const std::string& spell); /// \note Adding a spell that is already listed in *this is a no-op. - void remove (const std::string& spell, MWWorld::Environment& environment); + void remove (const std::string& spell); - MagicEffects getMagicEffects (MWWorld::Environment& environment) const; + MagicEffects getMagicEffects (const MWWorld::Environment& environment) const; ///< Return sum of magic effects resulting from abilities, blights, deseases and curses. void clear(); From 26a529111c760e639321b87a6659e0875be0fe67 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 11 Apr 2012 19:45:56 +0200 Subject: [PATCH 09/15] removed old known spell list from NpcStats --- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwmechanics/npcstats.hpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 2cf4cf41c..57cc3560a 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -63,7 +63,7 @@ namespace MWClass for (std::vector::const_iterator iter (ref->base->spells.list.begin()); iter!=ref->base->spells.list.end(); ++iter) - data->mNpcStats.mKnownSpells.insert (*iter); + data->mCreatureStats.mSpells.add (*iter); // creature stats data->mCreatureStats.mAttributes[0].set (ref->base->npdt52.strength); diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 59bfa2ac0..ece85f893 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -11,6 +11,8 @@ namespace MWMechanics /// \brief Additional stats for NPCs /// /// For non-NPC-specific stats, see the CreatureStats struct. + /// + /// \note For technical reasons the spell list is also handled by CreatureStats. struct NpcStats { @@ -26,7 +28,6 @@ namespace MWMechanics bool mSneak; bool mCombat; - std::set mKnownSpells; std::string mSelectedSpell; // can be an empty string (no spell selected) NpcStats() : mForceRun (false), mForceSneak (false), mRun (false), mSneak (false), From 800df7376ccc1b88c56c286af5e7a1fe1e12c091 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 12 Apr 2012 14:26:21 +0200 Subject: [PATCH 10/15] use the cursors from morrowind.bsa and remove mwpointer.png --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/engine.cpp | 4 ++++ apps/openmw/mwgui/cursorreplace.cpp | 16 ++++++++++++++++ apps/openmw/mwgui/cursorreplace.hpp | 16 ++++++++++++++++ files/mygui/CMakeLists.txt | 1 - files/mygui/mwpointer.png | Bin 4810 -> 0 bytes files/mygui/openmw_images.xml | 18 +++++++++--------- libs/openengine/ogre/imagerotate.cpp | 3 +-- libs/openengine/ogre/imagerotate.hpp | 2 +- 9 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 apps/openmw/mwgui/cursorreplace.cpp create mode 100644 apps/openmw/mwgui/cursorreplace.hpp delete mode 100644 files/mygui/mwpointer.png diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index a8ae0bd49..b417c764d 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -25,7 +25,7 @@ add_openmw_dir (mwinput add_openmw_dir (mwgui layouts text_input widgets race class birth review window_manager console dialogue dialogue_history window_base stats_window messagebox journalwindow charactercreation - map_window window_pinnable_base + map_window window_pinnable_base cursorreplace ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 259733600..8fe6963a9 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -28,6 +28,7 @@ #include "mwinput/inputmanager.hpp" #include "mwgui/window_manager.hpp" +#include "mwgui/cursorreplace.hpp" #include "mwscript/scriptmanager.hpp" #include "mwscript/compilercontext.hpp" @@ -368,6 +369,9 @@ void OMW::Engine::go() loadBSA(); + // cursor replacer (converts the cursor from the bsa so they can be used by mygui) + MWGui::CursorReplace replacer; + // Create the world mEnvironment.mWorld = new MWWorld::World (*mOgre, mFileCollections, mMaster, mResDir, mNewGame, mEnvironment, mEncoding, mFallbackMap); diff --git a/apps/openmw/mwgui/cursorreplace.cpp b/apps/openmw/mwgui/cursorreplace.cpp new file mode 100644 index 000000000..2079538fc --- /dev/null +++ b/apps/openmw/mwgui/cursorreplace.cpp @@ -0,0 +1,16 @@ +#include "cursorreplace.hpp" + +#include +#include + +#include +#include + +using namespace MWGui; + +CursorReplace::CursorReplace() +{ + OEngine::Render::ImageRotate::rotate("textures\\tx_cursormove.dds", "mwpointer_vresize.png", 90); + OEngine::Render::ImageRotate::rotate("textures\\tx_cursormove.dds", "mwpointer_dresize1.png", -45); + OEngine::Render::ImageRotate::rotate("textures\\tx_cursormove.dds", "mwpointer_dresize2.png", 45); +} diff --git a/apps/openmw/mwgui/cursorreplace.hpp b/apps/openmw/mwgui/cursorreplace.hpp new file mode 100644 index 000000000..06fe28e39 --- /dev/null +++ b/apps/openmw/mwgui/cursorreplace.hpp @@ -0,0 +1,16 @@ +#ifndef GAME_CURSORREPLACE_H +#define GAME_CURSORREPLACE_H + +#include + +namespace MWGui +{ + /// \brief MyGUI does not support rotating cursors, so we have to do it manually + class CursorReplace + { + public: + CursorReplace(); + }; +} + +#endif diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index dbc20f3f8..e3a7b9999 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -8,7 +8,6 @@ configure_file("${SDIR}/bigbars.png" "${DDIR}/bigbars.png" COPYONLY) configure_file("${SDIR}/black.png" "${DDIR}/black.png" COPYONLY) configure_file("${SDIR}/core.skin" "${DDIR}/core.skin" COPYONLY) configure_file("${SDIR}/core.xml" "${DDIR}/core.xml" COPYONLY) -configure_file("${SDIR}/mwpointer.png" "${DDIR}/mwpointer.png" COPYONLY) configure_file("${SDIR}/mwgui.png" "${DDIR}/mwgui.png" COPYONLY) configure_file("${SDIR}/openmw_images.xml" "${DDIR}/openmw_images.xml" COPYONLY) configure_file("${SDIR}/openmw_settings.xml" "${DDIR}/openmw_settings.xml" COPYONLY) diff --git a/files/mygui/mwpointer.png b/files/mygui/mwpointer.png deleted file mode 100644 index 90bc19b5e2c7ea4f30b895cc5b8cde00ce460e98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4810 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 diff --git a/files/mygui/openmw_images.xml b/files/mygui/openmw_images.xml index 6487742c3..e149273e2 100644 --- a/files/mygui/openmw_images.xml +++ b/files/mygui/openmw_images.xml @@ -2,37 +2,37 @@ - + - + - + - + - + - + - + - + - + diff --git a/libs/openengine/ogre/imagerotate.cpp b/libs/openengine/ogre/imagerotate.cpp index 166a1d3c6..b7522c100 100644 --- a/libs/openengine/ogre/imagerotate.cpp +++ b/libs/openengine/ogre/imagerotate.cpp @@ -49,7 +49,7 @@ void ImageRotate::rotate(const std::string& sourceImage, const std::string& dest unsigned int height = sourceTexture->getHeight(); TexturePtr destTexture = TextureManager::getSingleton().createManual( - "ImageRotateDestTexture", + destImage, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, width, height, @@ -69,7 +69,6 @@ void ImageRotate::rotate(const std::string& sourceImage, const std::string& dest rtt->writeContentsToFile(destImage); // remove all the junk we've created - TextureManager::getSingleton().remove("ImageRotateDestTexture"); MaterialManager::getSingleton().remove("ImageRotateMaterial"); root->destroySceneManager(sceneMgr); delete rect; diff --git a/libs/openengine/ogre/imagerotate.hpp b/libs/openengine/ogre/imagerotate.hpp index 85363d71f..a3f6d662f 100644 --- a/libs/openengine/ogre/imagerotate.hpp +++ b/libs/openengine/ogre/imagerotate.hpp @@ -15,7 +15,7 @@ namespace Render public: /** * @param source image (file name - has to exist in an resource group) - * @param destination image (absolute file path) + * @param name of the destination texture to save to (in memory) * @param angle in degrees to turn */ static void rotate(const std::string& sourceImage, const std::string& destImage, const float angle); From 4a6a8e5420eb24f203d6645b157e3aba63a21342 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 12 Apr 2012 14:28:35 +0200 Subject: [PATCH 11/15] don't write to disk --- libs/openengine/ogre/imagerotate.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openengine/ogre/imagerotate.cpp b/libs/openengine/ogre/imagerotate.cpp index b7522c100..1147559d6 100644 --- a/libs/openengine/ogre/imagerotate.cpp +++ b/libs/openengine/ogre/imagerotate.cpp @@ -66,7 +66,6 @@ void ImageRotate::rotate(const std::string& sourceImage, const std::string& dest vp->setClearEveryFrame(true, FBT_DEPTH); rtt->update(); - rtt->writeContentsToFile(destImage); // remove all the junk we've created MaterialManager::getSingleton().remove("ImageRotateMaterial"); From 2b8c81e7795a01c00a6e014714d31206abaa0af4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 12 Apr 2012 14:31:12 +0200 Subject: [PATCH 12/15] removed test.skin file --- files/mygui/test.skin | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 files/mygui/test.skin diff --git a/files/mygui/test.skin b/files/mygui/test.skin deleted file mode 100644 index 5f198ab4a..000000000 --- a/files/mygui/test.skin +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - From 52c7ee3b6ae8a9738289a1728cb02ad8d9a49e1f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 13 Apr 2012 10:49:45 +0200 Subject: [PATCH 13/15] moved selected spell from NpcStats to Spells --- apps/openmw/mwmechanics/npcstats.hpp | 5 ++--- apps/openmw/mwmechanics/spells.cpp | 13 +++++++++++++ apps/openmw/mwmechanics/spells.hpp | 11 ++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index ece85f893..b9c672722 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -12,7 +12,8 @@ namespace MWMechanics /// /// For non-NPC-specific stats, see the CreatureStats struct. /// - /// \note For technical reasons the spell list is also handled by CreatureStats. + /// \note For technical reasons the spell list and the currently selected spell is also handled by + /// CreatureStats, even though they are actually NPC stats. struct NpcStats { @@ -28,8 +29,6 @@ namespace MWMechanics bool mSneak; bool mCombat; - std::string mSelectedSpell; // can be an empty string (no spell selected) - NpcStats() : mForceRun (false), mForceSneak (false), mRun (false), mSneak (false), mCombat (false) {} }; diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 4e8c6fa5a..916239a84 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -43,6 +43,9 @@ namespace MWMechanics if (iter!=mSpells.end()) mSpells.erase (iter); + + if (spellId==mSelectedSpell) + mSelectedSpell.clear(); } MagicEffects Spells::getMagicEffects (const MWWorld::Environment& environment) const @@ -65,4 +68,14 @@ namespace MWMechanics { mSpells.clear(); } + + void Spells::setSelectedSpell (const std::string& spellId) + { + mSelectedSpell = spellId; + } + + const std::string Spells::getSelectedSpell() const + { + return mSelectedSpell; + } } diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 4c5f21d35..f7606c4ac 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -32,6 +32,7 @@ namespace MWMechanics private: std::vector mSpells; + std::string mSelectedSpell; void addSpell (const ESM::Spell *, MagicEffects& effects) const; @@ -42,15 +43,23 @@ namespace MWMechanics TIterator end() const; void add (const std::string& spell); - /// \note Adding a spell that is already listed in *this is a no-op. + ///< Adding a spell that is already listed in *this is a no-op. void remove (const std::string& spell); + ///< If the spell to be removed is the selected spell, the selected spell will be changed to + /// no spell (empty string). MagicEffects getMagicEffects (const MWWorld::Environment& environment) const; ///< Return sum of magic effects resulting from abilities, blights, deseases and curses. void clear(); ///< Remove all spells of al types. + + void setSelectedSpell (const std::string& spellId); + ///< This function does not verify, if the spell is available. + + const std::string getSelectedSpell() const; + ///< May return an empty string. }; } From b099e1baf583202cbaed50697011d09d50a72dc0 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 13 Apr 2012 11:12:53 +0200 Subject: [PATCH 14/15] added addspell and removespell script instructions --- apps/openmw/mwscript/docs/vmformat.txt | 6 ++- apps/openmw/mwscript/statsextensions.cpp | 47 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index df955ec19..705d65814 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -129,4 +129,8 @@ op 0x2000143: ModWaterLevel op 0x2000144: ToggleWater, twa op 0x2000145: ToggleFogOfWar (tfow) op 0x2000146: TogglePathgrid -opcodes 0x2000147-0x3ffffff unused +op 0x2000147: AddSpell +op 0x2000148: AddSpell, explicit reference +op 0x2000149: RemoveSpell +op 0x200014a: RemoveSpell, explicit reference +opcodes 0x200014b-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 0e97a39cf..10641903e 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -280,6 +280,38 @@ namespace MWScript } }; + template + class OpAddSpell : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + MWWorld::Class::get (ptr).getCreatureStats (ptr).mSpells.add (id); + } + }; + + template + class OpRemoveSpell : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + MWWorld::Class::get (ptr).getCreatureStats (ptr).mSpells.remove (id); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -311,6 +343,11 @@ namespace MWScript const int opcodeModSkill = 0x20000fa; const int opcodeModSkillExplicit = 0x2000115; + const int opcodeAddSpell = 0x2000147; + const int opcodeAddSpellExplicit = 0x2000148; + const int opcodeRemoveSpell = 0x2000149; + const int opcodeRemoveSpellExplicit = 0x200014a; + void registerExtensions (Compiler::Extensions& extensions) { static const char *attributes[numberOfAttributes] = @@ -381,6 +418,10 @@ namespace MWScript extensions.registerInstruction (mod + skills[i], "l", opcodeModSkill+i, opcodeModSkillExplicit+i); } + + extensions.registerInstruction ("addspell", "c", opcodeAddSpell, opcodeAddSpellExplicit); + extensions.registerInstruction ("removespell", "c", opcodeRemoveSpell, + opcodeRemoveSpellExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -436,6 +477,12 @@ namespace MWScript interpreter.installSegment5 (opcodeModSkill+i, new OpModSkill (i)); interpreter.installSegment5 (opcodeModSkillExplicit+i, new OpModSkill (i)); } + + interpreter.installSegment5 (opcodeAddSpell, new OpAddSpell); + interpreter.installSegment5 (opcodeAddSpellExplicit, new OpAddSpell); + interpreter.installSegment5 (opcodeRemoveSpell, new OpRemoveSpell); + interpreter.installSegment5 (opcodeRemoveSpellExplicit, + new OpRemoveSpell); } } } From e16daeed238c140754642388ffa6d7988884382e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 13 Apr 2012 13:17:57 +0200 Subject: [PATCH 15/15] added GetSpell script function --- apps/openmw/mwscript/docs/vmformat.txt | 4 ++- apps/openmw/mwscript/statsextensions.cpp | 32 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 705d65814..1317794fa 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -133,4 +133,6 @@ op 0x2000147: AddSpell op 0x2000148: AddSpell, explicit reference op 0x2000149: RemoveSpell op 0x200014a: RemoveSpell, explicit reference -opcodes 0x200014b-0x3ffffff unused +op 0x200014b: GetSpell +op 0x200014c: GetSpell, explicit reference +opcodes 0x200014d-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 10641903e..011b8b010 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -312,6 +312,33 @@ namespace MWScript } }; + template + class OpGetSpell : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Integer value = 0; + + for (MWMechanics::Spells::TIterator iter ( + MWWorld::Class::get (ptr).getCreatureStats (ptr).mSpells.begin()); + iter!=MWWorld::Class::get (ptr).getCreatureStats (ptr).mSpells.end(); ++iter) + if (*iter==id) + { + value = 1; + break; + } + + runtime.push (value); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -347,6 +374,8 @@ namespace MWScript const int opcodeAddSpellExplicit = 0x2000148; const int opcodeRemoveSpell = 0x2000149; const int opcodeRemoveSpellExplicit = 0x200014a; + const int opcodeGetSpell = 0x200014b; + const int opcodeGetSpellExplicit = 0x200014c; void registerExtensions (Compiler::Extensions& extensions) { @@ -422,6 +451,7 @@ namespace MWScript extensions.registerInstruction ("addspell", "c", opcodeAddSpell, opcodeAddSpellExplicit); extensions.registerInstruction ("removespell", "c", opcodeRemoveSpell, opcodeRemoveSpellExplicit); + extensions.registerFunction ("getspell", 'l', "c", opcodeGetSpell, opcodeGetSpellExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -483,6 +513,8 @@ namespace MWScript interpreter.installSegment5 (opcodeRemoveSpell, new OpRemoveSpell); interpreter.installSegment5 (opcodeRemoveSpellExplicit, new OpRemoveSpell); + interpreter.installSegment5 (opcodeGetSpell, new OpGetSpell); + interpreter.installSegment5 (opcodeGetSpellExplicit, new OpGetSpell); } } }