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: Table Loading Improvements #1492

Merged
merged 13 commits into from
Mar 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ void CDLootTableTable::LoadValuesFromDatabase() {
CDLootTable entry;
uint32_t lootTableIndex = tableData.getIntField("LootTableIndex", -1);

entries[lootTableIndex].push_back(ReadRow(tableData));
entries[lootTableIndex].emplace_back(ReadRow(tableData));
tableData.nextRow();
}
for (auto& [id, table] : entries) {
SortTable(table);
}
}

const LootTableEntries& CDLootTableTable::GetTable(uint32_t tableId) {
const LootTableEntries& CDLootTableTable::GetTable(const uint32_t tableId) {
auto& entries = GetEntriesMutable();
auto itr = entries.find(tableId);
if (itr != entries.end()) {
Expand All @@ -79,7 +79,7 @@ const LootTableEntries& CDLootTableTable::GetTable(uint32_t tableId) {

while (!tableData.eof()) {
CDLootTable entry;
entries[tableId].push_back(ReadRow(tableData));
entries[tableId].emplace_back(ReadRow(tableData));
tableData.nextRow();
}
SortTable(entries[tableId]);
Expand Down
5 changes: 3 additions & 2 deletions dDatabase/CDClientDatabase/CDClientTables/CDLootTableTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDLootTable {
uint32_t itemid; //!< The LOT of the item
uint32_t LootTableIndex; //!< The Loot Table Index
Expand All @@ -20,6 +22,5 @@ class CDLootTableTable : public CDTable<CDLootTableTable, std::unordered_map<Loo
public:
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
const LootTableEntries& GetTable(uint32_t tableId);
const LootTableEntries& GetTable(const uint32_t tableId);
};

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void CDMissionEmailTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MissionEmail");
while (!tableData.eof()) {
CDMissionEmail entry;
auto& entry = entries.emplace_back();
entry.ID = tableData.getIntField("ID", -1);
entry.messageType = tableData.getIntField("messageType", -1);
entry.notificationGroup = tableData.getIntField("notificationGroup", -1);
Expand All @@ -30,11 +30,8 @@ void CDMissionEmailTable::LoadValuesFromDatabase() {
entry.locStatus = tableData.getIntField("locStatus", -1);
entry.gate_version = tableData.getStringField("gate_version", "");

entries.push_back(entry);
tableData.nextRow();
}

tableData.finalize();
}

//! Queries the table with a custom "where" clause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDMissionEmail {
uint32_t ID;
uint32_t messageType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ void CDMissionNPCComponentTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MissionNPCComponent");
while (!tableData.eof()) {
CDMissionNPCComponent entry;
auto& entry = 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", "");

entries.push_back(entry);
tableData.nextRow();
}

tableData.finalize();
}

//! Queries the table with a custom "where" clause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDMissionNPCComponent {
uint32_t id; //!< The ID
uint32_t missionID; //!< The Mission ID
Expand All @@ -17,4 +19,3 @@ class CDMissionNPCComponentTable : public CDTable<CDMissionNPCComponentTable, st
// Queries the table with a custom "where" clause
std::vector<CDMissionNPCComponent> Query(std::function<bool(CDMissionNPCComponent)> predicate);
};

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void CDMissionTasksTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MissionTasks");
while (!tableData.eof()) {
CDMissionTasks entry;
auto& entry = entries.emplace_back();
entry.id = tableData.getIntField("id", -1);
UNUSED(entry.locStatus = tableData.getIntField("locStatus", -1));
entry.taskType = tableData.getIntField("taskType", -1);
Expand All @@ -35,11 +35,8 @@ void CDMissionTasksTable::LoadValuesFromDatabase() {
UNUSED(entry.localize = tableData.getIntField("localize", -1) == 1 ? true : false);
UNUSED(entry.gate_version = tableData.getStringField("gate_version", ""));

entries.push_back(entry);
tableData.nextRow();
}

tableData.finalize();
}

std::vector<CDMissionTasks> CDMissionTasksTable::Query(std::function<bool(CDMissionTasks)> predicate) {
Expand All @@ -51,7 +48,7 @@ std::vector<CDMissionTasks> CDMissionTasksTable::Query(std::function<bool(CDMiss
return data;
}

std::vector<CDMissionTasks*> CDMissionTasksTable::GetByMissionID(uint32_t missionID) {
std::vector<CDMissionTasks*> CDMissionTasksTable::GetByMissionID(const uint32_t missionID) {
std::vector<CDMissionTasks*> tasks;

// TODO: this should not be linear(?) and also shouldnt need to be a pointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDMissionTasks {
uint32_t id; //!< The Mission ID that the task belongs to
UNUSED(uint32_t locStatus); //!< ???
Expand All @@ -25,7 +27,7 @@ class CDMissionTasksTable : public CDTable<CDMissionTasksTable, std::vector<CDMi
// Queries the table with a custom "where" clause
std::vector<CDMissionTasks> Query(std::function<bool(CDMissionTasks)> predicate);

std::vector<CDMissionTasks*> GetByMissionID(uint32_t missionID);
std::vector<CDMissionTasks*> GetByMissionID(const uint32_t missionID);
jadebenn marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Remove this and replace it with a proper lookup function.
const CDTable::StorageType& GetEntries() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void CDMissionsTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Missions");
while (!tableData.eof()) {
CDMissions entry;
auto& entry = entries.emplace_back();
entry.id = tableData.getIntField("id", -1);
entry.defined_type = tableData.getStringField("defined_type", "");
entry.defined_subtype = tableData.getStringField("defined_subtype", "");
Expand Down Expand Up @@ -76,7 +76,6 @@ void CDMissionsTable::LoadValuesFromDatabase() {
UNUSED(entry.locStatus = tableData.getIntField("locStatus", -1));
entry.reward_bankinventory = tableData.getIntField("reward_bankinventory", -1);

entries.push_back(entry);
tableData.nextRow();
}
tableData.finalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,3 @@ class CDMissionsTable : public CDTable<CDMissionsTable, std::vector<CDMissions>>

static CDMissions Default;
};

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void CDMovementAIComponentTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MovementAIComponent");
while (!tableData.eof()) {
CDMovementAIComponent entry;
auto& entry = entries.emplace_back();
entry.id = tableData.getIntField("id", -1);
entry.MovementType = tableData.getStringField("MovementType", "");
entry.WanderChance = tableData.getFloatField("WanderChance", -1.0f);
Expand All @@ -30,11 +30,8 @@ void CDMovementAIComponentTable::LoadValuesFromDatabase() {
entry.WanderRadius = tableData.getFloatField("WanderRadius", -1.0f);
entry.attachedPath = tableData.getStringField("attachedPath", "");

entries.push_back(entry);
tableData.nextRow();
}

tableData.finalize();
}

std::vector<CDMovementAIComponent> CDMovementAIComponentTable::Query(std::function<bool(CDMovementAIComponent)> predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDMovementAIComponent {
uint32_t id;
std::string MovementType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ void CDObjectSkillsTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ObjectSkills");
while (!tableData.eof()) {
CDObjectSkills entry;
auto &entry = 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);

entries.push_back(entry);
tableData.nextRow();
}

tableData.finalize();
}

std::vector<CDObjectSkills> CDObjectSkillsTable::Query(std::function<bool(CDObjectSkills)> predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDObjectSkills {
uint32_t objectTemplate; //!< The LOT of the item
uint32_t skillID; //!< The Skill ID of the object
Expand Down
35 changes: 17 additions & 18 deletions dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "CDObjectsTable.h"

namespace {
CDObjects m_default;
CDObjects ObjDefault;
};

void CDObjectsTable::LoadValuesFromDatabase() {
Expand All @@ -20,8 +20,10 @@ void CDObjectsTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Objects");
auto& entries = GetEntriesMutable();
while (!tableData.eof()) {
CDObjects entry;
entry.id = tableData.getIntField("id", -1);
const uint32_t lot = tableData.getIntField("id", 0);

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", "");
Expand All @@ -36,35 +38,34 @@ void CDObjectsTable::LoadValuesFromDatabase() {
UNUSED_COLUMN(entry.gate_version = tableData.getStringField("gate_version", "");)
UNUSED_COLUMN(entry.HQ_valid = tableData.getIntField("HQ_valid", -1);)

entries.insert(std::make_pair(entry.id, entry));
tableData.nextRow();
}

tableData.finalize();

m_default.id = 0;
ObjDefault.id = 0;
}

const CDObjects& CDObjectsTable::GetByID(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<int32_t>(LOT));
query.bind(1, static_cast<int32_t>(lot));

auto tableData = query.execQuery();
if (tableData.eof()) {
entries.insert(std::make_pair(LOT, m_default));
return m_default;
entries.emplace(lot, ObjDefault);
return ObjDefault;
}

// 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 = entries[lot];
entry.id = lot;
entry.name = tableData.getStringField("name", "");
UNUSED(entry.placeable = tableData.getIntField("placeable", -1));
entry.type = tableData.getStringField("type", "");
Expand All @@ -79,17 +80,15 @@ const CDObjects& CDObjectsTable::GetByID(uint32_t LOT) {
UNUSED(entry.gate_version = tableData.getStringField("gate_version", ""));
UNUSED(entry.HQ_valid = tableData.getIntField("HQ_valid", -1));

entries.insert(std::make_pair(entry.id, entry));
tableData.nextRow();
}

tableData.finalize();

const auto& it2 = entries.find(LOT);
const auto& it2 = entries.find(lot);
if (it2 != entries.end()) {
return it2->second;
}

return m_default;
return ObjDefault;
}

4 changes: 3 additions & 1 deletion dDatabase/CDClientDatabase/CDClientTables/CDObjectsTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDObjects {
uint32_t id; //!< The LOT of the object
std::string name; //!< The internal name of the object
Expand All @@ -24,6 +26,6 @@ class CDObjectsTable : public CDTable<CDObjectsTable, std::map<uint32_t, CDObjec
public:
void LoadValuesFromDatabase();
// Gets an entry by ID
const CDObjects& GetByID(uint32_t LOT);
const CDObjects& GetByID(const uint32_t lot);
};

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ void CDPackageComponentTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PackageComponent");
while (!tableData.eof()) {
CDPackageComponent entry;
auto& entry = entries.emplace_back();
entry.id = tableData.getIntField("id", -1);
entry.LootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1);
entry.packageType = tableData.getIntField("packageType", -1);

entries.push_back(entry);
tableData.nextRow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Custom Classes
#include "CDTable.h"

#include <cstdint>

struct CDPackageComponent {
uint32_t id;
uint32_t LootMatrixIndex;
Expand Down
Loading
Loading