From 5a333ea910c01c0864229ac44b7ca3d03e6e4d72 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 6 Jan 2024 15:59:52 -0600 Subject: [PATCH 01/10] Assorted pet improvements --- dCommon/dEnums/ePetAbilityType.h | 11 +++ .../CDClientDatabase/CDClientDatabase.cpp | 4 + dDatabase/CDClientDatabase/CDClientDatabase.h | 4 + .../CDClientDatabase/CDClientManager.cpp | 85 ++++++++++--------- dDatabase/CDClientDatabase/CDClientManager.h | 3 + .../CDClientTables/CDPetComponentTable.cpp | 63 ++++++++++++++ .../CDClientTables/CDPetComponentTable.h | 49 +++++++++++ .../CDClientDatabase/CDClientTables/CDTable.h | 3 + .../CDClientTables/CMakeLists.txt | 1 + dGame/dComponents/BaseCombatAIComponent.cpp | 1 - dGame/dComponents/PetComponent.cpp | 62 +++++--------- dGame/dComponents/PetComponent.h | 27 +++--- dGame/dGameMessages/GameMessages.cpp | 5 +- dGame/dGameMessages/GameMessages.h | 3 +- tests/dGameTests/GameDependencies.h | 5 ++ .../dComponentsTests/CMakeLists.txt | 1 + .../dComponentsTests/PetComponentTests.cpp | 43 ++++++++++ 17 files changed, 272 insertions(+), 98 deletions(-) create mode 100644 dCommon/dEnums/ePetAbilityType.h create mode 100644 dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp create mode 100644 dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h create mode 100644 tests/dGameTests/dComponentsTests/PetComponentTests.cpp diff --git a/dCommon/dEnums/ePetAbilityType.h b/dCommon/dEnums/ePetAbilityType.h new file mode 100644 index 000000000..3b2e55204 --- /dev/null +++ b/dCommon/dEnums/ePetAbilityType.h @@ -0,0 +1,11 @@ +#ifndef __EPETABILITYTYPE__H__ +#define __EPETABILITYTYPE__H__ + +enum class ePetAbilityType : int32_t { + Invalid, + GoToObject, + JumpOnObject, + DigAtPosition +}; + +#endif //!__EPETABILITYTYPE__H__ diff --git a/dDatabase/CDClientDatabase/CDClientDatabase.cpp b/dDatabase/CDClientDatabase/CDClientDatabase.cpp index 4c2df1d28..886030a1b 100644 --- a/dDatabase/CDClientDatabase/CDClientDatabase.cpp +++ b/dDatabase/CDClientDatabase/CDClientDatabase.cpp @@ -4,9 +4,13 @@ // Static Variables static CppSQLite3DB* conn = new CppSQLite3DB(); +// Status Variables +bool CDClientDatabase::isConnected = false; + //! Opens a connection with the CDClient void CDClientDatabase::Connect(const std::string& filename) { conn->open(filename.c_str()); + isConnected = true; } //! Queries the CDClient diff --git a/dDatabase/CDClientDatabase/CDClientDatabase.h b/dDatabase/CDClientDatabase/CDClientDatabase.h index 7f42918d0..fa58906c3 100644 --- a/dDatabase/CDClientDatabase/CDClientDatabase.h +++ b/dDatabase/CDClientDatabase/CDClientDatabase.h @@ -15,6 +15,10 @@ //! The CDClient Database namespace namespace CDClientDatabase { + /** + * Boolean defining the connection status of CDClient + */ + extern bool isConnected; //! Opens a connection with the CDClient /*! diff --git a/dDatabase/CDClientDatabase/CDClientManager.cpp b/dDatabase/CDClientDatabase/CDClientManager.cpp index 74c5c9754..74e79f2b9 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.cpp +++ b/dDatabase/CDClientDatabase/CDClientManager.cpp @@ -52,43 +52,50 @@ #endif CDClientManager::CDClientManager() { - CDActivityRewardsTable::Instance().LoadValuesFromDatabase(); - CDActivitiesTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase()); - CDBehaviorParameterTable::Instance().LoadValuesFromDatabase(); - CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase(); - CDBrickIDTableTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDComponentsRegistryTable::Instance().LoadValuesFromDatabase()); - CDCurrencyTableTable::Instance().LoadValuesFromDatabase(); - CDDestructibleComponentTable::Instance().LoadValuesFromDatabase(); - CDEmoteTableTable::Instance().LoadValuesFromDatabase(); - CDFeatureGatingTable::Instance().LoadValuesFromDatabase(); - CDInventoryComponentTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDItemComponentTable::Instance().LoadValuesFromDatabase()); - CDItemSetSkillsTable::Instance().LoadValuesFromDatabase(); - CDItemSetsTable::Instance().LoadValuesFromDatabase(); - CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDLootMatrixTable::Instance().LoadValuesFromDatabase()); - CDCLIENT_DONT_CACHE_TABLE(CDLootTableTable::Instance().LoadValuesFromDatabase()); - CDMissionEmailTable::Instance().LoadValuesFromDatabase(); - CDMissionNPCComponentTable::Instance().LoadValuesFromDatabase(); - CDMissionTasksTable::Instance().LoadValuesFromDatabase(); - CDMissionsTable::Instance().LoadValuesFromDatabase(); - CDMovementAIComponentTable::Instance().LoadValuesFromDatabase(); - CDObjectSkillsTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase()); - CDPhysicsComponentTable::Instance().LoadValuesFromDatabase(); - CDPackageComponentTable::Instance().LoadValuesFromDatabase(); - CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase(); - CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase(); - CDPropertyTemplateTable::Instance().LoadValuesFromDatabase(); - CDRailActivatorComponentTable::Instance().LoadValuesFromDatabase(); - CDRarityTableTable::Instance().LoadValuesFromDatabase(); - CDRebuildComponentTable::Instance().LoadValuesFromDatabase(); - CDRewardCodesTable::Instance().LoadValuesFromDatabase(); - CDRewardsTable::Instance().LoadValuesFromDatabase(); - CDScriptComponentTable::Instance().LoadValuesFromDatabase(); - CDSkillBehaviorTable::Instance().LoadValuesFromDatabase(); - CDVendorComponentTable::Instance().LoadValuesFromDatabase(); - CDZoneTableTable::Instance().LoadValuesFromDatabase(); + if (CDClientDatabase::isConnected) { + CDActivityRewardsTable::Instance().LoadValuesFromDatabase(); + CDActivitiesTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase()); + CDBehaviorParameterTable::Instance().LoadValuesFromDatabase(); + CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase(); + CDBrickIDTableTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDComponentsRegistryTable::Instance().LoadValuesFromDatabase()); + CDCurrencyTableTable::Instance().LoadValuesFromDatabase(); + CDDestructibleComponentTable::Instance().LoadValuesFromDatabase(); + CDEmoteTableTable::Instance().LoadValuesFromDatabase(); + CDFeatureGatingTable::Instance().LoadValuesFromDatabase(); + CDInventoryComponentTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDItemComponentTable::Instance().LoadValuesFromDatabase()); + CDItemSetSkillsTable::Instance().LoadValuesFromDatabase(); + CDItemSetsTable::Instance().LoadValuesFromDatabase(); + CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDLootMatrixTable::Instance().LoadValuesFromDatabase()); + CDCLIENT_DONT_CACHE_TABLE(CDLootTableTable::Instance().LoadValuesFromDatabase()); + CDMissionEmailTable::Instance().LoadValuesFromDatabase(); + CDMissionNPCComponentTable::Instance().LoadValuesFromDatabase(); + CDMissionTasksTable::Instance().LoadValuesFromDatabase(); + CDMissionsTable::Instance().LoadValuesFromDatabase(); + CDMovementAIComponentTable::Instance().LoadValuesFromDatabase(); + CDObjectSkillsTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase()); + CDPhysicsComponentTable::Instance().LoadValuesFromDatabase(); + CDPackageComponentTable::Instance().LoadValuesFromDatabase(); + CDPetComponentTable::Instance().LoadValuesFromDatabase(); + CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase(); + CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase(); + CDPropertyTemplateTable::Instance().LoadValuesFromDatabase(); + CDRailActivatorComponentTable::Instance().LoadValuesFromDatabase(); + CDRarityTableTable::Instance().LoadValuesFromDatabase(); + CDRebuildComponentTable::Instance().LoadValuesFromDatabase(); + CDRewardCodesTable::Instance().LoadValuesFromDatabase(); + CDRewardsTable::Instance().LoadValuesFromDatabase(); + CDScriptComponentTable::Instance().LoadValuesFromDatabase(); + CDSkillBehaviorTable::Instance().LoadValuesFromDatabase(); + CDVendorComponentTable::Instance().LoadValuesFromDatabase(); + CDZoneTableTable::Instance().LoadValuesFromDatabase(); + } else { + LOG("Unable to connect to CDClientDatabase! Using default values instead!"); + + CDPetComponentTable::Instance().LoadValuesFromDefaults(); + } } diff --git a/dDatabase/CDClientDatabase/CDClientManager.h b/dDatabase/CDClientDatabase/CDClientManager.h index 74069ff45..06f237cff 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.h +++ b/dDatabase/CDClientDatabase/CDClientManager.h @@ -11,6 +11,9 @@ */ class CDClientManager : public Singleton { public: + /** + * Constructor for CDClientManager + */ CDClientManager(); /** diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp new file mode 100644 index 000000000..97c529826 --- /dev/null +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp @@ -0,0 +1,63 @@ +#include "CDPetComponentTable.h" + +namespace { + // Default entries for fallback + CDPetComponent defaultEntry { + .id = static_cast(-1), + UNUSED_DEFAULT(.minTameUpdateTime = 60.0f,) + UNUSED_DEFAULT(.maxTameUpdateTime = 300.0f,) + UNUSED_DEFAULT(.percentTameChance = 101.0f,) + UNUSED_DEFAULT(.tameability = 100.0f,) + UNUSED_DEFAULT(.elementType = 1,) + .walkSpeed = 2.5f, + .runSpeed = 5.0f, + .sprintSpeed = 10.0f, + UNUSED_DEFAULT(.idleTimeMin = 60.0f,) + UNUSED_DEFAULT(.idleTimeMax = 300.0f,) + UNUSED_DEFAULT(.petForm = 0,) + .imaginationDrainRate = 60.0f, + UNUSED_DEFAULT(.AudioMetaEventSet = "",) + UNUSED_DEFAULT(.buffIDs = "",) + }; +} + +void CDPetComponentTable::LoadValuesFromDatabase() { + auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PetComponent"); + while (!tableData.eof()) { + CDPetComponent entry; + entry.id = tableData.getIntField("id", defaultEntry.id); + UNUSED_COLUMN(entry.minTameUpdateTime = tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime);) + UNUSED_COLUMN(entry.maxTameUpdateTime = tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime);) + UNUSED_COLUMN(entry.percentTameChance = tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance);) + UNUSED_COLUMN(entry.tameability = tableData.getFloatField("tamability", defaultEntry.tameability);) // Mispelled as "tamability" in CDClient + UNUSED_COLUMN(entry.elementType = tableData.getIntField("elementType", defaultEntry.elementType);) + entry.walkSpeed = tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed); + entry.runSpeed = tableData.getFloatField("runSpeed", defaultEntry.runSpeed); + entry.sprintSpeed = tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed); + UNUSED_COLUMN(entry.idleTimeMin = tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin);) + UNUSED_COLUMN(entry.idleTimeMax = tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax);) + UNUSED_COLUMN(entry.petForm = tableData.getIntField("petForm", 0);) + entry.imaginationDrainRate = tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate); + UNUSED_COLUMN(entry.AudioMetaEventSet = tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet);) + UNUSED_COLUMN(entry.buffIDs = tableData.getStringField("buffIDs", defaultEntry.buffIDs);) + + m_entries.insert(std::make_pair(entry.id, entry)); + tableData.nextRow(); + } + + tableData.finalize(); + +} + +void CDPetComponentTable::LoadValuesFromDefaults() { + m_entries.insert(std::make_pair(defaultEntry.id, defaultEntry)); +} + +CDPetComponent& CDPetComponentTable::GetByID(unsigned int componentID) { + auto itr = m_entries.find(componentID); + if (itr == m_entries.end()) { + LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID); + return defaultEntry; + } + return itr->second; +} diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h new file mode 100644 index 000000000..5a2120214 --- /dev/null +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h @@ -0,0 +1,49 @@ +#pragma once +#include "CDTable.h" +#include + +struct CDPetComponent { + unsigned int id; + UNUSED_COLUMN(float minTameUpdateTime;) + UNUSED_COLUMN(float maxTameUpdateTime;) + UNUSED_COLUMN(float percentTameChance;) + UNUSED_COLUMN(float tameability;) // Mispelled as "tamability" in CDClient + UNUSED_COLUMN(unsigned int elementType;) + float walkSpeed; + float runSpeed; + float sprintSpeed; + UNUSED_COLUMN(float idleTimeMin;) + UNUSED_COLUMN(float idleTimeMax;) + UNUSED_COLUMN(unsigned int petForm;) + float imaginationDrainRate; + UNUSED_COLUMN(std::string AudioMetaEventSet;) + UNUSED_COLUMN(std::string buffIDs;) +}; + +class CDPetComponentTable : public CDTable { +public: + + /** + * Load values from the CD client database + */ + void LoadValuesFromDatabase(); + + /** + * Load the default values into memory instead of attempting to connect to the CD client database + */ + void LoadValuesFromDefaults(); + + /** + * @returns The name of the table + */ + static const std::string GetTableName() { return "PetComponent"; }; + + /** + * Gets the pet component table corresponding to the pet component ID + * @returns A reference to the corresponding table, or the default if one could not be found + */ + CDPetComponent& GetByID(unsigned int componentID); + +private: + std::map m_entries; +}; diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDTable.h index 0a8f29adb..3569a8614 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDTable.h @@ -23,6 +23,9 @@ // Enable this to skip some unused columns in some tables #define UNUSED_COLUMN(v) +// Use this to skip unused defaults for unused columns in some tables +#define UNUSED_DEFAULT(v, x) + #pragma warning (disable : 4244) //Disable double to float conversion warnings #pragma warning (disable : 4715) //Disable "not all control paths return a value" diff --git a/dDatabase/CDClientDatabase/CDClientTables/CMakeLists.txt b/dDatabase/CDClientDatabase/CDClientTables/CMakeLists.txt index b2551efa3..af401db29 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CMakeLists.txt +++ b/dDatabase/CDClientDatabase/CDClientTables/CMakeLists.txt @@ -23,6 +23,7 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp" "CDMovementAIComponentTable.cpp" "CDObjectSkillsTable.cpp" "CDObjectsTable.cpp" + "CDPetComponentTable.cpp" "CDPackageComponentTable.cpp" "CDPhysicsComponentTable.cpp" "CDPropertyEntranceComponentTable.cpp" diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index 4e969ced6..9cc92c26a 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -34,7 +34,6 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): m_MovementAI = nullptr; m_Disabled = false; m_SkillEntries = {}; - m_MovementAI = nullptr; m_SoftTimer = 5.0f; //Grab the aggro information from BaseCombatAI: diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index 902edffe0..8205f92dd 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -69,7 +69,8 @@ std::map PetComponent::petFlags = { { 13067, 838 }, // Skeleton dragon }; -PetComponent::PetComponent(Entity* parent, uint32_t componentId): Component(parent) { +PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity }, + m_PetInfo{ CDClientManager::Instance().GetTable()->GetByID(componentId) } { m_ComponentId = componentId; m_Interaction = LWOOBJID_EMPTY; @@ -81,31 +82,17 @@ PetComponent::PetComponent(Entity* parent, uint32_t componentId): Component(pare m_TimerAway = 0; m_DatabaseId = LWOOBJID_EMPTY; m_Status = 67108866; // Tamable - m_Ability = PetAbilityType::Invalid; + m_Ability = ePetAbilityType::Invalid; m_StartPosition = NiPoint3::ZERO; m_MovementAI = nullptr; m_TresureTime = 0; m_Preconditions = nullptr; - std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parent->GetVar(u"CheckPrecondition")); + std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parentEntity->GetVar(u"CheckPrecondition")); if (!checkPreconditions.empty()) { SetPreconditions(checkPreconditions); } - // Get the imagination drain rate from the CDClient - auto query = CDClientDatabase::CreatePreppedStmt("SELECT imaginationDrainRate FROM PetComponent WHERE id = ?;"); - - query.bind(1, static_cast(componentId)); - - auto result = query.execQuery(); - - // Should a result not exist for this pet default to 60 seconds. - if (!result.eof() && !result.fieldIsNull(0)) { - imaginationDrainRate = result.getFloatField(0, 60.0f); - } else { - imaginationDrainRate = 60.0f; - } - result.finalize(); } void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) { @@ -114,7 +101,7 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd outBitStream->Write1(); // Always serialize as dirty for now outBitStream->Write(m_Status); - outBitStream->Write(tamed ? m_Ability : PetAbilityType::Invalid); // Something with the overhead icon? + outBitStream->Write(tamed ? m_Ability : ePetAbilityType::Invalid); // Something with the overhead icon? const bool interacting = m_Interaction != LWOOBJID_EMPTY; @@ -835,11 +822,11 @@ void PetComponent::Wander() { return; } - m_MovementAI->SetMaxSpeed(info.wanderSpeed); + m_MovementAI->SetMaxSpeed(m_PetInfo.sprintSpeed); m_MovementAI->SetDestination(destination); - m_Timer += (m_MovementAI->GetParent()->GetPosition().x - destination.x) / info.wanderSpeed; + m_Timer += (m_MovementAI->GetParent()->GetPosition().x - destination.x) / m_PetInfo.sprintSpeed; } void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { @@ -905,8 +892,6 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) { GameMessages::SendRegisterPetDBID(m_Owner, m_DatabaseId, owner->GetSystemAddress()); } - - GameMessages::SendShowPetActionButton(m_Owner, 3, true, owner->GetSystemAddress()); } void PetComponent::AddDrainImaginationTimer(Item* item, bool fromTaming) { @@ -928,22 +913,22 @@ void PetComponent::AddDrainImaginationTimer(Item* item, bool fromTaming) { if (!fromTaming) playerDestroyableComponent->Imagine(-1); // Set this to a variable so when this is called back from the player the timer doesn't fire off. - m_Parent->AddCallbackTimer(imaginationDrainRate, [playerDestroyableComponent, this, item]() { + m_Parent->AddCallbackTimer(m_PetInfo.imaginationDrainRate, [playerDestroyableComponent, this, item]() { if (!playerDestroyableComponent) { LOG("No petComponent and/or no playerDestroyableComponent"); return; } - // If we are out of imagination despawn the pet. - if (playerDestroyableComponent->GetImagination() == 0) { - this->Deactivate(); - auto playerEntity = playerDestroyableComponent->GetParent(); - if (!playerEntity) return; + // If we are out of imagination despawn the pet. + if (playerDestroyableComponent->GetImagination() == 0) { + this->Deactivate(); + auto playerEntity = playerDestroyableComponent->GetParent(); + if (!playerEntity) return; - GameMessages::SendUseItemRequirementsResponse(playerEntity->GetObjectID(), playerEntity->GetSystemAddress(), eUseItemResponse::NoImaginationForPet); - } + GameMessages::SendUseItemRequirementsResponse(playerEntity->GetObjectID(), playerEntity->GetSystemAddress(), eUseItemResponse::NoImaginationForPet); + } - this->AddDrainImaginationTimer(item); + this->AddDrainImaginationTimer(item); }); } @@ -966,7 +951,7 @@ void PetComponent::Deactivate() { GameMessages::SendRegisterPetDBID(m_Owner, LWOOBJID_EMPTY, owner->GetSystemAddress()); - GameMessages::SendShowPetActionButton(m_Owner, 0, false, owner->GetSystemAddress()); + GameMessages::SendShowPetActionButton(m_Owner, ePetAbilityType::Invalid, false, owner->GetSystemAddress()); } void PetComponent::Release() { @@ -985,12 +970,9 @@ void PetComponent::Release() { item->SetCount(0, false, false); } -void PetComponent::Command(NiPoint3 position, LWOOBJID source, int32_t commandType, int32_t typeId, bool overrideObey) { +void PetComponent::Command(const NiPoint3& position, const LWOOBJID source, const int32_t commandType, const int32_t typeId, const bool overrideObey) { auto* owner = GetOwner(); - - if (owner == nullptr) { - return; - } + if (!owner) return; if (commandType == 1) { // Emotes @@ -1030,7 +1012,7 @@ uint32_t PetComponent::GetStatus() const { return m_Status; } -PetAbilityType PetComponent::GetAbility() const { +ePetAbilityType PetComponent::GetAbility() const { return m_Ability; } @@ -1042,7 +1024,7 @@ void PetComponent::SetStatus(uint32_t value) { m_Status = value; } -void PetComponent::SetAbility(PetAbilityType value) { +void PetComponent::SetAbility(ePetAbilityType value) { m_Ability = value; } @@ -1098,7 +1080,7 @@ void PetComponent::SetPetNameForModeration(const std::string& petName) { } //Save to db: - Database::Get()->SetPetNameModerationStatus(m_DatabaseId, IPetNames::Info{petName, approved}); + Database::Get()->SetPetNameModerationStatus(m_DatabaseId, IPetNames::Info{ petName, approved }); } void PetComponent::LoadPetNameFromModeration() { diff --git a/dGame/dComponents/PetComponent.h b/dGame/dComponents/PetComponent.h index ca4b5a747..16ac59789 100644 --- a/dGame/dComponents/PetComponent.h +++ b/dGame/dComponents/PetComponent.h @@ -1,18 +1,13 @@ -#pragma once +#ifndef PETCOMPONENT_H +#define PETCOMPONENT_H #include "Entity.h" #include "MovementAIComponent.h" #include "Component.h" #include "Preconditions.h" +#include "ePetAbilityType.h" #include "eReplicaComponentType.h" - -enum class PetAbilityType : uint32_t -{ - Invalid, - GoToObject, - JumpOnObject, - DigAtPosition -}; +#include "CDPetComponentTable.h" /** * Represents an entity that is a pet. This pet can be tamed and consequently follows the tamer around, allowing it @@ -103,7 +98,7 @@ class PetComponent : public Component * @param typeId extra information about the command, e.g. the emote to play * @param overrideObey unused */ - void Command(NiPoint3 position, LWOOBJID source, int32_t commandType, int32_t typeId, bool overrideObey); + void Command(const NiPoint3& position, const LWOOBJID source, const int32_t commandType, const int32_t typeId, const bool overrideObey); /** * Returns the ID of the owner of this pet (if any) @@ -158,13 +153,13 @@ class PetComponent : public Component * Returns an ability the pet may perform, currently unused * @return an ability the pet may perform */ - PetAbilityType GetAbility() const; + ePetAbilityType GetAbility() const; /** * Sets the ability of the pet, currently unused * @param value the ability to set */ - void SetAbility(PetAbilityType value); + void SetAbility(ePetAbilityType value); /** * Sets preconditions for the pet that need to be met before it can be tamed @@ -323,7 +318,7 @@ class PetComponent : public Component /** * A currently active ability, mostly unused */ - PetAbilityType m_Ability; + ePetAbilityType m_Ability; /** * The time an entity has left to complete the minigame @@ -357,7 +352,9 @@ class PetComponent : public Component PreconditionExpression* m_Preconditions; /** - * The rate at which imagination is drained from the user for having the pet out. + * Pet information loaded from the CDClientDatabase */ - float imaginationDrainRate; + CDPetComponent& m_PetInfo; }; + +#endif // !PETCOMPONENT_H diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index eb6f11bb9..c1da26c4b 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -95,6 +95,7 @@ #include "eReplicaComponentType.h" #include "eClientMessageType.h" #include "eGameMessageType.h" +#include "ePetAbilityType.h" #include "ActivityManager.h" #include "CDComponentsRegistryTable.h" @@ -3520,14 +3521,14 @@ void GameMessages::SendClientExitTamingMinigame(LWOOBJID objectId, bool bVolunta SEND_PACKET; } -void GameMessages::SendShowPetActionButton(LWOOBJID objectId, int32_t buttonLabel, bool bShow, const SystemAddress& sysAddr) { +void GameMessages::SendShowPetActionButton(const LWOOBJID objectId, const ePetAbilityType petAbility, const bool bShow, const SystemAddress& sysAddr) { CBITSTREAM; CMSGHEADER; bitStream.Write(objectId); bitStream.Write(eGameMessageType::SHOW_PET_ACTION_BUTTON); - bitStream.Write(buttonLabel); + bitStream.Write(petAbility); bitStream.Write(bShow); if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST; diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 6d29a3946..0011790c4 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -10,6 +10,7 @@ #include "eEndBehavior.h" #include "eCyclingMode.h" #include "eLootSourceType.h" +#include "ePetAbilityType.h" #include "Brick.h" class AMFBaseValue; @@ -386,7 +387,7 @@ namespace GameMessages { void SendClientExitTamingMinigame(LWOOBJID objectId, bool bVoluntaryExit, const SystemAddress& sysAddr); - void SendShowPetActionButton(LWOOBJID objectId, int32_t buttonLabel, bool bShow, const SystemAddress& sysAddr); + void SendShowPetActionButton(const LWOOBJID objectId, const ePetAbilityType petAbility, const bool bShow, const SystemAddress& sysAddr); void SendPlayEmote(LWOOBJID objectId, int32_t emoteID, LWOOBJID target, const SystemAddress& sysAddr); diff --git a/tests/dGameTests/GameDependencies.h b/tests/dGameTests/GameDependencies.h index 096dcb13e..e1c0d7068 100644 --- a/tests/dGameTests/GameDependencies.h +++ b/tests/dGameTests/GameDependencies.h @@ -4,6 +4,8 @@ #include "Game.h" #include "Logger.h" #include "dServer.h" +#include "CDClientManager.h" +#include "CDPetComponentTable.h" #include "EntityInfo.h" #include "EntityManager.h" #include "dConfig.h" @@ -33,6 +35,9 @@ class GameDependenciesTest : public ::testing::Test { Game::server = new dServerMock(); Game::config = new dConfig("worldconfig.ini"); Game::entityManager = new EntityManager(); + + // Create a CDClientManager instance + CDClientManager::Instance(); } void TearDownDependencies() { diff --git a/tests/dGameTests/dComponentsTests/CMakeLists.txt b/tests/dGameTests/dComponentsTests/CMakeLists.txt index e38f7a535..374095af0 100644 --- a/tests/dGameTests/dComponentsTests/CMakeLists.txt +++ b/tests/dGameTests/dComponentsTests/CMakeLists.txt @@ -1,5 +1,6 @@ set(DCOMPONENTS_TESTS "DestroyableComponentTests.cpp" + "PetComponentTests.cpp" "SimplePhysicsComponentTests.cpp" ) diff --git a/tests/dGameTests/dComponentsTests/PetComponentTests.cpp b/tests/dGameTests/dComponentsTests/PetComponentTests.cpp new file mode 100644 index 000000000..75ce4ec83 --- /dev/null +++ b/tests/dGameTests/dComponentsTests/PetComponentTests.cpp @@ -0,0 +1,43 @@ +#include "GameDependencies.h" +#include + +#include "BitStream.h" +#include "PetComponent.h" +#include "Entity.h" +#include "eReplicaComponentType.h" +#include "ePetAbilityType.h" +#include "eStateChangeType.h" + +class PetTest : public GameDependenciesTest { +protected: + Entity* baseEntity; + PetComponent* petComponent; + CBITSTREAM + + void SetUp() override { + SetUpDependencies(); + + // Set up entity and pet component + baseEntity = new Entity(15, GameDependenciesTest::info); + petComponent = baseEntity->AddComponent(1); + + // Initialize some values to be not default + + } + + void TearDown() override { + delete baseEntity; + TearDownDependencies(); + } +}; + +TEST_F(PetTest, PlacementNewAddComponentTest) { + // Test adding component + ASSERT_NE(petComponent, nullptr); + baseEntity->AddComponent(1); + ASSERT_NE(baseEntity->GetComponent(), nullptr); + + // Test getting initial status + ASSERT_EQ(petComponent->GetParent()->GetObjectID(), 15); + ASSERT_EQ(petComponent->GetAbility(), ePetAbilityType::Invalid); +} From e0f390c4c99f6597aed573592ca695f4624fd206 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sat, 6 Jan 2024 16:05:12 -0600 Subject: [PATCH 02/10] remove unecessary include --- tests/dGameTests/GameDependencies.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/dGameTests/GameDependencies.h b/tests/dGameTests/GameDependencies.h index e1c0d7068..08d09d18f 100644 --- a/tests/dGameTests/GameDependencies.h +++ b/tests/dGameTests/GameDependencies.h @@ -5,7 +5,6 @@ #include "Logger.h" #include "dServer.h" #include "CDClientManager.h" -#include "CDPetComponentTable.h" #include "EntityInfo.h" #include "EntityManager.h" #include "dConfig.h" From 786e840f7aa704825039e01538834b3ffc476d79 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 7 Jan 2024 16:10:29 -0600 Subject: [PATCH 03/10] updates to address some feedback --- dCommon/dEnums/ePetAbilityType.h | 4 +- dDatabase/CDClientDatabase/CDClientManager.h | 3 - .../CDClientTables/CDPetComponentTable.cpp | 72 +++++++++---------- .../CDClientTables/CDPetComponentTable.h | 16 ++--- .../CDClientDatabase/CDClientTables/CDTable.h | 4 +- dGame/dGameMessages/GameMessages.h | 2 +- 6 files changed, 48 insertions(+), 53 deletions(-) diff --git a/dCommon/dEnums/ePetAbilityType.h b/dCommon/dEnums/ePetAbilityType.h index 3b2e55204..0cc6d6bd7 100644 --- a/dCommon/dEnums/ePetAbilityType.h +++ b/dCommon/dEnums/ePetAbilityType.h @@ -1,7 +1,9 @@ #ifndef __EPETABILITYTYPE__H__ #define __EPETABILITYTYPE__H__ -enum class ePetAbilityType : int32_t { +#include + +enum class ePetAbilityType : uint32_t { Invalid, GoToObject, JumpOnObject, diff --git a/dDatabase/CDClientDatabase/CDClientManager.h b/dDatabase/CDClientDatabase/CDClientManager.h index 06f237cff..74069ff45 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.h +++ b/dDatabase/CDClientDatabase/CDClientManager.h @@ -11,9 +11,6 @@ */ class CDClientManager : public Singleton { public: - /** - * Constructor for CDClientManager - */ CDClientManager(); /** diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp index 97c529826..778605263 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp @@ -2,60 +2,60 @@ namespace { // Default entries for fallback - CDPetComponent defaultEntry { - .id = static_cast(-1), - UNUSED_DEFAULT(.minTameUpdateTime = 60.0f,) - UNUSED_DEFAULT(.maxTameUpdateTime = 300.0f,) - UNUSED_DEFAULT(.percentTameChance = 101.0f,) - UNUSED_DEFAULT(.tameability = 100.0f,) - UNUSED_DEFAULT(.elementType = 1,) + CDPetComponent defaultEntry{ + .id = 0, + UNUSED_ENTRY(.minTameUpdateTime = 60.0f,) + UNUSED_ENTRY(.maxTameUpdateTime = 300.0f,) + UNUSED_ENTRY(.percentTameChance = 101.0f,) + UNUSED_ENTRY(.tameability = 100.0f,) + UNUSED_ENTRY(.elementType = 1,) .walkSpeed = 2.5f, .runSpeed = 5.0f, .sprintSpeed = 10.0f, - UNUSED_DEFAULT(.idleTimeMin = 60.0f,) - UNUSED_DEFAULT(.idleTimeMax = 300.0f,) - UNUSED_DEFAULT(.petForm = 0,) + UNUSED_ENTRY(.idleTimeMin = 60.0f,) + UNUSED_ENTRY(.idleTimeMax = 300.0f,) + UNUSED_ENTRY(.petForm = 0,) .imaginationDrainRate = 60.0f, - UNUSED_DEFAULT(.AudioMetaEventSet = "",) - UNUSED_DEFAULT(.buffIDs = "",) + UNUSED_ENTRY(.AudioMetaEventSet = "",) + UNUSED_ENTRY(.buffIDs = "",) }; } void CDPetComponentTable::LoadValuesFromDatabase() { auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PetComponent"); while (!tableData.eof()) { - CDPetComponent entry; - entry.id = tableData.getIntField("id", defaultEntry.id); - UNUSED_COLUMN(entry.minTameUpdateTime = tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime);) - UNUSED_COLUMN(entry.maxTameUpdateTime = tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime);) - UNUSED_COLUMN(entry.percentTameChance = tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance);) - UNUSED_COLUMN(entry.tameability = tableData.getFloatField("tamability", defaultEntry.tameability);) // Mispelled as "tamability" in CDClient - UNUSED_COLUMN(entry.elementType = tableData.getIntField("elementType", defaultEntry.elementType);) - entry.walkSpeed = tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed); - entry.runSpeed = tableData.getFloatField("runSpeed", defaultEntry.runSpeed); - entry.sprintSpeed = tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed); - UNUSED_COLUMN(entry.idleTimeMin = tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin);) - UNUSED_COLUMN(entry.idleTimeMax = tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax);) - UNUSED_COLUMN(entry.petForm = tableData.getIntField("petForm", 0);) - entry.imaginationDrainRate = tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate); - UNUSED_COLUMN(entry.AudioMetaEventSet = tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet);) - UNUSED_COLUMN(entry.buffIDs = tableData.getStringField("buffIDs", defaultEntry.buffIDs);) + const uint32_t componentID = tableData.getIntField("id", defaultEntry.id); + + m_Entries.try_emplace( + componentID, + componentID, + UNUSED_ENTRY(tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime),) + UNUSED_ENTRY(tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime),) + UNUSED_ENTRY(tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance),) + UNUSED_ENTRY(tableData.getFloatField("tamability", defaultEntry.tameability),) // Mispelled as "tamability" in CDClient + UNUSED_ENTRY(tableData.getIntField("elementType", defaultEntry.elementType),) + static_cast(tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed)), + static_cast(tableData.getFloatField("runSpeed", defaultEntry.runSpeed)), + static_cast(tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed)), + UNUSED_ENTRY(tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin),) + UNUSED_ENTRY(tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax),) + UNUSED_ENTRY(tableData.getIntField("petForm", 0),) + static_cast(tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate)) + UNUSED_ENTRY(tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet),) + UNUSED_ENTRY(tableData.getStringField("buffIDs", defaultEntry.buffIDs),) + ); - m_entries.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } - - tableData.finalize(); - } void CDPetComponentTable::LoadValuesFromDefaults() { - m_entries.insert(std::make_pair(defaultEntry.id, defaultEntry)); + m_Entries.insert(std::make_pair(defaultEntry.id, defaultEntry)); } -CDPetComponent& CDPetComponentTable::GetByID(unsigned int componentID) { - auto itr = m_entries.find(componentID); - if (itr == m_entries.end()) { +CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) { + auto itr = m_Entries.find(componentID); + if (itr == m_Entries.end()) { LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID); return defaultEntry; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h index 5a2120214..fa54e4573 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h @@ -1,20 +1,21 @@ #pragma once #include "CDTable.h" +#include #include struct CDPetComponent { - unsigned int id; + uint32_t id; UNUSED_COLUMN(float minTameUpdateTime;) UNUSED_COLUMN(float maxTameUpdateTime;) UNUSED_COLUMN(float percentTameChance;) UNUSED_COLUMN(float tameability;) // Mispelled as "tamability" in CDClient - UNUSED_COLUMN(unsigned int elementType;) + UNUSED_COLUMN(uint32_t elementType;) float walkSpeed; float runSpeed; float sprintSpeed; UNUSED_COLUMN(float idleTimeMin;) UNUSED_COLUMN(float idleTimeMax;) - UNUSED_COLUMN(unsigned int petForm;) + UNUSED_COLUMN(uint32_t petForm;) float imaginationDrainRate; UNUSED_COLUMN(std::string AudioMetaEventSet;) UNUSED_COLUMN(std::string buffIDs;) @@ -33,17 +34,12 @@ class CDPetComponentTable : public CDTable { */ void LoadValuesFromDefaults(); - /** - * @returns The name of the table - */ - static const std::string GetTableName() { return "PetComponent"; }; - /** * Gets the pet component table corresponding to the pet component ID * @returns A reference to the corresponding table, or the default if one could not be found */ - CDPetComponent& GetByID(unsigned int componentID); + CDPetComponent& GetByID(const uint32_t componentID); private: - std::map m_entries; + std::map m_Entries; }; diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDTable.h index 3569a8614..ab9651279 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDTable.h @@ -23,8 +23,8 @@ // Enable this to skip some unused columns in some tables #define UNUSED_COLUMN(v) -// Use this to skip unused defaults for unused columns in some tables -#define UNUSED_DEFAULT(v, x) +// Use this to skip unused defaults for unused entries in some tables +#define UNUSED_ENTRY(v, x) #pragma warning (disable : 4244) //Disable double to float conversion warnings #pragma warning (disable : 4715) //Disable "not all control paths return a value" diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 0011790c4..9c8d183e6 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -10,7 +10,6 @@ #include "eEndBehavior.h" #include "eCyclingMode.h" #include "eLootSourceType.h" -#include "ePetAbilityType.h" #include "Brick.h" class AMFBaseValue; @@ -33,6 +32,7 @@ enum class eObjectWorldState : uint32_t; enum class eTerminateType : uint32_t; enum class eControlScheme : uint32_t; enum class eStateChangeType : uint32_t; +enum class ePetAbilityType : uint32_t; enum class ePetTamingNotifyType : uint32_t; enum class eUseItemResponse : uint32_t; enum class eQuickBuildFailReason : uint32_t; From 6bdce1ab5193ae2d5ede60e47aaf5d3d4f2b0a09 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 7 Jan 2024 20:22:54 -0600 Subject: [PATCH 04/10] fixed database code for testing --- CMakeLists.txt | 2 +- .../CDClientDatabase/CDClientManager.cpp | 104 ++++++++++-------- dDatabase/CDClientDatabase/CDClientManager.h | 5 +- .../CDClientTables/CDPetComponentTable.cpp | 34 +++--- dWorldServer/WorldServer.cpp | 2 +- tests/dGameTests/GameDependencies.h | 4 +- 6 files changed, 82 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd6577722..961064429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "" FORCE) # Disabled no-register # Disabled unknown pragmas because Linux doesn't understand Windows pragmas. if(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -O2 -Wuninitialized -fPIC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20 -O2 -Wuninitialized -fPIC") add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0) if(NOT APPLE) diff --git a/dDatabase/CDClientDatabase/CDClientManager.cpp b/dDatabase/CDClientDatabase/CDClientManager.cpp index 74e79f2b9..f270d8493 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.cpp +++ b/dDatabase/CDClientDatabase/CDClientManager.cpp @@ -3,6 +3,7 @@ #include "CDAnimationsTable.h" #include "CDBehaviorParameterTable.h" #include "CDBehaviorTemplateTable.h" +#include "CDClientDatabase.h" #include "CDComponentsRegistryTable.h" #include "CDCurrencyTableTable.h" #include "CDDestructibleComponentTable.h" @@ -39,6 +40,8 @@ #include "CDRailActivatorComponent.h" #include "CDRewardCodesTable.h" +#include + #ifndef CDCLIENT_CACHE_ALL // Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory. // A vanilla CDClient takes about 46MB of memory + the regular world data. @@ -51,51 +54,60 @@ #define CDCLIENT_DONT_CACHE_TABLE(x) #endif -CDClientManager::CDClientManager() { - if (CDClientDatabase::isConnected) { - CDActivityRewardsTable::Instance().LoadValuesFromDatabase(); - CDActivitiesTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase()); - CDBehaviorParameterTable::Instance().LoadValuesFromDatabase(); - CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase(); - CDBrickIDTableTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDComponentsRegistryTable::Instance().LoadValuesFromDatabase()); - CDCurrencyTableTable::Instance().LoadValuesFromDatabase(); - CDDestructibleComponentTable::Instance().LoadValuesFromDatabase(); - CDEmoteTableTable::Instance().LoadValuesFromDatabase(); - CDFeatureGatingTable::Instance().LoadValuesFromDatabase(); - CDInventoryComponentTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDItemComponentTable::Instance().LoadValuesFromDatabase()); - CDItemSetSkillsTable::Instance().LoadValuesFromDatabase(); - CDItemSetsTable::Instance().LoadValuesFromDatabase(); - CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDLootMatrixTable::Instance().LoadValuesFromDatabase()); - CDCLIENT_DONT_CACHE_TABLE(CDLootTableTable::Instance().LoadValuesFromDatabase()); - CDMissionEmailTable::Instance().LoadValuesFromDatabase(); - CDMissionNPCComponentTable::Instance().LoadValuesFromDatabase(); - CDMissionTasksTable::Instance().LoadValuesFromDatabase(); - CDMissionsTable::Instance().LoadValuesFromDatabase(); - CDMovementAIComponentTable::Instance().LoadValuesFromDatabase(); - CDObjectSkillsTable::Instance().LoadValuesFromDatabase(); - CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase()); - CDPhysicsComponentTable::Instance().LoadValuesFromDatabase(); - CDPackageComponentTable::Instance().LoadValuesFromDatabase(); - CDPetComponentTable::Instance().LoadValuesFromDatabase(); - CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase(); - CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase(); - CDPropertyTemplateTable::Instance().LoadValuesFromDatabase(); - CDRailActivatorComponentTable::Instance().LoadValuesFromDatabase(); - CDRarityTableTable::Instance().LoadValuesFromDatabase(); - CDRebuildComponentTable::Instance().LoadValuesFromDatabase(); - CDRewardCodesTable::Instance().LoadValuesFromDatabase(); - CDRewardsTable::Instance().LoadValuesFromDatabase(); - CDScriptComponentTable::Instance().LoadValuesFromDatabase(); - CDSkillBehaviorTable::Instance().LoadValuesFromDatabase(); - CDVendorComponentTable::Instance().LoadValuesFromDatabase(); - CDZoneTableTable::Instance().LoadValuesFromDatabase(); - } else { - LOG("Unable to connect to CDClientDatabase! Using default values instead!"); - - CDPetComponentTable::Instance().LoadValuesFromDefaults(); +class CDClientConnectionException : public std::exception { +public: + virtual const char* what() const throw() { + return "CDClientDatabase is not connected!"; } +}; + +void CDClientManager::LoadValuesFromDatabase() { + if (!CDClientDatabase::isConnected) throw CDClientConnectionException(); + + CDActivityRewardsTable::Instance().LoadValuesFromDatabase(); + CDActivitiesTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase()); + CDBehaviorParameterTable::Instance().LoadValuesFromDatabase(); + CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase(); + CDBrickIDTableTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDComponentsRegistryTable::Instance().LoadValuesFromDatabase()); + CDCurrencyTableTable::Instance().LoadValuesFromDatabase(); + CDDestructibleComponentTable::Instance().LoadValuesFromDatabase(); + CDEmoteTableTable::Instance().LoadValuesFromDatabase(); + CDFeatureGatingTable::Instance().LoadValuesFromDatabase(); + CDInventoryComponentTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDItemComponentTable::Instance().LoadValuesFromDatabase()); + CDItemSetSkillsTable::Instance().LoadValuesFromDatabase(); + CDItemSetsTable::Instance().LoadValuesFromDatabase(); + CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDLootMatrixTable::Instance().LoadValuesFromDatabase()); + CDCLIENT_DONT_CACHE_TABLE(CDLootTableTable::Instance().LoadValuesFromDatabase()); + CDMissionEmailTable::Instance().LoadValuesFromDatabase(); + CDMissionNPCComponentTable::Instance().LoadValuesFromDatabase(); + CDMissionTasksTable::Instance().LoadValuesFromDatabase(); + CDMissionsTable::Instance().LoadValuesFromDatabase(); + CDMovementAIComponentTable::Instance().LoadValuesFromDatabase(); + CDObjectSkillsTable::Instance().LoadValuesFromDatabase(); + CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase()); + CDPhysicsComponentTable::Instance().LoadValuesFromDatabase(); + CDPackageComponentTable::Instance().LoadValuesFromDatabase(); + CDPetComponentTable::Instance().LoadValuesFromDatabase(); + CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase(); + CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase(); + CDPropertyTemplateTable::Instance().LoadValuesFromDatabase(); + CDRailActivatorComponentTable::Instance().LoadValuesFromDatabase(); + CDRarityTableTable::Instance().LoadValuesFromDatabase(); + CDRebuildComponentTable::Instance().LoadValuesFromDatabase(); + CDRewardCodesTable::Instance().LoadValuesFromDatabase(); + CDRewardsTable::Instance().LoadValuesFromDatabase(); + CDScriptComponentTable::Instance().LoadValuesFromDatabase(); + CDSkillBehaviorTable::Instance().LoadValuesFromDatabase(); + CDVendorComponentTable::Instance().LoadValuesFromDatabase(); + CDZoneTableTable::Instance().LoadValuesFromDatabase(); +} + +void CDClientManager::LoadValuesFromDefaults() { + LOG("Loading default CDClient tables!"); + + CDPetComponentTable::Instance().LoadValuesFromDefaults(); } diff --git a/dDatabase/CDClientDatabase/CDClientManager.h b/dDatabase/CDClientDatabase/CDClientManager.h index 74069ff45..ae628a369 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.h +++ b/dDatabase/CDClientDatabase/CDClientManager.h @@ -11,7 +11,10 @@ */ class CDClientManager : public Singleton { public: - CDClientManager(); + CDClientManager() = default; + + void LoadValuesFromDatabase(); + void LoadValuesFromDefaults(); /** * Fetch a table from CDClient diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp index 778605263..c3dd5d508 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp @@ -26,24 +26,22 @@ void CDPetComponentTable::LoadValuesFromDatabase() { while (!tableData.eof()) { const uint32_t componentID = tableData.getIntField("id", defaultEntry.id); - m_Entries.try_emplace( - componentID, - componentID, - UNUSED_ENTRY(tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime),) - UNUSED_ENTRY(tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime),) - UNUSED_ENTRY(tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance),) - UNUSED_ENTRY(tableData.getFloatField("tamability", defaultEntry.tameability),) // Mispelled as "tamability" in CDClient - UNUSED_ENTRY(tableData.getIntField("elementType", defaultEntry.elementType),) - static_cast(tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed)), - static_cast(tableData.getFloatField("runSpeed", defaultEntry.runSpeed)), - static_cast(tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed)), - UNUSED_ENTRY(tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin),) - UNUSED_ENTRY(tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax),) - UNUSED_ENTRY(tableData.getIntField("petForm", 0),) - static_cast(tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate)) - UNUSED_ENTRY(tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet),) - UNUSED_ENTRY(tableData.getStringField("buffIDs", defaultEntry.buffIDs),) - ); + auto& entry = m_Entries[componentID]; + entry.id = componentID; + UNUSED_COLUMN(entry.minTameUpdateTime = tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime)); + UNUSED_COLUMN(entry.maxTameUpdateTime = tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime)); + UNUSED_COLUMN(entry.percentTameChance = tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance)); + UNUSED_COLUMN(entry.tameability = tableData.getFloatField("tamability", defaultEntry.tameability)); // Mispelled as "tamability" in CDClient + UNUSED_COLUMN(entry.elementType = tableData.getIntField("elementType", defaultEntry.elementType)); + entry.walkSpeed = static_cast(tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed)); + entry.runSpeed = static_cast(tableData.getFloatField("runSpeed", defaultEntry.runSpeed)); + entry.sprintSpeed = static_cast(tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed)); + UNUSED_COLUMN(entry.idleTimeMin = tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin)); + UNUSED_COLUMN(entry.idleTimeMax = tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax)); + UNUSED_COLUMN(entry.petForm = tableData.getIntField("petForm", defaultEntry.petForm)); + entry.imaginationDrainRate = static_cast(tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate)); + UNUSED_COLUMN(entry.AudioMetaEventSet = tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet)); + UNUSED_COLUMN(entry.buffIDs = tableData.getStringField("buffIDs", defaultEntry.buffIDs)); tableData.nextRow(); } diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index d65596b63..6b75b1b12 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -180,7 +180,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - CDClientManager::Instance(); + CDClientManager::Instance().LoadValuesFromDatabase(); Diagnostics::SetProduceMemoryDump(Game::config->GetValue("generate_dump") == "1"); diff --git a/tests/dGameTests/GameDependencies.h b/tests/dGameTests/GameDependencies.h index 08d09d18f..8aefaa3d5 100644 --- a/tests/dGameTests/GameDependencies.h +++ b/tests/dGameTests/GameDependencies.h @@ -35,8 +35,8 @@ class GameDependenciesTest : public ::testing::Test { Game::config = new dConfig("worldconfig.ini"); Game::entityManager = new EntityManager(); - // Create a CDClientManager instance - CDClientManager::Instance(); + // Create a CDClientManager instance and load from defaults + CDClientManager::Instance().LoadValuesFromDefaults(); } void TearDownDependencies() { From 8ffce0315cbc3552ac3bc1726db6aa922ed781a3 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Sun, 7 Jan 2024 21:00:26 -0600 Subject: [PATCH 05/10] messinng around with tables --- .../CDClientTables/CDLootTableTable.cpp | 20 ++-- .../CDClientTables/CDLootTableTable.h | 13 ++- .../CDClientTables/CDMissionEmailTable.cpp | 13 +-- .../CDClientTables/CDMissionEmailTable.h | 16 +-- .../CDMissionNPCComponentTable.cpp | 14 +-- .../CDMissionNPCComponentTable.h | 9 +- .../CDClientTables/CDMissionTasksTable.cpp | 16 +-- .../CDClientTables/CDMissionTasksTable.h | 32 ++--- .../CDClientTables/CDMissionsTable.cpp | 20 ++-- .../CDClientTables/CDMissionsTable.h | 109 +++++++++--------- .../CDMovementAIComponentTable.cpp | 14 +-- .../CDMovementAIComponentTable.h | 6 +- .../CDClientTables/CDObjectSkillsTable.cpp | 13 +-- .../CDClientTables/CDObjectSkillsTable.h | 12 +- .../CDClientTables/CDObjectsTable.cpp | 46 +++----- .../CDClientTables/CDObjectsTable.h | 22 ++-- .../CDPackageComponentTable.cpp | 11 +- .../CDClientTables/CDPackageComponentTable.h | 10 +- .../CDPhysicsComponentTable.cpp | 45 ++++---- .../CDClientTables/CDPhysicsComponentTable.h | 14 +-- 20 files changed, 216 insertions(+), 239 deletions(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp index 9ee875df7..a1e638860 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp @@ -40,7 +40,7 @@ CDLootTable CDLootTableTable::ReadRow(CppSQLite3Query& tableData) const { void CDLootTableTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM LootTable"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -49,7 +49,7 @@ void CDLootTableTable::LoadValuesFromDatabase() { } // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM LootTable"); @@ -57,17 +57,17 @@ void CDLootTableTable::LoadValuesFromDatabase() { CDLootTable entry; uint32_t lootTableIndex = tableData.getIntField("LootTableIndex", -1); - this->entries[lootTableIndex].push_back(ReadRow(tableData)); + m_Entries[lootTableIndex].push_back(ReadRow(tableData)); tableData.nextRow(); } - for (auto& [id, table] : this->entries) { + for (auto& [id, table] : m_Entries) { SortTable(table); } } -const LootTableEntries& CDLootTableTable::GetTable(uint32_t tableId) { - auto itr = this->entries.find(tableId); - if (itr != this->entries.end()) { +const LootTableEntries& CDLootTableTable::GetTable(const uint32_t tableId) { + auto itr = m_Entries.find(tableId); + if (itr != m_Entries.end()) { return itr->second; } @@ -77,10 +77,10 @@ const LootTableEntries& CDLootTableTable::GetTable(uint32_t tableId) { while (!tableData.eof()) { CDLootTable entry; - this->entries[tableId].push_back(ReadRow(tableData)); + m_Entries[tableId].push_back(ReadRow(tableData)); tableData.nextRow(); } - SortTable(this->entries[tableId]); + SortTable(m_Entries[tableId]); - return this->entries[tableId]; + return m_Entries[tableId]; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.h index b8ac2066f..9419deca0 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.h @@ -3,11 +3,13 @@ // Custom Classes #include "CDTable.h" +#include + struct CDLootTable { - unsigned int itemid; //!< The LOT of the item - unsigned int LootTableIndex; //!< The Loot Table Index + uint32_t itemid; //!< The LOT of the item + uint32_t LootTableIndex; //!< The Loot Table Index bool MissionDrop; //!< Whether or not this loot table is a mission drop - unsigned int sortPriority; //!< The sorting priority + uint32_t sortPriority; //!< The sorting priority }; typedef uint32_t LootTableIndex; @@ -16,11 +18,10 @@ typedef std::vector LootTableEntries; class CDLootTableTable : public CDTable { private: CDLootTable ReadRow(CppSQLite3Query& tableData) const; - std::unordered_map entries; + std::unordered_map m_Entries; public: void LoadValuesFromDatabase(); // Queries the table with a custom "where" clause - const LootTableEntries& GetTable(uint32_t tableId); + const LootTableEntries& GetTable(const uint32_t tableId); }; - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp index 0babef13e..4c303da76 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.cpp @@ -3,7 +3,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM MissionEmail"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -14,12 +14,12 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MissionEmail"); while (!tableData.eof()) { - CDMissionEmail entry; + auto& entry = m_Entries.emplace_back(); entry.ID = tableData.getIntField("ID", -1); entry.messageType = tableData.getIntField("messageType", -1); entry.notificationGroup = tableData.getIntField("notificationGroup", -1); @@ -29,17 +29,14 @@ void CDMissionEmailTable::LoadValuesFromDatabase() { entry.locStatus = tableData.getIntField("locStatus", -1); entry.gate_version = tableData.getStringField("gate_version", ""); - this->entries.push_back(entry); tableData.nextRow(); } - - tableData.finalize(); } //! Queries the table with a custom "where" clause std::vector CDMissionEmailTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -48,5 +45,5 @@ std::vector CDMissionEmailTable::Query(std::function& CDMissionEmailTable::GetEntries() const { - return this->entries; + return m_Entries; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.h index 954da78e4..cf68be8fc 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionEmailTable.h @@ -3,21 +3,23 @@ // Custom Classes #include "CDTable.h" +#include + struct CDMissionEmail { - unsigned int ID; - unsigned int messageType; - unsigned int notificationGroup; - unsigned int missionID; - unsigned int attachmentLOT; + uint32_t ID; + uint32_t messageType; + uint32_t notificationGroup; + uint32_t missionID; + uint32_t attachmentLOT; bool localize; - unsigned int locStatus; + uint32_t locStatus; std::string gate_version; }; class CDMissionEmailTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.cpp index 59ea40b7b..89e242957 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.cpp @@ -3,7 +3,7 @@ void CDMissionNPCComponentTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM MissionNPCComponent"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -14,29 +14,26 @@ void CDMissionNPCComponentTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MissionNPCComponent"); while (!tableData.eof()) { - CDMissionNPCComponent entry; + auto& entry = m_Entries.emplace_back(); entry.id = tableData.getIntField("id", -1); entry.missionID = tableData.getIntField("missionID", -1); entry.offersMission = tableData.getIntField("offersMission", -1) == 1 ? true : false; entry.acceptsMission = tableData.getIntField("acceptsMission", -1) == 1 ? true : false; entry.gate_version = tableData.getStringField("gate_version", ""); - this->entries.push_back(entry); tableData.nextRow(); } - - tableData.finalize(); } //! Queries the table with a custom "where" clause std::vector CDMissionNPCComponentTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -45,6 +42,5 @@ std::vector CDMissionNPCComponentTable::Query(std::functi //! Gets all the entries in the table const std::vector& CDMissionNPCComponentTable::GetEntries() const { - return this->entries; + return m_Entries; } - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.h index 2b2b33031..21b80990f 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionNPCComponentTable.h @@ -3,9 +3,11 @@ // Custom Classes #include "CDTable.h" +#include + struct CDMissionNPCComponent { - unsigned int id; //!< The ID - unsigned int missionID; //!< The Mission ID + uint32_t id; //!< The ID + uint32_t missionID; //!< The Mission ID bool offersMission; //!< Whether or not this NPC offers a mission bool acceptsMission; //!< Whether or not this NPC accepts a mission std::string gate_version; //!< The gate version @@ -13,7 +15,7 @@ struct CDMissionNPCComponent { class CDMissionNPCComponentTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); @@ -24,4 +26,3 @@ class CDMissionNPCComponentTable : public CDTable { const std::vector& GetEntries() const; }; - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp index 9795ea8f4..94d220a4f 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp @@ -3,7 +3,7 @@ void CDMissionTasksTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM MissionTasks"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -14,12 +14,12 @@ void CDMissionTasksTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MissionTasks"); while (!tableData.eof()) { - CDMissionTasks entry; + auto& entry = m_Entries.emplace_back(); entry.id = tableData.getIntField("id", -1); UNUSED(entry.locStatus = tableData.getIntField("locStatus", -1)); entry.taskType = tableData.getIntField("taskType", -1); @@ -34,16 +34,13 @@ void CDMissionTasksTable::LoadValuesFromDatabase() { UNUSED(entry.localize = tableData.getIntField("localize", -1) == 1 ? true : false); UNUSED(entry.gate_version = tableData.getStringField("gate_version", "")); - this->entries.push_back(entry); tableData.nextRow(); } - - tableData.finalize(); } std::vector CDMissionTasksTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -53,7 +50,7 @@ std::vector CDMissionTasksTable::Query(std::function CDMissionTasksTable::GetByMissionID(uint32_t missionID) { std::vector tasks; - for (auto& entry : this->entries) { + for (auto& entry : m_Entries) { if (entry.id == missionID) { tasks.push_back(&entry); } @@ -63,6 +60,5 @@ std::vector CDMissionTasksTable::GetByMissionID(uint32_t missio } const std::vector& CDMissionTasksTable::GetEntries() const { - return this->entries; + return m_Entries; } - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.h index 0b169db86..dc8d9d934 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.h @@ -3,32 +3,34 @@ // Custom Classes #include "CDTable.h" +#include + struct CDMissionTasks { - unsigned int id; //!< The Mission ID that the task belongs to - UNUSED(unsigned int locStatus); //!< ??? - unsigned int taskType; //!< The task type - unsigned int target; //!< The mission target - std::string targetGroup; //!< The mission target group - int targetValue; //!< The target value - std::string taskParam1; //!< The task param 1 - UNUSED(std::string largeTaskIcon); //!< ??? - UNUSED(unsigned int IconID); //!< ??? - unsigned int uid; //!< ??? - UNUSED(unsigned int largeTaskIconID); //!< ??? - UNUSED(bool localize); //!< Whether or not the task should be localized - UNUSED(std::string gate_version); //!< ??? + uint32_t id; //!< The Mission ID that the task belongs to + UNUSED(uint32_t locStatus); //!< ??? + uint32_t taskType; //!< The task type + uint32_t target; //!< The mission target + std::string targetGroup; //!< The mission target group + int32_t targetValue; //!< The target value + std::string taskParam1; //!< The task param 1 + UNUSED(std::string largeTaskIcon); //!< ??? + UNUSED(uint32_t IconID); //!< ??? + uint32_t uid; //!< ??? + UNUSED(uint32_t largeTaskIconID); //!< ??? + UNUSED(bool localize); //!< Whether or not the task should be localized + UNUSED(std::string gate_version); //!< ??? }; class CDMissionTasksTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); // Queries the table with a custom "where" clause std::vector Query(std::function predicate); - std::vector GetByMissionID(uint32_t missionID); + std::vector GetByMissionID(const uint32_t missionID); const std::vector& GetEntries() const; }; diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.cpp index 37f0c81cd..e2a2a4007 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.cpp @@ -16,12 +16,12 @@ void CDMissionsTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Missions"); while (!tableData.eof()) { - CDMissions entry; + auto& entry = m_Entries.emplace_back(); entry.id = tableData.getIntField("id", -1); entry.defined_type = tableData.getStringField("defined_type", ""); entry.defined_subtype = tableData.getStringField("defined_subtype", ""); @@ -75,18 +75,15 @@ void CDMissionsTable::LoadValuesFromDatabase() { UNUSED(entry.locStatus = tableData.getIntField("locStatus", -1)); entry.reward_bankinventory = tableData.getIntField("reward_bankinventory", -1); - this->entries.push_back(entry); tableData.nextRow(); } - tableData.finalize(); - Default.id = -1; } std::vector CDMissionsTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -94,11 +91,11 @@ std::vector CDMissionsTable::Query(std::function p } const std::vector& CDMissionsTable::GetEntries(void) const { - return this->entries; + return m_Entries; } -const CDMissions* CDMissionsTable::GetPtrByMissionID(uint32_t missionID) const { - for (const auto& entry : entries) { +const CDMissions* CDMissionsTable::GetPtrByMissionID(const uint32_t missionID) const { + for (const auto& entry : m_Entries) { if (entry.id == missionID) { return const_cast(&entry); } @@ -107,8 +104,8 @@ const CDMissions* CDMissionsTable::GetPtrByMissionID(uint32_t missionID) const { return &Default; } -const CDMissions& CDMissionsTable::GetByMissionID(uint32_t missionID, bool& found) const { - for (const auto& entry : entries) { +const CDMissions& CDMissionsTable::GetByMissionID(const uint32_t missionID, bool& found) const { + for (const auto& entry : m_Entries) { if (entry.id == missionID) { found = true; @@ -120,4 +117,3 @@ const CDMissions& CDMissionsTable::GetByMissionID(uint32_t missionID, bool& foun return Default; } - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.h index c8ddc2a3c..f37d498f3 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionsTable.h @@ -6,63 +6,63 @@ #include struct CDMissions { - int id; //!< The Mission ID - std::string defined_type; //!< The type of mission - std::string defined_subtype; //!< The subtype of the mission - int UISortOrder; //!< The UI Sort Order for the mission - int offer_objectID; //!< The LOT of the mission giver - int target_objectID; //!< The LOT of the mission's target - int64_t reward_currency; //!< The amount of currency to reward the player - int LegoScore; //!< The amount of LEGO Score to reward the player - int64_t reward_reputation; //!< The reputation to award the player - bool isChoiceReward; //!< Whether or not the user has the option to choose their loot - int reward_item1; //!< The first rewarded item - int reward_item1_count; //!< The count of the first item to be rewarded - int reward_item2; //!< The second rewarded item - int reward_item2_count; //!< The count of the second item to be rewarded - int reward_item3; //!< The third rewarded item - int reward_item3_count; //!< The count of the third item to be rewarded - int reward_item4; //!< The fourth rewarded item - int reward_item4_count; //!< The count of the fourth item to be rewarded - int reward_emote; //!< The first emote to be rewarded - int reward_emote2; //!< The second emote to be rewarded - int reward_emote3; //!< The third emote to be rewarded - int reward_emote4; //!< The fourth emote to be rewarded - int reward_maximagination; //!< The amount of max imagination to reward - int reward_maxhealth; //!< The amount of max health to reward - int reward_maxinventory; //!< The amount of max inventory to reward - int reward_maxmodel; //!< ??? - int reward_maxwidget; //!< ??? - int reward_maxwallet; //!< ??? - bool repeatable; //!< Whether or not this mission can be repeated (for instance, is it a daily mission) + int32_t id; //!< The Mission ID + std::string defined_type; //!< The type of mission + std::string defined_subtype; //!< The subtype of the mission + int32_t UISortOrder; //!< The UI Sort Order for the mission + int32_t offer_objectID; //!< The LOT of the mission giver + int32_t target_objectID; //!< The LOT of the mission's target + int64_t reward_currency; //!< The amount of currency to reward the player + int32_t LegoScore; //!< The amount of LEGO Score to reward the player + int64_t reward_reputation; //!< The reputation to award the player + bool isChoiceReward; //!< Whether or not the user has the option to choose their loot + int32_t reward_item1; //!< The first rewarded item + int32_t reward_item1_count; //!< The count of the first item to be rewarded + int32_t reward_item2; //!< The second rewarded item + int32_t reward_item2_count; //!< The count of the second item to be rewarded + int32_t reward_item3; //!< The third rewarded item + int32_t reward_item3_count; //!< The count of the third item to be rewarded + int32_t reward_item4; //!< The fourth rewarded item + int32_t reward_item4_count; //!< The count of the fourth item to be rewarded + int32_t reward_emote; //!< The first emote to be rewarded + int32_t reward_emote2; //!< The second emote to be rewarded + int32_t reward_emote3; //!< The third emote to be rewarded + int32_t reward_emote4; //!< The fourth emote to be rewarded + int32_t reward_maximagination; //!< The amount of max imagination to reward + int32_t reward_maxhealth; //!< The amount of max health to reward + int32_t reward_maxinventory; //!< The amount of max inventory to reward + int32_t reward_maxmodel; //!< ??? + int32_t reward_maxwidget; //!< ??? + int32_t reward_maxwallet; //!< ??? + bool repeatable; //!< Whether or not this mission can be repeated (for instance, is it a daily mission) int64_t reward_currency_repeatable; //!< The repeatable reward - int reward_item1_repeatable; //!< The first rewarded item - int reward_item1_repeat_count; //!< The count of the first item to be rewarded - int reward_item2_repeatable; //!< The second rewarded item - int reward_item2_repeat_count; //!< The count of the second item to be rewarded - int reward_item3_repeatable; //!< The third rewarded item - int reward_item3_repeat_count; //!< The count of the third item to be rewarded - int reward_item4_repeatable; //!< The fourth rewarded item - int reward_item4_repeat_count; //!< The count of the fourth item to be rewarded - int time_limit; //!< The time limit of the mission - bool isMission; //!< Maybe to differentiate between missions and achievements? - int missionIconID; //!< The mission icon ID - std::string prereqMissionID; //!< A '|' seperated list of prerequisite missions - bool localize; //!< Whether or not to localize the mission - bool inMOTD; //!< In Match of the Day(?) - int64_t cooldownTime; //!< The mission cooldown time - bool isRandom; //!< ??? - std::string randomPool; //!< ??? - int UIPrereqID; //!< ??? - UNUSED(std::string gate_version); //!< The gate version - UNUSED(std::string HUDStates); //!< ??? - UNUSED(int locStatus); //!< ??? - int reward_bankinventory; //!< The amount of bank space this mission rewards + int32_t reward_item1_repeatable; //!< The first rewarded item + int32_t reward_item1_repeat_count; //!< The count of the first item to be rewarded + int32_t reward_item2_repeatable; //!< The second rewarded item + int32_t reward_item2_repeat_count; //!< The count of the second item to be rewarded + int32_t reward_item3_repeatable; //!< The third rewarded item + int32_t reward_item3_repeat_count; //!< The count of the third item to be rewarded + int32_t reward_item4_repeatable; //!< The fourth rewarded item + int32_t reward_item4_repeat_count; //!< The count of the fourth item to be rewarded + int32_t time_limit; //!< The time limit of the mission + bool isMission; //!< Maybe to differentiate between missions and achievements? + int32_t missionIconID; //!< The mission icon ID + std::string prereqMissionID; //!< A '|' seperated list of prerequisite missions + bool localize; //!< Whether or not to localize the mission + bool inMOTD; //!< In Match of the Day(?) + int64_t cooldownTime; //!< The mission cooldown time + bool isRandom; //!< ??? + std::string randomPool; //!< ??? + int32_t UIPrereqID; //!< ??? + UNUSED(std::string gate_version); //!< The gate version + UNUSED(std::string HUDStates); //!< ??? + UNUSED(int32_t locStatus); //!< ??? + int32_t reward_bankinventory; //!< The amount of bank space this mission rewards }; class CDMissionsTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); @@ -72,10 +72,9 @@ class CDMissionsTable : public CDTable { // Gets all the entries in the table const std::vector& GetEntries() const; - const CDMissions* GetPtrByMissionID(uint32_t missionID) const; + const CDMissions* GetPtrByMissionID(const uint32_t missionID) const; - const CDMissions& GetByMissionID(uint32_t missionID, bool& found) const; + const CDMissions& GetByMissionID(const uint32_t missionID, bool& found) const; static CDMissions Default; }; - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.cpp index 35b464162..4e9ccb312 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.cpp @@ -3,7 +3,7 @@ void CDMovementAIComponentTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM MovementAIComponent"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -14,12 +14,12 @@ void CDMovementAIComponentTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MovementAIComponent"); while (!tableData.eof()) { - CDMovementAIComponent entry; + auto& entry = m_Entries.emplace_back(); entry.id = tableData.getIntField("id", -1); entry.MovementType = tableData.getStringField("MovementType", ""); entry.WanderChance = tableData.getFloatField("WanderChance", -1.0f); @@ -29,16 +29,13 @@ void CDMovementAIComponentTable::LoadValuesFromDatabase() { entry.WanderRadius = tableData.getFloatField("WanderRadius", -1.0f); entry.attachedPath = tableData.getStringField("attachedPath", ""); - this->entries.push_back(entry); tableData.nextRow(); } - - tableData.finalize(); } std::vector CDMovementAIComponentTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -46,6 +43,5 @@ std::vector CDMovementAIComponentTable::Query(std::functi } const std::vector& CDMovementAIComponentTable::GetEntries(void) const { - return this->entries; + return m_Entries; } - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.h index b40694bd8..aade7ec9e 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMovementAIComponentTable.h @@ -3,8 +3,10 @@ // Custom Classes #include "CDTable.h" +#include + struct CDMovementAIComponent { - unsigned int id; + uint32_t id; std::string MovementType; float WanderChance; float WanderDelayMin; @@ -16,7 +18,7 @@ struct CDMovementAIComponent { class CDMovementAIComponentTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.cpp index 2439622c0..f0179c1bb 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.cpp @@ -3,7 +3,7 @@ void CDObjectSkillsTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ObjectSkills"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -14,27 +14,24 @@ void CDObjectSkillsTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ObjectSkills"); while (!tableData.eof()) { - CDObjectSkills entry; + auto &entry = m_Entries.emplace_back(); entry.objectTemplate = tableData.getIntField("objectTemplate", -1); entry.skillID = tableData.getIntField("skillID", -1); entry.castOnType = tableData.getIntField("castOnType", -1); entry.AICombatWeight = tableData.getIntField("AICombatWeight", -1); - this->entries.push_back(entry); tableData.nextRow(); } - - tableData.finalize(); } std::vector CDObjectSkillsTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -42,5 +39,5 @@ std::vector CDObjectSkillsTable::Query(std::function& CDObjectSkillsTable::GetEntries() const { - return this->entries; + return m_Entries; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.h index bd9929e2c..a6d882c5d 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectSkillsTable.h @@ -3,16 +3,18 @@ // Custom Classes #include "CDTable.h" +#include + struct CDObjectSkills { - unsigned int objectTemplate; //!< The LOT of the item - unsigned int skillID; //!< The Skill ID of the object - unsigned int castOnType; //!< ??? - unsigned int AICombatWeight; //!< ??? + uint32_t objectTemplate; //!< The LOT of the item + uint32_t skillID; //!< The Skill ID of the object + uint32_t castOnType; //!< ??? + uint32_t AICombatWeight; //!< ??? }; class CDObjectSkillsTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp index d3094b684..534abfd35 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp @@ -1,22 +1,13 @@ #include "CDObjectsTable.h" void CDObjectsTable::LoadValuesFromDatabase() { - // First, get the size of the table - unsigned int size = 0; - auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Objects"); - while (!tableSize.eof()) { - size = tableSize.getIntField(0, 0); - - tableSize.nextRow(); - } - - tableSize.finalize(); - // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Objects"); while (!tableData.eof()) { - CDObjects entry; - entry.id = tableData.getIntField("id", -1); + const uint32_t LOT = tableData.getIntField("id", 0); + + auto& entry = m_Entries[LOT]; + entry.id = LOT; entry.name = tableData.getStringField("name", ""); UNUSED_COLUMN(entry.placeable = tableData.getIntField("placeable", -1);) entry.type = tableData.getStringField("type", ""); @@ -31,18 +22,15 @@ void CDObjectsTable::LoadValuesFromDatabase() { UNUSED_COLUMN(entry.gate_version = tableData.getStringField("gate_version", "");) UNUSED_COLUMN(entry.HQ_valid = tableData.getIntField("HQ_valid", -1);) - this->entries.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } - tableData.finalize(); - - m_default.id = 0; + m_Default.id = 0; } -const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) { - const auto& it = this->entries.find(LOT); - if (it != this->entries.end()) { +const CDObjects& CDObjectsTable::GetByID(const uint32_t LOT) { + const auto& it = m_Entries.find(LOT); + if (it != m_Entries.end()) { return it->second; } @@ -51,14 +39,16 @@ const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) { auto tableData = query.execQuery(); if (tableData.eof()) { - this->entries.insert(std::make_pair(LOT, m_default)); - return m_default; + m_Entries.insert(std::make_pair(LOT, m_Default)); + return m_Default; } // Now get the data while (!tableData.eof()) { - CDObjects entry; - entry.id = tableData.getIntField("id", -1); + const uint32_t LOT = tableData.getIntField("id", 0); + + auto& entry = m_Entries[LOT]; + entry.id = LOT; entry.name = tableData.getStringField("name", ""); UNUSED(entry.placeable = tableData.getIntField("placeable", -1)); entry.type = tableData.getStringField("type", ""); @@ -73,17 +63,15 @@ const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) { UNUSED(entry.gate_version = tableData.getStringField("gate_version", "")); UNUSED(entry.HQ_valid = tableData.getIntField("HQ_valid", -1)); - this->entries.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } tableData.finalize(); - const auto& it2 = entries.find(LOT); - if (it2 != entries.end()) { + const auto& it2 = m_Entries.find(LOT); + if (it2 != m_Entries.end()) { return it2->second; } - return m_default; + return m_Default; } - diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h index 3a776684e..05120e0b4 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h @@ -3,31 +3,33 @@ // Custom Classes #include "CDTable.h" +#include + struct CDObjects { - unsigned int id; //!< The LOT of the object + uint32_t id; //!< The LOT of the object std::string name; //!< The internal name of the object - UNUSED(unsigned int placeable); //!< Whether or not the object is placable + UNUSED(uint32_t placeable); //!< Whether or not the object is placable std::string type; //!< The object type UNUSED(std::string description); //!< An internal description of the object - UNUSED(unsigned int localize); //!< Whether or not the object should localize - UNUSED(unsigned int npcTemplateID); //!< Something related to NPCs... + UNUSED(uint32_t localize); //!< Whether or not the object should localize + UNUSED(uint32_t npcTemplateID); //!< Something related to NPCs... UNUSED(std::string displayName); //!< The display name of the object float interactionDistance; //!< The interaction distance of the object - UNUSED(unsigned int nametag); //!< ??? + UNUSED(uint32_t nametag); //!< ??? UNUSED(std::string _internalNotes); //!< Some internal notes (rarely used) - UNUSED(unsigned int locStatus); //!< ??? + UNUSED(uint32_t locStatus); //!< ??? UNUSED(std::string gate_version); //!< The gate version for the object - UNUSED(unsigned int HQ_valid); //!< Probably used for the Nexus HQ database on LEGOUniverse.com + UNUSED(uint32_t HQ_valid); //!< Probably used for the Nexus HQ database on LEGOUniverse.com }; class CDObjectsTable : public CDTable { private: - std::map entries; - CDObjects m_default; + std::map m_Entries; + CDObjects m_Default; public: void LoadValuesFromDatabase(); // Gets an entry by ID - const CDObjects& GetByID(unsigned int LOT); + const CDObjects& GetByID(const uint32_t LOT); }; diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp index 8b9551627..f04a527cb 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp @@ -3,7 +3,7 @@ void CDPackageComponentTable::LoadValuesFromDatabase() { // First, get the size of the table - unsigned int size = 0; + uint32_t size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM PackageComponent"); while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); @@ -14,17 +14,16 @@ void CDPackageComponentTable::LoadValuesFromDatabase() { tableSize.finalize(); // Reserve the size - this->entries.reserve(size); + m_Entries.reserve(size); // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PackageComponent"); while (!tableData.eof()) { - CDPackageComponent entry; + auto &entry = m_Entries.emplace_back(); entry.id = tableData.getIntField("id", -1); entry.LootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1); entry.packageType = tableData.getIntField("packageType", -1); - this->entries.push_back(entry); tableData.nextRow(); } @@ -34,7 +33,7 @@ void CDPackageComponentTable::LoadValuesFromDatabase() { //! Queries the table with a custom "where" clause std::vector CDPackageComponentTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->entries) + std::vector data = cpplinq::from(m_Entries) >> cpplinq::where(predicate) >> cpplinq::to_vector(); @@ -43,6 +42,6 @@ std::vector CDPackageComponentTable::Query(std::function& CDPackageComponentTable::GetEntries() const { - return this->entries; + return m_Entries; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.h index 7ee587618..c96df1fbb 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.h @@ -3,15 +3,17 @@ // Custom Classes #include "CDTable.h" +#include + struct CDPackageComponent { - unsigned int id; - unsigned int LootMatrixIndex; - unsigned int packageType; + uint32_t id; + uint32_t LootMatrixIndex; + uint32_t packageType; }; class CDPackageComponentTable : public CDTable { private: - std::vector entries; + std::vector m_Entries; public: void LoadValuesFromDatabase(); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp index e17be4df3..234ced5be 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp @@ -3,33 +3,32 @@ void CDPhysicsComponentTable::LoadValuesFromDatabase() { auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PhysicsComponent"); while (!tableData.eof()) { - CDPhysicsComponent entry; - entry.id = tableData.getIntField("id", -1); - entry.bStatic = tableData.getIntField("static", -1) != 0; - entry.physicsAsset = tableData.getStringField("physics_asset", ""); - UNUSED(entry->jump = tableData.getIntField("jump", -1) != 0); - UNUSED(entry->doublejump = tableData.getIntField("doublejump", -1) != 0); - entry.speed = tableData.getFloatField("speed", -1); - UNUSED(entry->rotSpeed = tableData.getFloatField("rotSpeed", -1)); - entry.playerHeight = tableData.getFloatField("playerHeight"); - entry.playerRadius = tableData.getFloatField("playerRadius"); - entry.pcShapeType = tableData.getIntField("pcShapeType"); - entry.collisionGroup = tableData.getIntField("collisionGroup"); - UNUSED(entry->airSpeed = tableData.getFloatField("airSpeed")); - UNUSED(entry->boundaryAsset = tableData.getStringField("boundaryAsset")); - UNUSED(entry->jumpAirSpeed = tableData.getFloatField("jumpAirSpeed")); - UNUSED(entry->friction = tableData.getFloatField("friction")); - UNUSED(entry->gravityVolumeAsset = tableData.getStringField("gravityVolumeAsset")); + const uint32_t componentID = tableData.getIntField("id", -1); + + auto& entry = m_Entries[componentID]; + entry.id = componentID, + entry.bStatic = tableData.getIntField("static", -1) != 0, + entry.physicsAsset = tableData.getStringField("physics_asset", ""), + UNUSED_ENTRY(entry.jump = tableData.getIntField("jump", -1) != 0,) + UNUSED_ENTRY(entry.doubleJump = tableData.getIntField("doublejump", -1) != 0,) + entry.speed = static_cast(tableData.getFloatField("speed", -1)), + UNUSED_ENTRY(entry.rotSpeed = tableData.getFloatField("rotSpeed", -1),) + entry.playerHeight = static_cast(tableData.getFloatField("playerHeight")), + entry.playerRadius = static_cast(tableData.getFloatField("playerRadius")), + entry.pcShapeType = tableData.getIntField("pcShapeType"), + entry.collisionGroup = tableData.getIntField("collisionGroup"), + UNUSED_ENTRY(entry.airSpeed = tableData.getFloatField("airSpeed"),) + UNUSED_ENTRY(entry.boundaryAsset = tableData.getStringField("boundaryAsset"),) + UNUSED_ENTRY(entry.jumpAirSpeed = tableData.getFloatField("jumpAirSpeed"),) + UNUSED_ENTRY(entry.friction = tableData.getFloatField("friction"),) + UNUSED_ENTRY(entry.gravityVolumeAsset = tableData.getStringField("gravityVolumeAsset"),) - m_entries.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } - - tableData.finalize(); } -CDPhysicsComponent* CDPhysicsComponentTable::GetByID(unsigned int componentID) { - auto itr = m_entries.find(componentID); - return itr != m_entries.end() ? &itr->second : nullptr; +CDPhysicsComponent* CDPhysicsComponentTable::GetByID(const uint32_t componentID) { + auto itr = m_Entries.find(componentID); + return itr != m_Entries.end() ? &itr->second : nullptr; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.h index 49f3b4c3a..847318425 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.h @@ -1,19 +1,20 @@ #pragma once #include "CDTable.h" +#include #include struct CDPhysicsComponent { - int id; + uint32_t id; bool bStatic; std::string physicsAsset; UNUSED(bool jump); - UNUSED(bool doublejump); + UNUSED(bool doubleJump); float speed; UNUSED(float rotSpeed); float playerHeight; float playerRadius; - int pcShapeType; - int collisionGroup; + int32_t pcShapeType; + int32_t collisionGroup; UNUSED(float airSpeed); UNUSED(std::string boundaryAsset); UNUSED(float jumpAirSpeed); @@ -25,9 +26,8 @@ class CDPhysicsComponentTable : public CDTable { public: void LoadValuesFromDatabase(); - static const std::string GetTableName() { return "PhysicsComponent"; }; - CDPhysicsComponent* GetByID(unsigned int componentID); + CDPhysicsComponent* GetByID(const uint32_t componentID); private: - std::map m_entries; + std::map m_Entries; }; From a847cd1bafd5d476e4b647827d34db6f02d56279 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 5 Mar 2024 20:28:33 -0600 Subject: [PATCH 06/10] updated to address feedback --- .../CDClientTables/CDLootTableTable.cpp | 2 +- .../CDClientTables/CDMissionTasksTable.cpp | 2 +- .../CDClientTables/CDObjectsTable.cpp | 10 +++--- .../CDPackageComponentTable.cpp | 2 +- .../CDPhysicsComponentTable.cpp | 32 +++++++++---------- dGame/dComponents/PetComponent.cpp | 4 +-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp index 1059dfbbd..cc6730bc6 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp @@ -79,7 +79,7 @@ const LootTableEntries& CDLootTableTable::GetTable(const uint32_t tableId) { while (!tableData.eof()) { CDLootTable entry; - entries.at(tableId).emplace_back(ReadRow(tableData)); + entries[tableId].emplace_back(ReadRow(tableData)); tableData.nextRow(); } SortTable(entries.at(tableId)); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp index 60bbe6f56..b95840327 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDMissionTasksTable.cpp @@ -48,7 +48,7 @@ std::vector CDMissionTasksTable::Query(std::function CDMissionTasksTable::GetByMissionID(uint32_t missionID) { +std::vector CDMissionTasksTable::GetByMissionID(const uint32_t missionID) { std::vector tasks; // TODO: this should not be linear(?) and also shouldnt need to be a pointer diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp index f5156657e..6207b5656 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp @@ -1,7 +1,7 @@ #include "CDObjectsTable.h" namespace { - CDObjects objDefault; + CDObjects ObjDefault; }; void CDObjectsTable::LoadValuesFromDatabase() { @@ -41,7 +41,7 @@ void CDObjectsTable::LoadValuesFromDatabase() { tableData.nextRow(); } - objDefault.id = 0; + ObjDefault.id = 0; } const CDObjects& CDObjectsTable::GetByID(const uint32_t LOT) { @@ -56,8 +56,8 @@ const CDObjects& CDObjectsTable::GetByID(const uint32_t LOT) { auto tableData = query.execQuery(); if (tableData.eof()) { - entries.emplace(LOT, objDefault); - return objDefault; + entries.emplace(LOT, ObjDefault); + return ObjDefault; } // Now get the data @@ -90,5 +90,5 @@ const CDObjects& CDObjectsTable::GetByID(const uint32_t LOT) { return it2->second; } - return objDefault; + return ObjDefault; } diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp index 6c93c8f81..a18ae8d98 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPackageComponentTable.cpp @@ -19,7 +19,7 @@ void CDPackageComponentTable::LoadValuesFromDatabase() { // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PackageComponent"); while (!tableData.eof()) { - auto &entry = entries.emplace_back(); + auto& entry = entries.emplace_back(); entry.id = tableData.getIntField("id", -1); entry.LootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1); entry.packageType = tableData.getIntField("packageType", -1); diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp index 878dae819..050312b11 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDPhysicsComponentTable.cpp @@ -7,22 +7,22 @@ void CDPhysicsComponentTable::LoadValuesFromDatabase() { const uint32_t componentID = tableData.getIntField("id", -1); auto& entry = entries[componentID]; - entry.id = componentID, - entry.bStatic = tableData.getIntField("static", -1) != 0, - entry.physicsAsset = tableData.getStringField("physics_asset", ""), - UNUSED_ENTRY(entry.jump = tableData.getIntField("jump", -1) != 0,) - UNUSED_ENTRY(entry.doubleJump = tableData.getIntField("doublejump", -1) != 0,) - entry.speed = static_cast(tableData.getFloatField("speed", -1)), - UNUSED_ENTRY(entry.rotSpeed = tableData.getFloatField("rotSpeed", -1),) - entry.playerHeight = static_cast(tableData.getFloatField("playerHeight")), - entry.playerRadius = static_cast(tableData.getFloatField("playerRadius")), - entry.pcShapeType = tableData.getIntField("pcShapeType"), - entry.collisionGroup = tableData.getIntField("collisionGroup"), - UNUSED_ENTRY(entry.airSpeed = tableData.getFloatField("airSpeed"),) - UNUSED_ENTRY(entry.boundaryAsset = tableData.getStringField("boundaryAsset"),) - UNUSED_ENTRY(entry.jumpAirSpeed = tableData.getFloatField("jumpAirSpeed"),) - UNUSED_ENTRY(entry.friction = tableData.getFloatField("friction"),) - UNUSED_ENTRY(entry.gravityVolumeAsset = tableData.getStringField("gravityVolumeAsset"),) + entry.id = componentID; + entry.bStatic = tableData.getIntField("static", -1) != 0; + entry.physicsAsset = tableData.getStringField("physics_asset", ""); + UNUSED_COLUMN(entry.jump = tableData.getIntField("jump", -1) != 0;) + UNUSED_COLUMN(entry.doubleJump = tableData.getIntField("doublejump", -1) != 0;) + entry.speed = static_cast(tableData.getFloatField("speed", -1)); + UNUSED_COLUMN(entry.rotSpeed = tableData.getFloatField("rotSpeed", -1);) + entry.playerHeight = static_cast(tableData.getFloatField("playerHeight")); + entry.playerRadius = static_cast(tableData.getFloatField("playerRadius")); + entry.pcShapeType = tableData.getIntField("pcShapeType"); + entry.collisionGroup = tableData.getIntField("collisionGroup"); + UNUSED_COLUMN(entry.airSpeed = tableData.getFloatField("airSpeed");) + UNUSED_COLUMN(entry.boundaryAsset = tableData.getStringField("boundaryAsset");) + UNUSED_COLUMN(entry.jumpAirSpeed = tableData.getFloatField("jumpAirSpeed");) + UNUSED_COLUMN(entry.friction = tableData.getFloatField("friction");) + UNUSED_COLUMN(entry.gravityVolumeAsset = tableData.getStringField("gravityVolumeAsset");) tableData.nextRow(); } diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index f17fa2258..a016eb36f 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -70,8 +70,8 @@ std::map PetComponent::petFlags = { { 13067, 838 }, // Skeleton dragon }; -PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity }, - m_PetInfo{ CDClientManager::GetTable()->GetByID(componentId) } { +PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity } { + m_PetInfo = CDClientManager::GetTable()->GetByID(componentId); // TODO: Make reference when safe m_ComponentId = componentId; m_Interaction = LWOOBJID_EMPTY; From 7aa0e61b4651e81c191366f8c4dfc3938b74bb63 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 5 Mar 2024 22:54:16 -0600 Subject: [PATCH 07/10] fix world hang --- dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp index cc6730bc6..6d7f1e22f 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp @@ -82,7 +82,7 @@ const LootTableEntries& CDLootTableTable::GetTable(const uint32_t tableId) { entries[tableId].emplace_back(ReadRow(tableData)); tableData.nextRow(); } - SortTable(entries.at(tableId)); + SortTable(entries[tableId]); return entries.at(tableId); } From c64f80d4a52b385151290d14a3e6f7962eef19d9 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Tue, 5 Mar 2024 23:54:05 -0600 Subject: [PATCH 08/10] Remove at() in CDLootTableTable.cpp --- .../CDClientDatabase/CDClientTables/CDLootTableTable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp index 6d7f1e22f..0781897f5 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.cpp @@ -58,7 +58,7 @@ void CDLootTableTable::LoadValuesFromDatabase() { CDLootTable entry; uint32_t lootTableIndex = tableData.getIntField("LootTableIndex", -1); - entries.at(lootTableIndex).emplace_back(ReadRow(tableData)); + entries[lootTableIndex].emplace_back(ReadRow(tableData)); tableData.nextRow(); } for (auto& [id, table] : entries) { @@ -84,5 +84,5 @@ const LootTableEntries& CDLootTableTable::GetTable(const uint32_t tableId) { } SortTable(entries[tableId]); - return entries.at(tableId); + return entries[tableId]; } From db3ca1bfdbbafcba70475b331dcf3db877e32cca Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 6 Mar 2024 06:56:49 -0600 Subject: [PATCH 09/10] Uncapitalize LOT variable --- .../CDClientTables/CDObjectsTable.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp index 6207b5656..738a13ac2 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp @@ -20,10 +20,10 @@ void CDObjectsTable::LoadValuesFromDatabase() { auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Objects"); auto& entries = GetEntriesMutable(); while (!tableData.eof()) { - const uint32_t LOT = tableData.getIntField("id", 0); + const uint32_t lot = tableData.getIntField("id", 0); - auto& entry = entries[LOT]; - entry.id = LOT; + auto& entry = entries[lot]; + entry.id = lot; entry.name = tableData.getStringField("name", ""); UNUSED_COLUMN(entry.placeable = tableData.getIntField("placeable", -1);) entry.type = tableData.getStringField("type", ""); @@ -44,28 +44,28 @@ void CDObjectsTable::LoadValuesFromDatabase() { ObjDefault.id = 0; } -const CDObjects& CDObjectsTable::GetByID(const uint32_t LOT) { +const CDObjects& CDObjectsTable::GetByID(const uint32_t lot) { auto& entries = GetEntriesMutable(); - const auto& it = entries.find(LOT); + const auto& it = entries.find(lot); if (it != entries.end()) { return it->second; } auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM Objects WHERE id = ?;"); - query.bind(1, static_cast(LOT)); + query.bind(1, static_cast(lot)); auto tableData = query.execQuery(); if (tableData.eof()) { - entries.emplace(LOT, ObjDefault); + entries.emplace(lot, ObjDefault); return ObjDefault; } // Now get the data while (!tableData.eof()) { - const uint32_t LOT = tableData.getIntField("id", 0); + const uint32_t lot = tableData.getIntField("id", 0); - auto& entry = entries[LOT]; - entry.id = LOT; + auto& entry = entries[lot]; + entry.id = lot; entry.name = tableData.getStringField("name", ""); UNUSED(entry.placeable = tableData.getIntField("placeable", -1)); entry.type = tableData.getStringField("type", ""); @@ -85,7 +85,7 @@ const CDObjects& CDObjectsTable::GetByID(const uint32_t LOT) { tableData.finalize(); - const auto& it2 = entries.find(LOT); + const auto& it2 = entries.find(lot); if (it2 != entries.end()) { return it2->second; } From f52ab1d4cc91da228a4a304ad92330cb3c4a4406 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Wed, 6 Mar 2024 06:58:04 -0600 Subject: [PATCH 10/10] Uncapitalize LOT variable --- dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h index f744ea37b..13bb90fab 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h @@ -26,6 +26,6 @@ class CDObjectsTable : public CDTable