switch cppscripts to references and unique_ptrs

This commit is contained in:
jadebenn
2024-12-17 23:33:46 -06:00
parent e1c20192f7
commit 42367deeca
5 changed files with 325 additions and 331 deletions

View File

@@ -1499,7 +1499,7 @@ void Entity::RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled)
CppScripts::Script* const Entity::GetScript() {
auto* scriptComponent = GetComponent<ScriptComponent>();
auto* script = scriptComponent ? scriptComponent->GetScript() : CppScripts::GetInvalidScript();
auto* script = scriptComponent ? scriptComponent->GetScript() : &CppScripts::GetInvalidScript();
DluAssert(script != nullptr);
return script;
}
@@ -2175,7 +2175,7 @@ void Entity::SetRespawnRot(const NiQuaternion& rotation) {
int32_t Entity::GetCollisionGroup() const {
for (const auto* component : m_Components | std::views::values) {
auto* compToCheck = dynamic_cast<const PhysicsComponent*>(component);
auto* compToCheck = dynamic_cast<const PhysicsComponent*>(component);
if (compToCheck) {
return compToCheck->GetCollisionGroup();
}

View File

@@ -913,11 +913,8 @@ void InventoryComponent::EquipScripts(Item* equippedItem) {
if (scriptComponentID > -1) {
CDScriptComponentTable* scriptCompTable = CDClientManager::GetTable<CDScriptComponentTable>();
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
if (!itemScript) {
LOG("null script?");
}
itemScript->OnFactionTriggerItemEquipped(m_Parent, equippedItem->GetId());
auto& itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
itemScript.OnFactionTriggerItemEquipped(m_Parent, equippedItem->GetId());
}
}
@@ -928,11 +925,8 @@ void InventoryComponent::UnequipScripts(Item* unequippedItem) {
if (scriptComponentID > -1) {
CDScriptComponentTable* scriptCompTable = CDClientManager::GetTable<CDScriptComponentTable>();
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
if (!itemScript) {
LOG("null script?");
}
itemScript->OnFactionTriggerItemUnequipped(m_Parent, unequippedItem->GetId());
auto& itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
itemScript.OnFactionTriggerItemUnequipped(m_Parent, unequippedItem->GetId());
}
}

View File

@@ -48,5 +48,5 @@ CppScripts::Script* const ScriptComponent::GetScript() {
void ScriptComponent::SetScript(const std::string& scriptName) {
// Scripts are managed by the CppScripts class and are effecitvely singletons
// and they may also be used by other script components so DON'T delete them.
m_Script = CppScripts::GetScript(m_Parent, scriptName);
m_Script = &CppScripts::GetScript(m_Parent, scriptName);
}