Fixes for low FPS on slower systems during battles - #3580
Open
VannevarXbox wants to merge 4 commits into
Open
Conversation
…eshGauge to update incrementally, or at least to skip redrawing content when not needed. The battle status window is no longer cleared by a call to Refresh(), but full-clear-and-redraw functionality would be very easy to add if needed. In order to accomplish the incremental updates, Window_BattleStatus keeps a cache of the displayed values for each item, updating the graphics if those values change. The UIs for RM2k3 battle type B (alternative) and C (gauge) both have overlapping content, meaning multiple items need to be redrawn if one of the overlapping items is redrawn in the UI, so further optimization would be possible there. The function DrawGauge, which draws the gauges for battle types A (traditional) and B (alternative), has been moved from Window_Base into Window_BattleStatus, as that seems to be the only code that uses it.
…ged, since it appears that at least in BattleType_alternative/B with a small window, the gauges can overlap into the row below. This makes sure the window gets redrawn properly, and this situation should be rare enough that this doesn't impact performance too much. Also, when re-drawing content in BattleType_gauge/C, clear the whole item/actor area in case of any face changes.
…ctor face if face redraw is needed, fixed a couple frames for clearing content, removed function ClearItemGraphics which is now unused
…rawn in Window_BattleStatus
Member
|
While the fix itself is reasonable I think its too complicated: Pretty sure just detecting "Anything of the Character changed" and "Gauge Changed" per line are enough to get rid of most redraws. Usually any of the values only changes when an event command executes which changes this or when a turn happens. In non-Maniac games events can only fire when somebody acts so these repaints are rare. Gauge redraws happen alot though. I cant remember why we even do so many repaints here. Probably was just hard to keep interpreter + this window in sync so that was the easy solution... |
Member
|
Havn't got around to test this properly as there are so many battle variants xD but does this simpler patch also work for you? diff --git a/src/window_battlestatus.cpp b/src/window_battlestatus.cpp
index f3be182ff..399920a6a 100644
--- a/src/window_battlestatus.cpp
+++ b/src/window_battlestatus.cpp
@@ -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();
}
@@ -73,6 +71,13 @@ void Window_BattleStatus::Refresh() {
item_max = std::min(item_max, 4);
+ if (item_max != last_item_max) {
+ contents->Clear();
+ line_states = {};
+ gauge_states = {};
+ last_item_max = item_max;
+ }
+
for (int i = 0; i < item_max; i++) {
// The party only contains valid battlers
const Game_Battler* actor;
@@ -83,26 +88,59 @@ void Window_BattleStatus::Refresh() {
actor = &(*Main_Data::game_party)[i];
}
+ LineState cur_state;
+ cur_state.battler = actor;
+
if (!enemy && lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_gauge) {
- DrawActorFace(*static_cast<const Game_Actor*>(actor), 80 * i, actor_face_height);
+ const auto* game_actor = static_cast<const Game_Actor*>(actor);
+ cur_state.face_name = game_actor->GetFaceName();
+ cur_state.face_index = game_actor->GetFaceIndex();
+
+ if (cur_state != line_states[i]) {
+ contents->ClearRect(Rect(80 * i, 0, 80, contents->GetHeight()));
+ DrawActorFace(*game_actor, 80 * i, actor_face_height);
+ line_states[i] = cur_state;
+ // Text/face and gauge overlap; clearing the face area invalidates the gauge/number overlay
+ gauge_states[i] = GaugeState{};
+ }
}
else {
- int y = menu_item_height / 8 + i * menu_item_height;
-
- DrawActorName(*actor, 4, y);
+ cur_state.name = actor->GetName();
+ cur_state.state = actor->GetSignificantState();
if (Feature::HasRpg2kBattleSystem()) {
- int hpdigits = (actor->MaxHpValue() >= 1000) ? 4 : 3;
- int spdigits = (actor->MaxSpValue() >= 1000) ? 4 : 3;
- DrawActorState(*actor, (hpdigits < 4 && spdigits < 4) ? 86 : 80, y);
- DrawActorHp(*actor, 178 - hpdigits * 6 - spdigits * 6, y, hpdigits, true);
- DrawActorSp(*actor, 220 - spdigits * 6, y, spdigits, false);
- } else {
- if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_traditional) {
- DrawActorState(*actor, 84, y);
- DrawActorHpValue(*actor, 136 + 4 * 6, y);
+ cur_state.hp = actor->GetHp();
+ cur_state.max_hp = actor->GetMaxHp();
+ cur_state.sp = actor->GetSp();
+ cur_state.max_sp = actor->GetMaxSp();
+ } else if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_traditional) {
+ cur_state.hp = actor->GetHp();
+ cur_state.max_hp = actor->GetMaxHp();
+ }
+
+ if (cur_state != line_states[i]) {
+ contents->ClearRect(Rect(0, i * menu_item_height, contents->GetWidth(), menu_item_height));
+
+ int y = menu_item_height / 8 + i * menu_item_height;
+
+ DrawActorName(*actor, 4, y);
+ if (Feature::HasRpg2kBattleSystem()) {
+ int hpdigits = (actor->MaxHpValue() >= 1000) ? 4 : 3;
+ int spdigits = (actor->MaxSpValue() >= 1000) ? 4 : 3;
+ DrawActorState(*actor, (hpdigits < 4 && spdigits < 4) ? 86 : 80, y);
+ DrawActorHp(*actor, 178 - hpdigits * 6 - spdigits * 6, y, hpdigits, true);
+ DrawActorSp(*actor, 220 - spdigits * 6, y, spdigits, false);
} else {
- DrawActorState(*actor, 80, y);
+ if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_traditional) {
+ DrawActorState(*actor, 84, y);
+ DrawActorHpValue(*actor, 136 + 4 * 6, y);
+ } else {
+ DrawActorState(*actor, 80, y);
+ }
}
+
+ line_states[i] = cur_state;
+ // Text and gauge overlap across the row; clearing the line invalidates the gauge for this row
+ gauge_states[i] = GaugeState{};
}
}
}
@@ -111,34 +149,37 @@ void Window_BattleStatus::Refresh() {
}
void Window_BattleStatus::RefreshGauge() {
- if (Feature::HasRpg2k3BattleSystem()) {
- 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));
- } else {
- contents->ClearRect(Rect(192, 0, 45, 64));
- }
+ if (!Feature::HasRpg2k3BattleSystem()) {
+ return;
+ }
+
+ for (int i = 0; i < item_max; ++i) {
+ // The party always contains valid battlers
+ Game_Battler* actor;
+ if (enemy) {
+ actor = &(*Main_Data::game_enemyparty)[i];
+ }
+ else {
+ actor = &(*Main_Data::game_party)[i];
}
- for (int i = 0; i < item_max; ++i) {
- // The party always contains valid battlers
- Game_Battler* actor;
- if (enemy) {
- actor = &(*Main_Data::game_enemyparty)[i];
- }
- else {
- actor = &(*Main_Data::game_party)[i];
- }
+ GaugeState cur_state;
+ cur_state.atb = actor->GetAtbGauge();
- if (!enemy && lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_gauge) {
+ if (!enemy && lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_gauge) {
+ cur_state.hp = actor->GetHp();
+ cur_state.max_hp = actor->GetMaxHp();
+ cur_state.sp = actor->GetSp();
+ cur_state.max_sp = actor->GetMaxSp();
+
+ if (cur_state != gauge_states[i]) {
BitmapRef system2 = Cache::System2();
if (system2) {
// Clear number and gauge drawing area
contents->ClearRect(Rect(40 + 80 * i, actor_face_height, 8 * 4, 48));
- // Number clearing removed part of the face, but both, clear and redraw
- // are needed because some games don't have face graphics that are huge enough
- // to clear the number area (e.g. Ara Fell)
+ // Number clearing removed part of the face, so the face must unconditionally be redrawn
+ // because the face graphic and the gauge/number area overlap (e.g. Ara Fell)
DrawActorFace(*static_cast<const Game_Actor*>(actor), 80 * i, actor_face_height);
int x = 32 + i * 80;
@@ -163,26 +204,49 @@ void Window_BattleStatus::RefreshGauge() {
// Gauge
DrawGaugeSystem2(fill_x, y + 16 * 2, actor->GetAtbGauge(), actor->GetMaxAtbGauge(), 2);
- // Numbers
+ // Numbers (unconditionally redrawn because they overlap the face & gauge area)
x = 40 + 80 * i;
DrawNumberSystem2(x, y, actor->GetHp());
DrawNumberSystem2(x, y + 12 + 4, actor->GetSp());
}
+
+ gauge_states[i] = cur_state;
}
- else {
- int y = menu_item_height / 8 + i * menu_item_height;
+ }
+ else {
+ int y = menu_item_height / 8 + i * menu_item_height;
+
+ if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_alternative) {
+ cur_state.hp = actor->GetHp();
+ cur_state.max_hp = actor->GetMaxHp();
+ cur_state.sp = actor->GetSp();
+ cur_state.max_sp = actor->GetMaxSp();
+ cur_state.gauge_hidden = (lcf::Data::battlecommands.transparency != lcf::rpg::BattleCommands::Transparency_opaque)
+ && (menu_item_height / 8 + index * menu_item_height == y);
+
+ if (cur_state != gauge_states[i]) {
+ int clear_y = i * menu_item_height;
+ int clear_h = (i == item_max - 1) ? (contents->GetHeight() - clear_y) : menu_item_height;
+ contents->ClearRect(Rect(192, clear_y, 45, clear_h));
- if (lcf::Data::battlecommands.battle_type == lcf::rpg::BattleCommands::BattleType_alternative) {
// RPG_RT Bug (?): Gauge hidden when selected due to transparency (wrong color when rendering)
- if (lcf::Data::battlecommands.transparency == lcf::rpg::BattleCommands::Transparency_opaque || (menu_item_height / 8 + index * menu_item_height != y)) {
+ if (!cur_state.gauge_hidden) {
DrawGauge(*actor, 202 - 10, y - 2, lcf::Data::battlecommands.transparency == lcf::rpg::BattleCommands::Transparency_opaque ? 96 : 255);
}
+
+ // HP and SP values overlap the gauge area in alternative style, so they must unconditionally
+ // be redrawn whenever this gauge line is cleared and repainted.
int hpdigits = (actor->MaxHpValue() >= 1000) ? 4 : 3;
int spdigits = (actor->MaxSpValue() >= 1000) ? 4 : 3;
DrawActorHp(*actor, 178 - hpdigits * 6 - spdigits * 6, y, hpdigits, true);
DrawActorSp(*actor, 220 - spdigits * 6, y, spdigits, false);
- } else {
+
+ gauge_states[i] = cur_state;
+ }
+ } else {
+ if (cur_state != gauge_states[i]) {
DrawGauge(*actor, 156, y - 2);
+ gauge_states[i] = cur_state;
}
}
}
diff --git a/src/window_battlestatus.h b/src/window_battlestatus.h
index 046beacdf..60a8ba89f 100644
--- a/src/window_battlestatus.h
+++ b/src/window_battlestatus.h
@@ -19,8 +19,18 @@
#define EP_WINDOW_BATTLESTATUS_H
// Headers
+#include <array>
+#include <string>
+#include <tuple>
#include "window_selectable.h"
-#include "bitmap.h"
+
+namespace lcf {
+namespace rpg {
+ struct State;
+}
+}
+
+class Game_Battler;
/**
* Window BattleStatus Class.
@@ -87,7 +97,7 @@ protected:
/**
* Tests whether actor is selectable in current ChoiceMode.
*
- * @return true: selection possible
+ * @return true: selection possible
*/
bool IsChoiceValid(const Game_Battler& battler) const;
@@ -99,6 +109,58 @@ protected:
FileRequestBinding request_id;
int actor_face_height = 24;
+
+private:
+ struct LineState {
+ const Game_Battler* battler = nullptr;
+ std::string name;
+ std::string face_name;
+ int face_index = -1;
+ const lcf::rpg::State* state = nullptr;
+ int hp = 0;
+ int max_hp = 0;
+ int sp = 0;
+ int max_sp = 0;
+
+ // TODO: default == and != after moving to C++20
+ auto Tie() const {
+ return std::tie(battler, name, face_name, face_index, state, hp, max_hp, sp, max_sp);
+ }
+
+ bool operator==(const LineState& o) const {
+ return Tie() == o.Tie();
+ }
+
+ bool operator!=(const LineState& o) const {
+ return !(*this == o);
+ }
+ };
+
+ struct GaugeState {
+ int atb = -1;
+ int hp = -1;
+ int max_hp = -1;
+ int sp = -1;
+ int max_sp = -1;
+ bool gauge_hidden = false;
+
+ // TODO: default == and != after moving to C++20
+ auto Tie() const {
+ return std::tie(atb, hp, max_hp, sp, max_sp, gauge_hidden);
+ }
+
+ bool operator==(const GaugeState& o) const {
+ return Tie() == o.Tie();
+ }
+
+ bool operator!=(const GaugeState& o) const {
+ return !(*this == o);
+ }
+ };
+
+ std::array<LineState, 4> line_states{};
+ std::array<GaugeState, 4> gauge_states{};
+ int last_item_max = -1;
};
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Window_BattleStatus::Refresh was being called for every frame during a battle, triggering a full re-draw of the battle status window. This was causing very low framerate at some points on slower systems:
#3494
#3497
These changes improve battle framerate to a playable level on original Xbox. I've tested them with RM2k, custom test games for battle types A, B, and C (both large and small windows), the Maniac test game, and the game Ara Fell which was mentioned in the source.
It's my first pull request, so hopefully I didn't do anything too dumb! I'd be happy to answer any questions or make any needed changes.