WIP
This commit is contained in:
@@ -32,6 +32,8 @@
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
#include "Network/EDisplayServerlist.h"
|
||||
#include "Network/EConnectRequest.h"
|
||||
#include "Network/EPlayerDisconnected.h"
|
||||
|
||||
class Client : public Network
|
||||
{
|
||||
public:
|
||||
@@ -100,6 +102,7 @@ private:
|
||||
void parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseAmmoPickup(Packet& packet);
|
||||
void parseRemoveWorld(Packet& packet);
|
||||
void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||
void parseSnapshot(Packet& packet);
|
||||
void identifyPacketLoss();
|
||||
@@ -109,7 +112,6 @@ private:
|
||||
void sendLocalPlayerTransform();
|
||||
void becomePlayer();
|
||||
void displayServerlist();
|
||||
void removeWorld();
|
||||
void createMainMenu();
|
||||
// Mapping Logic
|
||||
// Returns if local EntityID exist in map
|
||||
|
||||
@@ -23,6 +23,7 @@ enum class MessageType
|
||||
OnDashEffect,
|
||||
ServerlistRequest,
|
||||
AmmoPickup,
|
||||
RemoveWorld,
|
||||
Invalid
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ protected:
|
||||
void saveToFile();
|
||||
void updateNetworkData();
|
||||
void popNetworkSegmentOfHeader(Packet& packet);
|
||||
void removeWorld();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "Network/MessageType.h"
|
||||
#include "Network/PlayerDefinition.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "../Network/Network.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
@@ -24,6 +25,7 @@
|
||||
#include "Core/EPlayerDeath.h"
|
||||
#include "Network/EPlayerConnected.h"
|
||||
#include "Network/EKillDeath.h"
|
||||
#include "Core/EWin.h"
|
||||
|
||||
class Server : public Network
|
||||
{
|
||||
@@ -110,6 +112,8 @@ private:
|
||||
bool OnAmmoPickup(const Events::AmmoPickup& e);
|
||||
EventRelay<Server, Events::PlayerDeath> m_EPlayerDeath;
|
||||
bool OnPlayerDeath(const Events::PlayerDeath& e);
|
||||
EventRelay<Server, Events::Win> m_EWin;
|
||||
bool OnWin(const Events::Win& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef Restart_h__
|
||||
#define Restart_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct Restart : Event
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Network/Client.h"
|
||||
#include "Network/EPlayerDisconnected.h"
|
||||
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
Client::Client(World* world, EventBroker* eventBroker)
|
||||
@@ -159,6 +159,9 @@ void Client::parseMessageType(Packet& packet)
|
||||
case MessageType::AmmoPickup:
|
||||
parseAmmoPickup(packet);
|
||||
break;
|
||||
case MessageType::RemoveWorld:
|
||||
parseRemoveWorld(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -336,6 +339,12 @@ void Client::parseAmmoPickup(Packet & packet)
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void Client::parseRemoveWorld(Packet & packet)
|
||||
{
|
||||
removeWorld();
|
||||
|
||||
}
|
||||
|
||||
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
|
||||
{
|
||||
for (auto field : componentInfo.FieldsInOrder) {
|
||||
@@ -706,19 +715,6 @@ void Client::displayServerlist()
|
||||
}
|
||||
}
|
||||
|
||||
void Client::removeWorld()
|
||||
{
|
||||
std::vector<EntityID> childrenToBeDeleted;
|
||||
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
|
||||
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
|
||||
childrenToBeDeleted.push_back(it->second);
|
||||
}
|
||||
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
|
||||
m_World->DeleteEntity(childrenToBeDeleted[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Client::createMainMenu()
|
||||
{
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/StartMenu.xml");
|
||||
|
||||
@@ -92,3 +92,15 @@ void Network::popNetworkSegmentOfHeader(Packet & packet)
|
||||
packet.ReadPrimitive<int>();
|
||||
packet.ReadPrimitive<int>();
|
||||
}
|
||||
|
||||
void Network::removeWorld()
|
||||
{
|
||||
std::vector<EntityID> childrenToBeDeleted;
|
||||
auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid);
|
||||
for (auto it = rootEntites.first; it != rootEntites.second; it++) {
|
||||
childrenToBeDeleted.push_back(it->second);
|
||||
}
|
||||
for (int i = 0; i < childrenToBeDeleted.size(); ++i) {
|
||||
m_World->DeleteEntity(childrenToBeDeleted[i]);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &Server::OnPlayerDeath);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EWin, &Server::OnWin);
|
||||
// BindWW
|
||||
if (port == 0) {
|
||||
port = config->Get<float>("Networking.Port", 27666);
|
||||
@@ -542,6 +543,18 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Server::OnWin(const Events::Win & e)
|
||||
{
|
||||
Packet removeMap(MessageType::RemoveWorld);
|
||||
reliableBroadcast(removeMap);
|
||||
removeWorld();
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/CP_Rocky2.xml");
|
||||
entityFile->MergeInto(m_World);
|
||||
Packet newWorld(MessageType::Snapshot);
|
||||
reliableBroadcast(newWorld);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::parseClientPing()
|
||||
{
|
||||
LOG_INFO("%i: Parsing ping", m_PacketID);
|
||||
|
||||
Reference in New Issue
Block a user