Now uses config file to determine if client or server should be started.
This commit is contained in:
@@ -10,7 +10,10 @@ VSYNC=false
|
|||||||
Width=1280
|
Width=1280
|
||||||
Height=720
|
Height=720
|
||||||
FOV=45
|
FOV=45
|
||||||
|
|
||||||
[Networking]
|
[Networking]
|
||||||
StartNetwork=false
|
StartNetwork=false
|
||||||
|
IsServer=false
|
||||||
|
Name=Bob
|
||||||
Address=127.0.0.1
|
Address=127.0.0.1
|
||||||
Port=13
|
Port=13
|
||||||
@@ -20,3 +20,5 @@ F1=ToggleEditor
|
|||||||
3=EditorToolScale
|
3=EditorToolScale
|
||||||
X=EditorToggleTransformSpace
|
X=EditorToggleTransformSpace
|
||||||
C=ConnectToServer
|
C=ConnectToServer
|
||||||
|
N=SwitchToServer
|
||||||
|
M=SwitchToClient
|
||||||
@@ -10,6 +10,7 @@ Client::Client(ConfigFile* config) : m_Socket(m_IOService)
|
|||||||
int port = config->Get<int>("Networking.Port", 13);
|
int port = config->Get<int>("Networking.Port", 13);
|
||||||
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string(address), port);
|
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string(address), port);
|
||||||
// Set up network stream
|
// Set up network stream
|
||||||
|
m_PlayerName = config->Get<std::string>("Networking.Name", "Raptorcopter");
|
||||||
m_NextSnapshot.InputForward = "";
|
m_NextSnapshot.InputForward = "";
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputRight = "";
|
||||||
}
|
}
|
||||||
@@ -29,12 +30,11 @@ void Client::Start(World* world, EventBroker* eventBroker)
|
|||||||
m_EInputCommand = decltype(m_EInputCommand)(std::bind(&Client::OnInputCommand, this, std::placeholders::_1));
|
m_EInputCommand = decltype(m_EInputCommand)(std::bind(&Client::OnInputCommand, this, std::placeholders::_1));
|
||||||
m_EventBroker->Subscribe(m_EInputCommand);
|
m_EventBroker->Subscribe(m_EInputCommand);
|
||||||
|
|
||||||
LOG_INFO("Please enter your name: ");
|
|
||||||
std::cin >> m_PlayerName;
|
//while (m_PlayerName.size() > 7) {
|
||||||
while (m_PlayerName.size() > 7) {
|
// LOG_INFO("Please enter your name (No longer than 7 characters):");
|
||||||
LOG_INFO("Please enter your name (No longer than 7 characters):");
|
// std::cin >> m_PlayerName;
|
||||||
std::cin >> m_PlayerName;
|
//}
|
||||||
}
|
|
||||||
m_Socket.connect(m_ReceiverEndpoint);
|
m_Socket.connect(m_ReceiverEndpoint);
|
||||||
LOG_INFO("I am client. BIP BOP");
|
LOG_INFO("I am client. BIP BOP");
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-7
@@ -96,7 +96,6 @@ void Game::Tick()
|
|||||||
m_ClientOrServer->Update();
|
m_ClientOrServer->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Iterate through systems and update world!
|
// Iterate through systems and update world!
|
||||||
m_SystemPipeline->Update(m_World, dt);
|
m_SystemPipeline->Update(m_World, dt);
|
||||||
debugTick(dt);
|
debugTick(dt);
|
||||||
@@ -123,6 +122,16 @@ bool Game::debugOnInputCommand(const Events::InputCommand& e)
|
|||||||
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (e.Command == "SwitchToServer" && e.Value > 0) {
|
||||||
|
m_ClientOrServer = new Server();
|
||||||
|
LOG_INFO("Switching to server");
|
||||||
|
m_ClientOrServer->Start(m_World, m_EventBroker);
|
||||||
|
}
|
||||||
|
if (e.Command == "SwitchToClient" && e.Value > 0) {
|
||||||
|
m_ClientOrServer = new Client(m_Config);
|
||||||
|
m_ClientOrServer->Start(m_World, m_EventBroker);
|
||||||
|
LOG_INFO("Switching to client");
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -139,14 +148,12 @@ void Game::debugTick(double dt)
|
|||||||
|
|
||||||
void Game::networkFunction()
|
void Game::networkFunction()
|
||||||
{
|
{
|
||||||
std::string inputMessage;
|
bool isServer = m_Config->Get<bool>("Networking.IsServer", false);
|
||||||
LOG_INFO("Start client or server? (c/s)");
|
if (!isServer) {
|
||||||
std::cin >> inputMessage;
|
|
||||||
if (inputMessage == "c" || inputMessage == "C") {
|
|
||||||
m_IsClientOrServer = true;
|
m_IsClientOrServer = true;
|
||||||
m_ClientOrServer = new Client(m_Config);
|
m_ClientOrServer = new Client(m_Config);
|
||||||
}
|
}
|
||||||
if (inputMessage == "s" || inputMessage == "S") {
|
if (isServer) {
|
||||||
m_IsClientOrServer = true;
|
m_IsClientOrServer = true;
|
||||||
m_ClientOrServer = new Server();
|
m_ClientOrServer = new Server();
|
||||||
}
|
}
|
||||||
@@ -155,6 +162,6 @@ void Game::networkFunction()
|
|||||||
// ~Game() is not called if the game is exited by closing console windows
|
// ~Game() is not called if the game is exited by closing console windows
|
||||||
// When server or client is done set it to false.
|
// When server or client is done set it to false.
|
||||||
//m_IsClientOrServer = false;
|
//m_IsClientOrServer = false;
|
||||||
// Destroy it! (with fire)
|
// Destroy it
|
||||||
//delete m_ClientOrServer;
|
//delete m_ClientOrServer;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user