Skip to content

Commit

Permalink
Battle 2k: Do not redraw text in BattleStatus window when nothing cha…
Browse files Browse the repository at this point in the history
…nged (faster)
  • Loading branch information
Ghabry committed Aug 30, 2024
1 parent 5f9b68b commit ffebab2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
34 changes: 32 additions & 2 deletions src/window_battlestatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ Window_BattleStatus::Window_BattleStatus(int ix, int iy, int iwidth, int iheight
}

void Window_BattleStatus::Refresh() {
contents->Clear();

if (enemy) {
item_max = Main_Data::game_enemyparty->GetBattlerCount();
}
Expand All @@ -73,6 +71,14 @@ void Window_BattleStatus::Refresh() {

item_max = std::min(item_max, 4);

if (item_max != item_max_prev) {
Rect clear_rect = contents->GetRect();
clear_rect.y = menu_item_height / 8 + (4 - item_max) * menu_item_height;
contents->ClearRect(clear_rect);
}

item_max_prev = item_max;

for (int i = 0; i < item_max; i++) {
// The party only contains valid battlers
const Game_Battler* actor;
Expand All @@ -89,6 +95,15 @@ void Window_BattleStatus::Refresh() {
else {
int y = menu_item_height / 8 + i * menu_item_height;

if (data_cache[i].HasChanged(*actor)) {
Rect clear_rect = contents->GetRect();
clear_rect.y = y;
clear_rect.height = menu_item_height;
contents->ClearRect(clear_rect);
} else {
continue;
}

DrawActorName(*actor, 4, y);
if (Feature::HasRpg2kBattleSystem()) {
int hpdigits = (actor->MaxHpValue() >= 1000) ? 4 : 3;
Expand All @@ -112,6 +127,8 @@ void Window_BattleStatus::Refresh() {

void Window_BattleStatus::RefreshGauge() {
if (Feature::HasRpg2k3BattleSystem()) {
contents->Clear();

if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_alternative) {
if (lcf::Data::battlecommands.window_size == lcf::rpg::BattleCommands::WindowSize_small) {
contents->ClearRect(Rect(192, 0, 45, 58));
Expand Down Expand Up @@ -360,3 +377,16 @@ void Window_BattleStatus::RefreshActiveFromValid() {
}
UpdateCursorRect();
}

bool Window_BattleStatus::ActorDataCache::HasChanged(const Game_Battler& battler) {
if (battler.GetName() == name && battler.GetHp() == hp && battler.GetSp() == sp && battler.GetSignificantState()== state) {
return false;
}

name = ToString(battler.GetName());
hp = battler.GetHp();
sp = battler.GetSp();
state = battler.GetSignificantState();

return true;
}
14 changes: 13 additions & 1 deletion src/window_battlestatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Window_BattleStatus : public Window_Selectable {
/**
* Tests whether actor is selectable in current ChoiceMode.
*
* @return true: selection possible
* @return true: selection possible
*/
bool IsChoiceValid(const Game_Battler& battler) const;

Expand All @@ -99,6 +99,18 @@ class Window_BattleStatus : public Window_Selectable {
FileRequestBinding request_id;

int actor_face_height = 24;

struct ActorDataCache {
std::string name;
int hp;
int sp;
const lcf::rpg::State* state;

bool HasChanged(const Game_Battler& battler);
};

int item_max_prev = 0;
std::array<ActorDataCache, 4> data_cache;
};

#endif

0 comments on commit ffebab2

Please sign in to comment.