Merge pull request #155 from teamfisk/Respawning
Looks good man! 🇺🇸 🍔 😎
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "ObjectPool.h"
|
#include "ObjectPool.h"
|
||||||
#include "ComponentPool.h"
|
#include "ComponentPool.h"
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
|
struct EntityWrapper;
|
||||||
|
|
||||||
class World
|
class World
|
||||||
{
|
{
|
||||||
@@ -49,6 +50,8 @@ public:
|
|||||||
void SetName(EntityID entity, const std::string& name);
|
void SetName(EntityID entity, const std::string& name);
|
||||||
// Get the textual name of an entity
|
// Get the textual name of an entity
|
||||||
std::string GetName(EntityID entity) const;
|
std::string GetName(EntityID entity) const;
|
||||||
|
// Get the first entity in the world with the name.
|
||||||
|
EntityWrapper GetFirstEntityByName(const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventBroker* m_EventBroker = nullptr;
|
EventBroker* m_EventBroker = nullptr;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Core/EntityFileParser.h"
|
#include "Core/EntityFileParser.h"
|
||||||
|
|
||||||
#include "Core/EPlayerDeath.h"
|
#include "Core/EPlayerDeath.h"
|
||||||
|
#include "Core/EEntityDeleted.h"
|
||||||
|
|
||||||
class PlayerDeathSystem : public ImpureSystem
|
class PlayerDeathSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
@@ -20,8 +21,12 @@ public:
|
|||||||
virtual void Update(double dt) override;
|
virtual void Update(double dt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
EntityWrapper m_LocalPlayerDeathEffect;
|
||||||
|
|
||||||
EventRelay<PlayerDeathSystem, Events::PlayerDeath> m_OnPlayerDeath;
|
EventRelay<PlayerDeathSystem, Events::PlayerDeath> m_OnPlayerDeath;
|
||||||
bool OnPlayerDeath(Events::PlayerDeath& e);
|
bool OnPlayerDeath(Events::PlayerDeath& e);
|
||||||
|
EventRelay<PlayerDeathSystem, Events::EntityDeleted> m_EEntityDeleted;
|
||||||
|
bool OnEntityDeleted(Events::EntityDeleted& e);
|
||||||
|
|
||||||
void createDeathEffect(EntityWrapper player);
|
void createDeathEffect(EntityWrapper player);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ LoadMap=
|
|||||||
; if true -> Pool allocation is not used when calling Allocate/Free, just use regular dynamic allocation.
|
; if true -> Pool allocation is not used when calling Allocate/Free, just use regular dynamic allocation.
|
||||||
; if false -> Use pool allocation.
|
; if false -> Use pool allocation.
|
||||||
DisableMemoryPool=false
|
DisableMemoryPool=false
|
||||||
RespawnTime = 8.0
|
RespawnTime = -1.0
|
||||||
EditorEnabled=false
|
EditorEnabled=false
|
||||||
OutOfBodyExperience=false
|
OutOfBodyExperience=false
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,219 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<Entity name="SpectatorCamera" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||||
|
|
||||||
|
<Components>
|
||||||
|
<c:Camera/>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
|
||||||
|
<Children>
|
||||||
|
<Entity name="SpectatorHUD">
|
||||||
|
<Components>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="-0.5"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="RespawnTimer">
|
||||||
|
<Components>
|
||||||
|
<c:Text>
|
||||||
|
<Content>Time to respawn: 0</Content>
|
||||||
|
<Resource>Fonts/DroidSans.ttf,64</Resource>
|
||||||
|
<Color A="1" B="0" G="1" R="0.784313738"/>
|
||||||
|
<Alignment>
|
||||||
|
<Left/>
|
||||||
|
</Alignment>
|
||||||
|
</c:Text>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-0.115000000" Y="0.15304254" Z="0"/>
|
||||||
|
<Scale X="0.0250000004" Y="0.0250000004" Z="1"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="CapturePointHUD">
|
||||||
|
<Components>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0.190541431" Z="0"/>
|
||||||
|
<Scale X="0.0599999987" Y="0.0599999987" Z="0.0599999987"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="BackgroundHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
<Color A="0.300000012" B="1" G="1" R="1"/>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0.919596612" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ProgressionHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:CapturePointHUD>
|
||||||
|
<CapturePointNumber>2</CapturePointNumber>
|
||||||
|
</c:CapturePointHUD>
|
||||||
|
<c:Fill>
|
||||||
|
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||||
|
</c:Fill>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0.00999999978"/>
|
||||||
|
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
|
||||||
|
<Orientation X="0" Y="0" Z="1.57079637"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BackgroundHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
<Color A="0.300000012" B="1" G="1" R="1"/>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0.811270177" Y="0.440691769" Z="-0.100000001"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ProgressionHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:CapturePointHUD>
|
||||||
|
<CapturePointNumber>3</CapturePointNumber>
|
||||||
|
</c:CapturePointHUD>
|
||||||
|
<c:Fill>
|
||||||
|
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||||
|
</c:Fill>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0.00999999978"/>
|
||||||
|
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
|
||||||
|
<Orientation X="0" Y="0" Z="1.57079637"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BackgroundHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="1.62788737" Y="0.919596612" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ProgressionHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:CapturePointHUD>
|
||||||
|
<CapturePointNumber>4</CapturePointNumber>
|
||||||
|
</c:CapturePointHUD>
|
||||||
|
<c:Fill>
|
||||||
|
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||||
|
</c:Fill>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0.00999999978"/>
|
||||||
|
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
|
||||||
|
<Orientation X="0" Y="0" Z="1.57079637"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BackgroundHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
<Color A="0.300000012" B="1" G="1" R="1"/>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-0.820431828" Y="0.441878349" Z="-0.100000001"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ProgressionHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:CapturePointHUD>
|
||||||
|
<CapturePointNumber>1</CapturePointNumber>
|
||||||
|
</c:CapturePointHUD>
|
||||||
|
<c:Fill>
|
||||||
|
<Percentage>0.59265931447347009</Percentage>
|
||||||
|
<Color A="0.699999988" B="0" G="0" R="1"/>
|
||||||
|
</c:Fill>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0.00999999978"/>
|
||||||
|
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
|
||||||
|
<Orientation X="0" Y="0" Z="4.71238899"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BackgroundHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
<Color A="0.699999988" B="0" G="0" R="1"/>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-1.58304751" Y="0.919596612" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ProgressionHexagon">
|
||||||
|
<Components>
|
||||||
|
<c:CapturePointHUD/>
|
||||||
|
<c:Fill>
|
||||||
|
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||||
|
</c:Fill>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||||
|
<GlowMap></GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="0.00999999978"/>
|
||||||
|
<Scale X="0.800000012" Y="0.800000012" Z="0.800000012"/>
|
||||||
|
<Orientation X="0" Y="0" Z="1.57079637"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
|
||||||
|
</Entity>
|
||||||
@@ -54,6 +54,12 @@
|
|||||||
<xs:element ref="c:DefenderWeapon" minOccurs="0"/>
|
<xs:element ref="c:DefenderWeapon" minOccurs="0"/>
|
||||||
<xs:element ref="c:CapturePointArrowHUD" minOccurs="0"/>
|
<xs:element ref="c:CapturePointArrowHUD" minOccurs="0"/>
|
||||||
<xs:element ref="c:FloatingEffect" minOccurs="0"/>
|
<xs:element ref="c:FloatingEffect" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:AmmoPickup" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:HealthPickup" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:CapturePointGameMode" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:DoubleJump" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:HealthHUD" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:SpriteIndicator" minOccurs="0"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|||||||
@@ -33,13 +33,20 @@ void EntityFileParser::onStartEntity(EntityID entity, EntityID parent, const std
|
|||||||
|
|
||||||
void EntityFileParser::onStartComponent(EntityID entity, const std::string& component)
|
void EntityFileParser::onStartComponent(EntityID entity, const std::string& component)
|
||||||
{
|
{
|
||||||
EntityID realEntity = m_EntityIDMapper.at(entity);
|
if (m_World->GetComponentPools().count(component) != 0) {
|
||||||
m_World->AttachComponent(realEntity, component);
|
EntityID realEntity = m_EntityIDMapper.at(entity);
|
||||||
|
m_World->AttachComponent(realEntity, component);
|
||||||
|
} else {
|
||||||
|
LOG_ERROR("Tried to attach unregistered component \"%s\"! to entity #%i. Ignoring.", component.c_str(), entity);
|
||||||
|
}
|
||||||
//LOG_DEBUG("Attached component of type \"%s\" to entity #%i (%i)", component.c_str(), entity, realEntity);
|
//LOG_DEBUG("Attached component of type \"%s\" to entity #%i (%i)", component.c_str(), entity, realEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityFileParser::onStartComponentField(EntityID entity, const std::string& componentType, const std::string& fieldName, const std::map<std::string, std::string>& attributes)
|
void EntityFileParser::onStartComponentField(EntityID entity, const std::string& componentType, const std::string& fieldName, const std::map<std::string, std::string>& attributes)
|
||||||
{
|
{
|
||||||
|
if (m_World->GetComponentPools().count(componentType) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
EntityID realEntity = m_EntityIDMapper.at(entity);
|
EntityID realEntity = m_EntityIDMapper.at(entity);
|
||||||
ComponentWrapper component = m_World->GetComponent(realEntity, componentType);
|
ComponentWrapper component = m_World->GetComponent(realEntity, componentType);
|
||||||
auto fieldIt = component.Info.Fields.find(fieldName);
|
auto fieldIt = component.Info.Fields.find(fieldName);
|
||||||
@@ -61,6 +68,9 @@ void EntityFileParser::onStartComponentField(EntityID entity, const std::string&
|
|||||||
|
|
||||||
void EntityFileParser::onFieldData(EntityID entity, const std::string& componentType, const std::string& fieldName, const char* fieldData)
|
void EntityFileParser::onFieldData(EntityID entity, const std::string& componentType, const std::string& fieldName, const char* fieldData)
|
||||||
{
|
{
|
||||||
|
if (m_World->GetComponentPools().count(componentType) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
EntityID realEntity = m_EntityIDMapper.at(entity);
|
EntityID realEntity = m_EntityIDMapper.at(entity);
|
||||||
ComponentWrapper component = m_World->GetComponent(realEntity, componentType);
|
ComponentWrapper component = m_World->GetComponent(realEntity, componentType);
|
||||||
auto fieldIt = component.Info.Fields.find(fieldName);
|
auto fieldIt = component.Info.Fields.find(fieldName);
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (logLevel == LOG_LEVEL_ERROR) {
|
if (logLevel == LOG_LEVEL_ERROR) {
|
||||||
//std::cerr << file << ":" << line << " " << func << std::endl;
|
std::cerr << file << ":" << line << " " << func << std::endl;
|
||||||
//std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
#include "Core/EEntityDeleted.h"
|
#include "Core/EEntityDeleted.h"
|
||||||
#include "Core/EComponentDeleted.h"
|
#include "Core/EComponentDeleted.h"
|
||||||
|
#include "Core/EntityWrapper.h"
|
||||||
|
|
||||||
World::~World()
|
World::~World()
|
||||||
{
|
{
|
||||||
@@ -151,6 +152,23 @@ std::string World::GetName(EntityID entity) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityWrapper World::GetFirstEntityByName(const std::string& name)
|
||||||
|
{
|
||||||
|
auto itPair = GetDirectChildren(EntityID_Invalid);
|
||||||
|
for (auto it = itPair.first; it != itPair.second; it++) {
|
||||||
|
EntityID childEntityID = it->second;
|
||||||
|
EntityWrapper childEntity(this, childEntityID);
|
||||||
|
if (!childEntity.Valid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EntityWrapper entityWithName = childEntity.Name() == name ? childEntity : childEntity.FirstChildByName(name);
|
||||||
|
if (entityWithName.Valid()) {
|
||||||
|
return entityWithName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EntityWrapper::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
EntityID World::generateEntityID()
|
EntityID World::generateEntityID()
|
||||||
{
|
{
|
||||||
// TODO: Make EntityID generation smarter
|
// TODO: Make EntityID generation smarter
|
||||||
|
|||||||
@@ -265,7 +265,8 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem
|
|||||||
EntityFileParser fp(entityFile);
|
EntityFileParser fp(entityFile);
|
||||||
EntityID newEntity = fp.MergeEntities(parent.World, parent.ID);
|
EntityID newEntity = fp.MergeEntities(parent.World, parent.ID);
|
||||||
return EntityWrapper(parent.World, newEntity);
|
return EntityWrapper(parent.World, newEntity);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception& e) {
|
||||||
|
LOG_ERROR("Failed to import entity \"%s\": \"%s\"", filePath.string().c_str(), e.what());
|
||||||
return EntityWrapper::Invalid;
|
return EntityWrapper::Invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
|
|||||||
: System(params)
|
: System(params)
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerDeathSystem::OnPlayerDeath);
|
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerDeathSystem::OnPlayerDeath);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &PlayerDeathSystem::OnEntityDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerDeathSystem::Update(double dt)
|
void PlayerDeathSystem::Update(double dt)
|
||||||
@@ -59,9 +60,28 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
|||||||
|
|
||||||
//camera (with lifetime) behind the player
|
//camera (with lifetime) behind the player
|
||||||
if (player == LocalPlayer) {
|
if (player == LocalPlayer) {
|
||||||
|
m_LocalPlayerDeathEffect = deathEffectEW;
|
||||||
auto cam = deathEffectEW.FirstChildByName("Camera");
|
auto cam = deathEffectEW.FirstChildByName("Camera");
|
||||||
Events::SetCamera eSetCamera;
|
Events::SetCamera eSetCamera;
|
||||||
eSetCamera.CameraEntity = cam;
|
eSetCamera.CameraEntity = cam;
|
||||||
m_EventBroker->Publish(eSetCamera);
|
m_EventBroker->Publish(eSetCamera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
|
||||||
|
{
|
||||||
|
// We only care about when the local players death effect is removed.
|
||||||
|
if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for the spectator camera entity in the level.
|
||||||
|
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
|
||||||
|
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Events::SetCamera eSetCamera;
|
||||||
|
eSetCamera.CameraEntity = spectatorCam;
|
||||||
|
m_EventBroker->Publish(eSetCamera);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
|
|||||||
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
m_NetworkEnabled = config->Get("Networking.StartNetwork", false);
|
m_NetworkEnabled = config->Get("Networking.StartNetwork", false);
|
||||||
m_ForcedRespawnTime = config->Get("Debug.RespawnTime", -1.0f);
|
m_ForcedRespawnTime = config->Get("Debug.RespawnTime", -1.0f);
|
||||||
m_DbgConfigForceRespawn = m_ForcedRespawnTime > 0;
|
m_DbgConfigForceRespawn = m_ForcedRespawnTime > 0 && IsServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSpawnSystem::Update(double dt)
|
void PlayerSpawnSystem::Update(double dt)
|
||||||
@@ -26,7 +26,21 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
// Increase timer.
|
// Increase timer.
|
||||||
double& timer = (double&)modeComponent["RespawnTime"];
|
double& timer = (double&)modeComponent["RespawnTime"];
|
||||||
timer += dt;
|
timer += dt;
|
||||||
double maxRespawnTime = m_DbgConfigForceRespawn ? m_ForcedRespawnTime : (double)modeComponent["MaxRespawnTime"];
|
if (m_DbgConfigForceRespawn) {
|
||||||
|
(double&)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime;
|
||||||
|
}
|
||||||
|
double maxRespawnTime = (double)modeComponent["MaxRespawnTime"];
|
||||||
|
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
|
||||||
|
if (spectatorCam.Valid()) {
|
||||||
|
EntityWrapper HUD = spectatorCam.FirstChildByName("SpectatorHUD");
|
||||||
|
if (HUD.Valid()) {
|
||||||
|
EntityWrapper respawnTimer = spectatorCam.FirstChildByName("RespawnTimer");
|
||||||
|
if (respawnTimer.Valid()) {
|
||||||
|
//Update respawn time in the HUD element.
|
||||||
|
respawnTimer["Text"]["Content"] = std::to_string(1 + (int)(maxRespawnTime - timer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (timer < maxRespawnTime) {
|
if (timer < maxRespawnTime) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -54,7 +68,14 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
|
|
||||||
// If the spawner has a team affiliation, check it
|
// If the spawner has a team affiliation, check it
|
||||||
if (spawner.HasComponent("Team")) {
|
if (spawner.HasComponent("Team")) {
|
||||||
if ((int)spawner["Team"]["Team"] != req.Team) {
|
auto cSpawnerTeam = spawner["Team"];
|
||||||
|
if ((int)cSpawnerTeam["Team"] != req.Team) {
|
||||||
|
// Increase num spawned players if someone picks spectator, since it is valid to pick spectator
|
||||||
|
// but don't spawn anything, goto next spawnrequest.
|
||||||
|
if (req.Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) {
|
||||||
|
++numSpawnedPlayers;
|
||||||
|
break;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,9 +96,9 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numSpawnedPlayers != (int)m_SpawnRequests.size()) {
|
if (numSpawnedPlayers != (int)m_SpawnRequests.size()) {
|
||||||
LOG_DEBUG("%i players were supposed to be spawned, but %i was spawned.", (int)m_SpawnRequests.size(), numSpawnedPlayers);
|
LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", (int)m_SpawnRequests.size(), numSpawnedPlayers);
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("%i players were spawned.", numSpawnedPlayers);
|
LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers);
|
||||||
}
|
}
|
||||||
m_SpawnRequests.clear();
|
m_SpawnRequests.clear();
|
||||||
}
|
}
|
||||||
@@ -88,24 +109,29 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.Value == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A dead client should be able to swap to the spectator camera.
|
||||||
|
if (IsClient && !LocalPlayer.Valid()) {
|
||||||
|
// Set the spectator camera as active, if it exists.
|
||||||
|
// Find the camera.
|
||||||
|
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
|
||||||
|
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
|
||||||
|
Events::SetCamera eSetCamera;
|
||||||
|
eSetCamera.CameraEntity = spectatorCam;
|
||||||
|
m_EventBroker->Publish(eSetCamera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Team picks should be processed ONLY server-side!
|
// Team picks should be processed ONLY server-side!
|
||||||
// Don't make a spawn request if we're the client.
|
// Don't make a spawn request if we're the client.
|
||||||
if (!IsServer && m_NetworkEnabled) {
|
if (!IsServer && m_NetworkEnabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.Value == 0) {
|
// Check if the player already requested spawn.
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Spectating?
|
|
||||||
//Right now, return if someone picks spectator.
|
|
||||||
//1 signifies spectator here, could not get Playerteam component since it may be invalid or without team comp.
|
|
||||||
if ((ComponentInfo::EnumType)e.Value == 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if the player already requested spawn.
|
|
||||||
auto iter = m_SpawnRequests.begin();
|
auto iter = m_SpawnRequests.begin();
|
||||||
for (; iter != m_SpawnRequests.end(); ++iter) {
|
for (; iter != m_SpawnRequests.end(); ++iter) {
|
||||||
if (iter->PlayerID == e.PlayerID) {
|
if (iter->PlayerID == e.PlayerID) {
|
||||||
@@ -114,11 +140,11 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iter != m_SpawnRequests.end()) {
|
if (iter != m_SpawnRequests.end()) {
|
||||||
//If player is in queue to spawn, then change their team affiliation in the request.
|
// If player is in queue to spawn, then change their team affiliation in the request.
|
||||||
iter->Team = (ComponentInfo::EnumType)e.Value;
|
iter->Team = (ComponentInfo::EnumType)e.Value;
|
||||||
} else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) {
|
} else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) {
|
||||||
//If player is not in queue to spawn, then create a spawn request,
|
// If player is not in queue to spawn, then create a spawn request,
|
||||||
//but only if they are spectating and/or just connected.
|
// but only if they are spectating and/or just connected.
|
||||||
SpawnRequest req;
|
SpawnRequest req;
|
||||||
req.PlayerID = e.PlayerID;
|
req.PlayerID = e.PlayerID;
|
||||||
req.Team = (ComponentInfo::EnumType)e.Value;
|
req.Team = (ComponentInfo::EnumType)e.Value;
|
||||||
|
|||||||
Reference in New Issue
Block a user