Merge branch 'master' of github.com:teamfisk/TacticalZ
This commit is contained in:
@@ -1,162 +0,0 @@
|
||||
#include "Core/TransformSystem.h"
|
||||
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::PositionCache;
|
||||
std::unordered_map<EntityWrapper, glm::quat> TransformSystem::OrientationCache;
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::ScaleCache;
|
||||
std::unordered_map<EntityWrapper, glm::mat4> TransformSystem::MatrixCache;
|
||||
|
||||
int TransformSystem::RecalculatedPositions = 0;
|
||||
int TransformSystem::RecalculatedOrientations = 0;
|
||||
int TransformSystem::RecalculatedScales = 0;
|
||||
|
||||
TransformSystem::TransformSystem(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &TransformSystem::OnEntityDeleted);
|
||||
}
|
||||
|
||||
bool TransformSystem::OnEntityDeleted(const Events::EntityDeleted& e)
|
||||
{
|
||||
// Clean up deleted entity
|
||||
PositionCache.erase(e.DeletedEntity);
|
||||
OrientationCache.erase(e.DeletedEntity);
|
||||
ScaleCache.erase(e.DeletedEntity);
|
||||
MatrixCache.erase(e.DeletedEntity);
|
||||
return true;
|
||||
}
|
||||
|
||||
//glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
|
||||
//{
|
||||
// glm::mat4 t = glm::mat4(1.f);
|
||||
//
|
||||
// while (entity.Valid()) {
|
||||
// t = glm::translate((const glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((const glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((const glm::vec3&)entity["Transform"]["Scale"]) * t;
|
||||
// entity = entity.Parent();
|
||||
// }
|
||||
//
|
||||
// return t;
|
||||
//}
|
||||
|
||||
glm::vec3 TransformSystem::AbsolutePosition(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsolutePosition(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsolutePosition(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3();
|
||||
}
|
||||
|
||||
auto cacheIt = PositionCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformPosition = cTransform["Position"];
|
||||
if (cacheIt != PositionCache.end() && !cTransformPosition.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate position
|
||||
glm::vec3 position = AbsolutePosition(parent) + TransformSystem::AbsoluteOrientation(parent) * (TransformSystem::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
|
||||
// Cache it
|
||||
PositionCache[entity] = position;
|
||||
RecalculatedPositions++;
|
||||
// Unset dirty flag
|
||||
cTransformPosition.SetDirty(DirtySetType::Transform, false);
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteOrientationEuler(EntityWrapper entity)
|
||||
{
|
||||
glm::vec3 orientation;
|
||||
|
||||
while (entity.Valid()) {
|
||||
ComponentWrapper transform = entity["Transform"];
|
||||
orientation += (Field<glm::vec3>)transform["Orientation"];
|
||||
entity = entity.Parent();
|
||||
}
|
||||
|
||||
return orientation;
|
||||
}
|
||||
|
||||
glm::quat TransformSystem::AbsoluteOrientation(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsoluteOrientation(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::quat TransformSystem::AbsoluteOrientation(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::quat();
|
||||
}
|
||||
|
||||
auto cacheIt = OrientationCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformOrientation = cTransform["Orientation"];
|
||||
if (cacheIt != OrientationCache.end() && !cTransformOrientation.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate orientation
|
||||
glm::quat orientation = AbsoluteOrientation(parent) * glm::quat((const glm::vec3&)cTransformOrientation);
|
||||
// Cache it
|
||||
OrientationCache[entity] = orientation;
|
||||
RecalculatedOrientations++;
|
||||
// Unset dirty flag
|
||||
cTransformOrientation.SetDirty(DirtySetType::Transform, false);
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteScale(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsoluteScale(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteScale(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3(1.f);
|
||||
}
|
||||
|
||||
auto cacheIt = ScaleCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformScale = cTransform["Scale"];
|
||||
if (cacheIt != ScaleCache.end() && !cTransformScale.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate scale
|
||||
glm::vec3 scale = AbsoluteScale(parent) * (const glm::vec3&)cTransformScale;
|
||||
// Cache it
|
||||
ScaleCache[entity] = scale;
|
||||
RecalculatedPositions++;
|
||||
// Unset dirty flag
|
||||
cTransformScale.SetDirty(DirtySetType::Transform, false);
|
||||
return scale;
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityID entityID, World* world)
|
||||
{
|
||||
return ModelMatrix(EntityWrapper(world, entityID));
|
||||
}
|
||||
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityWrapper entity)
|
||||
{
|
||||
auto cacheIt = MatrixCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
bool isDirty = cTransform["Position"].Dirty(DirtySetType::Transform) || cTransform["Orientation"].Dirty(DirtySetType::Transform) || cTransform["Scale"].Dirty(DirtySetType::Transform);
|
||||
if (cacheIt != MatrixCache.end() && !isDirty) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
glm::mat4 matrix = glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
|
||||
MatrixCache[entity] = matrix;
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
|
||||
{
|
||||
return glm::vec3(matrix * glm::vec4(point.x, point.y, point.z, 1));
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Network/Client.h"
|
||||
#include "Network/EPlayerDisconnected.h"
|
||||
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
Client::Client(World* world, EventBroker* eventBroker)
|
||||
@@ -12,7 +12,7 @@ Client::Client(World* world, EventBroker* eventBroker)
|
||||
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_PlayerName = config->Get<std::string>("Networking.Name", "Raptorcopter");
|
||||
m_SendInputIntervalMs = config->Get<int>("Networking.SendInputIntervalMs", 33);
|
||||
m_SendInputInterval = config->Get<int>("Networking.SendInputIntervalMs", 33) / 1000.0;
|
||||
LOG_INFO("Client initialized");
|
||||
|
||||
m_ServerlistRequest.Connect(m_PlayerName, "192.168.1.255", 32554);
|
||||
@@ -48,7 +48,7 @@ void Client::Connect(std::string address, int port)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::Update()
|
||||
void Client::Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<Client>();
|
||||
while (m_Unreliable.IsSocketAvailable()) {
|
||||
@@ -85,7 +85,9 @@ void Client::Update()
|
||||
}
|
||||
|
||||
if (m_SearchingForServers) {
|
||||
if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
|
||||
m_TimeSearched += dt;
|
||||
if (m_SearchingTime < m_TimeSearched) {
|
||||
m_TimeSearched = 0;
|
||||
m_SearchingForServers = false;
|
||||
//displayServerlist();
|
||||
Events::DisplayServerlist e;
|
||||
@@ -96,16 +98,25 @@ void Client::Update()
|
||||
|
||||
if (m_IsConnected) {
|
||||
// Don't send 1 input in 1 packet, bunch em up.
|
||||
if (m_SendInputIntervalMs < (1000 * (std::clock() - m_TimeSinceSentInputs) / (double)CLOCKS_PER_SEC)) {
|
||||
m_TimeSinceSentInputs += dt;
|
||||
if (m_SendInputInterval < m_TimeSinceSentInputs) {
|
||||
sendInputCommands();
|
||||
m_TimeSinceSentInputs = std::clock();
|
||||
m_TimeSinceSentInputs = 0;
|
||||
}
|
||||
// HACK: Send absolute player positions for now to avoid desync until we have reliable messages
|
||||
sendLocalPlayerTransform();
|
||||
|
||||
hasServerTimedOut();
|
||||
}
|
||||
//Network::Update();
|
||||
|
||||
if (ImGui::BeginPopupModal("Disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text("You have been disconnected from server.\n\n");
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvailWidth() - 120);
|
||||
if (ImGui::Button("OK", ImVec2(120, 0))) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void Client::parseMessageType(Packet& packet)
|
||||
@@ -159,6 +170,9 @@ void Client::parseMessageType(Packet& packet)
|
||||
case MessageType::AmmoPickup:
|
||||
parseAmmoPickup(packet);
|
||||
break;
|
||||
case MessageType::RemoveWorld:
|
||||
parseRemoveWorld(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -190,7 +204,7 @@ void Client::parseTCPConnect(Packet& packet)
|
||||
packet.WritePrimitive(m_PlayerID);
|
||||
m_Unreliable.Send(packet);
|
||||
|
||||
// LOG_INFO("Sent UDP Connect Server");
|
||||
// LOG_INFO("Sent UDP Connect Server");
|
||||
}
|
||||
|
||||
void Client::parsePlayerConnected(Packet & packet)
|
||||
@@ -336,6 +350,13 @@ void Client::parseAmmoPickup(Packet & packet)
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void Client::parseRemoveWorld(Packet & packet)
|
||||
{
|
||||
removeWorld();
|
||||
Events::Reset e;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
|
||||
{
|
||||
for (auto field : componentInfo.FieldsInOrder) {
|
||||
@@ -583,7 +604,7 @@ bool Client::OnConnectRequest(const Events::ConnectRequest& e)
|
||||
bool Client::OnSearchForServers(const Events::SearchForServers& e)
|
||||
{
|
||||
m_SearchingForServers = true;
|
||||
m_StartSearchTime = std::clock();
|
||||
m_TimeSearched = 0;
|
||||
m_Serverlist.clear();
|
||||
Packet packet(MessageType::ServerlistRequest);
|
||||
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
|
||||
@@ -663,6 +684,7 @@ void Client::hasServerTimedOut()
|
||||
if (timeSincePing > m_TimeoutMs) {
|
||||
// Clear everything and go to menu.
|
||||
LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
|
||||
ImGui::OpenPopup("Disconnected");
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
@@ -706,19 +728,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");
|
||||
|
||||
@@ -9,7 +9,7 @@ Network::Network(World* world, EventBroker* eventBroker)
|
||||
m_TimeoutMs = config->Get<int>("Networking.TimeoutMs", 20000);
|
||||
}
|
||||
|
||||
void Network::Update()
|
||||
void Network::Update(double dt)
|
||||
{
|
||||
updateNetworkData();
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
|
||||
, m_ServerlistRequest(13)
|
||||
{
|
||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05f);
|
||||
pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
|
||||
snapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05);
|
||||
pingInterval = config->Get<float>("Networking.PingIntervalMs", 1000) / 1000.0;
|
||||
m_ServerName = config->Get<std::string>("Networking.Name", "Unnamed");
|
||||
|
||||
// Subscribe to events
|
||||
@@ -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);
|
||||
@@ -30,7 +31,7 @@ Server::~Server()
|
||||
|
||||
}
|
||||
|
||||
void Server::Update()
|
||||
void Server::Update(double dt)
|
||||
{
|
||||
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
|
||||
|
||||
@@ -86,26 +87,44 @@ void Server::Update()
|
||||
}
|
||||
m_PlayersToDisconnect.clear();
|
||||
|
||||
std::clock_t currentTime = std::clock();
|
||||
// Send snapshot
|
||||
if (snapshotInterval < (1000 * (currentTime - previousSnapshotMessage) / (double)CLOCKS_PER_SEC)) {
|
||||
previousSnapshotMessage += dt;
|
||||
if (snapshotInterval < previousSnapshotMessage) {
|
||||
sendSnapshot();
|
||||
previousSnapshotMessage = currentTime;
|
||||
previousSnapshotMessage = 0;
|
||||
}
|
||||
// Send pings each
|
||||
if (pingIntervalMs < (1000 * (currentTime - previousePingMessage) / (double)CLOCKS_PER_SEC)) {
|
||||
previousPingMessage += dt;
|
||||
if (pingInterval < previousPingMessage) {
|
||||
sendPing();
|
||||
previousePingMessage = currentTime;
|
||||
previousPingMessage = 0;
|
||||
}
|
||||
|
||||
// Time out logic
|
||||
if (checkTimeOutInterval < (1000 * (currentTime - timOutTimer) / (double)CLOCKS_PER_SEC)) {
|
||||
timeOutTimer += dt;
|
||||
if (checkTimeOutInterval < timeOutTimer) {
|
||||
checkForTimeOuts();
|
||||
timOutTimer = currentTime;
|
||||
timeOutTimer = 0;
|
||||
}
|
||||
m_EventBroker->Process<Server>();
|
||||
if (isReadingData) {
|
||||
Network::Update();
|
||||
Network::Update(dt);
|
||||
}
|
||||
|
||||
if (m_GameIsOver) {
|
||||
auto pool = m_World->GetComponents("CapturePointGameMode");
|
||||
if (pool != nullptr && pool->size() > 0) {
|
||||
// Take the first CapturePointGameMode component found.
|
||||
ComponentWrapper& modeComponent = *pool->begin();
|
||||
// Decrease timer.
|
||||
Field<double> timer = modeComponent["ResetCountdown"];
|
||||
timer -= dt;
|
||||
if (timer < 0) {
|
||||
resetMap();
|
||||
}
|
||||
} else {
|
||||
resetMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +183,7 @@ void Server::reliableBroadcast(Packet& packet)
|
||||
|
||||
void Server::unreliableBroadcast(Packet& packet)
|
||||
{
|
||||
m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers);
|
||||
m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers);
|
||||
}
|
||||
|
||||
// Send snapshot fields
|
||||
@@ -173,10 +192,16 @@ void Server::sendSnapshot()
|
||||
Packet packet(MessageType::Snapshot);
|
||||
addInputCommandsToPacket(packet);
|
||||
addPlayersToPacket(packet, EntityID_Invalid);
|
||||
//addChildrenToPacket(packet, EntityID_Invalid);
|
||||
unreliableBroadcast(packet);
|
||||
}
|
||||
|
||||
// Send snapshot fields
|
||||
void Server::createWorldSnapshot(Packet& packet)
|
||||
{
|
||||
addInputCommandsToPacket(packet);
|
||||
addChildrenToPacket(packet, EntityID_Invalid);
|
||||
}
|
||||
|
||||
void Server::addInputCommandsToPacket(Packet& packet)
|
||||
{
|
||||
// Number of input commands
|
||||
@@ -379,8 +404,7 @@ void Server::parseTCPConnect(Packet & packet)
|
||||
m_Reliable.Send(connnectPacket, m_ConnectedPlayers.at(playerID));
|
||||
|
||||
Packet firstSnapshot(MessageType::Snapshot);
|
||||
addInputCommandsToPacket(firstSnapshot);
|
||||
addChildrenToPacket(firstSnapshot, EntityID_Invalid);
|
||||
createWorldSnapshot(firstSnapshot);
|
||||
m_Reliable.Send(firstSnapshot);
|
||||
|
||||
// Send notification that a player has connected
|
||||
@@ -542,6 +566,13 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Server::OnWin(const Events::Win & e)
|
||||
{
|
||||
// Postpone the gameover reset
|
||||
m_GameIsOver = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::parseClientPing()
|
||||
{
|
||||
LOG_INFO("%i: Parsing ping", m_PacketID);
|
||||
@@ -663,4 +694,20 @@ PlayerID Server::getPlayerIDFromEntityID(EntityID entityID)
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Server::resetMap()
|
||||
{
|
||||
m_GameIsOver = false;
|
||||
Events::Reset reset;
|
||||
m_EventBroker->Publish(reset);
|
||||
Packet removeMap(MessageType::RemoveWorld);
|
||||
reliableBroadcast(removeMap);
|
||||
removeWorld();
|
||||
// Hardcoded for now.
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/CP_Rocky2.xml");
|
||||
entityFile->MergeInto(m_World);
|
||||
Packet newWorld(MessageType::Snapshot);
|
||||
createWorldSnapshot(newWorld);
|
||||
reliableBroadcast(newWorld);
|
||||
}
|
||||
+2
-2
@@ -232,10 +232,10 @@ void Game::Tick()
|
||||
PerformanceTimer::StartTimerAndStopPrevious("Network");
|
||||
m_EventBroker->Process<MultiplayerSnapshotFilter>();
|
||||
if (m_NetworkClient != nullptr) {
|
||||
m_NetworkClient->Update();
|
||||
m_NetworkClient->Update(dt);
|
||||
}
|
||||
if (m_NetworkServer != nullptr) {
|
||||
m_NetworkServer->Update();
|
||||
m_NetworkServer->Update(dt);
|
||||
}
|
||||
//m_SoundManager->Update(dt);
|
||||
|
||||
|
||||
@@ -10,8 +10,26 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EReset, &CapturePointSystem::OnReset);
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
void CapturePointSystem::Init()
|
||||
{
|
||||
m_WinnerWasFound = false;
|
||||
//need to track these variables for the captureSystem to work as per design!
|
||||
m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint;
|
||||
m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint;
|
||||
m_RedTeamHomeCapturePoint = m_NotACapturePoint;
|
||||
m_BlueTeamHomeCapturePoint = m_NotACapturePoint;
|
||||
m_NumberOfCapturePoints = 0;
|
||||
m_ResetTimers = false;
|
||||
m_RecentlyCapturedNeedNextCapturePointNow = false;
|
||||
m_CapturePointNumberToEntityMap.clear();
|
||||
//vectors which will keep track of enter/leave changes
|
||||
m_ETriggerTouchVector.clear();
|
||||
m_ETriggerLeaveVector.clear();
|
||||
}
|
||||
|
||||
//here all capturepoints will update their component
|
||||
@@ -24,6 +42,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
if (m_WinnerWasFound) {
|
||||
return;
|
||||
}
|
||||
if (!capturePointEntity.Valid()) {
|
||||
return;
|
||||
}
|
||||
const int capturePointNumber = cCapturePoint["CapturePointNumber"];
|
||||
const bool hasTeamComponent = capturePointEntity.HasComponent("Team");
|
||||
|
||||
@@ -60,7 +81,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
}
|
||||
|
||||
//if we havent received all capturepoints yet, just return
|
||||
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) {
|
||||
if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints > m_CapturePointNumberToEntityMap.size()) {
|
||||
m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity));
|
||||
return;
|
||||
}
|
||||
@@ -232,10 +253,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
|
||||
}
|
||||
|
||||
void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) {
|
||||
void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner)
|
||||
{
|
||||
(Field<bool>)capturePointModels["Model"]["Visible"] = isOwner;
|
||||
for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform"))
|
||||
{
|
||||
for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) {
|
||||
if (capModel.HasComponent("Model")) {
|
||||
(Field<bool>)capModel["Model"]["Visible"] = isOwner;
|
||||
}
|
||||
@@ -269,3 +290,9 @@ bool CapturePointSystem::OnCaptured(const Events::Captured& e)
|
||||
m_ResetTimers = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CapturePointSystem::OnReset(const Events::Reset& e)
|
||||
{
|
||||
Init();
|
||||
return true;
|
||||
}
|
||||
@@ -9,6 +9,8 @@ ScoreScreenSystem::ScoreScreenSystem(SystemParams params)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &ScoreScreenSystem::OnPlayerSpawn);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerConnected, &ScoreScreenSystem::OnPlayerConnected);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDisconnected, &ScoreScreenSystem::OnPlayerDisconnected);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EReset, &ScoreScreenSystem::OnReset);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &ScoreScreenSystem::OnInputCommand);
|
||||
}
|
||||
|
||||
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt)
|
||||
@@ -156,3 +158,25 @@ bool ScoreScreenSystem::OnPlayerDisconnected(const Events::PlayerDisconnected& e
|
||||
m_DisconnectedIdentities.push_back(e.PlayerID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ScoreScreenSystem::OnReset(const Events::Reset & e)
|
||||
{
|
||||
for (auto& it : m_PlayerIdentities) {
|
||||
it.second.Deaths = 0;
|
||||
it.second.Kills = 0;
|
||||
it.second.Team = 1;
|
||||
it.second.Player = EntityWrapper::Invalid;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScoreScreenSystem::OnInputCommand(const Events::InputCommand & e)
|
||||
{
|
||||
if (e.Command != "PickTeam" || e.PlayerID == -1 || e.Value == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_PlayerIdentities.at(e.PlayerID).Team = e.Value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EReset, &SpectatorCameraSystem::OnReset);
|
||||
}
|
||||
|
||||
void SpectatorCameraSystem::Update(double dt)
|
||||
@@ -27,6 +28,14 @@ void SpectatorCameraSystem::Update(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
void SpectatorCameraSystem::reset()
|
||||
{
|
||||
m_CamSetToTeamPick = false;
|
||||
// They will also be set to menu, so unlock mouse just in case they were in game with locked mouse.
|
||||
Events::UnlockMouse unlock;
|
||||
m_EventBroker->Publish(unlock);
|
||||
}
|
||||
|
||||
bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
{
|
||||
// Only the client should do this, and only if player is not spawned.
|
||||
@@ -99,10 +108,13 @@ bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e)
|
||||
// If local player gets disconnected, they should be set to
|
||||
// the spectator camera next time a map loads that has one.
|
||||
if (e.Entity == LocalPlayer.ID) {
|
||||
m_CamSetToTeamPick = false;
|
||||
// They will also be set to menu, so unlock mouse just in case they were in game with locked mouse.
|
||||
Events::UnlockMouse unlock;
|
||||
m_EventBroker->Publish(unlock);
|
||||
reset();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpectatorCameraSystem::OnReset(const Events::Reset & e)
|
||||
{
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user