Optimize HUD update (do not do unnecessary work)

pull/541/head
Andrei Kortunov 6 years ago
parent 592d29f7db
commit 8580a58ba0

@ -417,8 +417,7 @@ namespace MWGui
icon.insert(slashPos+1, "b_"); icon.insert(slashPos+1, "b_");
icon = MWBase::Environment::get().getWindowManager()->correctIconPath(icon); icon = MWBase::Environment::get().getWindowManager()->correctIconPath(icon);
mSpellImage->setItem(MWWorld::Ptr()); mSpellImage->setSpellIcon(icon);
mSpellImage->setIcon(icon);
} }
void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent)

@ -15,6 +15,7 @@ namespace MWGui
class DragAndDrop; class DragAndDrop;
class SpellIcons; class SpellIcons;
class ItemWidget; class ItemWidget;
class SpellWidget;
class HUD : public WindowBase, public LocalMapBase class HUD : public WindowBase, public LocalMapBase
{ {
@ -64,7 +65,8 @@ namespace MWGui
MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth, *mDrowning; MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth, *mDrowning;
MyGUI::Widget* mHealthFrame; MyGUI::Widget* mHealthFrame;
MyGUI::Widget *mWeapBox, *mSpellBox, *mSneakBox; MyGUI::Widget *mWeapBox, *mSpellBox, *mSneakBox;
ItemWidget *mWeapImage, *mSpellImage; ItemWidget *mWeapImage;
SpellWidget *mSpellImage;
MyGUI::ProgressBar *mWeapStatus, *mSpellStatus; MyGUI::ProgressBar *mWeapStatus, *mSpellStatus;
MyGUI::Widget *mEffectBox, *mMinimapBox; MyGUI::Widget *mEffectBox, *mMinimapBox;
MyGUI::Button* mMinimapButton; MyGUI::Button* mMinimapButton;

@ -43,6 +43,7 @@ namespace MWGui
void ItemWidget::registerComponents() void ItemWidget::registerComponents()
{ {
MyGUI::FactoryManager::getInstance().registerFactory<ItemWidget>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<ItemWidget>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<SpellWidget>("Widget");
} }
void ItemWidget::initialiseOverride() void ItemWidget::initialiseOverride()
@ -153,4 +154,14 @@ namespace MWGui
setIcon(ptr); setIcon(ptr);
} }
void SpellWidget::setSpellIcon(const std::string& icon)
{
if (mFrame)
mFrame->setImageTexture("");
if (mItemShadow)
mItemShadow->setImageTexture(icon);
if (mItem)
mItem->setImageTexture(icon);
}
} }

@ -40,7 +40,7 @@ namespace MWGui
void setIcon (const MWWorld::Ptr& ptr); void setIcon (const MWWorld::Ptr& ptr);
void setFrame (const std::string& frame, const MyGUI::IntCoord& coord); void setFrame (const std::string& frame, const MyGUI::IntCoord& coord);
private: protected:
virtual void initialiseOverride(); virtual void initialiseOverride();
MyGUI::ImageBox* mItem; MyGUI::ImageBox* mItem;
@ -52,6 +52,14 @@ namespace MWGui
std::string mCurrentFrame; std::string mCurrentFrame;
}; };
class SpellWidget : public ItemWidget
{
MYGUI_RTTI_DERIVED(SpellWidget)
public:
void setSpellIcon (const std::string& icon);
};
} }
#endif #endif

@ -58,7 +58,10 @@ namespace MWGui
void Layout::setTitle(const std::string& title) void Layout::setTitle(const std::string& title)
{ {
static_cast<MyGUI::Window*>(mMainWidget)->setCaptionWithReplacing(title); MyGUI::Window* window = static_cast<MyGUI::Window*>(mMainWidget);
if (window->getCaption() != title)
window->setCaptionWithReplacing(title);
} }
MyGUI::Widget* Layout::getWidget(const std::string &_name) MyGUI::Widget* Layout::getWidget(const std::string &_name)

