Removed old input events from client
This commit is contained in:
@@ -76,10 +76,6 @@ private:
|
||||
|
||||
// Events
|
||||
EventBroker* m_EventBroker;
|
||||
EventRelay<Client, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown &e);
|
||||
EventRelay<Client, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp &e);
|
||||
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand &e);
|
||||
};
|
||||
|
||||
@@ -24,10 +24,6 @@ void Client::Start(World* world, EventBroker* eventBroker)
|
||||
m_World = world;
|
||||
|
||||
// Subscribe to events
|
||||
m_EKeyDown = decltype(m_EKeyDown)(std::bind(&Client::OnKeyDown, this, std::placeholders::_1));
|
||||
m_EventBroker->Subscribe(m_EKeyDown);
|
||||
m_EKeyUp = decltype(m_EKeyUp)(std::bind(&Client::OnKeyUp, this, std::placeholders::_1));
|
||||
m_EventBroker->Subscribe(m_EKeyUp);
|
||||
m_EInputCommand = decltype(m_EInputCommand)(std::bind(&Client::OnInputCommand, this, std::placeholders::_1));
|
||||
m_EventBroker->Subscribe(m_EInputCommand);
|
||||
std::cout << "Please enter you name: ";
|
||||
@@ -60,8 +56,7 @@ void Client::Close()
|
||||
if (m_WasStarted) {
|
||||
Disconnect();
|
||||
m_ThreadIsRunning = false;
|
||||
m_EventBroker->Unsubscribe(m_EKeyDown);
|
||||
m_EventBroker->Unsubscribe(m_EKeyUp);
|
||||
m_EventBroker->Unsubscribe(m_EInputCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,54 +297,6 @@ void Client::MoveMessageHead(char*& data, size_t& length, size_t stepSize)
|
||||
length -= stepSize;
|
||||
}
|
||||
|
||||
bool Client::OnKeyDown(const Events::KeyDown& event)
|
||||
{
|
||||
if (event.KeyCode == GLFW_KEY_W) {
|
||||
m_IsWASDKeyDown.W = true;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_A) {
|
||||
m_IsWASDKeyDown.A = true;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_S) {
|
||||
m_IsWASDKeyDown.S = true;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_D) {
|
||||
m_IsWASDKeyDown.D = true;
|
||||
}
|
||||
|
||||
if (event.KeyCode == GLFW_KEY_V) {
|
||||
Disconnect();
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_C) {
|
||||
Connect();
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_P) {
|
||||
Ping();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::OnKeyUp(const Events::KeyUp & e)
|
||||
{
|
||||
if (e.KeyCode == GLFW_KEY_W) {
|
||||
m_IsWASDKeyDown.W = false;
|
||||
return true;
|
||||
}
|
||||
if (e.KeyCode == GLFW_KEY_A) {
|
||||
m_IsWASDKeyDown.A = false;
|
||||
return true;
|
||||
}
|
||||
if (e.KeyCode == GLFW_KEY_S) {
|
||||
m_IsWASDKeyDown.S = false;
|
||||
return true;
|
||||
}
|
||||
if (e.KeyCode == GLFW_KEY_D) {
|
||||
m_IsWASDKeyDown.D = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||
{
|
||||
if (e.Command == "Forward") {
|
||||
|
||||
@@ -303,15 +303,19 @@ void Server::ParseEvent(char * data, size_t length)
|
||||
|
||||
if ("+Forward" == std::string(data)) {
|
||||
m_World->GetComponent(entityId, "Player")["Forward"] = true;
|
||||
m_World->GetComponent(entityId, "Player")["Back"] = false;
|
||||
} else if ("-Forward" == std::string(data)) {
|
||||
m_World->GetComponent(entityId, "Player")["Forward"] = false;
|
||||
m_World->GetComponent(entityId, "Player")["Back"] = true;
|
||||
} else if ("0Forward" == std::string(data)) {
|
||||
m_World->GetComponent(entityId, "Player")["Forward"] = false;
|
||||
m_World->GetComponent(entityId, "Player")["Back"] = false;
|
||||
}
|
||||
if ("+Right" == std::string(data)) {
|
||||
m_World->GetComponent(entityId, "Player")["Left"] = false;
|
||||
m_World->GetComponent(entityId, "Player")["Right"] = true;
|
||||
} else if ("-Right" == std::string(data)) {
|
||||
m_World->GetComponent(entityId, "Player")["Right"] = false;
|
||||
m_World->GetComponent(entityId, "Player")["Left"] = true;
|
||||
} else if ("0Right" == std::string(data)) {
|
||||
m_World->GetComponent(entityId, "Player")["Right"] = false;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, double dt)
|
||||
{
|
||||
(glm::vec3)player["Velocity"] = glm::vec3(0.f);
|
||||
(glm::vec3)player["Velocity"] = glm::vec3(0.f, 0.f, 0.f);
|
||||
if (player["Forward"]) {
|
||||
((glm::vec3&)player["Velocity"]).z = m_Speed * float(dt) * -1;
|
||||
}
|
||||
@@ -16,6 +16,8 @@ void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, dou
|
||||
((glm::vec3&)player["Velocity"]).x = m_Speed * float(dt);
|
||||
}
|
||||
|
||||
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
|
||||
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
|
||||
if ((glm::vec3)player["Velocity"] != glm::vec3(0.f)) {
|
||||
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
|
||||
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user