Skip to content

Commit

Permalink
feat: integrated es parser into server
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Jan 20, 2022
1 parent fb45e77 commit 7bd1acd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 34 deletions.
23 changes: 12 additions & 11 deletions Code/components/es_loader/ESLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
#include <Records/CLMT.h>
#include <Records/NPC.h>

ESLoader::ESLoader(String aDirectory)
: m_directory(std::move(aDirectory))
ESLoader::ESLoader()
{
m_directory = "Data\\";
}

UniquePtr<RecordCollection> ESLoader::BuildRecordCollection() noexcept
{
FindFiles();
return LoadFiles();
}
if (!fs::is_directory(m_directory))
{
spdlog::error("Data directory not found.");
return MakeUnique<RecordCollection>();
}

void ESLoader::FindFiles()
{
if (m_directory.empty())
if (!LoadLoadOrder())
{
spdlog::error("Directory string is empty.");
return;
spdlog::error("Failed to load load order.");
return MakeUnique<RecordCollection>();
}

bool result = LoadLoadOrder();
return LoadFiles();
}


bool ESLoader::LoadLoadOrder()
{
std::ifstream loadOrderFile;
Expand Down
4 changes: 1 addition & 3 deletions Code/components/es_loader/ESLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ class ESLoader
static String ReadZString(Buffer::Reader& aReader) noexcept;
static String ReadWString(Buffer::Reader& aReader) noexcept;

ESLoader() = delete;
ESLoader(String aDirectory);
ESLoader();

UniquePtr<RecordCollection> BuildRecordCollection() noexcept;

private:
void FindFiles();
bool LoadLoadOrder();
UniquePtr<RecordCollection> LoadFiles();

Expand Down
16 changes: 0 additions & 16 deletions Code/components/es_loader/main.cpp

This file was deleted.

10 changes: 6 additions & 4 deletions Code/components/es_loader/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
add_requires("zlib")

component("ESLoader")
set_kind("binary")
set_pcxxheader("stdafx.h")
set_pcxxheader("stdafx.h")
add_headerfiles("stdafx.h", {prefixdir = "ESLoader"})
add_files("**.cpp", "stdafx.cpp")
add_packages("zlib")


unittest("ESLoader-Test")
unittest("ESLoader")
set_pcxxheader("stdafx.h")
add_headerfiles("stdafx.h", {prefixdir = "ESLoader"})
add_files("**.cpp", "stdafx.cpp")
add_packages("zlib")
5 changes: 5 additions & 0 deletions Code/server/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <Services/InventoryService.h>
#include <Services/MagicService.h>

#include <es_loader/ESLoader.h>

World::World()
{
m_spAdminService = std::make_shared<AdminService>(*this, m_dispatcher);
Expand All @@ -30,6 +32,9 @@ World::World()
set<InventoryService>(*this, m_dispatcher);
set<MagicService>(*this, m_dispatcher);

ESLoader loader;
m_recordCollection = loader.BuildRecordCollection();

// late initialize the ScriptService to ensure all components are valid
m_scriptService = std::make_unique<ScriptService>(*this, m_dispatcher);
}
5 changes: 5 additions & 0 deletions Code/server/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "Game/PlayerManager.h"

#include <es_loader/RecordCollection.h>

struct World : entt::registry
{
World();
Expand All @@ -31,6 +33,8 @@ struct World : entt::registry
const QuestService& GetQuestService() const noexcept { return ctx<const QuestService>(); }
PlayerManager& GetPlayerManager() noexcept { return m_playerManager; }
const PlayerManager& GetPlayerManager() const noexcept { return m_playerManager; }
RecordCollection& GetRecordCollection() noexcept { return *m_recordCollection; }
const RecordCollection& GetRecordCollection() const noexcept { return *m_recordCollection; }

[[nodiscard]] static uint32_t ToInteger(entt::entity aEntity) { return to_integral(aEntity); }

Expand All @@ -40,4 +44,5 @@ struct World : entt::registry
std::shared_ptr<AdminService> m_spAdminService;
std::unique_ptr<ScriptService> m_scriptService;
PlayerManager m_playerManager;
UniquePtr<RecordCollection> m_recordCollection;
};
1 change: 1 addition & 0 deletions Code/server/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ target(name)
add_deps(
"Common",
"Console",
"ESLoader",
"Base",
"TiltedScript",
"TiltedConnect",
Expand Down

0 comments on commit 7bd1acd

Please sign in to comment.