Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Assorted pet improvements #1402

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
EmosewaMC marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20 -O2 -Wuninitialized -fPIC")
jadebenn marked this conversation as resolved.
Show resolved Hide resolved
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0)

if(NOT APPLE)
Expand Down
4 changes: 3 additions & 1 deletion dCommon/dEnums/ePetAbilityType.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef __EPETABILITYTYPE__H__
#define __EPETABILITYTYPE__H__

jadebenn marked this conversation as resolved.
Show resolved Hide resolved
enum class ePetAbilityType : int32_t {
#include <cstdint>

enum class ePetAbilityType : uint32_t {
Invalid,
GoToObject,
JumpOnObject,
Expand Down
104 changes: 58 additions & 46 deletions dDatabase/CDClientDatabase/CDClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -39,6 +40,8 @@
#include "CDRailActivatorComponent.h"
#include "CDRewardCodesTable.h"

#include <exception>

#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.
Expand All @@ -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();
}
8 changes: 4 additions & 4 deletions dDatabase/CDClientDatabase/CDClientManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/
class CDClientManager : public Singleton<CDClientManager> {
public:
/**
* Constructor for CDClientManager
*/
CDClientManager();
CDClientManager() = default;

void LoadValuesFromDatabase();
void LoadValuesFromDefaults();

/**
* Fetch a table from CDClient
Expand Down
70 changes: 34 additions & 36 deletions dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,58 @@

namespace {
// Default entries for fallback
CDPetComponent defaultEntry {
.id = static_cast<unsigned int>(-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);

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<float>(tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed));
entry.runSpeed = static_cast<float>(tableData.getFloatField("runSpeed", defaultEntry.runSpeed));
entry.sprintSpeed = static_cast<float>(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<float>(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));
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);
EmosewaMC marked this conversation as resolved.
Show resolved Hide resolved
return defaultEntry;
}
Expand Down
16 changes: 6 additions & 10 deletions dDatabase/CDClientDatabase/CDClientTables/CDPetComponentTable.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#pragma once
#include "CDTable.h"
#include <cstdint>
#include <string>

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;)
Expand All @@ -33,17 +34,12 @@ class CDPetComponentTable : public CDTable<CDPetComponentTable> {
*/
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<unsigned int, CDPetComponent> m_entries;
std::map<uint32_t, CDPetComponent> m_Entries;
};
4 changes: 2 additions & 2 deletions dDatabase/CDClientDatabase/CDClientTables/CDTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions dGame/dComponents/PetComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ std::map<LOT, int32_t> PetComponent::petFlags = {
{ 13067, 838 }, // Skeleton dragon
};

PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity },
m_PetInfo{ CDClientManager::Instance().GetTable<CDPetComponentTable>()->GetByID(componentId) } {
PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity } {
m_PetInfo = CDClientManager::Instance().GetTable<CDPetComponentTable>()->GetByID(componentId); // TODO: Make reference when safe
m_ComponentId = componentId;

m_Interaction = LWOOBJID_EMPTY;
Expand Down
3 changes: 2 additions & 1 deletion dGame/dComponents/PetComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ class PetComponent : public Component

/**
* Pet information loaded from the CDClientDatabase
* TODO: Switch to a reference when safe to do so
*/
CDPetComponent& m_PetInfo;
CDPetComponent m_PetInfo;
};

#endif // !PETCOMPONENT_H
2 changes: 1 addition & 1 deletion dGame/dGameMessages/GameMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "eEndBehavior.h"
#include "eCyclingMode.h"
#include "eLootSourceType.h"
#include "ePetAbilityType.h"
#include "Brick.h"

class AMFBaseValue;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dWorldServer/WorldServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions tests/dGameTests/GameDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down