@ -236,7 +236,7 @@ namespace MWMechanics
// mWatchedTimeToStartDrowning = -1 for correct drowning state check, // mWatchedTimeToStartDrowning = -1 for correct drowning state check,
// if stats.getTimeToStartDrowning() == 0 already on game start // if stats.getTimeToStartDrowning() == 0 already on game start
MechanicsManager::MechanicsManager() MechanicsManager::MechanicsManager()
: mWatchedTimeToStartDrowning(-1), mWatchedStatsEmpty (true), mUpdatePlayer (true), mClassSelected (false), : mWatchedLevel(-1), mWatchedTimeToStartDrowning(-1), mWatchedStatsEmpty (true), mUpdatePlayer (true), mClassSelected (false),
mRaceSelected (false), mAI(true) mRaceSelected (false), mAI(true)
{ {
//buildPlayer no longer here, needs to be done explicitly after all subsystems are up and running //buildPlayer no longer here, needs to be done explicitly after all subsystems are up and running
@ -361,7 +361,11 @@ namespace MWMechanics
} }
} }
winMgr->setValue("level", stats.getLevel()); if(stats.getLevel() != mWatchedLevel)
{
mWatchedLevel = stats.getLevel();
winMgr->setValue("level", mWatchedLevel);
}
mWatchedStatsEmpty = false; mWatchedStatsEmpty = false;
@ -377,10 +381,15 @@ namespace MWMechanics
MWWorld::ContainerStoreIterator enchantItem = inv.getSelectedEnchantItem(); MWWorld::ContainerStoreIterator enchantItem = inv.getSelectedEnchantItem();
if (enchantItem != inv.end()) if (enchantItem != inv.end())
winMgr->setSelectedEnchantItem(*enchantItem); winMgr->setSelectedEnchantItem(*enchantItem);
else if (!winMgr->getSelectedSpell().empty())
winMgr->setSelectedSpell(winMgr->getSelectedSpell(), int(MWMechanics::getSpellSuccessChance(winMgr->getSelectedSpell(), mWatched)));
else else
winMgr->unsetSelectedSpell(); {
const std::string& spell = winMgr->getSelectedSpell();
if (!spell.empty())
winMgr->setSelectedSpell(spell, int(MWMechanics::getSpellSuccessChance(spell, mWatched)));
else
winMgr->unsetSelectedSpell();
}
} }
if (mUpdatePlayer) if (mUpdatePlayer)

@ -30,6 +30,8 @@ namespace MWMechanics
DynamicStat<float> mWatchedMagicka; DynamicStat<float> mWatchedMagicka;
DynamicStat<float> mWatchedFatigue; DynamicStat<float> mWatchedFatigue;
int mWatchedLevel;
float mWatchedTimeToStartDrowning; float mWatchedTimeToStartDrowning;
bool mWatchedStatsEmpty; bool mWatchedStatsEmpty;

@ -72,7 +72,7 @@
<!-- Selected spell box --> <!-- Selected spell box -->
<Widget type="Button" position="122 146 36 41" align="Left Bottom" name="SpellBox"> <Widget type="Button" position="122 146 36 41" align="Left Bottom" name="SpellBox">
<Widget type="Widget" skin="HUD_Box" position="0 0 36 36"> <Widget type="Widget" skin="HUD_Box" position="0 0 36 36">
<Widget type="ItemWidget" skin="MW_ItemIconNoShadow" position="-3 -3 42 42" align="Left Top" name="SpellImage"/> <Widget type="SpellWidget" skin="MW_ItemIconNoShadow" position="-3 -3 42 42" align="Left Top" name="SpellImage"/>
<Property key="NeedMouse" value="false"/> <Property key="NeedMouse" value="false"/>
</Widget> </Widget>
<Widget type="ProgressBar" skin="MW_EnergyBar_Magic" position="0 36 36 6" align="Left Bottom" name="SpellStatus"> <Widget type="ProgressBar" skin="MW_EnergyBar_Magic" position="0 36 36 6" align="Left Bottom" name="SpellStatus">

Loading…
Cancel
Save