From a3a9e4a8eca1bf1b0efdf96b76650dbeaa4f9f51 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Tue, 25 Aug 2020 23:26:03 -0400 Subject: [PATCH 01/21] Use lcf fwd header --- src/game_actor.h | 11 +---------- src/game_battle.h | 7 +------ src/game_battlealgorithm.h | 10 +--------- src/game_interpreter.h | 7 +------ src/game_player.h | 6 +----- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/game_actor.h b/src/game_actor.h index 8d2442437b..421b0f3e2b 100644 --- a/src/game_actor.h +++ b/src/game_actor.h @@ -22,20 +22,11 @@ #include #include #include +#include #include #include #include "game_battler.h" -namespace lcf { -namespace rpg { - class Actor; - class Skill; - class BattleCommand; - class Item; - class Class; -} // namespace rpg -} // namespace lcf - class PendingMessage; /** diff --git a/src/game_battle.h b/src/game_battle.h index e14c0cbc62..b4fb5dc861 100644 --- a/src/game_battle.h +++ b/src/game_battle.h @@ -19,6 +19,7 @@ #define EP_GAME_BATTLE_H #include +#include #include #include #include "teleport_target.h" @@ -31,12 +32,6 @@ class Game_Actor; class Game_Interpreter; class Spriteset_Battle; -namespace lcf { -namespace rpg { - class EventPage; -} // namespace rpg -} // namespace lcf - enum class BattleResult { Victory, Escape, diff --git a/src/game_battlealgorithm.h b/src/game_battlealgorithm.h index 5fc975efc1..3155f3a5f9 100644 --- a/src/game_battlealgorithm.h +++ b/src/game_battlealgorithm.h @@ -20,19 +20,11 @@ #include #include +#include #include class Game_Battler; class Game_Party_Base; -namespace lcf { -namespace rpg { - class Animation; - class Item; - class State; - class Skill; - class Sound; -} // namespace rpg -} // namespace lcf /** * Contains algorithms to handle the different battle attacks, skills and items. diff --git a/src/game_interpreter.h b/src/game_interpreter.h index c62fa8c916..6a3e64a5c4 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -24,6 +24,7 @@ #include "async_handler.h" #include "game_character.h" #include "game_actor.h" +#include #include #include "system.h" #include @@ -34,12 +35,6 @@ class Game_Event; class Game_CommonEvent; class PendingMessage; -namespace lcf { -namespace rpg { - class EventPage; -} // namespace rpg -} // namespace lcf - /** * Game_Interpreter class */ diff --git a/src/game_player.h b/src/game_player.h index b013a2b79d..afbb7ca34d 100644 --- a/src/game_player.h +++ b/src/game_player.h @@ -19,6 +19,7 @@ #define EP_GAME_PLAYER_H // Headers +#include #include #include #include "game_character.h" @@ -27,11 +28,6 @@ #include class Game_Vehicle; -namespace lcf { -namespace rpg { - class SaveTarget; -} // namespace rpg -} // namespace lcf /** * Game Player class From 94427467dd9043ba9ab41f16490ba43d17e9d90f Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 04:45:23 -0400 Subject: [PATCH 02/21] Game_Actor::GetSkillName - use StringView Allows abstraction between different underlying string types --- src/game_actor.cpp | 4 ++-- src/game_actor.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game_actor.cpp b/src/game_actor.cpp index 3110cf6adf..0e96b404f5 100644 --- a/src/game_actor.cpp +++ b/src/game_actor.cpp @@ -823,9 +823,9 @@ Point Game_Actor::GetOriginalPosition() const { return { actor.battle_x, actor.battle_y }; } -const std::string& Game_Actor::GetSkillName() const { +StringView Game_Actor::GetSkillName() const { auto& a = GetActor(); - return a.rename_skill ? a.skill_name : lcf::Data::terms.command_skill; + return a.rename_skill ? StringView(a.skill_name) : StringView(lcf::Data::terms.command_skill); } void Game_Actor::SetSprite(const std::string &file, int index, bool transparent) { diff --git a/src/game_actor.h b/src/game_actor.h index 421b0f3e2b..0b693950cd 100644 --- a/src/game_actor.h +++ b/src/game_actor.h @@ -672,7 +672,7 @@ class Game_Actor final : public Game_Battler { * * @return name of skill menu item */ - const std::string& GetSkillName() const; + StringView GetSkillName() const; /** * Sets new actor name. From 093f057ef0734bdc1f4ced87b8785c54ff93dd50 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 04:52:17 -0400 Subject: [PATCH 03/21] Actor name and sprite name - uste StringView --- src/game_actor.h | 9 +++++---- src/game_battlealgorithm.cpp | 26 +++++++++++++------------- src/game_battler.h | 5 +++-- src/game_enemy.h | 8 ++++---- src/game_player.cpp | 2 +- src/pending_message.cpp | 2 +- src/scene_battle_rpg2k.cpp | 5 ++--- src/scene_battle_rpg2k3.cpp | 5 ++--- src/scene_name.cpp | 4 ++-- src/scene_order.cpp | 7 +++---- src/scene_save.cpp | 2 +- src/sprite_battler.cpp | 2 +- src/sprite_character.cpp | 2 +- src/sprite_character.h | 2 +- src/window_shopparty.cpp | 4 ++-- 15 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/game_actor.h b/src/game_actor.h index 0b693950cd..f6250ae5b2 100644 --- a/src/game_actor.h +++ b/src/game_actor.h @@ -26,6 +26,7 @@ #include #include #include "game_battler.h" +#include "string_view.h" class PendingMessage; @@ -236,14 +237,14 @@ class Game_Actor final : public Game_Battler { * * @return name. */ - const std::string& GetName() const override; + StringView GetName() const override; /** * Gets actor character sprite filename. * * @return character sprite filename. */ - const std::string& GetSpriteName() const override; + StringView GetSpriteName() const override; /** * Gets actor character sprite index. @@ -880,7 +881,7 @@ inline void Game_Actor::SetName(const std::string &new_name) { } -inline const std::string& Game_Actor::GetName() const { +inline StringView Game_Actor::GetName() const { return GetData().name; } @@ -892,7 +893,7 @@ inline const std::string& Game_Actor::GetTitle() const { return GetData().title; } -inline const std::string& Game_Actor::GetSpriteName() const { +inline StringView Game_Actor::GetSpriteName() const { return GetData().sprite_name; } diff --git a/src/game_battlealgorithm.cpp b/src/game_battlealgorithm.cpp index 7ab9046422..f73d0936ff 100644 --- a/src/game_battlealgorithm.cpp +++ b/src/game_battlealgorithm.cpp @@ -369,7 +369,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDeathMessage() const { ); } else { - return GetTarget()->GetName() + message; + return ToString(GetTarget()->GetName()) + message; } } @@ -386,7 +386,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(const s ); } else { - return GetTarget()->GetName() + message; + return ToString(GetTarget()->GetName()) + message; } } @@ -432,7 +432,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetUndamagedMessage() const { ); } else { - return GetTarget()->GetName() + message; + return ToString(GetTarget()->GetName()) + message; } } @@ -561,7 +561,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(const std::stri ); } else { - return GetTarget()->GetName() + message; + return ToString(GetTarget()->GetName()) + message; } } @@ -1110,7 +1110,7 @@ std::string Game_BattleAlgorithm::Normal::GetStartMessage() const { ); } else { - return source->GetName() + lcf::Data::terms.attacking; + return ToString(source->GetName()) + lcf::Data::terms.attacking; } } else { @@ -1418,7 +1418,7 @@ std::string Game_BattleAlgorithm::Skill::GetStartMessage() const { ); } else { - return source->GetName() + skill.using_message1; + return ToString(source->GetName()) + skill.using_message1; } } else { @@ -1678,7 +1678,7 @@ std::string Game_BattleAlgorithm::Item::GetStartMessage() const { particle = "は"; else particle = " "; - return source->GetName() + particle + item.name + lcf::Data::terms.use_item; + return ToString(source->GetName()) + particle + item.name + lcf::Data::terms.use_item; } else { return item.name; @@ -1716,7 +1716,7 @@ std::string Game_BattleAlgorithm::Defend::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return source->GetName() + lcf::Data::terms.defending; + return ToString(source->GetName()) + lcf::Data::terms.defending; } else { return ""; @@ -1750,7 +1750,7 @@ std::string Game_BattleAlgorithm::Observe::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return source->GetName() + lcf::Data::terms.observing; + return ToString(source->GetName()) + lcf::Data::terms.observing; } else { return ""; @@ -1777,7 +1777,7 @@ std::string Game_BattleAlgorithm::Charge::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return source->GetName() + lcf::Data::terms.focus; + return ToString(source->GetName()) + lcf::Data::terms.focus; } else { return ""; @@ -1808,7 +1808,7 @@ std::string Game_BattleAlgorithm::SelfDestruct::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return source->GetName() + lcf::Data::terms.autodestruction; + return ToString(source->GetName()) + lcf::Data::terms.autodestruction; } else { return ""; @@ -1888,7 +1888,7 @@ std::string Game_BattleAlgorithm::Escape::GetStartMessage() const { } else if (Player::IsRPG2k()) { if (source->GetType() == Game_Battler::Type_Enemy) { - return source->GetName() + lcf::Data::terms.enemy_escape; + return ToString(source->GetName()) + lcf::Data::terms.enemy_escape; } } @@ -1940,7 +1940,7 @@ std::string Game_BattleAlgorithm::Transform::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return source->GetName() + lcf::Data::terms.enemy_transform; + return ToString(source->GetName()) + lcf::Data::terms.enemy_transform; } else { return ""; diff --git a/src/game_battler.h b/src/game_battler.h index 2df92af7ac..9a3523a6a6 100644 --- a/src/game_battler.h +++ b/src/game_battler.h @@ -29,6 +29,7 @@ #include "flash.h" #include "utils.h" #include "point.h" +#include "string_view.h" class Game_Actor; class Game_Party_Base; @@ -209,14 +210,14 @@ class Game_Battler { * * @return Character name */ - virtual const std::string& GetName() const = 0; + virtual StringView GetName() const = 0; /** * Gets the filename of the character sprite * * @return Filename of character sprite */ - virtual const std::string& GetSpriteName() const = 0; + virtual StringView GetSpriteName() const = 0; /** * Gets battler HP. diff --git a/src/game_enemy.h b/src/game_enemy.h index 5658ecf8e8..948644a52b 100644 --- a/src/game_enemy.h +++ b/src/game_enemy.h @@ -71,14 +71,14 @@ class Game_Enemy final : public Game_Battler * * @return Character name */ - const std::string& GetName() const override; + StringView GetName() const override; /** * Gets the filename of the enemy sprite * * @return Filename of enemy sprite */ - const std::string& GetSpriteName() const override; + StringView GetSpriteName() const override; /** * Gets the maximum HP for the current level. @@ -253,11 +253,11 @@ inline std::vector& Game_Enemy::GetStates() { return states; } -inline const std::string& Game_Enemy::GetName() const { +inline StringView Game_Enemy::GetName() const { return enemy->name; } -inline const std::string& Game_Enemy::GetSpriteName() const { +inline StringView Game_Enemy::GetSpriteName() const { return enemy->battler_name; } diff --git a/src/game_player.cpp b/src/game_player.cpp index b17a43e917..6e20e43451 100644 --- a/src/game_player.cpp +++ b/src/game_player.cpp @@ -453,7 +453,7 @@ void Game_Player::Refresh() { return; } - SetSpriteGraphic(actor->GetSpriteName(), actor->GetSpriteIndex()); + SetSpriteGraphic(ToString(actor->GetSpriteName()), actor->GetSpriteIndex()); SetTransparency(actor->GetSpriteTransparency()); if (data()->aboard) diff --git a/src/pending_message.cpp b/src/pending_message.cpp index 9fe4bc7623..8ad873bbb2 100644 --- a/src/pending_message.cpp +++ b/src/pending_message.cpp @@ -112,7 +112,7 @@ std::string PendingMessage::ApplyTextInsertingCommands(std::string input, uint32 if (!actor) { Output::Warning("Invalid Actor Id {} in message text", value); } else{ - output.append(actor->GetName()); + output.append(ToString(actor->GetName())); } start_copy = iter; diff --git a/src/scene_battle_rpg2k.cpp b/src/scene_battle_rpg2k.cpp index d00e4fbbe6..c34f923c88 100644 --- a/src/scene_battle_rpg2k.cpp +++ b/src/scene_battle_rpg2k.cpp @@ -75,9 +75,8 @@ void Scene_Battle_Rpg2k::CreateBattleTargetWindow() { std::vector enemies; Main_Data::game_enemyparty->GetActiveBattlers(enemies); - for (std::vector::iterator it = enemies.begin(); - it != enemies.end(); ++it) { - commands.push_back((*it)->GetName()); + for (auto& enemy: enemies) { + commands.push_back(ToString(enemy->GetName())); } target_window.reset(new Window_Command(commands, 136, 4)); diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 58b41a3e7b..2d6333cefd 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -486,9 +486,8 @@ void Scene_Battle_Rpg2k3::CreateBattleTargetWindow() { std::vector enemies; Main_Data::game_enemyparty->GetActiveBattlers(enemies); - for (std::vector::iterator it = enemies.begin(); - it != enemies.end(); ++it) { - commands.push_back((*it)->GetName()); + for (auto& enemy: enemies) { + commands.push_back(ToString(enemy->GetName())); } target_window.reset(new Window_Command(commands, 136, 4)); diff --git a/src/scene_name.cpp b/src/scene_name.cpp index 71ac772d0c..6966bd4c28 100644 --- a/src/scene_name.cpp +++ b/src/scene_name.cpp @@ -42,7 +42,7 @@ void Scene_Name::Start() { assert(actor); name_window.reset(new Window_Name(96, 40, 192, 32)); - name_window->Set(use_default_name ? actor->GetName() : ""); + name_window->Set(use_default_name ? ToString(actor->GetName()) : ""); name_window->Refresh(); face_window.reset(new Window_Face(32, 8, 64, 64)); @@ -112,7 +112,7 @@ void Scene_Name::Update() { auto* actor = Game_Actors::GetActor(actor_id); if (actor != nullptr) { if (name_window->Get().empty()) { - name_window->Set(actor->GetName()); + name_window->Set(ToString(actor->GetName())); name_window->Refresh(); } else { actor->SetName(name_window->Get()); diff --git a/src/scene_order.cpp b/src/scene_order.cpp index 5b5c0f8bac..6f28d8c7d1 100644 --- a/src/scene_order.cpp +++ b/src/scene_order.cpp @@ -103,10 +103,9 @@ void Scene_Order::CreateCommandWindow() { std::vector options_right; std::vector options_confirm; - std::vector actors = Main_Data::game_party->GetActors(); - for (std::vector::const_iterator it = actors.begin(); - it != actors.end(); ++it) { - options_left.push_back((*it)->GetName()); + const auto actors = Main_Data::game_party->GetActors(); + for (auto& actor: actors) { + options_left.push_back(ToString(actor->GetName())); options_right.push_back(""); } diff --git a/src/scene_save.cpp b/src/scene_save.cpp index 0975b766cb..05c3cb5a83 100644 --- a/src/scene_save.cpp +++ b/src/scene_save.cpp @@ -110,7 +110,7 @@ void Scene_Save::Save(std::ostream& os, int slot_id, bool prepare_save) { title.face1_name = actor->GetFaceName(); title.hero_hp = actor->GetHp(); title.hero_level = actor->GetLevel(); - title.hero_name = actor->GetName(); + title.hero_name = ToString(actor->GetName()); } Main_Data::game_data.title = title; diff --git a/src/sprite_battler.cpp b/src/sprite_battler.cpp index d4653a8242..491048b5dc 100644 --- a/src/sprite_battler.cpp +++ b/src/sprite_battler.cpp @@ -298,7 +298,7 @@ void Sprite_Battler::ResetZ() { } void Sprite_Battler::CreateSprite() { - sprite_name = battler->GetSpriteName(); + sprite_name = ToString(battler->GetSpriteName()); hue = battler->GetHue(); SetX(battler->GetDisplayX()); diff --git a/src/sprite_character.cpp b/src/sprite_character.cpp index 839801c805..44c3313508 100644 --- a/src/sprite_character.cpp +++ b/src/sprite_character.cpp @@ -117,7 +117,7 @@ void Sprite_Character::ChipsetUpdated() { refresh_bitmap = true; } -Rect Sprite_Character::GetCharacterRect(const std::string& name, int index, const Rect bitmap_rect) { +Rect Sprite_Character::GetCharacterRect(StringView name, int index, const Rect bitmap_rect) { Rect rect; // Allow large 4x2 spriteset of 3x4 sprites // when the character name starts with a $ sign. diff --git a/src/sprite_character.h b/src/sprite_character.h index e79f90f287..16920c48da 100644 --- a/src/sprite_character.h +++ b/src/sprite_character.h @@ -74,7 +74,7 @@ class Sprite_Character : public Sprite { * * @return Rect describing image sub region containing character frames. */ - static Rect GetCharacterRect(const std::string& name, int index, Rect bitmap_rect); + static Rect GetCharacterRect(StringView name, int index, Rect bitmap_rect); /** * Called when the map chipset is changed by an event diff --git a/src/window_shopparty.cpp b/src/window_shopparty.cpp index 948a05dbe6..0cdde94011 100644 --- a/src/window_shopparty.cpp +++ b/src/window_shopparty.cpp @@ -36,7 +36,7 @@ Window_ShopParty::Window_ShopParty(int ix, int iy, int iwidth, int iheight) : const std::vector& actors = Main_Data::game_party->GetActors(); for (size_t i = 0; i < actors.size() && i < 4; i++) { - const std::string& sprite_name = actors[i]->GetSpriteName(); + const auto& sprite_name = actors[i]->GetSpriteName(); FileRequestAsync* request = AsyncHandler::RequestFile("CharSet", sprite_name); request->SetGraphicFile(true); request_ids.push_back(request->Bind(&Window_ShopParty::OnCharsetSpriteReady, this, (int)i)); @@ -160,7 +160,7 @@ void Window_ShopParty::Update() { void Window_ShopParty::OnCharsetSpriteReady(FileRequestResult* /* result */, int party_index) { Game_Actor *actor = Main_Data::game_party->GetActors()[party_index]; - const std::string& sprite_name = actor->GetSpriteName(); + StringView sprite_name = actor->GetSpriteName(); int sprite_id = actor->GetSpriteIndex(); BitmapRef bm = Cache::Charset(sprite_name); auto rect = Sprite_Character::GetCharacterRect(sprite_name, sprite_id, bm->GetRect()); From 155257f898216236764395f4f470c249daa2103b Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 04:55:47 -0400 Subject: [PATCH 04/21] Game_Actor::GetFaceName - use StringView --- src/game_actor.h | 4 ++-- src/scene_save.cpp | 8 ++++---- src/window_base.cpp | 6 ++---- src/window_base.h | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/game_actor.h b/src/game_actor.h index f6250ae5b2..f020e15fad 100644 --- a/src/game_actor.h +++ b/src/game_actor.h @@ -263,7 +263,7 @@ class Game_Actor final : public Game_Battler { * * @return face graphic filename. */ - const std::string& GetFaceName() const; + StringView GetFaceName() const; /** * Gets actor face graphic index. @@ -905,7 +905,7 @@ inline int Game_Actor::GetSpriteTransparency() const { return GetData().transparency; } -inline const std::string& Game_Actor::GetFaceName() const { +inline StringView Game_Actor::GetFaceName() const { return GetData().face_name; } diff --git a/src/scene_save.cpp b/src/scene_save.cpp index 05c3cb5a83..6ab8a4a5ec 100644 --- a/src/scene_save.cpp +++ b/src/scene_save.cpp @@ -92,22 +92,22 @@ void Scene_Save::Save(std::ostream& os, int slot_id, bool prepare_save) { if (size > 3) { actor = Main_Data::game_party->GetActors()[3]; title.face4_id = actor->GetFaceIndex(); - title.face4_name = actor->GetFaceName(); + title.face4_name = ToString(actor->GetFaceName()); } if (size > 2) { actor = Main_Data::game_party->GetActors()[2]; title.face3_id = actor->GetFaceIndex(); - title.face3_name = actor->GetFaceName(); + title.face3_name = ToString(actor->GetFaceName()); } if (size > 1) { actor = Main_Data::game_party->GetActors()[1]; title.face2_id = actor->GetFaceIndex(); - title.face2_name = actor->GetFaceName(); + title.face2_name = ToString(actor->GetFaceName()); } if (size > 0) { actor = Main_Data::game_party->GetActors()[0]; title.face1_id = actor->GetFaceIndex(); - title.face1_name = actor->GetFaceName(); + title.face1_name = ToString(actor->GetFaceName()); title.hero_hp = actor->GetHp(); title.hero_level = actor->GetLevel(); title.hero_name = ToString(actor->GetName()); diff --git a/src/window_base.cpp b/src/window_base.cpp index 198161c925..f25253da40 100644 --- a/src/window_base.cpp +++ b/src/window_base.cpp @@ -95,7 +95,7 @@ void Window_Base::OnFaceReady(FileRequestResult* result, int face_index, int cx, // All these functions assume that the input is valid -void Window_Base::DrawFace(const std::string& face_name, int face_index, int cx, int cy, bool flip) { +void Window_Base::DrawFace(StringView face_name, int face_index, int cx, int cy, bool flip) { if (face_name.empty()) { return; } FileRequestAsync* request = AsyncHandler::RequestFile("FaceSet", face_name); @@ -125,9 +125,7 @@ void Window_Base::DrawActorLevel(const Game_Actor& actor, int cx, int cy) const contents->TextDraw(cx, cy, 1, lcf::Data::terms.lvl_short); // Draw Level of the Actor - std::stringstream ss; - ss << actor.GetLevel(); - contents->TextDraw(cx + 24, cy, Font::ColorDefault, ss.str(), Text::AlignRight); + contents->TextDraw(cx + 24, cy, Font::ColorDefault, std::to_string(actor.GetLevel()), Text::AlignRight); } void Window_Base::DrawActorState(const Game_Battler& actor, int cx, int cy) const { diff --git a/src/window_base.h b/src/window_base.h index f553944f20..cda76b7a78 100644 --- a/src/window_base.h +++ b/src/window_base.h @@ -52,7 +52,7 @@ class Window_Base : public Window { * Draw helpers. */ /** @{ */ - void DrawFace(const std::string& face_name, int face_index, int cx, int cy, bool flip = false); + void DrawFace(StringView face_name, int face_index, int cx, int cy, bool flip = false); void DrawActorFace(const Game_Actor& actor, int cx, int cy); void DrawActorName(const Game_Battler& actor, int cx, int cy) const; void DrawActorTitle(const Game_Actor& actor, int cx, int cy) const; From 971708d0f6ddd912352999ac218fd8a16c391d6d Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 05:25:25 -0400 Subject: [PATCH 05/21] Use Skill DBString type --- src/game_actor.cpp | 2 +- src/game_battlealgorithm.cpp | 6 +++--- src/scene_actortarget.cpp | 2 +- src/window_help.cpp | 11 ++++++----- src/window_skill.cpp | 3 +-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/game_actor.cpp b/src/game_actor.cpp index 0e96b404f5..1a52bb8f27 100644 --- a/src/game_actor.cpp +++ b/src/game_actor.cpp @@ -747,7 +747,7 @@ std::string Game_Actor::GetLearningMessage(const lcf::rpg::Skill& skill) const { ); } - return skill.name + (Player::IsRPG2k3E() ? " " : "") + lcf::Data::terms.skill_learned; + return ToString(skill.name) + (Player::IsRPG2k3E() ? " " : "") + lcf::Data::terms.skill_learned; } void Game_Actor::ChangeLevel(int new_level, PendingMessage* pm) { diff --git a/src/game_battlealgorithm.cpp b/src/game_battlealgorithm.cpp index f73d0936ff..5145fc3402 100644 --- a/src/game_battlealgorithm.cpp +++ b/src/game_battlealgorithm.cpp @@ -1418,11 +1418,11 @@ std::string Game_BattleAlgorithm::Skill::GetStartMessage() const { ); } else { - return ToString(source->GetName()) + skill.using_message1; + return ToString(source->GetName()) + ToString(skill.using_message1); } } else { - return skill.name; + return ToString(skill.name); } } @@ -1444,7 +1444,7 @@ std::string Game_BattleAlgorithm::Skill::GetSecondStartMessage() const { ); } else { - return skill.using_message2; + return ToString(skill.using_message2); } } else { diff --git a/src/scene_actortarget.cpp b/src/scene_actortarget.cpp index 254d3bfa8e..1849983231 100644 --- a/src/scene_actortarget.cpp +++ b/src/scene_actortarget.cpp @@ -88,7 +88,7 @@ void Scene_ActorTarget::Start() { } status_window->SetData(id, false, actor_index); - help_window->SetText(skill->name); + help_window->SetText(ToString(skill->name)); } } diff --git a/src/window_help.cpp b/src/window_help.cpp index 743c689464..9cd7ea138a 100644 --- a/src/window_help.cpp +++ b/src/window_help.cpp @@ -33,23 +33,24 @@ void Window_Help::SetText(std::string text, Text::Alignment align) { if (this->text != text || this->align != align) { contents->Clear(); - this->text = text; - this->align = align; - int x = 0; std::string::size_type pos = 0; std::string::size_type nextpos = 0; while (nextpos != std::string::npos) { nextpos = text.find(' ', pos); - auto segment = text.substr(pos, nextpos - pos); + auto segment = ToStringView(text).substr(pos, nextpos - pos); contents->TextDraw(x, 2, Font::ColorDefault, segment, align); x += Font::Default()->GetSize(segment).width; - if (nextpos != std::string::npos) { + if (nextpos != decltype(text)::npos) { x += Font::Default()->GetSize(" ").width / 2; pos = nextpos + 1; } } + + this->text = std::move(text); + this->align = align; + } } diff --git a/src/window_skill.cpp b/src/window_skill.cpp index 445bec1dc2..3cf97c9b8d 100644 --- a/src/window_skill.cpp +++ b/src/window_skill.cpp @@ -95,8 +95,7 @@ void Window_Skill::DrawItem(int index) { } void Window_Skill::UpdateHelp() { - help_window->SetText(GetSkill() == NULL ? "" : - GetSkill()->description); + help_window->SetText(GetSkill() == nullptr ? "" : ToString(GetSkill()->description)); } bool Window_Skill::CheckInclude(int skill_id) { From 65779dfefa2e60c8b35e0723a20510f40a42eb16 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 05:46:36 -0400 Subject: [PATCH 06/21] Use item DBString type --- src/game_battlealgorithm.cpp | 4 ++-- src/scene_actortarget.cpp | 2 +- src/scene_battle_rpg2k.cpp | 5 +---- src/scene_battle_rpg2k3.cpp | 5 +---- src/string_view.h | 1 - src/window_equip.cpp | 2 +- src/window_item.cpp | 3 +-- src/window_shopbuy.cpp | 4 ++-- 8 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/game_battlealgorithm.cpp b/src/game_battlealgorithm.cpp index 5145fc3402..9002d46a57 100644 --- a/src/game_battlealgorithm.cpp +++ b/src/game_battlealgorithm.cpp @@ -1678,10 +1678,10 @@ std::string Game_BattleAlgorithm::Item::GetStartMessage() const { particle = "は"; else particle = " "; - return ToString(source->GetName()) + particle + item.name + lcf::Data::terms.use_item; + return ToString(source->GetName()) + particle + ToString(item.name) + lcf::Data::terms.use_item; } else { - return item.name; + return ToString(item.name); } } diff --git a/src/scene_actortarget.cpp b/src/scene_actortarget.cpp index 1849983231..f8608a3ec5 100644 --- a/src/scene_actortarget.cpp +++ b/src/scene_actortarget.cpp @@ -71,7 +71,7 @@ void Scene_ActorTarget::Start() { } } status_window->SetData(id, true, 0); - help_window->SetText(item->name); + help_window->SetText(ToString(item->name)); return; } else { const lcf::rpg::Skill* skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, id); diff --git a/src/scene_battle_rpg2k.cpp b/src/scene_battle_rpg2k.cpp index c34f923c88..a99063835f 100644 --- a/src/scene_battle_rpg2k.cpp +++ b/src/scene_battle_rpg2k.cpp @@ -1501,10 +1501,7 @@ void Scene_Battle_Rpg2k::PushItemRecievedMessages(PendingMessage& pm, std::vecto for (std::vector::iterator it = drops.begin(); it != drops.end(); ++it) { const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, *it); // No Output::Warning needed here, reported later when the item is added - std::string item_name = "??? BAD ITEM ???"; - if (item) { - item_name = item->name; - } + StringView item_name = item ? item->name : "??? BAD ITEM ???"; if (Player::IsRPG2kE()) { pm.PushLine( diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 2d6333cefd..ee1e98f51b 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -1330,10 +1330,7 @@ bool Scene_Battle_Rpg2k3::CheckWin() { for (std::vector::iterator it = drops.begin(); it != drops.end(); ++it) { const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, *it); // No Output::Warning needed here, reported later when the item is added - std::string item_name = "??? BAD ITEM ???"; - if (item) { - item_name = item->name; - } + StringView item_name = item ? item->name : "??? BAD ITEM ???"; ss.str(""); ss << item_name << space << lcf::Data::terms.item_recieved; diff --git a/src/string_view.h b/src/string_view.h index a790b78c43..2563f361b4 100644 --- a/src/string_view.h +++ b/src/string_view.h @@ -34,5 +34,4 @@ inline fmt::basic_string_view to_string_view(basic_string_view s) { } } } - #endif diff --git a/src/window_equip.cpp b/src/window_equip.cpp index 63e6709c53..73edbb02e2 100644 --- a/src/window_equip.cpp +++ b/src/window_equip.cpp @@ -61,5 +61,5 @@ void Window_Equip::Refresh() { void Window_Equip::UpdateHelp() { help_window->SetText(GetItemId() == 0 ? "" : - lcf::ReaderUtil::GetElement(lcf::Data::items, GetItemId())->description); + ToString(lcf::ReaderUtil::GetElement(lcf::Data::items, GetItemId())->description)); } diff --git a/src/window_item.cpp b/src/window_item.cpp index 832d8875be..67c6a87589 100644 --- a/src/window_item.cpp +++ b/src/window_item.cpp @@ -132,8 +132,7 @@ void Window_Item::DrawItem(int index) { } void Window_Item::UpdateHelp() { - help_window->SetText(GetItem() == NULL ? "" : - GetItem()->description); + help_window->SetText(GetItem() == nullptr ? "" : ToString(GetItem()->description)); } void Window_Item::SetActor(Game_Actor * actor) { diff --git a/src/window_shopbuy.cpp b/src/window_shopbuy.cpp index 15933e2b7a..9476c5c651 100644 --- a/src/window_shopbuy.cpp +++ b/src/window_shopbuy.cpp @@ -85,13 +85,13 @@ void Window_ShopBuy::UpdateHelp() { if (!data.empty()) { const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, data[index]); if (item) { - help_text = item->description; + help_text = ToString(item->description); } else { help_text = "??? BAD ITEM ???"; } } - help_window->SetText(help_text); + help_window->SetText(std::move(help_text)); } bool Window_ShopBuy::CheckEnable(int item_id) { From 483a6ac8e076613f3298e5acbf46b9b0b9349fad Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 06:25:17 -0400 Subject: [PATCH 07/21] State - use DBString --- src/game_battlealgorithm.cpp | 20 ++++++++++---------- src/game_battlealgorithm.h | 13 +++++++------ src/scene_battle_rpg2k.cpp | 4 ++-- src/scene_battle_rpg2k3.cpp | 2 +- src/string_view.h | 1 + 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/game_battlealgorithm.cpp b/src/game_battlealgorithm.cpp index 9002d46a57..49dff62e34 100644 --- a/src/game_battlealgorithm.cpp +++ b/src/game_battlealgorithm.cpp @@ -358,7 +358,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDeathMessage() const { bool is_ally = GetTarget()->GetType() == Game_Battler::Type_Ally; const lcf::rpg::State* state = lcf::ReaderUtil::GetElement(lcf::Data::states, 1); - const std::string& message = is_ally ? state->message_actor + StringView message = is_ally ? state->message_actor : state->message_enemy; if (Player::IsRPG2kE()) { @@ -369,7 +369,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDeathMessage() const { ); } else { - return ToString(GetTarget()->GetName()) + message; + return ToString(GetTarget()->GetName()) + ToString(message); } } @@ -377,7 +377,7 @@ lcf::rpg::State::Restriction Game_BattleAlgorithm::AlgorithmBase::GetSourceRestr return source_restriction; } -std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(const std::string& message) const { +std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(StringView message) const { if (Player::IsRPG2kE()) { return Utils::ReplacePlaceholders( message, @@ -386,11 +386,11 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetAttackFailureMessage(const s ); } else { - return ToString(GetTarget()->GetName()) + message; + return ToString(GetTarget()->GetName()) + ToString(message); } } -std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpRecoveredMessage(int value, const std::string& points) const { +std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpRecoveredMessage(int value, StringView points) const { if (Player::IsRPG2kE()) { return Utils::ReplacePlaceholders( lcf::Data::terms.hp_recovery, @@ -455,7 +455,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetCriticalHitMessage() const { } } -std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int value, const std::string& points) const { +std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int value, StringView points) const { bool target_is_ally = (GetTarget()->GetType() == Game_Battler::Type_Ally); const std::string& message = target_is_ally ? @@ -520,7 +520,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDamagedMessage() const { } } -std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool is_positive, int value, const std::string& points) const { +std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool is_positive, int value, StringView points) const { const std::string& message = is_positive ? lcf::Data::terms.parameter_increase : lcf::Data::terms.parameter_decrease; @@ -552,7 +552,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool } } -std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(const std::string& message) const { +std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(StringView message) const { if (Player::IsRPG2kE()) { return Utils::ReplacePlaceholders( message, @@ -561,11 +561,11 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(const std::stri ); } else { - return ToString(GetTarget()->GetName()) + message; + return ToString(GetTarget()->GetName()) + ToString(message); } } -std::string Game_BattleAlgorithm::AlgorithmBase::GetAttributeShiftMessage( const std::string& attribute) const { +std::string Game_BattleAlgorithm::AlgorithmBase::GetAttributeShiftMessage(StringView attribute) const { const std::string& message = IsPositive() ? lcf::Data::terms.resistance_increase : lcf::Data::terms.resistance_decrease; diff --git a/src/game_battlealgorithm.h b/src/game_battlealgorithm.h index 3155f3a5f9..df1b084763 100644 --- a/src/game_battlealgorithm.h +++ b/src/game_battlealgorithm.h @@ -22,6 +22,7 @@ #include #include #include +#include "string_view.h" class Game_Battler; class Game_Party_Base; @@ -423,19 +424,19 @@ class AlgorithmBase { std::string GetCriticalHitMessage() const; std::string GetUndamagedMessage() const; - std::string GetHpSpAbsorbedMessage(int value, const std::string& points) const; + std::string GetHpSpAbsorbedMessage(int value, StringView points) const; std::string GetDamagedMessage() const; - std::string GetHpSpRecoveredMessage(int value, const std::string& points) const; - std::string GetParameterChangeMessage(bool is_positive, int value, const std::string& points) const; - std::string GetStateMessage(const std::string& message) const; - std::string GetAttributeShiftMessage(const std::string& attribute) const; + std::string GetHpSpRecoveredMessage(int value, StringView points) const; + std::string GetParameterChangeMessage(bool is_positive, int value, StringView points) const; + std::string GetStateMessage(StringView message) const; + std::string GetAttributeShiftMessage(StringView attribute) const; protected: AlgorithmBase(Type t, Game_Battler* source); AlgorithmBase(Type t, Game_Battler* source, Game_Battler* target); AlgorithmBase(Type t, Game_Battler* source, Game_Party_Base* target); - std::string GetAttackFailureMessage(const std::string& points) const; + std::string GetAttackFailureMessage(StringView points) const; void ApplyActionSwitches(); diff --git a/src/scene_battle_rpg2k.cpp b/src/scene_battle_rpg2k.cpp index a99063835f..d682ac9c3d 100644 --- a/src/scene_battle_rpg2k.cpp +++ b/src/scene_battle_rpg2k.cpp @@ -495,7 +495,7 @@ bool Scene_Battle_Rpg2k::ProcessActionBegin(Game_BattleAlgorithm::AlgorithmBase* } if (pri_state != nullptr) { - const auto& msg = pri_was_healed + StringView msg = pri_was_healed ? pri_state->message_recovery : pri_state->message_affected; @@ -504,7 +504,7 @@ bool Scene_Battle_Rpg2k::ProcessActionBegin(Game_BattleAlgorithm::AlgorithmBase* // If state is inflicted, only prints if msg not empty. if (pri_was_healed || !msg.empty()) { show_message = true; - pending_message = msg; + pending_message = ToString(msg); } } diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index ee1e98f51b..da0a5a355a 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -440,7 +440,7 @@ void Scene_Battle_Rpg2k3::UpdateCursors() { for (auto state_id : states) { // States are sanitized in Game_Battler const lcf::rpg::State* state = lcf::ReaderUtil::GetElement(lcf::Data::states, state_id); - std::string name = state->name; + auto name = ToString(state->name); int color = state->color; FontRef font = Font::Default(); contents->TextDraw(text_width, 2, color, name, Text::AlignLeft); diff --git a/src/string_view.h b/src/string_view.h index 2563f361b4..1cd1241444 100644 --- a/src/string_view.h +++ b/src/string_view.h @@ -19,6 +19,7 @@ #define EP_STRING_VIEW_H #include +#include #include using StringView = lcf::StringView; From 57d0108e9bb4b4c319b7369fbc3c257b06dc3098 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 06:46:18 -0400 Subject: [PATCH 08/21] Terms: Use DBString --- src/game_actor.cpp | 2 +- src/game_battlealgorithm.cpp | 32 ++++++++++++++++---------------- src/scene_battle.cpp | 6 +++--- src/scene_battle_rpg2k.cpp | 12 ++++++------ src/scene_battle_rpg2k3.cpp | 12 ++++++------ src/scene_battle_rpg2k3.h | 4 ++-- src/scene_end.cpp | 6 +++--- src/scene_load.cpp | 2 +- src/scene_menu.cpp | 18 +++++++++--------- src/scene_save.cpp | 2 +- src/scene_title.cpp | 6 +++--- src/window_base.cpp | 8 +++----- src/window_battlecommand.cpp | 8 ++++---- src/window_equipstatus.cpp | 2 +- src/window_paramstatus.cpp | 2 +- src/window_savefile.cpp | 4 ++-- src/window_shop.h | 22 +++++++++++----------- 17 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/game_actor.cpp b/src/game_actor.cpp index 1a52bb8f27..84f85f5078 100644 --- a/src/game_actor.cpp +++ b/src/game_actor.cpp @@ -747,7 +747,7 @@ std::string Game_Actor::GetLearningMessage(const lcf::rpg::Skill& skill) const { ); } - return ToString(skill.name) + (Player::IsRPG2k3E() ? " " : "") + lcf::Data::terms.skill_learned; + return ToString(skill.name) + (Player::IsRPG2k3E() ? " " : "") + ToString(lcf::Data::terms.skill_learned); } void Game_Actor::ChangeLevel(int new_level, PendingMessage* pm) { diff --git a/src/game_battlealgorithm.cpp b/src/game_battlealgorithm.cpp index 49dff62e34..32894bf1e3 100644 --- a/src/game_battlealgorithm.cpp +++ b/src/game_battlealgorithm.cpp @@ -420,7 +420,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpRecoveredMessage(int val std::string Game_BattleAlgorithm::AlgorithmBase::GetUndamagedMessage() const { bool target_is_ally = (GetTarget()->GetType() == Game_Battler::Type_Ally); - const std::string& message = target_is_ally ? + StringView message = target_is_ally ? lcf::Data::terms.actor_undamaged : lcf::Data::terms.enemy_undamaged; @@ -432,14 +432,14 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetUndamagedMessage() const { ); } else { - return ToString(GetTarget()->GetName()) + message; + return ToString(GetTarget()->GetName()) + ToString(message); } } std::string Game_BattleAlgorithm::AlgorithmBase::GetCriticalHitMessage() const { bool target_is_ally = (GetTarget()->GetType() == Game_Battler::Type_Ally); - const std::string& message = target_is_ally ? + StringView message = target_is_ally ? lcf::Data::terms.actor_critical : lcf::Data::terms.enemy_critical; @@ -451,14 +451,14 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetCriticalHitMessage() const { ); } else { - return message; + return ToString(message); } } std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int value, StringView points) const { bool target_is_ally = (GetTarget()->GetType() == Game_Battler::Type_Ally); - const std::string& message = target_is_ally ? + StringView message = target_is_ally ? lcf::Data::terms.actor_hp_absorbed : lcf::Data::terms.enemy_hp_absorbed; @@ -492,7 +492,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetHpSpAbsorbedMessage(int valu std::string Game_BattleAlgorithm::AlgorithmBase::GetDamagedMessage() const { bool target_is_ally = (GetTarget()->GetType() == Game_Battler::Type_Ally); - const std::string& message = target_is_ally ? + StringView message = target_is_ally ? lcf::Data::terms.actor_damaged : lcf::Data::terms.enemy_damaged; int value = GetAffectedHp(); @@ -521,7 +521,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetDamagedMessage() const { } std::string Game_BattleAlgorithm::AlgorithmBase::GetParameterChangeMessage(bool is_positive, int value, StringView points) const { - const std::string& message = is_positive ? + StringView message = is_positive ? lcf::Data::terms.parameter_increase : lcf::Data::terms.parameter_decrease; @@ -566,7 +566,7 @@ std::string Game_BattleAlgorithm::AlgorithmBase::GetStateMessage(StringView mess } std::string Game_BattleAlgorithm::AlgorithmBase::GetAttributeShiftMessage(StringView attribute) const { - const std::string& message = IsPositive() ? + StringView message = IsPositive() ? lcf::Data::terms.resistance_increase : lcf::Data::terms.resistance_decrease; std::stringstream ss; @@ -1110,7 +1110,7 @@ std::string Game_BattleAlgorithm::Normal::GetStartMessage() const { ); } else { - return ToString(source->GetName()) + lcf::Data::terms.attacking; + return ToString(source->GetName()) + ToString(lcf::Data::terms.attacking); } } else { @@ -1678,7 +1678,7 @@ std::string Game_BattleAlgorithm::Item::GetStartMessage() const { particle = "は"; else particle = " "; - return ToString(source->GetName()) + particle + ToString(item.name) + lcf::Data::terms.use_item; + return ToString(source->GetName()) + particle + ToString(item.name) + ToString(lcf::Data::terms.use_item); } else { return ToString(item.name); @@ -1716,7 +1716,7 @@ std::string Game_BattleAlgorithm::Defend::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return ToString(source->GetName()) + lcf::Data::terms.defending; + return ToString(source->GetName()) + ToString(lcf::Data::terms.defending); } else { return ""; @@ -1750,7 +1750,7 @@ std::string Game_BattleAlgorithm::Observe::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return ToString(source->GetName()) + lcf::Data::terms.observing; + return ToString(source->GetName()) + ToString(lcf::Data::terms.observing); } else { return ""; @@ -1777,7 +1777,7 @@ std::string Game_BattleAlgorithm::Charge::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return ToString(source->GetName()) + lcf::Data::terms.focus; + return ToString(source->GetName()) + ToString(lcf::Data::terms.focus); } else { return ""; @@ -1808,7 +1808,7 @@ std::string Game_BattleAlgorithm::SelfDestruct::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return ToString(source->GetName()) + lcf::Data::terms.autodestruction; + return ToString(source->GetName()) + ToString(lcf::Data::terms.autodestruction); } else { return ""; @@ -1888,7 +1888,7 @@ std::string Game_BattleAlgorithm::Escape::GetStartMessage() const { } else if (Player::IsRPG2k()) { if (source->GetType() == Game_Battler::Type_Enemy) { - return ToString(source->GetName()) + lcf::Data::terms.enemy_escape; + return ToString(source->GetName()) + ToString(lcf::Data::terms.enemy_escape); } } @@ -1940,7 +1940,7 @@ std::string Game_BattleAlgorithm::Transform::GetStartMessage() const { ); } else if (Player::IsRPG2k()) { - return ToString(source->GetName()) + lcf::Data::terms.enemy_transform; + return ToString(source->GetName()) + ToString(lcf::Data::terms.enemy_transform); } else { return ""; diff --git a/src/scene_battle.cpp b/src/scene_battle.cpp index 4a9bc15b9c..57f6a07943 100644 --- a/src/scene_battle.cpp +++ b/src/scene_battle.cpp @@ -160,9 +160,9 @@ void Scene_Battle::DrawBackground(Bitmap& dst) { void Scene_Battle::CreateUi() { std::vector commands; - commands.push_back(lcf::Data::terms.battle_fight); - commands.push_back(lcf::Data::terms.battle_auto); - commands.push_back(lcf::Data::terms.battle_escape); + commands.push_back(ToString(lcf::Data::terms.battle_fight)); + commands.push_back(ToString(lcf::Data::terms.battle_auto)); + commands.push_back(ToString(lcf::Data::terms.battle_escape)); options_window.reset(new Window_Command(commands, option_command_mov)); options_window->SetHeight(80); options_window->SetY(SCREEN_TARGET_HEIGHT - 80); diff --git a/src/scene_battle_rpg2k.cpp b/src/scene_battle_rpg2k.cpp index d682ac9c3d..48fa1651cb 100644 --- a/src/scene_battle_rpg2k.cpp +++ b/src/scene_battle_rpg2k.cpp @@ -88,10 +88,10 @@ void Scene_Battle_Rpg2k::CreateBattleTargetWindow() { void Scene_Battle_Rpg2k::CreateBattleCommandWindow() { std::vector commands; - commands.push_back(lcf::Data::terms.command_attack); - commands.push_back(lcf::Data::terms.command_skill); - commands.push_back(lcf::Data::terms.command_defend); - commands.push_back(lcf::Data::terms.command_item); + commands.push_back(ToString(lcf::Data::terms.command_attack)); + commands.push_back(ToString(lcf::Data::terms.command_skill)); + commands.push_back(ToString(lcf::Data::terms.command_defend)); + commands.push_back(ToString(lcf::Data::terms.command_item)); command_window.reset(new Window_Command(commands, 76)); command_window->SetHeight(80); @@ -1533,7 +1533,7 @@ bool Scene_Battle_Rpg2k::CheckWin() { pm.SetEnableFace(false); pm.SetWordWrapped(Player::IsRPG2kE()); - pm.PushLine(lcf::Data::terms.victory + Player::escape_symbol + "|"); + pm.PushLine(ToString(lcf::Data::terms.victory) + Player::escape_symbol + "|"); std::stringstream ss; if (exp > 0) { @@ -1582,7 +1582,7 @@ bool Scene_Battle_Rpg2k::CheckLose() { pm.SetWordWrapped(Player::IsRPG2kE()); - pm.PushLine(lcf::Data::terms.defeat); + pm.PushLine(ToString(lcf::Data::terms.defeat)); Game_System::BgmPlay(Game_System::GetSystemBGM(Game_System::BGM_GameOver)); diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index da0a5a355a..172398959b 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -458,7 +458,7 @@ void Scene_Battle_Rpg2k3::UpdateCursors() { } } -void Scene_Battle_Rpg2k3::DrawFloatText(int x, int y, int color, const std::string& text) { +void Scene_Battle_Rpg2k3::DrawFloatText(int x, int y, int color, StringView text) { Rect rect = Font::Default()->GetSize(text); BitmapRef graphic = Bitmap::Create(rect.width, rect.height); @@ -1286,7 +1286,7 @@ void Scene_Battle_Rpg2k3::Escape(bool force_allow) { } SetState(State_SelectActor); - ShowNotification(lcf::Data::terms.escape_failure); + ShowNotification(ToString(lcf::Data::terms.escape_failure)); } bool Scene_Battle_Rpg2k3::CheckWin() { @@ -1310,7 +1310,7 @@ bool Scene_Battle_Rpg2k3::CheckWin() { auto pm = PendingMessage(); pm.SetEnableFace(false); - pm.PushLine(lcf::Data::terms.victory + Player::escape_symbol + "|"); + pm.PushLine(ToString(lcf::Data::terms.victory) + Player::escape_symbol + "|"); pm.PushPageEnd(); std::string space = Player::IsRPG2k3E() ? " " : ""; @@ -1377,7 +1377,7 @@ bool Scene_Battle_Rpg2k3::CheckLose() { auto pm = PendingMessage(); pm.SetEnableFace(false); - pm.PushLine(lcf::Data::terms.defeat); + pm.PushLine(ToString(lcf::Data::terms.defeat)); Game_System::BgmPlay(Game_System::GetSystemBGM(Game_System::BGM_GameOver)); Game_Message::SetPendingMessage(std::move(pm)); @@ -1475,12 +1475,12 @@ void Scene_Battle_Rpg2k3::ActionSelectedCallback(Game_Battler* for_battler) { first_strike = false; } -void Scene_Battle_Rpg2k3::ShowNotification(const std::string& text) { +void Scene_Battle_Rpg2k3::ShowNotification(std::string text) { if (text.empty()) { return; } help_window->SetVisible(true); message_timer = 60; - help_window->SetText(text); + help_window->SetText(std::move(text)); } diff --git a/src/scene_battle_rpg2k3.h b/src/scene_battle_rpg2k3.h index 9dd5ec45a0..310ca5002a 100644 --- a/src/scene_battle_rpg2k3.h +++ b/src/scene_battle_rpg2k3.h @@ -93,7 +93,7 @@ class Scene_Battle_Rpg2k3 : public Scene_Battle { void CreateBattleCommandWindow(); void UpdateCursors() override; - void DrawFloatText(int x, int y, int color, const std::string& text); + void DrawFloatText(int x, int y, int color, StringView text); void RefreshCommandWindow(); @@ -120,7 +120,7 @@ class Scene_Battle_Rpg2k3 : public Scene_Battle { void ActionSelectedCallback(Game_Battler* for_battler) override; - void ShowNotification(const std::string& text); + void ShowNotification(std::string text); bool IsEscapeAllowed() const = delete; // disable accidental calls to base class version bool IsEscapeAllowedFromOptionWindow() const; diff --git a/src/scene_end.cpp b/src/scene_end.cpp index 39e1620874..7a867ffc71 100644 --- a/src/scene_end.cpp +++ b/src/scene_end.cpp @@ -60,8 +60,8 @@ void Scene_End::Update() { void Scene_End::CreateCommandWindow() { // Create Options Window std::vector options; - options.push_back(lcf::Data::terms.yes); - options.push_back(lcf::Data::terms.no); + options.push_back(ToString(lcf::Data::terms.yes)); + options.push_back(ToString(lcf::Data::terms.no)); command_window.reset(new Window_Command(options)); command_window->SetX((SCREEN_TARGET_WIDTH/2) - command_window->GetWidth() / 2); @@ -74,7 +74,7 @@ void Scene_End::CreateHelpWindow() { help_window.reset(new Window_Help((SCREEN_TARGET_WIDTH/2) - (text_size + 16)/ 2, 72, text_size + 16, 32)); - help_window->SetText(lcf::Data::terms.exit_game_message); + help_window->SetText(ToString(lcf::Data::terms.exit_game_message)); command_window->SetHelpWindow(help_window.get()); } diff --git a/src/scene_load.cpp b/src/scene_load.cpp index 8933ab3737..d6f855935d 100644 --- a/src/scene_load.cpp +++ b/src/scene_load.cpp @@ -25,7 +25,7 @@ #include "scene_map.h" Scene_Load::Scene_Load() : - Scene_File(lcf::Data::terms.load_game_message) { + Scene_File(ToString(lcf::Data::terms.load_game_message)) { Scene::type = Scene::Load; } diff --git a/src/scene_menu.cpp b/src/scene_menu.cpp index a52ba6af04..61606c3773 100644 --- a/src/scene_menu.cpp +++ b/src/scene_menu.cpp @@ -96,34 +96,34 @@ void Scene_Menu::CreateCommandWindow() { for (it = command_options.begin(); it != command_options.end(); ++it) { switch(*it) { case Item: - options.push_back(lcf::Data::terms.command_item); + options.push_back(ToString(lcf::Data::terms.command_item)); break; case Skill: - options.push_back(lcf::Data::terms.command_skill); + options.push_back(ToString(lcf::Data::terms.command_skill)); break; case Equipment: - options.push_back(lcf::Data::terms.menu_equipment); + options.push_back(ToString(lcf::Data::terms.menu_equipment)); break; case Save: - options.push_back(lcf::Data::terms.menu_save); + options.push_back(ToString(lcf::Data::terms.menu_save)); break; case Status: - options.push_back(lcf::Data::terms.status); + options.push_back(ToString(lcf::Data::terms.status)); break; case Row: - options.push_back(lcf::Data::terms.row); + options.push_back(ToString(lcf::Data::terms.row)); break; case Order: - options.push_back(lcf::Data::terms.order); + options.push_back(ToString(lcf::Data::terms.order)); break; case Wait: - options.push_back(Game_System::GetAtbMode() == lcf::rpg::SaveSystem::AtbMode_atb_wait ? lcf::Data::terms.wait_on : lcf::Data::terms.wait_off); + options.push_back(ToString(Game_System::GetAtbMode() == lcf::rpg::SaveSystem::AtbMode_atb_wait ? lcf::Data::terms.wait_on : lcf::Data::terms.wait_off)); break; case Debug: options.push_back("Debug"); break; default: - options.push_back(lcf::Data::terms.menu_quit); + options.push_back(ToString(lcf::Data::terms.menu_quit)); break; } } diff --git a/src/scene_save.cpp b/src/scene_save.cpp index 6ab8a4a5ec..8019a747f9 100644 --- a/src/scene_save.cpp +++ b/src/scene_save.cpp @@ -43,7 +43,7 @@ #include "version.h" Scene_Save::Scene_Save() : - Scene_File(lcf::Data::terms.save_game_message) { + Scene_File(ToString(lcf::Data::terms.save_game_message)) { Scene::type = Scene::Save; } diff --git a/src/scene_title.cpp b/src/scene_title.cpp index 1efde3c1e7..c006049b5d 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -142,8 +142,8 @@ void Scene_Title::CreateTitleGraphic() { void Scene_Title::CreateCommandWindow() { // Create Options Window std::vector options; - options.push_back(lcf::Data::terms.new_game); - options.push_back(lcf::Data::terms.load_game); + options.push_back(ToString(lcf::Data::terms.new_game)); + options.push_back(ToString(lcf::Data::terms.load_game)); // Set "Import" based on metadata if (Player::meta->IsImportEnabled()) { @@ -152,7 +152,7 @@ void Scene_Title::CreateCommandWindow() { exit_index = 3; } - options.push_back(lcf::Data::terms.exit_game); + options.push_back(ToString(lcf::Data::terms.exit_game)); command_window.reset(new Window_Command(options)); if (!Player::hide_title_flag) { diff --git a/src/window_base.cpp b/src/window_base.cpp index f25253da40..893305ed3a 100644 --- a/src/window_base.cpp +++ b/src/window_base.cpp @@ -214,7 +214,7 @@ void Window_Base::DrawActorSp(const Game_Battler& actor, int cx, int cy, int dig } void Window_Base::DrawActorParameter(const Game_Battler& actor, int cx, int cy, int type) const { - std::string name; + StringView name; int value; switch (type) { @@ -242,13 +242,11 @@ void Window_Base::DrawActorParameter(const Game_Battler& actor, int cx, int cy, contents->TextDraw(cx, cy, 1, name); // Draw Value - std::stringstream ss; - ss << value; - contents->TextDraw(cx + 78, cy, Font::ColorDefault, ss.str(), Text::AlignRight); + contents->TextDraw(cx + 78, cy, Font::ColorDefault, std::to_string(value), Text::AlignRight); } void Window_Base::DrawEquipmentType(const Game_Actor& actor, int cx, int cy, int type) const { - std::string name; + StringView name; switch (type) { case 0: diff --git a/src/window_battlecommand.cpp b/src/window_battlecommand.cpp index d8f0a4e4ae..44930c391a 100644 --- a/src/window_battlecommand.cpp +++ b/src/window_battlecommand.cpp @@ -137,10 +137,10 @@ void Window_BattleCommand::SetActor(int _actor_id) { commands.clear(); if (actor_id == 0) { - commands.push_back(!lcf::Data::terms.command_attack.empty() ? lcf::Data::terms.command_attack : "Attack"); - commands.push_back(!lcf::Data::terms.command_defend.empty() ? lcf::Data::terms.command_defend : "Defend"); - commands.push_back(!lcf::Data::terms.command_item.empty() ? lcf::Data::terms.command_item : "Item"); - commands.push_back(!lcf::Data::terms.command_skill.empty() ? lcf::Data::terms.command_skill : "Skill"); + commands.push_back(!lcf::Data::terms.command_attack.empty() ? ToString(lcf::Data::terms.command_attack) : "Attack"); + commands.push_back(!lcf::Data::terms.command_defend.empty() ? ToString(lcf::Data::terms.command_defend) : "Defend"); + commands.push_back(!lcf::Data::terms.command_item.empty() ? ToString(lcf::Data::terms.command_item) : "Item"); + commands.push_back(!lcf::Data::terms.command_skill.empty() ? ToString(lcf::Data::terms.command_skill) : "Skill"); } else { Game_Actor* actor = Game_Actors::GetActor(actor_id); diff --git a/src/window_equipstatus.cpp b/src/window_equipstatus.cpp index fd67c2d53b..ee62834d03 100644 --- a/src/window_equipstatus.cpp +++ b/src/window_equipstatus.cpp @@ -84,7 +84,7 @@ int Window_EquipStatus::GetNewParameterColor(int old_value, int new_value) { } void Window_EquipStatus::DrawParameter(int cx, int cy, int type) { - std::string name; + StringView name; int value; int new_value; diff --git a/src/window_paramstatus.cpp b/src/window_paramstatus.cpp index 8b31ecf73b..7b83b2185d 100644 --- a/src/window_paramstatus.cpp +++ b/src/window_paramstatus.cpp @@ -38,7 +38,7 @@ void Window_ParamStatus::Refresh() { auto* actor = Game_Actors::GetActor(actor_id); - auto draw = [this](int y, const std::string& name, int value) { + auto draw = [this](int y, StringView name, int value) { // Draw Term contents->TextDraw(0, y, 1, name); diff --git a/src/window_savefile.cpp b/src/window_savefile.cpp index 0755a9aa4f..35530243d8 100644 --- a/src/window_savefile.cpp +++ b/src/window_savefile.cpp @@ -110,7 +110,7 @@ void Window_SaveFile::Refresh() { contents->TextDraw(4, 16 + 2, fc, data.hero_name); } - auto lvl_short = lcf::Data::terms.lvl_short; + auto lvl_short = ToString(lcf::Data::terms.lvl_short); if (lvl_short.size() != 2) { lvl_short.resize(2, ' '); } @@ -122,7 +122,7 @@ void Window_SaveFile::Refresh() { out << std::setw(2) << std::setfill(' ') << data.hero_level; contents->TextDraw(4 + lx, 32 + 2, fc, out.str()); - auto hp_short = lcf::Data::terms.hp_short; + auto hp_short = ToString(lcf::Data::terms.hp_short); if (hp_short.size() != 2) { hp_short.resize(2, ' '); } diff --git a/src/window_shop.h b/src/window_shop.h index d44d7b168f..742f05786e 100644 --- a/src/window_shop.h +++ b/src/window_shop.h @@ -56,17 +56,17 @@ class Window_Shop : public Window_Base { protected: void UpdateCursorRect(); - std::string greeting; - std::string regreeting; - std::string buy_msg; - std::string sell_msg; - std::string leave_msg; - std::string buy_select; - std::string buy_number; - std::string purchased; - std::string sell_select; - std::string sell_number; - std::string sold_msg; + StringView greeting; + StringView regreeting; + StringView buy_msg; + StringView sell_msg; + StringView leave_msg; + StringView buy_select; + StringView buy_number; + StringView purchased; + StringView sell_select; + StringView sell_number; + StringView sold_msg; int index; int mode; int buy_index; From dccd299280306805f001f05ae4d0152fd3844ae3 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 06:48:12 -0400 Subject: [PATCH 09/21] Animation - use DBString --- src/battle_animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_animation.cpp b/src/battle_animation.cpp index 794d4fdb9a..645fc01a79 100644 --- a/src/battle_animation.cpp +++ b/src/battle_animation.cpp @@ -42,7 +42,7 @@ BattleAnimation::BattleAnimation(const lcf::rpg::Animation& anim, bool only_soun SetZ(Priority_BattleAnimation); - const std::string& name = animation.animation_name; + StringView name = animation.animation_name; BitmapRef graphic; if (name.empty()) return; From a828c9ca5abd7ba72b272745bb550baf0fd0f4f4 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 07:06:50 -0400 Subject: [PATCH 10/21] System - use StringView --- src/game_system.cpp | 6 +++--- src/game_system.h | 5 +++-- src/game_vehicle.cpp | 11 +++++------ src/game_vehicle.h | 2 +- src/scene_title.cpp | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/game_system.cpp b/src/game_system.cpp index 015f9f1924..7176ed7ca7 100644 --- a/src/game_system.cpp +++ b/src/game_system.cpp @@ -192,9 +192,9 @@ void Game_System::SePlay(const lcf::rpg::Animation &animation) { } } -const std::string& Game_System::GetSystemName() { +StringView Game_System::GetSystemName() { return !data.graphics_name.empty() ? - data.graphics_name : lcf::Data::system.system_name; + StringView(data.graphics_name) : StringView(lcf::Data::system.system_name); } static void OnChangeSystemGraphicReady(FileRequestResult* result) { @@ -240,7 +240,7 @@ void Game_System::ResetSystemGraphic() { ReloadSystemGraphic(); } -const std::string& Game_System::GetSystem2Name() { +StringView Game_System::GetSystem2Name() { return lcf::Data::system.system2_name; } diff --git a/src/game_system.h b/src/game_system.h index e8e0c7940d..44fd3bb212 100644 --- a/src/game_system.h +++ b/src/game_system.h @@ -27,6 +27,7 @@ #include #include "color.h" #include "transition.h" +#include "string_view.h" struct FileRequestResult; @@ -135,7 +136,7 @@ namespace Game_System { void SePlay(const lcf::rpg::Animation& animation); /** @return system graphic filename. */ - const std::string& GetSystemName(); + StringView GetSystemName(); /** @return message stretch style */ lcf::rpg::System::Stretch GetMessageStretch(); @@ -158,7 +159,7 @@ namespace Game_System { void ResetSystemGraphic(); /** @return the system2 graphic name */ - const std::string& GetSystem2Name(); + StringView GetSystem2Name(); /** @return true if the game has a configured system graphic */ bool HasSystemGraphic(); diff --git a/src/game_vehicle.cpp b/src/game_vehicle.cpp index 9f182f2424..2da862961b 100644 --- a/src/game_vehicle.cpp +++ b/src/game_vehicle.cpp @@ -47,19 +47,19 @@ void Game_Vehicle::LoadSystemSettings() { case None: break; case Boat: - SetSpriteGraphic(lcf::Data::system.boat_name, lcf::Data::system.boat_index); + SetSpriteGraphic(ToString(lcf::Data::system.boat_name), lcf::Data::system.boat_index); SetMapId(lcf::Data::treemap.start.boat_map_id); SetX(lcf::Data::treemap.start.boat_x); SetY(lcf::Data::treemap.start.boat_y); break; case Ship: - SetSpriteGraphic(lcf::Data::system.ship_name, lcf::Data::system.ship_index); + SetSpriteGraphic(ToString(lcf::Data::system.ship_name), lcf::Data::system.ship_index); SetMapId(lcf::Data::treemap.start.ship_map_id); SetX(lcf::Data::treemap.start.ship_x); SetY(lcf::Data::treemap.start.ship_y); break; case Airship: - SetSpriteGraphic(lcf::Data::system.airship_name, lcf::Data::system.airship_index); + SetSpriteGraphic(ToString(lcf::Data::system.airship_name), lcf::Data::system.airship_index); SetMapId(lcf::Data::treemap.start.airship_map_id); SetX(lcf::Data::treemap.start.airship_x); SetY(lcf::Data::treemap.start.airship_y); @@ -265,7 +265,7 @@ int Game_Vehicle::GetVehicleType() const { return data()->vehicle; } -const std::string& Game_Vehicle::GetOrigSpriteName() const { +StringView Game_Vehicle::GetOrigSpriteName() const { if (!data()->orig_sprite_name.empty()) { return data()->orig_sprite_name; } @@ -279,8 +279,7 @@ const std::string& Game_Vehicle::GetOrigSpriteName() const { default: break; } - static const std::string _sentinel = {}; - return _sentinel; + return {}; } int Game_Vehicle::GetOrigSpriteIndex() const { diff --git a/src/game_vehicle.h b/src/game_vehicle.h index 07bc75b45e..5bf6822679 100644 --- a/src/game_vehicle.h +++ b/src/game_vehicle.h @@ -81,7 +81,7 @@ class Game_Vehicle : public Game_Character { void SetOrigSpriteGraphic(std::string sprite_name, int index); /** Gets the original sprite graphic name */ - const std::string& GetOrigSpriteName() const; + StringView GetOrigSpriteName() const; /** Gets the original sprite graphic index */ int GetOrigSpriteIndex() const; diff --git a/src/scene_title.cpp b/src/scene_title.cpp index c006049b5d..201ecdb118 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -205,7 +205,7 @@ void Scene_Title::PrepareBattleTest() { args.troop_id = Game_Battle::battle_test.troop_id; args.first_strike = false; args.allow_escape = true; - args.background = lcf::Data::system.battletest_background; + args.background = ToString(lcf::Data::system.battletest_background); args.terrain_id = 1; //Not used in 2k, for 2k3 only used to determine grid layout if formation == terrain. if (Player::IsRPG2k3()) { From ee1b0444b434fe56bab6b4451d4e9004b53a1dfb Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 07:11:08 -0400 Subject: [PATCH 11/21] Switch, Var, CommonEvent use DBString --- src/game_commonevent.cpp | 2 +- src/game_commonevent.h | 3 ++- src/game_switches.cpp | 4 ++-- src/game_switches.h | 3 ++- src/game_variables.cpp | 4 ++-- src/game_variables.h | 3 ++- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/game_commonevent.cpp b/src/game_commonevent.cpp index 4a0e7588b0..98a1d0b936 100644 --- a/src/game_commonevent.cpp +++ b/src/game_commonevent.cpp @@ -69,7 +69,7 @@ int Game_CommonEvent::GetIndex() const { // Game_Map ensures validity of Common Events -std::string Game_CommonEvent::GetName() const { +StringView Game_CommonEvent::GetName() const { return lcf::ReaderUtil::GetElement(lcf::Data::commonevents, common_event_id)->name; } diff --git a/src/game_commonevent.h b/src/game_commonevent.h index fcc4ecf5d0..4bdceb86cc 100644 --- a/src/game_commonevent.h +++ b/src/game_commonevent.h @@ -25,6 +25,7 @@ #include #include #include "async_op.h" +#include "string_view.h" /** * Game_CommonEvent class. @@ -65,7 +66,7 @@ class Game_CommonEvent { * * @return event name. */ - std::string GetName() const; + StringView GetName() const; /** * Gets trigger condition. diff --git a/src/game_switches.cpp b/src/game_switches.cpp index c33fc9b056..711af755c5 100644 --- a/src/game_switches.cpp +++ b/src/game_switches.cpp @@ -87,12 +87,12 @@ void Game_Switches::FlipRange(int first_id, int last_id) { } } -std::string Game_Switches::GetName(int _id) const { +StringView Game_Switches::GetName(int _id) const { const auto* sw = lcf::ReaderUtil::GetElement(lcf::Data::switches, _id); if (!sw) { // No warning, is valid because the switch array resizes dynamic during runtime - return ""; + return {}; } else { return sw->name; } diff --git a/src/game_switches.h b/src/game_switches.h index 4d1435a40f..f325e03d2b 100644 --- a/src/game_switches.h +++ b/src/game_switches.h @@ -23,6 +23,7 @@ #include #include #include "compiler.h" +#include "string_view.h" /** * Game_Switches class @@ -45,7 +46,7 @@ class Game_Switches { bool Flip(int switch_id); void FlipRange(int first_id, int last_id); - std::string GetName(int switch_id) const; + StringView GetName(int switch_id) const; bool IsValid(int switch_id) const; diff --git a/src/game_variables.cpp b/src/game_variables.cpp index a839ffa644..ce8f0d3e9f 100644 --- a/src/game_variables.cpp +++ b/src/game_variables.cpp @@ -258,12 +258,12 @@ void Game_Variables::ModRangeRandom(int first_id, int last_id, Var_t minval, Var WriteRange(first_id, last_id, [this,minval,maxval](){ return Utils::GetRandomNumber(minval, maxval); }, VarMod); } -std::string Game_Variables::GetName(int _id) const { +StringView Game_Variables::GetName(int _id) const { const auto* var = lcf::ReaderUtil::GetElement(lcf::Data::variables, _id); if (!var) { // No warning, is valid because the variable array resizes dynamic during runtime - return ""; + return {}; } else { return var->name; } diff --git a/src/game_variables.h b/src/game_variables.h index 4c1eabc346..1f0a7fd600 100644 --- a/src/game_variables.h +++ b/src/game_variables.h @@ -21,6 +21,7 @@ // Headers #include #include "compiler.h" +#include "string_view.h" #include /** @@ -79,7 +80,7 @@ class Game_Variables { void DivRangeRandom(int first_id, int last_id, Var_t minval, Var_t maxval); void ModRangeRandom(int first_id, int last_id, Var_t minval, Var_t maxval); - std::string GetName(int _id) const; + StringView GetName(int _id) const; int GetSize() const; From acef802cc9d23419430f4cdccdcb8c0449b0d97a Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 07:17:47 -0400 Subject: [PATCH 12/21] Class, BattlerAnim, BattleCommand use DBString --- src/game_actor.cpp | 4 ++-- src/game_actor.h | 2 +- src/scene_battle_rpg2k3.cpp | 2 +- src/sprite_battler.cpp | 2 +- src/sprite_battler.h | 1 - src/window_battlecommand.cpp | 22 +--------------------- src/window_battlecommand.h | 1 - 7 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/game_actor.cpp b/src/game_actor.cpp index 84f85f5078..fbf871a419 100644 --- a/src/game_actor.cpp +++ b/src/game_actor.cpp @@ -1041,9 +1041,9 @@ void Game_Actor::ChangeClass(int new_class_id, } } -std::string Game_Actor::GetClassName() const { +StringView Game_Actor::GetClassName() const { if (!GetClass()) { - return ""; + return {}; } return GetClass()->name; } diff --git a/src/game_actor.h b/src/game_actor.h index f020e15fad..46c9e995dd 100644 --- a/src/game_actor.h +++ b/src/game_actor.h @@ -756,7 +756,7 @@ class Game_Actor final : public Game_Battler { * * @return Rpg2k3 hero class name */ - std::string GetClassName() const; + StringView GetClassName() const; /** * Gets battle commands. diff --git a/src/scene_battle_rpg2k3.cpp b/src/scene_battle_rpg2k3.cpp index 172398959b..992d2d9237 100644 --- a/src/scene_battle_rpg2k3.cpp +++ b/src/scene_battle_rpg2k3.cpp @@ -519,7 +519,7 @@ void Scene_Battle_Rpg2k3::CreateBattleCommandWindow() { const std::vector bcmds = actor->GetBattleCommands(); int i = 0; for (const lcf::rpg::BattleCommand* command : bcmds) { - commands.push_back(command->name); + commands.push_back(ToString(command->name)); if (!IsEscapeAllowedFromActorCommand() && command->type == lcf::rpg::BattleCommand::Type_escape) { disabled_items.push_back(i); diff --git a/src/sprite_battler.cpp b/src/sprite_battler.cpp index 491048b5dc..c352300a15 100644 --- a/src/sprite_battler.cpp +++ b/src/sprite_battler.cpp @@ -223,7 +223,7 @@ void Sprite_Battler::SetAnimationState(int state, LoopState loop) { return; } - sprite_file = ext->battler_name; + StringView sprite_file = ext->battler_name; if (ext->animation_type == lcf::rpg::BattlerAnimationExtension::AnimType_animation) { SetBitmap(BitmapRef()); diff --git a/src/sprite_battler.h b/src/sprite_battler.h index 4d90081d1d..ff40a487b1 100644 --- a/src/sprite_battler.h +++ b/src/sprite_battler.h @@ -118,7 +118,6 @@ class Sprite_Battler : public Sprite { BitmapRef graphic; int anim_state = AnimationState_Idle; int cycle = 0; - std::string sprite_file; int sprite_frame = -1; int fade_out = 255; int fade_out_incr = 15; diff --git a/src/window_battlecommand.cpp b/src/window_battlecommand.cpp index 44930c391a..1b543890c0 100644 --- a/src/window_battlecommand.cpp +++ b/src/window_battlecommand.cpp @@ -146,7 +146,7 @@ void Window_BattleCommand::SetActor(int _actor_id) { Game_Actor* actor = Game_Actors::GetActor(actor_id); const std::vector bcmds = actor->GetBattleCommands(); for (const lcf::rpg::BattleCommand* command : bcmds) { - commands.push_back(command->name); + commands.push_back(ToString(command->name)); } } @@ -154,26 +154,6 @@ void Window_BattleCommand::SetActor(int _actor_id) { Refresh(); } -lcf::rpg::BattleCommand Window_BattleCommand::GetCommand() { - if (actor_id > 0) { - Game_Actor* actor = Game_Actors::GetActor(actor_id); - return *actor->GetBattleCommands()[index]; - } - - lcf::rpg::BattleCommand command; - static const int types[] = { - lcf::rpg::BattleCommand::Type_attack, - lcf::rpg::BattleCommand::Type_defense, - lcf::rpg::BattleCommand::Type_item, - lcf::rpg::BattleCommand::Type_special - }; - - command.ID = index + 1; - command.name = commands[index]; - command.type = types[index]; - return command; -} - int Window_BattleCommand::GetSkillSubset() { if (actor_id == 0) return lcf::rpg::Skill::Type_normal; diff --git a/src/window_battlecommand.h b/src/window_battlecommand.h index 18ab6712b2..dae98b09d8 100644 --- a/src/window_battlecommand.h +++ b/src/window_battlecommand.h @@ -59,7 +59,6 @@ class Window_BattleCommand: public Window_Base { void SetIndex(int index); void SetActive(bool active); void UpdateCursorRect(); - lcf::rpg::BattleCommand GetCommand(); int GetSkillSubset(); protected: From bc95a64a88650bf47f7734bdb47d2b594e93d23f Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 07:20:01 -0400 Subject: [PATCH 13/21] Chipset name dbstring --- src/game_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game_map.cpp b/src/game_map.cpp index 9e99d2ff4b..32139e39bf 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -1523,7 +1523,7 @@ void Game_Map::SetChipset(int id) { if (!chipset) { Output::Warning("SetChipset: Invalid chipset ID {}", map_info.chipset_id); } else { - chipset_name = chipset->chipset_name; + chipset_name = ToString(chipset->chipset_name); passages_down = chipset->passable_data_lower; passages_up = chipset->passable_data_upper; animation_type = chipset->animation_type; From d4a48a90a0b85958dbf9ec7fc0a9ff0525e7c8fb Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 07:22:42 -0400 Subject: [PATCH 14/21] MapInfo - use DBString --- src/game_map.cpp | 4 ++-- src/game_map.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game_map.cpp b/src/game_map.cpp index 32139e39bf..fe2afa77c6 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -1488,14 +1488,14 @@ int Game_Map::GetMapIndex(int id) { return -1; } -std::string Game_Map::GetMapName(int id) { +StringView Game_Map::GetMapName(int id) { for (unsigned int i = 0; i < lcf::Data::treemap.maps.size(); ++i) { if (lcf::Data::treemap.maps[i].ID == id) { return lcf::Data::treemap.maps[i].name; } } // nothing found - return ""; + return {}; } int Game_Map::GetMapType(int map_id) { diff --git a/src/game_map.h b/src/game_map.h index 7e4ee6a395..38d1408176 100644 --- a/src/game_map.h +++ b/src/game_map.h @@ -551,7 +551,7 @@ namespace Game_Map { * @param id map ID. * @return map name from MapInfo vector. */ - std::string GetMapName(int id); + StringView GetMapName(int id); /** * Gets the type (1 = normal, 2 = area) of the map. From 368676595fd80069edc339a86751d17ea04dec09 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 14:07:08 -0400 Subject: [PATCH 15/21] Use EventCommand DBString --- src/game_interpreter.cpp | 36 ++++++++++++++++----------------- src/game_interpreter_battle.cpp | 2 +- src/game_interpreter_map.cpp | 4 ++-- src/game_screen.cpp | 4 ++-- src/game_screen.h | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 68e2d92252..2aad895c2b 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -760,7 +760,7 @@ std::vector Game_Interpreter::GetChoices(int max_num_choices) { if (static_cast(com.code) == Cmd::ShowChoiceOption && com.parameters.size() > 0 && com.parameters[0] < max_num_choices) { // Choice found - s_choices.push_back(list[index_temp].string); + s_choices.push_back(ToString(list[index_temp].string)); } if (static_cast(com.code) == Cmd::ShowChoiceEnd) { @@ -793,14 +793,14 @@ bool Game_Interpreter::CommandShowMessage(lcf::rpg::EventCommand const& com) { / auto pm = PendingMessage(); // Set first line - pm.PushLine(com.string); + pm.PushLine(ToString(com.string)); ++index; // Check for continued lines via ShowMessage_2 while (index < static_cast(list.size()) && static_cast(list[index].code) == Cmd::ShowMessage_2) { // Add second (another) line - pm.PushLine(list[index].string); + pm.PushLine(ToString(list[index].string)); ++index; } @@ -850,7 +850,7 @@ bool Game_Interpreter::CommandChangeFaceGraphic(lcf::rpg::EventCommand const& co return false; } - Game_Message::SetFaceName(com.string); + Game_Message::SetFaceName(ToString(com.string)); Game_Message::SetFaceIndex(com.parameters[0]); Game_Message::SetFaceRightPosition(com.parameters[1] != 0); Game_Message::SetFaceFlipped(com.parameters[2] != 0); @@ -1835,7 +1835,7 @@ bool Game_Interpreter::CommandWait(lcf::rpg::EventCommand const& com) { // code bool Game_Interpreter::CommandPlayBGM(lcf::rpg::EventCommand const& com) { // code 11510 lcf::rpg::Music music; - music.name = com.string; + music.name = ToString(com.string); music.fadein = com.parameters[0]; music.volume = com.parameters[1]; music.tempo = com.parameters[2]; @@ -1852,7 +1852,7 @@ bool Game_Interpreter::CommandFadeOutBGM(lcf::rpg::EventCommand const& com) { // bool Game_Interpreter::CommandPlaySound(lcf::rpg::EventCommand const& com) { // code 11550 lcf::rpg::Sound sound; - sound.name = com.string; + sound.name = ToString(com.string); sound.volume = com.parameters[0]; sound.tempo = com.parameters[1]; sound.balance = com.parameters[2]; @@ -1893,7 +1893,7 @@ bool Game_Interpreter::CommandChangeHeroName(lcf::rpg::EventCommand const& com) return true; } - actor->SetName(com.string); + actor->SetName(ToString(com.string)); return true; } @@ -1905,7 +1905,7 @@ bool Game_Interpreter::CommandChangeHeroTitle(lcf::rpg::EventCommand const& com) return true; } - actor->SetTitle(com.string); + actor->SetTitle(ToString(com.string)); return true; } @@ -1917,7 +1917,7 @@ bool Game_Interpreter::CommandChangeSpriteAssociation(lcf::rpg::EventCommand con return true; } - const std::string &file = com.string; + auto file = ToString(com.string); int idx = com.parameters[1]; bool transparent = com.parameters[2] != 0; actor->SetSprite(file, idx, transparent); @@ -1933,7 +1933,7 @@ bool Game_Interpreter::CommandChangeActorFace(lcf::rpg::EventCommand const& com) return true; } - actor->SetFace(com.string, com.parameters[1]); + actor->SetFace(ToString(com.string), com.parameters[1]); return true; } @@ -1946,7 +1946,7 @@ bool Game_Interpreter::CommandChangeVehicleGraphic(lcf::rpg::EventCommand const& return true; } - const std::string& name = com.string; + const std::string& name = ToString(com.string); int vehicle_index = com.parameters[1]; vehicle->SetSpriteGraphic(name, vehicle_index); @@ -1958,7 +1958,7 @@ bool Game_Interpreter::CommandChangeVehicleGraphic(lcf::rpg::EventCommand const& bool Game_Interpreter::CommandChangeSystemBGM(lcf::rpg::EventCommand const& com) { //code 10660 lcf::rpg::Music music; int context = com.parameters[0]; - music.name = com.string; + music.name = ToString(com.string); music.fadein = com.parameters[1]; music.volume = com.parameters[2]; music.tempo = com.parameters[3]; @@ -1970,7 +1970,7 @@ bool Game_Interpreter::CommandChangeSystemBGM(lcf::rpg::EventCommand const& com) bool Game_Interpreter::CommandChangeSystemSFX(lcf::rpg::EventCommand const& com) { //code 10670 lcf::rpg::Sound sound; int context = com.parameters[0]; - sound.name = com.string; + sound.name = ToString(com.string); sound.volume = com.parameters[1]; sound.tempo = com.parameters[2]; sound.balance = com.parameters[3]; @@ -1979,9 +1979,9 @@ bool Game_Interpreter::CommandChangeSystemSFX(lcf::rpg::EventCommand const& com) } bool Game_Interpreter::CommandChangeSystemGraphics(lcf::rpg::EventCommand const& com) { // code 10680 - Game_System::SetSystemGraphic(com.string, - (lcf::rpg::System::Stretch)com.parameters[0], - (lcf::rpg::System::Font)com.parameters[1]); + Game_System::SetSystemGraphic(ToString(com.string), + static_cast(com.parameters[0]), + static_cast(com.parameters[1])); return true; } @@ -2488,7 +2488,7 @@ bool Game_Interpreter::CommandShowPicture(lcf::rpg::EventCommand const& com) { / int pic_id = com.parameters[0]; Game_Pictures::ShowParams params = {}; - params.name = com.string; + params.name = ToString(com.string); params.position_x = ValueOrVariable(com.parameters[1], com.parameters[2]); params.position_y = ValueOrVariable(com.parameters[1], com.parameters[3]); params.fixed_to_map = com.parameters[4] > 0; @@ -2872,7 +2872,7 @@ bool Game_Interpreter::CommandChangeMapTileset(lcf::rpg::EventCommand const& com bool Game_Interpreter::CommandChangePBG(lcf::rpg::EventCommand const& com) { // code 11720 Game_Map::Parallax::Params params; - params.name = com.string; + params.name = ToString(com.string); params.scroll_horz = com.parameters[0] != 0; params.scroll_vert = com.parameters[1] != 0; params.scroll_horz_auto = com.parameters[2] != 0; diff --git a/src/game_interpreter_battle.cpp b/src/game_interpreter_battle.cpp index f8ff1d171b..8b4d916ff5 100644 --- a/src/game_interpreter_battle.cpp +++ b/src/game_interpreter_battle.cpp @@ -239,7 +239,7 @@ bool Game_Interpreter_Battle::CommandShowHiddenMonster(lcf::rpg::EventCommand co } bool Game_Interpreter_Battle::CommandChangeBattleBG(lcf::rpg::EventCommand const& com) { - Game_Battle::ChangeBackground(com.string); + Game_Battle::ChangeBackground(ToString(com.string)); return true; } diff --git a/src/game_interpreter_map.cpp b/src/game_interpreter_map.cpp index 678aed0b84..61c6d5639c 100644 --- a/src/game_interpreter_map.cpp +++ b/src/game_interpreter_map.cpp @@ -199,7 +199,7 @@ bool Game_Interpreter_Map::CommandEnemyEncounter(lcf::rpg::EventCommand const& c Game_Map::SetupBattle(args); break; case 1: - args.background = com.string; + args.background = ToString(com.string); if (Player::IsRPG2k3()) { args.formation = static_cast(com.parameters[7]); @@ -608,7 +608,7 @@ bool Game_Interpreter_Map::CommandPlayMovie(lcf::rpg::EventCommand const& com) { return false; } - const std::string& filename = com.string; + auto filename = ToString(com.string); int pos_x = ValueOrVariable(com.parameters[0], com.parameters[1]); int pos_y = ValueOrVariable(com.parameters[0], com.parameters[2]); int res_x = com.parameters[3]; diff --git a/src/game_screen.cpp b/src/game_screen.cpp index 1a7840a5fc..2fe5227088 100644 --- a/src/game_screen.cpp +++ b/src/game_screen.cpp @@ -168,9 +168,9 @@ void Game_Screen::SetWeatherEffect(int type, int strength) { } } -void Game_Screen::PlayMovie(const std::string& filename, +void Game_Screen::PlayMovie(std::string filename, int pos_x, int pos_y, int res_x, int res_y) { - movie_filename = filename; + movie_filename = std::move(filename); movie_pos_x = pos_x; movie_pos_y = pos_y; movie_res_x = res_x; diff --git a/src/game_screen.h b/src/game_screen.h index c424f0e6ff..50f9379f34 100644 --- a/src/game_screen.h +++ b/src/game_screen.h @@ -52,7 +52,7 @@ class Game_Screen { void ShakeBegin(int power, int speed); void ShakeEnd(); void SetWeatherEffect(int type, int strength); - void PlayMovie(const std::string& filename, + void PlayMovie(std::string filename, int pos_x, int pos_y, int res_x, int res_y); void Update(); From 438de031f12ab4252670c7c79171c5ea6aab793c Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 22:55:54 -0400 Subject: [PATCH 16/21] MapInfo::background_name DBString --- src/game_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game_map.cpp b/src/game_map.cpp index fe2afa77c6..f2c0b6453b 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -1364,7 +1364,7 @@ void Game_Map::SetupBattle(BattleArgs& args) { current_index = GetMapIndex(lcf::Data::treemap.maps[current_index].parent_map); } if (lcf::Data::treemap.maps[current_index].background_type == 2) { - args.background = lcf::Data::treemap.maps[current_index].background_name; + args.background = ToString(lcf::Data::treemap.maps[current_index].background_name); } } From e4876fa62e4e9295e0a048891d8fdf89fd55aff6 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 23:00:57 -0400 Subject: [PATCH 17/21] Support Map db string --- src/game_event.cpp | 4 ++-- src/game_event.h | 2 +- src/game_map.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game_event.cpp b/src/game_event.cpp index 0232bd5068..eccf2513fa 100644 --- a/src/game_event.cpp +++ b/src/game_event.cpp @@ -91,7 +91,7 @@ void Game_Event::Setup(const lcf::rpg::EventPage* new_page) { return; } - SetSpriteGraphic(page->character_name, page->character_index); + SetSpriteGraphic(ToString(page->character_name), page->character_index); SetMoveSpeed(page->move_speed); SetMoveFrequency(page->move_frequency); @@ -286,7 +286,7 @@ int Game_Event::GetId() const { return event.ID; } -std::string Game_Event::GetName() const { +StringView Game_Event::GetName() const { return event.name; } diff --git a/src/game_event.h b/src/game_event.h index d5b2999fd3..5843506344 100644 --- a/src/game_event.h +++ b/src/game_event.h @@ -71,7 +71,7 @@ class Game_Event : public Game_Character { * * @return event name. */ - std::string GetName() const; + StringView GetName() const; /** Clears waiting_execution flag */ void ClearWaitingForegroundExecution(); diff --git a/src/game_map.cpp b/src/game_map.cpp index f2c0b6453b..efb125ae10 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -1735,7 +1735,7 @@ static Game_Map::Parallax::Params GetParallaxParams() { params.scroll_vert_auto = map_info.parallax_vert_auto; params.scroll_vert_speed = map_info.parallax_vert_speed; } else if (map->parallax_flag) { - params.name = map->parallax_name; + params.name = ToString(map->parallax_name); params.scroll_horz = map->parallax_loop_x; params.scroll_horz_auto = map->parallax_auto_loop_x; params.scroll_horz_speed = map->parallax_sx; From 3e7374926d6dee52d62d17e862dd1611c9d2de46 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Sun, 16 Aug 2020 23:06:12 -0400 Subject: [PATCH 18/21] MoveCommand: UseDBString --- src/game_character.cpp | 4 ++-- src/game_interpreter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game_character.cpp b/src/game_character.cpp index 809e34b298..c22b1127e0 100644 --- a/src/game_character.cpp +++ b/src/game_character.cpp @@ -365,12 +365,12 @@ void Game_Character::UpdateMoveRoute(int32_t& current_index, const lcf::rpg::Mov Game_Map::Refresh(); break; case lcf::rpg::MoveCommand::Code::change_graphic: // String: File, Parameter A: index - SetSpriteGraphic(move_command.parameter_string, move_command.parameter_a); + SetSpriteGraphic(ToString(move_command.parameter_string), move_command.parameter_a); break; case lcf::rpg::MoveCommand::Code::play_sound_effect: // String: File, Parameters: Volume, Tempo, Balance if (move_command.parameter_string != "(OFF)" && move_command.parameter_string != "(Brak)") { lcf::rpg::Sound sound; - sound.name = move_command.parameter_string; + sound.name = ToString(move_command.parameter_string); sound.volume = move_command.parameter_a; sound.tempo = move_command.parameter_b; sound.balance = move_command.parameter_c; diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 2aad895c2b..27d1dde9db 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -517,11 +517,11 @@ lcf::rpg::MoveCommand Game_Interpreter::DecodeMove(std::vector::const_i cmd.parameter_a = DecodeInt(it); break; case 34: // Change Graphic - cmd.parameter_string = DecodeString(it); + cmd.parameter_string = lcf::DBString(DecodeString(it)); cmd.parameter_a = DecodeInt(it); break; case 35: // Play Sound Effect - cmd.parameter_string = DecodeString(it); + cmd.parameter_string = lcf::DBString(DecodeString(it)); cmd.parameter_a = DecodeInt(it); cmd.parameter_b = DecodeInt(it); cmd.parameter_c = DecodeInt(it); From 5425560b411d253f44ccebd1b9437745cb3bc475 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Tue, 25 Aug 2020 23:08:57 -0400 Subject: [PATCH 19/21] Add DBString fmt support --- src/output.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/output.h b/src/output.h index 92b1c237c0..2fe5899dc5 100644 --- a/src/output.h +++ b/src/output.h @@ -22,9 +22,17 @@ #include #include #include +#include #include "filesystem_stream.h" +namespace lcf { +// FIXME: liblcf doesn't depend on fmt, so we need to add this here to enable fmtlib support for lcf::DBString +inline fmt::basic_string_view to_string_view(const lcf::DBString& s) { + return to_string_view(StringView(s)); +} +} + /** * Output Namespace. */ From 445fea8e680c6770f9750812b72f4d65fe26f54b Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Tue, 25 Aug 2020 23:39:36 -0400 Subject: [PATCH 20/21] Window_Command - use StringView --- src/window_command.cpp | 4 ++-- src/window_command.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/window_command.cpp b/src/window_command.cpp index 76bf598397..0836a8b7a4 100644 --- a/src/window_command.cpp +++ b/src/window_command.cpp @@ -65,9 +65,9 @@ void Window_Command::EnableItem(int i) { DrawItem(i, Font::ColorDefault); } -void Window_Command::SetItemText(unsigned index, std::string const& text) { +void Window_Command::SetItemText(unsigned index, StringView text) { if (index < commands.size()) { - commands[index] = text; + commands[index] = ToString(text); DrawItem(index, Font::ColorDefault); } } diff --git a/src/window_command.h b/src/window_command.h index a9a6bec57a..706770bbcb 100644 --- a/src/window_command.h +++ b/src/window_command.h @@ -65,7 +65,7 @@ class Window_Command: public Window_Selectable { * @param index command index. * @param text new item text. */ - void SetItemText(unsigned index, std::string const& text); + void SetItemText(unsigned index, StringView text); protected: std::vector commands; From 2ef5483a92d2482e183d6e10f5f31918312bc258 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Wed, 26 Aug 2020 00:41:29 -0400 Subject: [PATCH 21/21] Use DBArray for EventCommand::parameters --- src/game_interpreter.cpp | 10 +++++----- src/game_interpreter.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 27d1dde9db..faf1dfc796 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -481,7 +481,7 @@ void Game_Interpreter::SkipToNextConditional(std::initializer_list codes, i } } -int Game_Interpreter::DecodeInt(std::vector::const_iterator& it) { +int Game_Interpreter::DecodeInt(lcf::DBArray::const_iterator& it) { int value = 0; for (;;) { @@ -495,7 +495,7 @@ int Game_Interpreter::DecodeInt(std::vector::const_iterator& it) { return value; } -const std::string Game_Interpreter::DecodeString(std::vector::const_iterator& it) { +const std::string Game_Interpreter::DecodeString(lcf::DBArray::const_iterator& it) { std::ostringstream out; int len = DecodeInt(it); @@ -507,7 +507,7 @@ const std::string Game_Interpreter::DecodeString(std::vector::const_ite return result; } -lcf::rpg::MoveCommand Game_Interpreter::DecodeMove(std::vector::const_iterator& it) { +lcf::rpg::MoveCommand Game_Interpreter::DecodeMove(lcf::DBArray::const_iterator& it) { lcf::rpg::MoveCommand cmd; cmd.command_id = *it++; @@ -2696,9 +2696,9 @@ bool Game_Interpreter::CommandMoveEvent(lcf::rpg::EventCommand const& com) { // route.repeat = com.parameters[2] != 0; route.skippable = com.parameters[3] != 0; - std::vector::const_iterator it; - for (it = com.parameters.begin() + 4; it < com.parameters.end(); ) + for (auto it = com.parameters.begin() + 4; it < com.parameters.end(); ) { route.move_commands.push_back(DecodeMove(it)); + } event->ForceMoveRoute(route, move_freq); } diff --git a/src/game_interpreter.h b/src/game_interpreter.h index 6a3e64a5c4..815b34a01b 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -24,6 +24,7 @@ #include "async_handler.h" #include "game_character.h" #include "game_actor.h" +#include #include #include #include "system.h" @@ -253,9 +254,9 @@ class Game_Interpreter bool CommandExitGame(lcf::rpg::EventCommand const& com); bool CommandToggleFullscreen(lcf::rpg::EventCommand const& com); - int DecodeInt(std::vector::const_iterator& it); - const std::string DecodeString(std::vector::const_iterator& it); - lcf::rpg::MoveCommand DecodeMove(std::vector::const_iterator& it); + int DecodeInt(lcf::DBArray::const_iterator& it); + const std::string DecodeString(lcf::DBArray::const_iterator& it); + lcf::rpg::MoveCommand DecodeMove(lcf::DBArray::const_iterator& it); void SetSubcommandIndex(int indent, int idx); uint8_t& ReserveSubcommandIndex(int indent);