WIP now subscribing to the created event in game.cpp.
This commit is contained in:
@@ -6,9 +6,9 @@
|
|||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct BecomeServer : public Event { };
|
struct BecomeServer : public Event
|
||||||
|
{ };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "Network/Network.h"
|
#include "Network/Network.h"
|
||||||
#include "Network/Server.h"
|
#include "Network/Server.h"
|
||||||
#include "Network/Client.h"
|
#include "Network/Client.h"
|
||||||
|
#include "Network/EBecomeServer.h"
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
#include "Sound/SoundManager.h"
|
#include "Sound/SoundManager.h"
|
||||||
@@ -70,6 +71,7 @@ private:
|
|||||||
bool m_IsServer = false;
|
bool m_IsServer = false;
|
||||||
|
|
||||||
int parseArgs(int argc, char* argv[]);
|
int parseArgs(int argc, char* argv[]);
|
||||||
|
|
||||||
EventRelay<Game, Events::BecomeServer> m_EBecomeServer;
|
EventRelay<Game, Events::BecomeServer> m_EBecomeServer;
|
||||||
bool OnBecomeServer(const Events::BecomeServer& e);
|
bool OnBecomeServer(const Events::BecomeServer& e);
|
||||||
};
|
};
|
||||||
|
|||||||
+21
-17
@@ -58,7 +58,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||||
ResourceManager::RegisterType<Font>("FontFile");
|
ResourceManager::RegisterType<Font>("FontFile");
|
||||||
|
|
||||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
|
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
|
||||||
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
|
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
|
||||||
@@ -99,21 +98,7 @@ Game::Game(int argc, char* argv[])
|
|||||||
// Create the sound manager
|
// Create the sound manager
|
||||||
m_SoundManager = new SoundManager(m_World, m_EventBroker);
|
m_SoundManager = new SoundManager(m_World, m_EventBroker);
|
||||||
|
|
||||||
// Initialize network
|
|
||||||
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
|
|
||||||
if (m_IsServer) {
|
|
||||||
m_NetworkServer = new Server(m_World, m_EventBroker, m_NetworkPort);
|
|
||||||
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " SERVER");
|
|
||||||
} else if (m_IsClient) {
|
|
||||||
m_NetworkClient = new Client(m_World, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
|
|
||||||
m_NetworkClient->Connect(m_NetworkAddress, m_NetworkPort);
|
|
||||||
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " CLIENT");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If network is disabled, pretend we're a server
|
|
||||||
m_IsClient = true;
|
|
||||||
m_IsServer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Octrees
|
// Create Octrees
|
||||||
// TODO: Perhaps the world bounds should be set in some non-arbitrary way instead of this.
|
// TODO: Perhaps the world bounds should be set in some non-arbitrary way instead of this.
|
||||||
@@ -179,6 +164,8 @@ Game::Game(int argc, char* argv[])
|
|||||||
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
m_SystemPipeline->AddSystem<EditorSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
||||||
|
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EBecomeServer, &Game::OnBecomeServer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
@@ -210,6 +197,7 @@ void Game::Tick()
|
|||||||
double dt = currentTime - m_LastTime;
|
double dt = currentTime - m_LastTime;
|
||||||
m_LastTime = currentTime;
|
m_LastTime = currentTime;
|
||||||
|
|
||||||
|
m_EventBroker->Process<Game>();
|
||||||
// Handle input in a weird looking but responsive way
|
// Handle input in a weird looking but responsive way
|
||||||
m_EventBroker->Process<InputManager>();
|
m_EventBroker->Process<InputManager>();
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
@@ -287,5 +275,21 @@ int Game::parseArgs(int argc, char* argv[])
|
|||||||
|
|
||||||
bool Game::OnBecomeServer(const Events::BecomeServer& e)
|
bool Game::OnBecomeServer(const Events::BecomeServer& e)
|
||||||
{
|
{
|
||||||
|
//// Initialize network
|
||||||
|
//if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
|
||||||
|
// if (m_IsServer) {
|
||||||
|
// m_NetworkServer = new Server(m_World, m_EventBroker, m_NetworkPort);
|
||||||
|
// m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " SERVER");
|
||||||
|
// } else if (m_IsClient) {
|
||||||
|
// m_NetworkClient = new Client(m_World, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
|
||||||
|
// m_NetworkClient->Connect(m_NetworkAddress, m_NetworkPort);
|
||||||
|
// m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " CLIENT");
|
||||||
|
// }
|
||||||
|
//} else {
|
||||||
|
// // If network is disabled, pretend we're a server
|
||||||
|
// m_IsClient = true;
|
||||||
|
// m_IsServer = true;
|
||||||
|
//}
|
||||||
|
//printf("Event received LOL\n");
|
||||||
|
//return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
|
|||||||
bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
|
bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
|
||||||
{
|
{
|
||||||
if (e.Command == "Host" && e.Value == 1) {
|
if (e.Command == "Host" && e.Value == 1) {
|
||||||
|
printf("Sending event...\n");
|
||||||
m_EventBroker->Publish(Events::BecomeServer());
|
m_EventBroker->Publish(Events::BecomeServer());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (e.Command == "Play" && e.Value == 1) {
|
if (e.Command == "Play" && e.Value == 1) {
|
||||||
auto menus = m_World->GetComponents("Menu");
|
auto menus = m_World->GetComponents("Menu");
|
||||||
|
|||||||
Reference in New Issue
Block a user