1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:23:51 +00:00

Return cloned AiPackage as unique_ptr

This commit is contained in:
elsid 2020-06-01 15:36:14 +02:00
parent f5e2e53bcf
commit ce7c47ee12
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
3 changed files with 9 additions and 7 deletions

View file

@ -1,6 +1,8 @@
#ifndef GAME_MWMECHANICS_AIPACKAGE_H #ifndef GAME_MWMECHANICS_AIPACKAGE_H
#define GAME_MWMECHANICS_AIPACKAGE_H #define GAME_MWMECHANICS_AIPACKAGE_H
#include <memory>
#include <components/esm/defs.hpp> #include <components/esm/defs.hpp>
#include "pathfinding.hpp" #include "pathfinding.hpp"
@ -59,7 +61,7 @@ namespace MWMechanics
virtual ~AiPackage() = default; virtual ~AiPackage() = default;
///Clones the package ///Clones the package
virtual AiPackage *clone() const = 0; virtual std::unique_ptr<AiPackage> clone() const = 0;
/// Updates and runs the package (Should run every frame) /// Updates and runs the package (Should run every frame)
/// \return Package completed? /// \return Package completed?

View file

@ -27,7 +27,7 @@ void AiSequence::copy (const AiSequence& sequence)
{ {
for (std::list<AiPackage *>::const_iterator iter (sequence.mPackages.begin()); for (std::list<AiPackage *>::const_iterator iter (sequence.mPackages.begin());
iter!=sequence.mPackages.end(); ++iter) iter!=sequence.mPackages.end(); ++iter)
mPackages.push_back ((*iter)->clone()); mPackages.push_back ((*iter)->clone().release());
// We need to keep an AiWander storage, if present - it has a state machine. // We need to keep an AiWander storage, if present - it has a state machine.
// Not sure about another temporary storages // Not sure about another temporary storages
@ -288,7 +288,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac
if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat())) if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat()))
{ {
package->reset(); package->reset();
mPackages.push_back(package->clone()); mPackages.push_back(package->clone().release());
} }
// To account for the rare case where AiPackage::execute() queued another AI package // To account for the rare case where AiPackage::execute() queued another AI package
// (e.g. AiPursue executing a dialogue script that uses startCombat) // (e.g. AiPursue executing a dialogue script that uses startCombat)
@ -380,12 +380,12 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor, boo
if((*it)->getPriority() <= package.getPriority()) if((*it)->getPriority() <= package.getPriority())
{ {
mPackages.insert(it,package.clone()); mPackages.insert(it,package.clone().release());
return; return;
} }
} }
mPackages.push_back (package.clone()); mPackages.push_back (package.clone().release());
// Make sure that temporary storage is empty // Make sure that temporary storage is empty
if (cancelOther) if (cancelOther)

View file

@ -8,9 +8,9 @@ namespace MWMechanics
template <class T> template <class T>
struct TypedAiPackage : public AiPackage struct TypedAiPackage : public AiPackage
{ {
virtual TypedAiPackage<T> *clone() const override virtual std::unique_ptr<AiPackage> clone() const override
{ {
return new T(*static_cast<const T*>(this)); return std::make_unique<T>(*static_cast<const T*>(this));
} }
}; };
} }