refactor: move event disptacher into service locator

This commit is contained in:
k0t9i
2023-10-16 23:38:01 +04:00
parent b948273172
commit ede55a870e
15 changed files with 160 additions and 94 deletions

View File

@@ -9,6 +9,8 @@
#include "Serializers/JsonIncomingMessageFactory.h"
#include "Transports/NamedPipeTransport.h"
#include "Versions/VersionAbstractFactory.h"
#include "Services/ServiceLocator.h"
#include "Events/HeroDeletedEvent.h"
using namespace L2Bot::Domain;
@@ -33,20 +35,13 @@ public:
m_Transport
)
{
}
Application() = delete;
virtual ~Application() = default;
void Start()
{
HMODULE hEngine = GetModuleHandleA("Engine.dll");
HMODULE hCore = GetModuleHandleA("Core.dll");
m_AbstractFactory.GetNetworkHandler().Init(hEngine);
m_AbstractFactory.GetGameEngine().Init(hEngine);
m_AbstractFactory.GetL2GameData().Init(hEngine);
m_AbstractFactory.GetFName().Init(hCore);
Init();
m_WorldHandler.Start();
}
@@ -58,6 +53,20 @@ public:
m_AbstractFactory.GetNetworkHandler().Restore();
}
private:
void Init()
{
ServiceLocator::GetInstance().SetEventDispatcher(std::make_unique<EventDispatcher>());
HMODULE hEngine = GetModuleHandleA("Engine.dll");
HMODULE hCore = GetModuleHandleA("Core.dll");
m_AbstractFactory.GetNetworkHandler().Init(hEngine);
m_AbstractFactory.GetGameEngine().Init(hEngine);
m_AbstractFactory.GetL2GameData().Init(hEngine);
m_AbstractFactory.GetFName().Init(hCore);
}
private:
const VersionAbstractFactory& m_AbstractFactory;
Services::WorldHandler m_WorldHandler;