diff --git a/dDatabase/Tables/CDBehaviorParameterTable.cpp b/dDatabase/Tables/CDBehaviorParameterTable.cpp index af37fc8..acd7a88 100644 --- a/dDatabase/Tables/CDBehaviorParameterTable.cpp +++ b/dDatabase/Tables/CDBehaviorParameterTable.cpp @@ -1,4 +1,5 @@ #include "CDBehaviorParameterTable.h" +#include "GeneralUtils.h" //Generated by xmlDb2dDatabaseGenerator on 2022-03-04 00:23:32.881145 //DO NOT EDIT THIS FILE MANUALLY! @@ -11,20 +12,33 @@ CDBehaviorParameterTable::CDBehaviorParameterTable() { } tableSize.finalize(); - this->m_entries.reserve(size); + //this->m_Entries.reserve(size); - auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter"); + /*auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter"); while (!tableData.eof()) { CDBehaviorParameter entry; entry.behaviorID = tableData.getIntField(0, int{}); entry.parameterID = tableData.getStringField(1, std::string{}.c_str()); entry.value = tableData.getFloatField(2, float{}); entry._internalSkillID = tableData.getIntField(3, int{}); - this->m_entries.push_back(entry); + + //Check if we have an entry with this ID: + auto it = m_entries.find(entry.behaviorID); + if (it != m_entries.end()) { + it->second.insert(std::make_pair(entry.parameterID, entry.value)); + } else { + //Otherwise, insert it: + m_entries.insert(std::make_pair(entry.behaviorID, std::map())); + auto jit = m_entries.find(entry.behaviorID); + + //Add our value as well: + jit->second.insert(std::make_pair(entry.parameterID, entry.value)); + } + tableData.nextRow(); } - tableData.finalize(); + tableData.finalize();*/ } CDBehaviorParameterTable::~CDBehaviorParameterTable() { @@ -34,14 +48,50 @@ std::string CDBehaviorParameterTable::GetName(void) const { return "BehaviorParameter"; } -std::vector CDBehaviorParameterTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->m_entries) - >> cpplinq::where(predicate) - >> cpplinq::to_vector(); +float CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::string& name, const float defaultValue) { + size_t hash = 0; + GeneralUtils::hash_combine(hash, behaviorID); + GeneralUtils::hash_combine(hash, name); - return data; -} + // Search for specific parameter + const auto& it = m_Entries.find(hash); + if (it != m_Entries.end()) { + return it->second; + } -std::vector CDBehaviorParameterTable::GetEntries(void) const { - return this->m_entries; -} + // Check if this behavior has already been checked + const auto& itChecked = m_Entries.find(behaviorID); + if (itChecked != m_Entries.end()) { + return defaultValue; + } + +#ifndef CDCLIENT_CACHE_ALL + std::stringstream query; + + query << "SELECT parameterID, value FROM BehaviorParameter WHERE behaviorID = " << std::to_string(behaviorID); + + auto tableData = CDClientDatabase::ExecuteQuery(query.str()); + + m_Entries.insert_or_assign(behaviorID, 0); + + while (!tableData.eof()) { + const std::string parameterID = tableData.getStringField(0, ""); + const float value = tableData.getFloatField(1, 0); + + size_t parameterHash = 0; + GeneralUtils::hash_combine(parameterHash, behaviorID); + GeneralUtils::hash_combine(parameterHash, parameterID); + + m_Entries.insert_or_assign(parameterHash, value); + + tableData.nextRow(); + } + + const auto& it2 = m_Entries.find(hash); + if (it2 != m_Entries.end()) { + return it2->second; + } +#endif + + return defaultValue; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDBehaviorParameterTable.h b/dDatabase/Tables/CDBehaviorParameterTable.h index e816a86..7c4ebda 100644 --- a/dDatabase/Tables/CDBehaviorParameterTable.h +++ b/dDatabase/Tables/CDBehaviorParameterTable.h @@ -13,12 +13,15 @@ struct CDBehaviorParameter { class CDBehaviorParameterTable : public CDTable { private: - std::vector m_entries; + std::map m_Entries; + public: CDBehaviorParameterTable(); ~CDBehaviorParameterTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); - std::vector GetEntries(void) const; + std::vector Query(std::function predicate); + //std::vector GetEntries(void) const; + + float GetEntry(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0); }; diff --git a/dDatabase/Tables/CDComponentsRegistryTable.cpp b/dDatabase/Tables/CDComponentsRegistryTable.cpp index fb083cc..967345c 100644 --- a/dDatabase/Tables/CDComponentsRegistryTable.cpp +++ b/dDatabase/Tables/CDComponentsRegistryTable.cpp @@ -1,46 +1,128 @@ #include "CDComponentsRegistryTable.h" -//Generated by xmlDb2dDatabaseGenerator on 2022-03-04 00:23:32.923033 -//DO NOT EDIT THIS FILE MANUALLY! -CDComponentsRegistryTable::CDComponentsRegistryTable() { +#define CDCLIENT_CACHE_ALL + +//! Constructor +CDComponentsRegistryTable::CDComponentsRegistryTable(void) { + +#ifdef CDCLIENT_CACHE_ALL + // First, get the size of the table unsigned int size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ComponentsRegistry"); - while (!tableSize.eof()) { + while (!tableSize.eof()) { size = tableSize.getIntField(0, 0); + tableSize.nextRow(); } tableSize.finalize(); - this->m_entries.reserve(size); + // Reserve the size + //this->entries.reserve(size); + + // Now get the data auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ComponentsRegistry"); while (!tableData.eof()) { CDComponentsRegistry entry; - entry.id = tableData.getIntField(0, int{}); - entry.component_type = tableData.getIntField(1, int{}); - entry.component_id = tableData.getIntField(2, int{}); - this->m_entries.push_back(entry); + entry.id = tableData.getIntField(0, -1); + entry.component_type = tableData.getIntField(1, -1); + entry.component_id = tableData.getIntField(2, -1); + + this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id); + + //this->entries.push_back(entry); + + /* + //Darwin's stuff: + const auto& it = this->mappedEntries.find(entry.id); + if (it != mappedEntries.end()) { + const auto& iter = it->second.find(entry.component_type); + if (iter == it->second.end()) { + it->second.insert(std::make_pair(entry.component_type, entry.component_id)); + } + } + else { + std::map map; + map.insert(std::make_pair(entry.component_type, entry.component_id)); + this->mappedEntries.insert(std::make_pair(entry.id, map)); + } + */ + tableData.nextRow(); } tableData.finalize(); +#endif } -CDComponentsRegistryTable::~CDComponentsRegistryTable() { -} +//! Destructor +CDComponentsRegistryTable::~CDComponentsRegistryTable(void) {} +//! Returns the table's name std::string CDComponentsRegistryTable::GetName(void) const { return "ComponentsRegistry"; } -std::vector CDComponentsRegistryTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->m_entries) - >> cpplinq::where(predicate) - >> cpplinq::to_vector(); +int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, uint32_t componentType, int32_t defaultValue) { + const auto& iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id)); - return data; -} + if (iter == this->mappedEntries.end()) { + return defaultValue; + } -std::vector CDComponentsRegistryTable::GetEntries(void) const { - return this->m_entries; -} + return iter->second; + + /* + const auto& it = this->mappedEntries.find(id); + if (it != mappedEntries.end()) { + const auto& iter = it->second.find(componentType); + if (iter != it->second.end()) { + return iter->second; + } + } + */ + +#ifndef CDCLIENT_CACHE_ALL + // Now get the data + std::stringstream query; + + query << "SELECT * FROM ComponentsRegistry WHERE id = " << std::to_string(id); + + auto tableData = CDClientDatabase::ExecuteQuery(query.str()); + while (!tableData.eof()) { + CDComponentsRegistry entry; + entry.id = tableData.getIntField(0, -1); + entry.component_type = tableData.getIntField(1, -1); + entry.component_id = tableData.getIntField(2, -1); + + //this->entries.push_back(entry); + + //Darwin's stuff: + const auto& it = this->mappedEntries.find(entry.id); + if (it != mappedEntries.end()) { + const auto& iter = it->second.find(entry.component_type); + if (iter == it->second.end()) { + it->second.insert(std::make_pair(entry.component_type, entry.component_id)); + } + } else { + std::map map; + map.insert(std::make_pair(entry.component_type, entry.component_id)); + this->mappedEntries.insert(std::make_pair(entry.id, map)); + } + + tableData.nextRow(); + } + + tableData.finalize(); + + const auto& it2 = this->mappedEntries.find(id); + if (it2 != mappedEntries.end()) { + const auto& iter = it2->second.find(componentType); + if (iter != it2->second.end()) { + return iter->second; + } + } + + return defaultValue; +#endif +} \ No newline at end of file diff --git a/dDatabase/Tables/CDComponentsRegistryTable.h b/dDatabase/Tables/CDComponentsRegistryTable.h index f85a9a3..833901e 100644 --- a/dDatabase/Tables/CDComponentsRegistryTable.h +++ b/dDatabase/Tables/CDComponentsRegistryTable.h @@ -1,23 +1,40 @@ #pragma once + +// Custom Classes #include "CDTable.h" -//Generated by xmlDb2dDatabaseGenerator on 2022-03-04 00:23:32.922038 -//DO NOT EDIT THIS FILE MANUALLY! +/*! + \file CDComponentsRegistryTable.hpp + \brief Contains data for the ComponentsRegistry table + */ + //! ComponentsRegistry Entry Struct struct CDComponentsRegistry { - int id; - int component_type; - int component_id; + unsigned int id; //!< The LOT is used as the ID + unsigned int component_type; //!< See ComponentTypes enum for values + unsigned int component_id; //!< The ID used within the component's table (0 may either mean it's non-networked, or that the ID is actually 0 }; + +//! ComponentsRegistry table class CDComponentsRegistryTable : public CDTable { private: - std::vector m_entries; -public: - CDComponentsRegistryTable(); - ~CDComponentsRegistryTable(); - std::string GetName(void) const override; + //std::vector entries; + std::map mappedEntries; //id, component_type, component_id -std::vector Query(std::function predicate); - std::vector GetEntries(void) const; -}; +public: + + //! Constructor + CDComponentsRegistryTable(void); + + //! Destructor + ~CDComponentsRegistryTable(void); + + //! Returns the table's name + /*! + \return The table name + */ + std::string GetName(void) const override; + + int32_t GetByIDAndType(uint32_t id, uint32_t componentType, int32_t defaultValue = 0); +}; \ No newline at end of file diff --git a/dDatabase/Tables/CDInventoryComponentTable.h b/dDatabase/Tables/CDInventoryComponentTable.h index 6033da8..c97b8e5 100644 --- a/dDatabase/Tables/CDInventoryComponentTable.h +++ b/dDatabase/Tables/CDInventoryComponentTable.h @@ -5,9 +5,9 @@ //DO NOT EDIT THIS FILE MANUALLY! struct CDInventoryComponent { - int id; + unsigned int id; int itemid; - int count; + unsigned int count; bool equip; }; diff --git a/dDatabase/Tables/CDItemComponentTable.cpp b/dDatabase/Tables/CDItemComponentTable.cpp index 9f5244a..e17d7fb 100644 --- a/dDatabase/Tables/CDItemComponentTable.cpp +++ b/dDatabase/Tables/CDItemComponentTable.cpp @@ -2,6 +2,8 @@ //Generated by xmlDb2dDatabaseGenerator on 2022-03-04 00:23:32.999829 //DO NOT EDIT THIS FILE MANUALLY! +CDItemComponent CDItemComponentTable::Default = {}; + CDItemComponentTable::CDItemComponentTable() { unsigned int size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ItemComponent"); @@ -11,7 +13,7 @@ CDItemComponentTable::CDItemComponentTable() { } tableSize.finalize(); - this->m_entries.reserve(size); + //this->m_entries.reserve(size); auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ItemComponent"); while (!tableData.eof()) { @@ -47,7 +49,7 @@ CDItemComponentTable::CDItemComponentTable() { entry.delResIndex = tableData.getIntField(28, int{}); entry.currencyLOT = tableData.getIntField(29, int{}); entry.altCurrencyCost = tableData.getIntField(30, int{}); - this->m_entries.push_back(entry); + //this->m_entries.push_back(entry); tableData.nextRow(); } @@ -61,14 +63,11 @@ std::string CDItemComponentTable::GetName(void) const { return "ItemComponent"; } -std::vector CDItemComponentTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->m_entries) - >> cpplinq::where(predicate) - >> cpplinq::to_vector(); +const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int skillID) { + const auto& it = this->entries.find(skillID); + if (it != this->entries.end()) { + return it->second; + } - return data; -} - -std::vector CDItemComponentTable::GetEntries(void) const { - return this->m_entries; -} + return Default; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDItemComponentTable.h b/dDatabase/Tables/CDItemComponentTable.h index 4b81805..25100aa 100644 --- a/dDatabase/Tables/CDItemComponentTable.h +++ b/dDatabase/Tables/CDItemComponentTable.h @@ -40,12 +40,12 @@ struct CDItemComponent { class CDItemComponentTable : public CDTable { private: - std::vector m_entries; + std::map entries; public: CDItemComponentTable(); ~CDItemComponentTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); - std::vector GetEntries(void) const; + static CDItemComponent Default; + const CDItemComponent& GetItemComponentByID(unsigned int skillID); }; diff --git a/dDatabase/Tables/CDMissionTasksTable.cpp b/dDatabase/Tables/CDMissionTasksTable.cpp index 06623ba..cf62bf0 100644 --- a/dDatabase/Tables/CDMissionTasksTable.cpp +++ b/dDatabase/Tables/CDMissionTasksTable.cpp @@ -52,3 +52,17 @@ std::vector CDMissionTasksTable::Query(std::function CDMissionTasksTable::GetEntries(void) const { return this->m_entries; } + +std::vector CDMissionTasksTable::GetByMissionID(uint32_t missionID) { + std::vector tasks; + + for (auto& entry : this->m_entries) { + if (entry.id == missionID) { + CDMissionTasks* task = const_cast(&entry); + + tasks.push_back(task); + } + } + + return tasks; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDMissionTasksTable.h b/dDatabase/Tables/CDMissionTasksTable.h index 3519d79..482b6de 100644 --- a/dDatabase/Tables/CDMissionTasksTable.h +++ b/dDatabase/Tables/CDMissionTasksTable.h @@ -26,6 +26,8 @@ public: ~CDMissionTasksTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); + std::vector Query(std::function predicate); std::vector GetEntries(void) const; + + std::vector GetByMissionID(uint32_t missionID); }; diff --git a/dDatabase/Tables/CDMissionsTable.cpp b/dDatabase/Tables/CDMissionsTable.cpp index fe46522..1b0f8d4 100644 --- a/dDatabase/Tables/CDMissionsTable.cpp +++ b/dDatabase/Tables/CDMissionsTable.cpp @@ -2,6 +2,8 @@ //Generated by xmlDb2dDatabaseGenerator on 2022-03-04 00:23:33.212261 //DO NOT EDIT THIS FILE MANUALLY! +CDMissions CDMissionsTable::Default = {}; + CDMissionsTable::CDMissionsTable() { unsigned int size = 0; auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Missions"); @@ -83,3 +85,27 @@ std::vector CDMissionsTable::Query(std::function p std::vector CDMissionsTable::GetEntries(void) const { return this->m_entries; } + +const CDMissions* CDMissionsTable::GetPtrByMissionID(uint32_t missionID) const { + for (const auto& entry : m_entries) { + if (entry.id == missionID) { + return const_cast(&entry); + } + } + + return &Default; +} + +const CDMissions& CDMissionsTable::GetByMissionID(uint32_t missionID, bool& found) const { + for (const auto& entry : m_entries) { + if (entry.id == missionID) { + found = true; + + return entry; + } + } + + found = false; + + return Default; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDMissionsTable.h b/dDatabase/Tables/CDMissionsTable.h index 173b43a..ea6afdf 100644 --- a/dDatabase/Tables/CDMissionsTable.h +++ b/dDatabase/Tables/CDMissionsTable.h @@ -57,6 +57,11 @@ public: ~CDMissionsTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); + std::vector Query(std::function predicate); std::vector GetEntries(void) const; + + const CDMissions* GetPtrByMissionID(uint32_t missionID) const; + + const CDMissions& GetByMissionID(uint32_t missionID, bool& found) const; + static CDMissions Default; }; diff --git a/dDatabase/Tables/CDObjectsTable.cpp b/dDatabase/Tables/CDObjectsTable.cpp index 099c10b..77d893b 100644 --- a/dDatabase/Tables/CDObjectsTable.cpp +++ b/dDatabase/Tables/CDObjectsTable.cpp @@ -27,6 +27,7 @@ CDObjectsTable::CDObjectsTable() { entry.interactionDistance = tableData.getFloatField(8, float{}); entry.nametag = tableData.getIntField(9, bool{}); this->m_entries.push_back(entry); + this->m_mappedEntries.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } @@ -51,3 +52,12 @@ std::vector CDObjectsTable::Query(std::function pred std::vector CDObjectsTable::GetEntries(void) const { return this->m_entries; } + +CDObjects CDObjectsTable::GetByID(unsigned int lot) { + const auto& it = this->m_mappedEntries.find(lot); + if (it != this->m_mappedEntries.end()) { + return it->second; + } + + return m_default; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDObjectsTable.h b/dDatabase/Tables/CDObjectsTable.h index c8b8d3c..fb1c57c 100644 --- a/dDatabase/Tables/CDObjectsTable.h +++ b/dDatabase/Tables/CDObjectsTable.h @@ -20,6 +20,9 @@ struct CDObjects { class CDObjectsTable : public CDTable { private: std::vector m_entries; + std::map m_mappedEntries; + CDObjects m_default{}; + public: CDObjectsTable(); ~CDObjectsTable(); @@ -27,4 +30,6 @@ public: std::vector Query(std::function predicate); std::vector GetEntries(void) const; + + CDObjects GetByID(unsigned int lot); }; diff --git a/dDatabase/Tables/CDPhysicsComponentTable.cpp b/dDatabase/Tables/CDPhysicsComponentTable.cpp index ef5d897..f816141 100644 --- a/dDatabase/Tables/CDPhysicsComponentTable.cpp +++ b/dDatabase/Tables/CDPhysicsComponentTable.cpp @@ -32,6 +32,7 @@ CDPhysicsComponentTable::CDPhysicsComponentTable() { entry.jumpAirSpeed = tableData.getFloatField(13, float{}); entry.friction = tableData.getFloatField(14, float{}); this->m_entries.push_back(entry); + m_mappedEntities.insert(std::make_pair(entry.id, entry)); tableData.nextRow(); } @@ -56,3 +57,11 @@ std::vector CDPhysicsComponentTable::Query(std::function CDPhysicsComponentTable::GetEntries(void) const { return this->m_entries; } + +CDPhysicsComponent* CDPhysicsComponentTable::GetByID(unsigned int ID) { + for (auto e : m_mappedEntities) { + if (e.first == ID) return &e.second; + } + + return nullptr; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDPhysicsComponentTable.h b/dDatabase/Tables/CDPhysicsComponentTable.h index e984798..9b4d838 100644 --- a/dDatabase/Tables/CDPhysicsComponentTable.h +++ b/dDatabase/Tables/CDPhysicsComponentTable.h @@ -25,11 +25,15 @@ struct CDPhysicsComponent { class CDPhysicsComponentTable : public CDTable { private: std::vector m_entries; + std::map m_mappedEntities; + public: CDPhysicsComponentTable(); ~CDPhysicsComponentTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); + std::vector Query(std::function predicate); std::vector GetEntries(void) const; + + CDPhysicsComponent* GetByID(unsigned int ID); }; diff --git a/dDatabase/Tables/CDScriptComponentTable.cpp b/dDatabase/Tables/CDScriptComponentTable.cpp index d642fb1..788a430 100644 --- a/dDatabase/Tables/CDScriptComponentTable.cpp +++ b/dDatabase/Tables/CDScriptComponentTable.cpp @@ -19,6 +19,7 @@ CDScriptComponentTable::CDScriptComponentTable() { entry.id = tableData.getIntField(0, int{}); entry.script_name = tableData.getStringField(1, std::string{}.c_str()); entry.client_script_name = tableData.getStringField(2, std::string{}.c_str()); + this->entries.insert(std::make_pair(entry.id, entry)); this->m_entries.push_back(entry); tableData.nextRow(); } @@ -44,3 +45,12 @@ std::vector CDScriptComponentTable::Query(std::function CDScriptComponentTable::GetEntries(void) const { return this->m_entries; } + +const CDScriptComponent& CDScriptComponentTable::GetByID(int id) { + std::map::iterator it = this->entries.find(id); + if (it != this->entries.end()) { + return it->second; + } + + return m_default; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDScriptComponentTable.h b/dDatabase/Tables/CDScriptComponentTable.h index 62ff584..2a98792 100644 --- a/dDatabase/Tables/CDScriptComponentTable.h +++ b/dDatabase/Tables/CDScriptComponentTable.h @@ -13,11 +13,17 @@ struct CDScriptComponent { class CDScriptComponentTable : public CDTable { private: std::vector m_entries; + std::map entries; + + CDScriptComponent m_default{}; + public: CDScriptComponentTable(); ~CDScriptComponentTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); + std::vector Query(std::function predicate); std::vector GetEntries(void) const; + + const CDScriptComponent& GetByID(int id); }; diff --git a/dDatabase/Tables/CDSkillBehaviorTable.cpp b/dDatabase/Tables/CDSkillBehaviorTable.cpp index 67b8ede..1f5c059 100644 --- a/dDatabase/Tables/CDSkillBehaviorTable.cpp +++ b/dDatabase/Tables/CDSkillBehaviorTable.cpp @@ -37,6 +37,7 @@ CDSkillBehaviorTable::CDSkillBehaviorTable() { entry.damageUI = tableData.getIntField(18, int{}); entry.descriptionUI = tableData.getStringField(19, std::string{}.c_str()); this->m_entries.push_back(entry); + this->entries.insert(std::make_pair(entry.skillID, entry)); tableData.nextRow(); } @@ -61,3 +62,12 @@ std::vector CDSkillBehaviorTable::Query(std::function CDSkillBehaviorTable::GetEntries(void) const { return this->m_entries; } + +CDSkillBehavior CDSkillBehaviorTable::GetSkillByID(int id) { + const auto& it = this->entries.find(id); + if (it != this->entries.end()) { + return it->second; + } + + return m_default; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDSkillBehaviorTable.h b/dDatabase/Tables/CDSkillBehaviorTable.h index f57b320..ebbcfc5 100644 --- a/dDatabase/Tables/CDSkillBehaviorTable.h +++ b/dDatabase/Tables/CDSkillBehaviorTable.h @@ -30,11 +30,17 @@ struct CDSkillBehavior { class CDSkillBehaviorTable : public CDTable { private: std::vector m_entries; + std::map entries; + + CDSkillBehavior m_default{}; + public: CDSkillBehaviorTable(); ~CDSkillBehaviorTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); + std::vector Query(std::function predicate); std::vector GetEntries(void) const; + + CDSkillBehavior GetSkillByID(int id); }; diff --git a/dDatabase/Tables/CDZoneTableTable.cpp b/dDatabase/Tables/CDZoneTableTable.cpp index 1e32866..eeac71c 100644 --- a/dDatabase/Tables/CDZoneTableTable.cpp +++ b/dDatabase/Tables/CDZoneTableTable.cpp @@ -11,7 +11,6 @@ CDZoneTableTable::CDZoneTableTable() { } tableSize.finalize(); - this->m_entries.reserve(size); auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ZoneTable"); while (!tableData.eof()) { @@ -30,7 +29,7 @@ CDZoneTableTable::CDZoneTableTable() { entry.clientPhysicsFramerate = tableData.getStringField(11, std::string{}.c_str()); entry.serverPhysicsFramerate = tableData.getStringField(12, std::string{}.c_str()); entry.zoneControlTemplate = tableData.getIntField(13, int{}); - this->m_entries.push_back(entry); + this->m_Entries.insert(std::make_pair(entry.zoneID, entry)); tableData.nextRow(); } @@ -44,14 +43,12 @@ std::string CDZoneTableTable::GetName(void) const { return "ZoneTable"; } -std::vector CDZoneTableTable::Query(std::function predicate) { - std::vector data = cpplinq::from(this->m_entries) - >> cpplinq::where(predicate) - >> cpplinq::to_vector(); +const CDZoneTable* CDZoneTableTable::Query(unsigned int zoneID) { + const auto& iter = m_Entries.find(zoneID); - return data; -} + if (iter != m_Entries.end()) { + return &iter->second; + } -std::vector CDZoneTableTable::GetEntries(void) const { - return this->m_entries; -} + return nullptr; +} \ No newline at end of file diff --git a/dDatabase/Tables/CDZoneTableTable.h b/dDatabase/Tables/CDZoneTableTable.h index 6302a1d..35ac684 100644 --- a/dDatabase/Tables/CDZoneTableTable.h +++ b/dDatabase/Tables/CDZoneTableTable.h @@ -23,12 +23,12 @@ struct CDZoneTable { class CDZoneTableTable : public CDTable { private: - std::vector m_entries; + std::map m_Entries; + public: CDZoneTableTable(); ~CDZoneTableTable(); std::string GetName(void) const override; -std::vector Query(std::function predicate); - std::vector GetEntries(void) const; + const CDZoneTable* Query(unsigned int zoneID); };