1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-13 14:00:54 +00:00

Optimize HUD memory layout and replace actor id with a RefNum

This commit is contained in:
Evil Eye 2024-12-20 23:05:12 +01:00
parent 1d24ad54d9
commit 42b9f1ec2b
2 changed files with 36 additions and 69 deletions

View file

@ -19,6 +19,7 @@
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/worldmodel.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/npcstats.hpp"
@ -34,36 +35,7 @@ namespace MWGui
HUD::HUD(CustomMarkerCollection& customMarkers, DragAndDrop* dragAndDrop, MWRender::LocalMap* localMapRender)
: WindowBase("openmw_hud.layout")
, LocalMapBase(customMarkers, localMapRender, Settings::map().mLocalMapHudFogOfWar)
, mHealth(nullptr)
, mMagicka(nullptr)
, mStamina(nullptr)
, mDrowning(nullptr)
, mWeapImage(nullptr)
, mSpellImage(nullptr)
, mWeapStatus(nullptr)
, mSpellStatus(nullptr)
, mEffectBox(nullptr)
, mMinimap(nullptr)
, mCrosshair(nullptr)
, mCellNameBox(nullptr)
, mDrowningBar(nullptr)
, mDrowningFlash(nullptr)
, mHealthManaStaminaBaseLeft(0)
, mWeapBoxBaseLeft(0)
, mSpellBoxBaseLeft(0)
, mMinimapBoxBaseRight(0)
, mEffectBoxBaseRight(0)
, mDragAndDrop(dragAndDrop)
, mCellNameTimer(0.0f)
, mWeaponSpellTimer(0.f)
, mMapVisible(true)
, mWeaponVisible(true)
, mSpellVisible(true)
, mWorldMouseOver(false)
, mEnemyActorId(-1)
, mEnemyHealthTimer(-1)
, mIsDrowning(false)
, mDrowningFlashTheta(0.f)
{
// Energy bars
getWidget(mHealthFrame, "HealthFrame");
@ -338,7 +310,7 @@ namespace MWGui
mSpellIcons->updateWidgets(mEffectBox, true);
if (mEnemyActorId != -1 && mEnemyHealth->getVisible())
if (mEnemyActor.isSet() && mEnemyHealth->getVisible())
{
updateEnemyHealthBar();
}
@ -579,7 +551,7 @@ namespace MWGui
void HUD::updateEnemyHealthBar()
{
MWWorld::Ptr enemy = MWBase::Environment::get().getWorld()->searchPtrViaActorId(mEnemyActorId);
MWWorld::Ptr enemy = MWBase::Environment::get().getWorldModel()->getPtr(mEnemyActor);
if (enemy.isEmpty())
return;
MWMechanics::CreatureStats& stats = enemy.getClass().getCreatureStats(enemy);
@ -599,7 +571,7 @@ namespace MWGui
void HUD::setEnemy(const MWWorld::Ptr& enemy)
{
mEnemyActorId = enemy.getClass().getCreatureStats(enemy).getActorId();
mEnemyActor = enemy.getCellRef().getRefNum();
mEnemyHealthTimer = MWBase::Environment::get()
.getESMStore()
->get<ESM::GameSetting>()
@ -613,12 +585,12 @@ namespace MWGui
void HUD::clear()
{
mEnemyActorId = -1;
mEnemyActor = {};
mEnemyHealthTimer = -1;
mWeaponSpellTimer = 0.f;
mWeaponName = std::string();
mSpellName = std::string();
mWeaponName.clear();
mSpellName.clear();
mWeaponSpellBox->setVisible(false);
mWeapStatus->setProgressRange(100);

View file

@ -64,47 +64,42 @@ namespace MWGui
void dropDraggedItem(float mouseX, float mouseY);
private:
MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth, *mDrowning;
MyGUI::Widget* mHealthFrame;
MyGUI::Widget *mWeapBox, *mSpellBox, *mSneakBox;
ItemWidget* mWeapImage;
SpellWidget* mSpellImage;
MyGUI::ProgressBar *mWeapStatus, *mSpellStatus;
MyGUI::Widget *mEffectBox, *mMinimapBox;
MyGUI::Button* mMinimapButton;
MyGUI::ScrollView* mMinimap;
MyGUI::ImageBox* mCrosshair;
MyGUI::TextBox* mCellNameBox;
MyGUI::TextBox* mWeaponSpellBox;
MyGUI::Widget *mDrowningBar, *mDrowningFrame, *mDrowningFlash;
MyGUI::ProgressBar *mHealth = nullptr, *mMagicka = nullptr, *mStamina = nullptr, *mEnemyHealth = nullptr,
*mDrowning = nullptr;
MyGUI::Widget* mHealthFrame = nullptr;
MyGUI::Widget *mWeapBox = nullptr, *mSpellBox = nullptr, *mSneakBox = nullptr;
ItemWidget* mWeapImage = nullptr;
SpellWidget* mSpellImage = nullptr;
MyGUI::ProgressBar *mWeapStatus = nullptr, *mSpellStatus = nullptr;
MyGUI::Widget *mEffectBox = nullptr, *mMinimapBox = nullptr;
MyGUI::Button* mMinimapButton = nullptr;
MyGUI::ScrollView* mMinimap = nullptr;
MyGUI::ImageBox* mCrosshair = nullptr;
MyGUI::TextBox* mCellNameBox = nullptr;
MyGUI::TextBox* mWeaponSpellBox = nullptr;
MyGUI::Widget *mDrowningBar = nullptr, *mDrowningFrame = nullptr, *mDrowningFlash = nullptr;
DragAndDrop* mDragAndDrop;
std::string mCellName;
std::string mWeaponName;
std::string mSpellName;
std::unique_ptr<SpellIcons> mSpellIcons;
ESM::RefNum mEnemyActor;
// bottom left elements
int mHealthManaStaminaBaseLeft, mWeapBoxBaseLeft, mSpellBoxBaseLeft, mSneakBoxBaseLeft;
// bottom right elements
int mMinimapBoxBaseRight, mEffectBoxBaseRight;
DragAndDrop* mDragAndDrop;
float mCellNameTimer = 0.f;
float mWeaponSpellTimer = 0.f;
float mEnemyHealthTimer = -1;
float mDrowningFlashTheta = 0.f;
std::string mCellName;
float mCellNameTimer;
std::string mWeaponName;
std::string mSpellName;
float mWeaponSpellTimer;
bool mMapVisible;
bool mWeaponVisible;
bool mSpellVisible;
bool mWorldMouseOver;
std::unique_ptr<SpellIcons> mSpellIcons;
int mEnemyActorId;
float mEnemyHealthTimer;
bool mIsDrowning;
float mDrowningFlashTheta;
bool mMapVisible = true;
bool mWeaponVisible = true;
bool mSpellVisible = true;
bool mWorldMouseOver = false;
bool mIsDrowning = false;
void onWorldClicked(MyGUI::Widget* sender);
void onWorldMouseOver(MyGUI::Widget* sender, int x, int y);