Improve performance of inventory window resize (don't update selection buffer unnecessarily)

deque
scrawl 11 years ago
parent 177de58884
commit 025f50a2df

@ -37,6 +37,7 @@ namespace MWGui
, mLastYSize(0) , mLastYSize(0)
, mPreview(new MWRender::InventoryPreview(MWBase::Environment::get().getWorld ()->getPlayerPtr())) , mPreview(new MWRender::InventoryPreview(MWBase::Environment::get().getWorld ()->getPlayerPtr()))
, mPreviewDirty(true) , mPreviewDirty(true)
, mPreviewResize(true)
, mDragAndDrop(dragAndDrop) , mDragAndDrop(dragAndDrop)
, mSelectedItem(-1) , mSelectedItem(-1)
, mGuiMode(GM_Inventory) , mGuiMode(GM_Inventory)
@ -100,6 +101,9 @@ namespace MWGui
mPreview.reset(new MWRender::InventoryPreview(mPtr)); mPreview.reset(new MWRender::InventoryPreview(mPtr));
mPreview->setup(); mPreview->setup();
mPreviewDirty = true;
mPreviewResize = true;
} }
void InventoryWindow::setGuiMode(GuiMode mode) void InventoryWindow::setGuiMode(GuiMode mode)
@ -132,7 +136,7 @@ namespace MWGui
Settings::Manager::getFloat(setting + " h", "Windows") * viewSize.height); Settings::Manager::getFloat(setting + " h", "Windows") * viewSize.height);
if (size.width != mMainWidget->getWidth() || size.height != mMainWidget->getHeight()) if (size.width != mMainWidget->getWidth() || size.height != mMainWidget->getHeight())
mPreviewDirty = true; mPreviewResize = true;
mMainWidget->setPosition(pos); mMainWidget->setPosition(pos);
mMainWidget->setSize(size); mMainWidget->setSize(size);
@ -340,7 +344,7 @@ namespace MWGui
{ {
mLastXSize = mMainWidget->getSize().width; mLastXSize = mMainWidget->getSize().width;
mLastYSize = mMainWidget->getSize().height; mLastYSize = mMainWidget->getSize().height;
mPreviewDirty = true; mPreviewResize = true;
} }
} }
@ -416,9 +420,13 @@ namespace MWGui
else else
mSkippedToEquip = ptr; mSkippedToEquip = ptr;
mItemView->update(); if (isVisible())
{
mItemView->update();
notifyContentChanged(); notifyContentChanged();
}
// else: will be updated in open()
} }
void InventoryWindow::onAvatarClicked(MyGUI::Widget* _sender) void InventoryWindow::onAvatarClicked(MyGUI::Widget* _sender)
@ -505,16 +513,22 @@ namespace MWGui
void InventoryWindow::doRenderUpdate () void InventoryWindow::doRenderUpdate ()
{ {
mPreview->onFrame(); mPreview->onFrame();
if (mPreviewDirty) if (mPreviewResize)
{ {
mPreviewDirty = false; mPreviewResize = false;
MyGUI::IntSize size = mAvatarImage->getSize(); MyGUI::IntSize size = mAvatarImage->getSize();
mPreview->resize(size.width, size.height);
mPreview->update (size.width, size.height);
mAvatarImage->setImageTexture("CharacterPreview"); mAvatarImage->setImageTexture("CharacterPreview");
mAvatarImage->setImageCoord(MyGUI::IntCoord(0, 0, std::min(512, size.width), std::min(1024, size.height))); mAvatarImage->setImageCoord(MyGUI::IntCoord(0, 0, std::min(512, size.width), std::min(1024, size.height)));
mAvatarImage->setImageTile(MyGUI::IntSize(std::min(512, size.width), std::min(1024, size.height))); mAvatarImage->setImageTile(MyGUI::IntSize(std::min(512, size.width), std::min(1024, size.height)));
}
if (mPreviewDirty)
{
mPreviewDirty = false;
mPreview->update ();
mAvatarImage->setImageTexture("CharacterPreview");
mArmorRating->setCaptionWithReplacing ("#{sArmor}: " mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
+ boost::lexical_cast<std::string>(static_cast<int>(mPtr.getClass().getArmorRating(mPtr)))); + boost::lexical_cast<std::string>(static_cast<int>(mPtr.getClass().getArmorRating(mPtr))));

@ -53,6 +53,7 @@ namespace MWGui
DragAndDrop* mDragAndDrop; DragAndDrop* mDragAndDrop;
bool mPreviewDirty; bool mPreviewDirty;
bool mPreviewResize;
int mSelectedItem; int mSelectedItem;
MWWorld::Ptr mPtr; MWWorld::Ptr mPtr;

@ -171,11 +171,22 @@ namespace MWRender
delete mSelectionBuffer; delete mSelectionBuffer;
} }
void InventoryPreview::update(int sizeX, int sizeY) void InventoryPreview::resize(int sizeX, int sizeY)
{ {
mSizeX = sizeX; mSizeX = sizeX;
mSizeY = sizeY; mSizeY = sizeY;
mViewport->setDimensions (0, 0, std::min(1.f, float(mSizeX) / float(512)), std::min(1.f, float(mSizeY) / float(1024)));
mTexture->load();
if (!mRenderTarget)
setupRenderTarget();
mRenderTarget->update();
}
void InventoryPreview::update()
{
mAnimation->updateParts(); mAnimation->updateParts();
MWWorld::InventoryStore &inv = mCharacter.getClass().getInventoryStore(mCharacter); MWWorld::InventoryStore &inv = mCharacter.getClass().getInventoryStore(mCharacter);

@ -81,7 +81,8 @@ namespace MWRender
virtual ~InventoryPreview(); virtual ~InventoryPreview();
virtual void onSetup(); virtual void onSetup();
void update(int sizeX, int sizeY); void update(); // Render preview again, e.g. after changed equipment
void resize(int sizeX, int sizeY);
int getSlotSelected(int posX, int posY); int getSlotSelected(int posX, int posY);

Loading…
Cancel
Save