Make CreatureParty use smart pointers.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
01f6e59cb6
commit
69f6a89c0d
|
@ -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);)
|
||||
Try(out = p->GetAtIndex(index).operator->();)
|
||||
}
|
||||
|
||||
export uint8_t CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { Try(p->Switch(a, b);) }
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
|
||||
inline bool HasCreaturesNotInField() const {
|
||||
auto p = _party->GetParty();
|
||||
auto& p = _party->GetParty();
|
||||
for (const auto& creature : p) {
|
||||
if (creature == nullptr)
|
||||
continue;
|
||||
|
|
|
@ -6,20 +6,16 @@
|
|||
|
||||
namespace CreatureLib::Battling {
|
||||
class CreatureParty {
|
||||
ArbUt::List<Creature*> _party;
|
||||
ArbUt::UniquePtrList<Creature> _party;
|
||||
|
||||
public:
|
||||
CreatureParty(size_t size) noexcept : _party(size) {}
|
||||
CreatureParty(ArbUt::List<Creature*> party) noexcept : _party(party) {}
|
||||
CreatureParty(ArbUt::List<Creature*> party) noexcept : _party(party.GetStdList()) {}
|
||||
CreatureParty(std::initializer_list<Creature*> party) noexcept : _party(party) {}
|
||||
|
||||
virtual ~CreatureParty() noexcept {
|
||||
for (auto c : _party) {
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
virtual ~CreatureParty() = default;
|
||||
|
||||
Creature* GetAtIndex(size_t index) const noexcept { return _party[index]; }
|
||||
ArbUt::BorrowedPtr<Creature> GetAtIndex(size_t index) const noexcept { return _party[index]; }
|
||||
|
||||
void Switch(size_t a, size_t b) noexcept {
|
||||
auto ca = _party[a];
|
||||
|
@ -38,8 +34,8 @@ namespace CreatureLib::Battling {
|
|||
return false;
|
||||
}
|
||||
|
||||
ArbUt::List<Creature*>& GetParty() noexcept { return _party; }
|
||||
const ArbUt::List<Creature*>& GetParty() const noexcept { return _party; }
|
||||
ArbUt::UniquePtrList<Creature>& GetParty() noexcept { return _party; }
|
||||
const ArbUt::UniquePtrList<Creature>& GetParty() const noexcept { return _party; }
|
||||
|
||||
size_t GetLength() const noexcept { return _party.Count(); }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue