From 5c39694f19556e661536692fcbf6f9c31d65e919 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 12 Dec 2020 12:22:48 +0100 Subject: [PATCH] Overhaul memory model to new Arbutils memory. Signed-off-by: Deukhoofd --- CInterface/Battling/Battle.cpp | 8 +- CInterface/Battling/BattleSide.cpp | 2 +- CInterface/Battling/Creature.cpp | 8 +- CInterface/Battling/CreatureParty.cpp | 2 +- CInterface/Battling/ExecutingAttack.cpp | 2 +- CInterface/Battling/HistoryHandler.cpp | 6 +- CInterface/Battling/TurnChoices.cpp | 2 +- CInterface/Core.hpp | 6 ++ src/Battling/EventHooks/EventHook.hpp | 4 +- src/Battling/Flow/ResolveTarget.hpp | 19 ++--- src/Battling/Flow/TurnHandler.cpp | 61 ++++++++------ src/Battling/History/HistoryHolder.hpp | 4 +- src/Battling/Library/MiscLibrary.cpp | 8 +- src/Battling/Models/Battle.cpp | 11 +-- src/Battling/Models/Battle.hpp | 13 +-- src/Battling/Models/BattleSide.cpp | 45 ++++++----- src/Battling/Models/BattleSide.hpp | 16 ++-- src/Battling/Models/Creature.cpp | 80 +++++++++---------- src/Battling/Models/Creature.hpp | 22 ++--- src/Battling/Models/CreatureParty.hpp | 8 +- src/Battling/Models/ExecutingAttack.hpp | 21 +++-- .../ScriptHandling/ScriptAggregator.hpp | 4 +- src/Battling/ScriptHandling/ScriptSet.hpp | 8 +- src/Battling/TurnChoices/AttackTurnChoice.hpp | 4 +- src/Battling/TurnChoices/SwitchTurnChoice.hpp | 6 +- src/Library/CreatureData/LearnableAttacks.cpp | 6 +- src/Library/CreatureData/LearnableAttacks.hpp | 2 +- src/Precompiled.hxx | 3 +- tests/BattleTests/ChoiceSetTests.cpp | 17 +++- tests/BattleTests/EventHookTests.cpp | 20 ++--- .../ScriptTests/ScriptAggregatorTests.cpp | 14 +--- .../ScriptTests/ScriptSourceTest.cpp | 12 +-- tests/BattleTests/TurnOrderTests.cpp | 46 +++++++---- 33 files changed, 279 insertions(+), 211 deletions(-) diff --git a/CInterface/Battling/Battle.cpp b/CInterface/Battling/Battle.cpp index 6af7f5b..6ba6225 100644 --- a/CInterface/Battling/Battle.cpp +++ b/CInterface/Battling/Battle.cpp @@ -31,7 +31,7 @@ export uint8_t CreatureLib_Battle_CreatureInField(bool& out, const Battle* p, Cr Try(out = p->CreatureInField(c);) } export uint8_t CreatureLib_Battle_GetCreature(Creature*& out, const Battle* p, uint8_t side, uint8_t target) { - Try(out = p->GetCreature(side, target).GetRaw();) + Try(out = p->GetCreature(side, target).GetValue();) } export uint8_t CreatureLib_Battle_ForceRecall(Battle* p, uint8_t side, uint8_t target) { @@ -58,7 +58,11 @@ export BattleParty* const* CreatureLib_Battle_GetParties(const Battle* p) { } export Script* CreatureLib_Battle_GetVolatileScript(Battle* p, const char* key) { - return p->GetVolatileScript(ArbUt::StringView::CalculateHash(key)).GetRaw(); + auto v = p->GetVolatileScript(ArbUt::StringView::CalculateHash(key)); + if (!v.has_value()) { + return nullptr; + } + return v.value(); } export uint8_t CreatureLib_Battle_AddVolatileScriptByName(Battle* p, const char* key) { Try(p->AddVolatileScript(ArbUt::StringView(key));) diff --git a/CInterface/Battling/BattleSide.cpp b/CInterface/Battling/BattleSide.cpp index a8b85ea..6e297c6 100644 --- a/CInterface/Battling/BattleSide.cpp +++ b/CInterface/Battling/BattleSide.cpp @@ -23,7 +23,7 @@ export uint8_t CreatureLib_BattleSide_SetCreature(BattleSide* p, Creature* creat } export uint8_t CreatureLib_BattleSide_GetCreature(Creature*& out, BattleSide* p, uint8_t index) { - Try(out = p->GetCreature(index).GetRaw()); + Try(out = p->GetCreature(index).GetValue()); } export uint8_t CreatureLib_BattleSide_GetSideIndex(BattleSide* p) { return p->GetSideIndex(); } diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 07504b9..e177b4b 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -51,8 +51,8 @@ export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const Creature return p->SetHeldItem(ArbUt::BorrowedPtr(item)); } SIMPLE_GET_FUNC(Creature, GetCurrentHealth, uint32_t); -BORROWED_GET_FUNC(Creature, GetBattle, Battle*); -BORROWED_GET_FUNC(Creature, GetBattleSide, BattleSide*); +OPTIONAL_GET_FUNC(Creature, GetBattle, Battle*); +OPTIONAL_GET_FUNC(Creature, GetBattleSide, BattleSide*); SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool); export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().data(); } export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); } @@ -101,8 +101,8 @@ export LearnedAttack* const* CreatureLib_Creature_GetAttacks(Creature* p) { retu export bool CreatureLib_Creature_HasAttack(Creature* p, const char* scriptName) { return p->HasAttack(ArbUt::StringView(scriptName)); } -BORROWED_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*); -BORROWED_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*); +OPTIONAL_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*); +OPTIONAL_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*); export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species) { return p->SetDisplaySpecies(ArbUt::BorrowedPtr(species)); } diff --git a/CInterface/Battling/CreatureParty.cpp b/CInterface/Battling/CreatureParty.cpp index a53af41..2c3c65f 100644 --- a/CInterface/Battling/CreatureParty.cpp +++ b/CInterface/Battling/CreatureParty.cpp @@ -10,7 +10,7 @@ export CreatureParty* CreatureLib_CreatureParty_ConstructFromArray(Creature* cre export void CreatureLib_CreatureParty_Destruct(const CreatureParty* p) { delete p; } export uint8_t CreatureLib_CreatureParty_GetAtIndex(Creature*& out, const CreatureParty* p, size_t index) { - Try(out = p->GetAtIndex(index).GetRaw();) + Try(out = p->GetAtIndex(index).GetValue();) } export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) } diff --git a/CInterface/Battling/ExecutingAttack.cpp b/CInterface/Battling/ExecutingAttack.cpp index 3a52988..aa816d4 100644 --- a/CInterface/Battling/ExecutingAttack.cpp +++ b/CInterface/Battling/ExecutingAttack.cpp @@ -5,7 +5,7 @@ using namespace CreatureLib::Battling; export uint8_t CreatureLib_ExecutingAttack_Construct(ExecutingAttack*& out, Creature* const* targets, size_t targetCount, uint8_t numberHits, Creature* user, LearnedAttack* attack, Script* script) { - Try(auto ls = ArbUt::List>(targetCount); + Try(auto ls = ArbUt::List>(targetCount); for (size_t i = 0; i < targetCount; i++) { ls.Append(targets[i]); } auto s = std::unique_ptr