Add current progression
This commit is contained in:
@@ -12,6 +12,8 @@ Command *Command::create(int clientIndex, yojimbo::Message *message)
|
||||
return new TestCommand(clientIndex, ((TestMessage *)message)->m_data);
|
||||
case (int)GameMessageType::SETNAME:
|
||||
return new SetNameCommand(clientIndex, std::string(((SetNameMessage *)message)->buffer));
|
||||
case (int)GameMessageType::INPUTSTATEMESSAGE:
|
||||
return new PlayerInputCommand(clientIndex, ((InputStateMessage *) message)->m_vel_x, ((InputStateMessage *) message)->m_vel_y);
|
||||
default:
|
||||
std::cout << "Unknown message type received over network!" << std::endl;
|
||||
return nullptr;
|
||||
@@ -31,6 +33,9 @@ Command *Command::create(std::string command)
|
||||
else if (token == "test")
|
||||
{
|
||||
return new TestCommand(-1, 100);
|
||||
} else if (token == "sendTest")
|
||||
{
|
||||
return new SendTestCommand(0, 42);
|
||||
}
|
||||
std::cout << "Local command don't exists: " << command << std::endl;
|
||||
return nullptr;
|
||||
|
||||
@@ -25,9 +25,10 @@ class TestCommand : public Command
|
||||
{
|
||||
public:
|
||||
TestCommand(int clientIndex, int data)
|
||||
: m_clientIndex(clientIndex),
|
||||
m_data(data)
|
||||
{}
|
||||
: m_clientIndex(clientIndex),
|
||||
m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void execute(GameServer *server) override;
|
||||
|
||||
@@ -40,9 +41,10 @@ class SetNameCommand : public Command
|
||||
{
|
||||
public:
|
||||
SetNameCommand(int clientIndex, std::string name)
|
||||
: m_clientIndex(clientIndex),
|
||||
m_name(name)
|
||||
{}
|
||||
: m_clientIndex(clientIndex),
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void execute(GameServer *server) override;
|
||||
|
||||
@@ -57,4 +59,36 @@ class StopCommand : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(GameServer *server) override;
|
||||
};
|
||||
};
|
||||
|
||||
class SendTestCommand : public Command
|
||||
{
|
||||
public:
|
||||
SendTestCommand(int clientIndex, int data)
|
||||
: m_clientIndex(clientIndex),
|
||||
m_data(data)
|
||||
{
|
||||
}
|
||||
virtual void execute(GameServer *server) override;
|
||||
|
||||
private:
|
||||
int m_clientIndex;
|
||||
int m_data;
|
||||
};
|
||||
|
||||
class PlayerInputCommand : public Command
|
||||
{
|
||||
public:
|
||||
PlayerInputCommand(int clientIndex, float vel_x, float vel_y)
|
||||
: m_clientIndex(clientIndex),
|
||||
m_vel_x(vel_x),
|
||||
m_vel_y(vel_y)
|
||||
{
|
||||
}
|
||||
virtual void execute(GameServer *server) override;
|
||||
|
||||
private:
|
||||
int m_clientIndex;
|
||||
float m_vel_x, m_vel_y;
|
||||
};
|
||||
|
||||
|
||||
14
src/commands/PlayerInputCommand.cpp
Normal file
14
src/commands/PlayerInputCommand.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "Command.h"
|
||||
|
||||
#include "../core/Components.h"
|
||||
|
||||
void PlayerInputCommand::execute(GameServer *server)
|
||||
{
|
||||
entityx::Entity entity = server->serverToEntityX.at(m_clientIndex);
|
||||
entityx::ComponentHandle<InputVelocity> iVel = entity.component<InputVelocity>();
|
||||
if (iVel)
|
||||
{
|
||||
iVel->m_vel_x = this->m_vel_x;
|
||||
iVel->m_vel_y = this->m_vel_y;
|
||||
}
|
||||
}
|
||||
9
src/commands/SendTestCommand.cpp
Normal file
9
src/commands/SendTestCommand.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "Command.h"
|
||||
|
||||
void SendTestCommand::execute(GameServer *server)
|
||||
{
|
||||
std::cout << "Sending Test command to ClientID: " << this->m_clientIndex << " with data: " << this->m_data << std::endl;
|
||||
TestMessage *msg = (TestMessage *)server->m_server.CreateMessage(this->m_clientIndex, (int)GameMessageType::TEST);
|
||||
msg->m_data = this->m_data;
|
||||
server->m_server.SendMessage(this->m_clientIndex, (int)GameChannel::RELIABLE, msg);
|
||||
}
|
||||
Reference in New Issue
Block a user