refactor: replace unique_ptr to shared_ptr

This commit is contained in:
k0t9i
2023-02-10 18:49:47 +04:00
parent bb4538794b
commit 81e26a7e52
13 changed files with 51 additions and 67 deletions

View File

@@ -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),

View File

@@ -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),

View File

@@ -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),

View File

@@ -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,

View File

@@ -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),

View File

@@ -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),

View File

@@ -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,