Added component CapturePointGameMode that contains respawntime.
This commit is contained in:
@@ -14,8 +14,6 @@ public:
|
|||||||
|
|
||||||
virtual void Update(double dt) override;
|
virtual void Update(double dt) override;
|
||||||
|
|
||||||
static void SetRespawnTime(float respawnTime) { m_RespawnTime = respawnTime; };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SpawnRequest
|
struct SpawnRequest
|
||||||
{
|
{
|
||||||
@@ -31,8 +29,8 @@ private:
|
|||||||
//EntityWrapper ID -> Player ID.
|
//EntityWrapper ID -> Player ID.
|
||||||
std::map<EntityID, int> m_PlayerIDs;
|
std::map<EntityID, int> m_PlayerIDs;
|
||||||
|
|
||||||
static float m_RespawnTime;
|
float m_ForcedRespawnTime;
|
||||||
float m_Timer;
|
bool m_DbgConfigForceRespawn;
|
||||||
|
|
||||||
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
||||||
bool OnInputCommand(Events::InputCommand& e);
|
bool OnInputCommand(Events::InputCommand& e);
|
||||||
|
|||||||
@@ -48,4 +48,5 @@
|
|||||||
<xs:include schemaLocation="Components/Button.xsd"/>
|
<xs:include schemaLocation="Components/Button.xsd"/>
|
||||||
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
|
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
|
||||||
<xs:include schemaLocation="Components/DefenderWeapon.xsd"/>
|
<xs:include schemaLocation="Components/DefenderWeapon.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/CapturePointGameMode.xsd"/>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<CapturePointGameMode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CapturePointGameMode.xsd">
|
||||||
|
<RespawnTime>0.0</RespawnTime>
|
||||||
|
<MaxRespawnTime>8.0</MaxRespawnTime>
|
||||||
|
</CapturePointGameMode>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||||
|
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||||
|
|
||||||
|
<xs:element name="CapturePointGameMode">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="RespawnTime" type="t:double" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>The time since the last respawn wave. Players will be spawned when this reaches MaxRespawnTime.</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
<xs:element name="MaxRespawnTime" type="t:double" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>Players will be spawned when RespawnTime reaches this.</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -48,7 +48,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
|
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
|
||||||
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
|
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
|
||||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||||
PlayerSpawnSystem::SetRespawnTime(m_Config->Get<float>("Debug.RespawnTime", 15.0f));
|
|
||||||
|
|
||||||
// Create the core event broker
|
// Create the core event broker
|
||||||
m_EventBroker = new EventBroker();
|
m_EventBroker = new EventBroker();
|
||||||
|
|||||||
@@ -1,29 +1,40 @@
|
|||||||
#include "Systems/PlayerSpawnSystem.h"
|
#include "Systems/PlayerSpawnSystem.h"
|
||||||
|
|
||||||
//This should be set by the config anyway.
|
|
||||||
float PlayerSpawnSystem::m_RespawnTime = 15.0f;
|
|
||||||
|
|
||||||
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
|
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
|
||||||
: System(params)
|
: System(params)
|
||||||
, m_Timer(0.f)
|
, m_DbgConfigForceRespawn(false)
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerSpawnerd, &PlayerSpawnSystem::OnPlayerSpawned);
|
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerSpawnerd, &PlayerSpawnSystem::OnPlayerSpawned);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerSpawnSystem::OnPlayerDeath);
|
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerSpawnSystem::OnPlayerDeath);
|
||||||
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
|
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
|
m_NetworkEnabled = config->Get("Networking.StartNetwork", false);
|
||||||
|
m_ForcedRespawnTime = config->Get("Debug.RespawnTime", -1.0f);
|
||||||
|
m_DbgConfigForceRespawn = m_ForcedRespawnTime > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSpawnSystem::Update(double dt)
|
void PlayerSpawnSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
//Increase timer.
|
// If there are no CapturePointGameMode components we will just spawn immediately.
|
||||||
m_Timer += dt;
|
// Should be able to support older maps with this.
|
||||||
if (m_Timer < m_RespawnTime) {
|
// TODO: In the future we might want to return instead, to avoid spawning in the menu for instance.
|
||||||
return;
|
auto pool = m_World->GetComponents("CapturePointGameMode");
|
||||||
|
if (pool != nullptr)
|
||||||
|
{
|
||||||
|
// Take the first CapturePointGameMode component found.
|
||||||
|
ComponentWrapper& modeComponent = *pool->begin();
|
||||||
|
// Increase timer.
|
||||||
|
double& timer = (double&)modeComponent["RespawnTime"];
|
||||||
|
timer += dt;
|
||||||
|
double maxRespawnTime = m_DbgConfigForceRespawn ? m_ForcedRespawnTime : (double)modeComponent["MaxRespawnTime"];
|
||||||
|
if (timer < maxRespawnTime) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If respawn time has passed, we spawn all players that have requested to be spawned.
|
||||||
|
timer = 0;
|
||||||
}
|
}
|
||||||
//If respawn time has passed, we spawn all players that have requested to be spawned.
|
|
||||||
m_Timer = 0.f;
|
|
||||||
|
|
||||||
//If there are no spawn requests, return immediately, if we are client the SpawnRequests should always be empty.
|
// If there are no spawn requests, return immediately, if we are client the SpawnRequests should always be empty.
|
||||||
if (m_SpawnRequests.size() == 0) {
|
if (m_SpawnRequests.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user