refactor: replace unique_ptr to shared_ptr
This commit is contained in:
parent
bb4538794b
commit
81e26a7e52
@ -10,7 +10,7 @@ namespace L2Bot::Domain::DTO
|
||||
class EntityState
|
||||
{
|
||||
public:
|
||||
const std::unique_ptr<Entities::EntityInterface>& GetEntity() const
|
||||
const std::shared_ptr<Entities::EntityInterface>& GetEntity() const
|
||||
{
|
||||
return m_Entity;
|
||||
}
|
||||
@ -23,8 +23,8 @@ namespace L2Bot::Domain::DTO
|
||||
m_State = state;
|
||||
}
|
||||
|
||||
EntityState(std::unique_ptr<Entities::EntityInterface> object, Enums::EntityStateEnum state) :
|
||||
m_Entity(std::move(object)),
|
||||
EntityState(std::shared_ptr<Entities::EntityInterface> object, Enums::EntityStateEnum state) :
|
||||
m_Entity(object),
|
||||
m_State(state)
|
||||
{
|
||||
|
||||
@ -33,7 +33,7 @@ namespace L2Bot::Domain::DTO
|
||||
EntityState() = default;
|
||||
virtual ~EntityState() = default;
|
||||
private:
|
||||
std::unique_ptr<Entities::EntityInterface> m_Entity = nullptr;
|
||||
std::shared_ptr<Entities::EntityInterface> m_Entity = nullptr;
|
||||
Enums::EntityStateEnum m_State = Enums::EntityStateEnum::none;
|
||||
};
|
||||
}
|
@ -98,7 +98,8 @@ namespace L2Bot::Domain::Entities
|
||||
EtcItem(const EtcItem* other) :
|
||||
BaseItem(other),
|
||||
m_Amount(other->m_Amount),
|
||||
m_IsAutoused(other->m_IsAutoused)
|
||||
m_IsAutoused(other->m_IsAutoused),
|
||||
m_IsQuest(other->m_IsQuest)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ class EntityFinder
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
const std::map<uint32_t, std::shared_ptr<DTO::EntityState>>& FindEntities(const std::map<uint32_t, T> items, std::function<std::unique_ptr<Entities::EntityInterface>(T)> callback)
|
||||
const std::map<uint32_t, std::shared_ptr<DTO::EntityState>>& FindEntities(const std::map<uint32_t, T> items, std::function<std::shared_ptr<Entities::EntityInterface>(T)> callback)
|
||||
{
|
||||
RemoveOutdatedStates();
|
||||
|
||||
@ -36,7 +36,7 @@ public:
|
||||
const auto objectId = newObject->GetId();
|
||||
m_Objects.emplace(
|
||||
objectId,
|
||||
std::make_shared<DTO::EntityState>(std::move(newObject), Enums::EntityStateEnum::created)
|
||||
std::make_shared<DTO::EntityState>(newObject, Enums::EntityStateEnum::created)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace Interlude
|
||||
AbnormalEffectFactory() = delete;
|
||||
virtual ~AbnormalEffectFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::AbnormalEffect> Create(const uint32_t skillId, const uint32_t level) const
|
||||
std::shared_ptr<Entities::AbnormalEffect> Create(const uint32_t skillId, const uint32_t level) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
@ -32,7 +32,7 @@ namespace Interlude
|
||||
const auto description = data && data->description ? data->description : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
|
||||
return std::make_unique<Entities::AbnormalEffect>(
|
||||
return std::make_shared<Entities::AbnormalEffect>(
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
std::wstring(name),
|
||||
|
@ -21,13 +21,13 @@ namespace Interlude
|
||||
DropFactory() = delete;
|
||||
virtual ~DropFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::Drop> Create(const Item* item) const
|
||||
std::shared_ptr<Entities::Drop> Create(const Item* item) const
|
||||
{
|
||||
const auto itemData = m_L2GameData.GetItemData(item->itemId);
|
||||
const auto nameEntry = itemData ? m_FName.GetEntry(itemData->nameIndex) : nullptr;
|
||||
const auto iconEntry = itemData ? m_FName.GetEntry(itemData->iconNameIndex) : nullptr;
|
||||
|
||||
return std::make_unique<Entities::Drop>(
|
||||
return std::make_shared<Entities::Drop>(
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -13,11 +13,11 @@ namespace Interlude
|
||||
HeroFactory() = default;
|
||||
virtual ~HeroFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::Hero> Create(const User* item) const
|
||||
std::shared_ptr<Entities::Hero> Create(const User* item) const
|
||||
{
|
||||
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
|
||||
|
||||
return std::make_unique<Entities::Hero>(
|
||||
return std::make_shared<Entities::Hero>(
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -30,7 +30,7 @@ namespace Interlude
|
||||
ItemFactory() = delete;
|
||||
virtual ~ItemFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::BaseItem> Create(const ItemData& itemInfo) const
|
||||
std::shared_ptr<Entities::BaseItem> Create(const ItemData& itemInfo) const
|
||||
{
|
||||
//FIXME during first start data may be undefined
|
||||
const auto data = m_L2GameData.GetItemData(itemInfo.itemId);
|
||||
@ -55,42 +55,43 @@ namespace Interlude
|
||||
return CreateEtc(itemInfo, data, name, icon, description);
|
||||
}
|
||||
|
||||
std::unique_ptr<Entities::BaseItem> CreateFromPointer(const Entities::BaseItem* other) const
|
||||
std::shared_ptr<Entities::BaseItem> Copy(std::shared_ptr<Entities::BaseItem> other) const
|
||||
{
|
||||
auto otherPtr = other.get();
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::EtcItem*>(other);
|
||||
const auto object = dynamic_cast<const Entities::EtcItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_unique<Entities::EtcItem>(object);
|
||||
return std::make_shared<Entities::EtcItem>(object);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::ArmorItem*>(other);
|
||||
const auto object = dynamic_cast<const Entities::ArmorItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_unique<Entities::ArmorItem>(object);
|
||||
return std::make_shared<Entities::ArmorItem>(object);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::WeaponItem*>(other);
|
||||
const auto object = dynamic_cast<const Entities::WeaponItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_unique<Entities::WeaponItem>(object);
|
||||
return std::make_shared<Entities::WeaponItem>(object);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::ShieldItem*>(other);
|
||||
const auto object = dynamic_cast<const Entities::ShieldItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_unique<Entities::ShieldItem>(object);
|
||||
return std::make_shared<Entities::ShieldItem>(object);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_unique<Entities::BaseItem>(other);
|
||||
return std::make_shared<Entities::BaseItem>(otherPtr);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Entities::BaseItem> CreateEtc(
|
||||
std::shared_ptr<Entities::BaseItem> CreateEtc(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::wstring& name,
|
||||
@ -98,7 +99,7 @@ namespace Interlude
|
||||
const std::wstring& description
|
||||
) const
|
||||
{
|
||||
return std::make_unique<Entities::EtcItem>(
|
||||
return std::make_shared<Entities::EtcItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
@ -111,7 +112,7 @@ namespace Interlude
|
||||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<Entities::BaseItem> CreateArmor(
|
||||
std::shared_ptr<Entities::BaseItem> CreateArmor(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::wstring& name,
|
||||
@ -125,7 +126,7 @@ namespace Interlude
|
||||
const auto addSetEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
|
||||
const auto enchantEffect = casted && casted->enchantEffect ? std::wstring(casted->enchantEffect) : L"";
|
||||
|
||||
return std::make_unique<Entities::ArmorItem>(
|
||||
return std::make_shared<Entities::ArmorItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
@ -145,7 +146,7 @@ namespace Interlude
|
||||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<Entities::BaseItem> CreateWeaponOrShield(
|
||||
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::wstring& name,
|
||||
@ -157,7 +158,7 @@ namespace Interlude
|
||||
|
||||
if (casted->weaponType != L2::WeaponType::SHIELD)
|
||||
{
|
||||
return std::make_unique<Entities::WeaponItem>(
|
||||
return std::make_shared<Entities::WeaponItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
@ -181,7 +182,7 @@ namespace Interlude
|
||||
);
|
||||
}
|
||||
|
||||
return std::make_unique<Entities::ShieldItem>(
|
||||
return std::make_shared<Entities::ShieldItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
|
@ -12,9 +12,9 @@ namespace Interlude
|
||||
NPCFactory() = default;
|
||||
virtual ~NPCFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::NPC> Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
std::shared_ptr<Entities::NPC> Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
{
|
||||
return std::make_unique<Entities::NPC>(
|
||||
return std::make_shared<Entities::NPC>(
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -12,9 +12,9 @@ namespace Interlude
|
||||
PlayerFactory() = default;
|
||||
virtual ~PlayerFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::Player> Create(const User* item) const
|
||||
std::shared_ptr<Entities::Player> Create(const User* item) const
|
||||
{
|
||||
return std::make_unique<Entities::Player>(
|
||||
return std::make_shared<Entities::Player>(
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -24,7 +24,7 @@ namespace Interlude
|
||||
SkillFactory() = delete;
|
||||
virtual ~SkillFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::Skill> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
std::shared_ptr<Entities::Skill> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
@ -34,7 +34,7 @@ namespace Interlude
|
||||
const auto description = data && data->description ? data->description : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
|
||||
return std::make_unique<Entities::Skill>(
|
||||
return std::make_shared<Entities::Skill>(
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
isActive != 1,
|
||||
|
@ -22,14 +22,8 @@ namespace Interlude
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
std::map<uint32_t, Entities::AbnormalEffect*> skillPtrs;
|
||||
for (const auto& kvp : m_Effects)
|
||||
{
|
||||
skillPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<Entities::AbnormalEffect*>(skillPtrs, [this](Entities::AbnormalEffect* item) {
|
||||
return std::make_unique<Entities::AbnormalEffect>(item);
|
||||
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::AbnormalEffect>>(m_Effects, [this](std::shared_ptr<Entities::AbnormalEffect> item) {
|
||||
return std::make_shared<Entities::AbnormalEffect>(item.get());
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
@ -90,7 +84,7 @@ namespace Interlude
|
||||
const auto level = skillInfo[i + 1];
|
||||
|
||||
auto effect = m_Factory.Create(effectId, level);
|
||||
m_Effects.emplace(effect->GetId(), std::move(effect));
|
||||
m_Effects.emplace(effect->GetId(), effect);
|
||||
|
||||
ids[effectId] = effectId;
|
||||
}
|
||||
@ -113,7 +107,7 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const AbnormalEffectFactory& m_Factory;
|
||||
std::map<uint32_t, std::unique_ptr<Entities::AbnormalEffect>> m_Effects;
|
||||
std::map<uint32_t, std::shared_ptr<Entities::AbnormalEffect>> m_Effects;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
|
@ -26,14 +26,8 @@ namespace Interlude
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
std::map<uint32_t, Entities::BaseItem*> itemPtrs;
|
||||
for (const auto& kvp : m_Items)
|
||||
{
|
||||
itemPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<Entities::BaseItem*>(itemPtrs, [this](Entities::BaseItem* item) {
|
||||
return m_Factory.CreateFromPointer(item);
|
||||
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::BaseItem>>(m_Items, [this](std::shared_ptr<Entities::BaseItem> item) {
|
||||
return m_Factory.Copy(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
@ -152,7 +146,7 @@ namespace Interlude
|
||||
auto item = m_Factory.Create(data);
|
||||
if (m_Items.find(data.objectId) == m_Items.end())
|
||||
{
|
||||
m_Items.emplace(data.objectId, std::move(item));
|
||||
m_Items.emplace(data.objectId, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -211,7 +205,7 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const ItemFactory& m_Factory;
|
||||
std::map<uint32_t, std::unique_ptr<Entities::BaseItem>> m_Items;
|
||||
std::map<uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items;
|
||||
std::map<uint32_t, uint32_t> m_NewItems;
|
||||
bool m_IsNewCycle = true;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
|
@ -27,14 +27,8 @@ namespace Interlude
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
std::map<uint32_t, Entities::Skill*> skillPtrs;
|
||||
for (const auto& kvp : m_Skills)
|
||||
{
|
||||
skillPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<Entities::Skill*>(skillPtrs, [this](Entities::Skill* item) {
|
||||
return std::make_unique<Entities::Skill>(item);
|
||||
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::Skill>>(m_Skills, [this](std::shared_ptr<Entities::Skill> item) {
|
||||
return std::make_shared<Entities::Skill>(item.get());
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
@ -141,7 +135,7 @@ namespace Interlude
|
||||
);
|
||||
if (m_Skills.find(skillId) == m_Skills.end())
|
||||
{
|
||||
m_Skills.emplace(skill->GetId(), std::move(skill));
|
||||
m_Skills.emplace(skill->GetId(), skill);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -245,7 +239,7 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const SkillFactory& m_Factory;
|
||||
std::map<uint32_t, std::unique_ptr<Entities::Skill>> m_Skills;
|
||||
std::map<uint32_t, std::shared_ptr<Entities::Skill>> m_Skills;
|
||||
std::map<uint32_t, uint32_t> m_NewSkills;
|
||||
bool m_IsNewCycle = true;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user