Browse Source

Save 1.5 MiB RAM in-game by freeing more DiabloUI art

pull/1393/head
Gleb Mazovetskiy 5 years ago
parent
commit
87dcbcb6d7
  1. 2
      Source/diablo.cpp
  2. 54
      SourceX/DiabloUI/diabloui.cpp
  3. 5
      SourceX/DiabloUI/diabloui.h

2
Source/diablo.cpp

@ -377,7 +377,7 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer)
break; break;
} }
// Save 1.3 MiB of RAM by freeing all main menu resources // Save 2.8 MiB of RAM by freeing all main menu resources
// before starting the game. // before starting the game.
UiDestroy(); UiDestroy();

54
SourceX/DiabloUI/diabloui.cpp

@ -1,23 +1,21 @@
#include "all.h" #include "DiabloUI/diabloui.h"
#include "display.h"
#include "stubs.h"
#include "utf8.h"
#include <string>
#include <algorithm> #include <algorithm>
#include <string>
#include "../3rdParty/Storm/Source/storm.h" #include "../3rdParty/Storm/Source/storm.h"
#include "controls/controller.h"
#include "controls/menu_controls.h" #include "controls/menu_controls.h"
#include "DiabloUI/scrollbar.h"
#include "DiabloUI/diabloui.h"
#include "DiabloUI/art_draw.h" #include "DiabloUI/art_draw.h"
#include "DiabloUI/text_draw.h"
#include "DiabloUI/fonts.h"
#include "DiabloUI/button.h" #include "DiabloUI/button.h"
#include "DiabloUI/dialogs.h" #include "DiabloUI/dialogs.h"
#include "controls/controller.h" #include "DiabloUI/fonts.h"
#include "DiabloUI/scrollbar.h"
#include "DiabloUI/text_draw.h"
#include "display.h"
#include "stubs.h"
#include "utf8.h"
#ifdef __SWITCH__ #ifdef __SWITCH__
// for virtual keyboard on Switch // for virtual keyboard on Switch
@ -30,8 +28,8 @@ std::size_t SelectedItemMax;
std::size_t ListViewportSize = 1; std::size_t ListViewportSize = 1;
const std::size_t *ListOffset = NULL; const std::size_t *ListOffset = NULL;
Art ArtLogos[3]; std::array<Art, 3> ArtLogos;
Art ArtFocus[3]; std::array<Art, 3> ArtFocus;
Art ArtBackgroundWidescreen; Art ArtBackgroundWidescreen;
Art ArtBackground; Art ArtBackground;
Art ArtCursor; Art ArtCursor;
@ -69,13 +67,6 @@ struct scrollBarState {
} // namespace } // namespace
void UiDestroy()
{
ArtHero.Unload();
UnloadTtfFont();
UnloadArtFonts();
}
void UiInitList(int count, void (*fnFocus)(int value), void (*fnSelect)(int value), void (*fnEsc)(), std::vector<UiItemBase *> items, bool itemsWraps, bool (*fnYesNo)()) void UiInitList(int count, void (*fnFocus)(int value), void (*fnSelect)(int value), void (*fnEsc)(), std::vector<UiItemBase *> items, bool itemsWraps, bool (*fnYesNo)())
{ {
SelectedItem = 0; SelectedItem = 0;
@ -422,6 +413,8 @@ void UiFocusNavigationYesNo()
UiPlaySelectSound(); UiPlaySelectSound();
} }
namespace {
bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect) bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect)
{ {
const SDL_Point point = { event.button.x, event.button.y }; const SDL_Point point = { event.button.x, event.button.y };
@ -489,6 +482,18 @@ void LoadUiGFX()
LoadHeros(); LoadHeros();
} }
void UnloadUiGFX()
{
ArtHero.Unload();
ArtCursor.Unload();
for (auto &art : ArtFocus)
art.Unload();
for (auto &art : ArtLogos)
art.Unload();
}
} // namespace
void UiInitialize() void UiInitialize()
{ {
LoadUiGFX(); LoadUiGFX();
@ -500,6 +505,13 @@ void UiInitialize()
} }
} }
void UiDestroy()
{
UnloadTtfFont();
UnloadArtFonts();
UnloadUiGFX();
}
char connect_plrinfostr[128]; char connect_plrinfostr[128];
char connect_categorystr[128]; char connect_categorystr[128];
void UiSetupPlayerInfo(char *infostr, _uiheroinfo *pInfo, Uint32 type) void UiSetupPlayerInfo(char *infostr, _uiheroinfo *pInfo, Uint32 type)

5
SourceX/DiabloUI/diabloui.h

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include <cstddef> #include <cstddef>
#include <SDL.h> #include <SDL.h>
@ -24,8 +25,8 @@ typedef enum _artLogo {
LOGO_BIG, LOGO_BIG,
} _artLogo; } _artLogo;
extern Art ArtLogos[3]; extern std::array<Art, 3> ArtLogos;
extern Art ArtFocus[3]; extern std::array<Art, 3> ArtFocus;
extern Art ArtBackground; extern Art ArtBackground;
extern Art ArtBackgroundWidescreen; extern Art ArtBackgroundWidescreen;
extern Art ArtCursor; extern Art ArtCursor;

Loading…
Cancel
Save