Compare commits

...

9 Commits

27 changed files with 200 additions and 45 deletions
+2 -2
View File
@@ -2,14 +2,14 @@
#define EEntityDeleted_h__
#include "Event.h"
#include "Entity.h"
#include "EntityWrapper.h"
namespace Events
{
struct EntityDeleted : Event
{
EntityID DeletedEntity;
EntityWrapper DeletedEntity;
// True if the entity deletion was triggered because the entity's parent was deleted before it
bool Cascaded;
};
+28
View File
@@ -0,0 +1,28 @@
#ifndef RespawnSystem_h__
#define RespawnSystem_h__
#include "System.h"
#include "SpawnerSystem.h"
#include "EEntityDeleted.h"
#include "EPause.h"
class RespawnSystem : public PureSystem
{
public:
RespawnSystem(SystemParams params);
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRespawn, double dt) override;
private:
std::unordered_map<EntityWrapper, EntityWrapper> m_LastRespawnedEntity;
bool m_Paused = false;
EventRelay<RespawnSystem, Events::EntityDeleted> m_EEntityDeleted;
bool OnEntityDeleted(const Events::EntityDeleted& e);
EventRelay<RespawnSystem, Events::Pause> m_EPause;
bool OnPause(const Events::Pause& e);
EventRelay<RespawnSystem, Events::Resume> m_EResume;
bool OnResume(const Events::Resume& e);
};
#endif
@@ -5,7 +5,7 @@
#include "Common.h"
#include "GLM.h"
#include "Core/System.h"
#include "Events/ESpawnerSpawn.h"
#include "Core/ESpawnerSpawn.h"
#include "Core/Transform.h"
#include "Core/EntityFile.h"
+1 -1
View File
@@ -68,7 +68,7 @@ protected:
const std::string m_ComponentType;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt) = 0;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt) = 0;
};
class ImpureSystem : public virtual System
+1 -1
View File
@@ -22,7 +22,7 @@
#include "../Core/ELockMouse.h"
#include "../Core/EFileDropped.h"
#include "../Rendering/Texture.h"
#include "Game/Events/ESpawnerSpawn.h"
#include "../Core/ESpawnerSpawn.h"
class EditorGUI
{
+1 -1
View File
@@ -5,7 +5,7 @@
#include "Rendering/IRenderer.h"
#include "Core/ResourceManager.h"
#include "Core/Event.h"
#include "Systems/SpawnerSystem.h"
#include "Core/SpawnerSystem.h"
#include "GUI/EButtonClicked.h"
+2 -2
View File
@@ -1,7 +1,7 @@
#include "Core/System.h"
#include "Input/EInputCommand.h"
#include "Systems/SpawnerSystem.h"
#include "Events/ESpawnerSpawn.h"
#include "Core/SpawnerSystem.h"
#include "Core/ESpawnerSpawn.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EPlayerDeath.h"
#include "Rendering/ESetCamera.h"
+1 -1
View File
@@ -5,7 +5,7 @@
#include "Rendering/IRenderer.h"
#include "Core/ResourceManager.h"
#include "Core/Event.h"
#include "Systems/SpawnerSystem.h"
#include "Core/SpawnerSystem.h"
#include "Core/EventBroker.h"
#include "Network/ESearchForServers.h"
@@ -6,7 +6,7 @@
#include "Core/Octree.h"
#include "Collision/EntityAABB.h"
#include "Input/EInputCommand.h"
#include "Systems/SpawnerSystem.h"
#include "Core/SpawnerSystem.h"
#include "Rendering/ESetCamera.h"
#include "Core/ConfigFile.h"
#include "Rendering/EAutoAnimationBlend.h"
+1
View File
@@ -68,4 +68,5 @@
<xs:include schemaLocation="Components/NetworkComponent.xsd"/>
<xs:include schemaLocation="Components/ServerIdentity.xsd"/>
<xs:include schemaLocation="Components/ServerList.xsd"/>
<xs:include schemaLocation="Components/Respawn.xsd"/>
</xs:schema>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Respawn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Respawn.xsd">
<Delay>0</Delay>
<_RespawnCountdown>0</_RespawnCountdown>
</Respawn>
+17
View File
@@ -0,0 +1,17 @@
<?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="Respawn">
<xs:annotation>
<xs:documentation>Triggers a Spawner component after its last spawned entity is destroyed with an optional delay.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Delay" type="t:double" minOccurs="0"/>
<xs:element name="_RespawnCountdown" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+2 -8
View File
@@ -2,19 +2,13 @@
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:NetworkComponent/>
<c:HealthPickup/>
<c:Model>
<Resource>Models/Props/PickUps/HealthPickUp.mesh</Resource>
</c:Model>
<c:RaptorCopter>
<Speed>8</Speed>
<Axis X="0" Y="0.100000001" Z="0"/>
</c:RaptorCopter>
<c:NetworkComponent/>
<c:Transform>
<Position X="0" Y="2.36784196" Z="0"/>
<Scale X="0.600000024" Y="0.600000024" Z="0.600000024"/>
<Orientation X="0" Y="18767.0273" Z="0"/>
<Scale X="0.25" Y="0.25" Z="0.25"/>
</c:Transform>
<c:Trigger/>
</Components>
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform>
<Position X="0" Y="-0.871185362" Z="1.77631724"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>Models/Props/PickUps/PickUpHolder.mesh</Resource>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Scale X="0.479999989" Y="0.479999989" Z="0.479999989"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0" Y="1.41138339" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Respawn>
<Delay>3</Delay>
</c:Respawn>
<c:RaptorCopter>
<Speed>1</Speed>
<Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter>
<c:FloatingEffect>
<Period>2</Period>
<Time>75.797556530109119</Time>
<Axis X="0" Y="0.200000003" Z="0"/>
</c:FloatingEffect>
<c:Spawner>
<EntityFile>Schema/Entities/HealthPickup.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="-0" Y="-0.118795805" Z="-0"/>
<Orientation X="0" Y="13.0735149" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+1
View File
@@ -71,6 +71,7 @@
<xs:element ref="c:NetworkComponent" minOccurs="0"/>
<xs:element ref="c:ServerIdentity" minOccurs="0"/>
<xs:element ref="c:ServerList" minOccurs="0"/>
<xs:element ref="c:Respawn" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
+54
View File
@@ -0,0 +1,54 @@
#include "Core/RespawnSystem.h"
RespawnSystem::RespawnSystem(SystemParams params)
: System(params)
, PureSystem("Respawn")
{
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &RespawnSystem::OnEntityDeleted);
EVENT_SUBSCRIBE_MEMBER(m_EPause, &RespawnSystem::OnPause);
EVENT_SUBSCRIBE_MEMBER(m_EResume, &RespawnSystem::OnResume);
}
void RespawnSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cRespawn, double dt)
{
if (m_Paused) {
return;
}
if (!entity.HasComponent("Spawner")) {
return;
}
EntityWrapper& lastRespawnedEntity = m_LastRespawnedEntity[entity];
if (!lastRespawnedEntity.Valid()) {
double& _respawnCountdown = cRespawn["_RespawnCountdown"];
_respawnCountdown -= dt;
if (_respawnCountdown <= 0) {
lastRespawnedEntity = SpawnerSystem::Spawn(entity, entity);
_respawnCountdown = cRespawn["Delay"];
}
}
}
bool RespawnSystem::OnEntityDeleted(const Events::EntityDeleted& e)
{
m_LastRespawnedEntity.erase(e.DeletedEntity);
return true;
}
bool RespawnSystem::OnPause(const Events::Pause& e)
{
if (e.World == m_World) {
m_Paused = true;
}
return true;
}
bool RespawnSystem::OnResume(const Events::Resume& e)
{
if (e.World == m_World) {
m_Paused = false;
}
return true;
}
@@ -1,4 +1,4 @@
#include "Systems/SpawnerSystem.h"
#include "Core/SpawnerSystem.h"
#include "Collision/Collision.h"
SpawnerSystem::SpawnerSystem(SystemParams params)
+6 -6
View File
@@ -24,7 +24,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
while (entity != EntityID_Invalid) {
ComponentWrapper transform = world->GetComponent(entity, "Transform");
EntityID parent = world->GetParent(entity);
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
position += Transform::AbsoluteScale(world, parent) * (Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]);
entity = parent;
}
@@ -89,12 +89,12 @@ glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
{
return AbsoluteTransformation(EntityWrapper(world, entity));
glm::vec3 position = Transform::AbsolutePosition(world, entity);
glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
glm::vec3 scale = Transform::AbsoluteScale(world, entity);
//glm::vec3 position = Transform::AbsolutePosition(world, entity);
//glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
//glm::vec3 scale = Transform::AbsoluteScale(world, entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
return modelMatrix;
//glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
//return modelMatrix;
}
glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
+1 -1
View File
@@ -223,7 +223,7 @@ void World::deleteEntityRecursive(EntityID entity, bool cascaded /*= false*/)
if (m_EventBroker != nullptr) {
Events::EntityDeleted e;
e.DeletedEntity = entity;
e.DeletedEntity = EntityWrapper(this, entity);
e.Cascaded = cascaded;
m_EventBroker->Publish(e);
}
+1 -1
View File
@@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer,
{
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera);
auto resolution = Rectangle::Rectangle(1280, 720);
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.001f, 500.f);
}
void EditorRenderSystem::Update(double dt)
+9 -2
View File
@@ -204,14 +204,21 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
if (m_CurrentSelection.Valid()) {
if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) {
glm::quat parentOrientation;
glm::vec3 parentScale(1.f);
EntityWrapper parent = m_CurrentSelection.Parent();
if (parent.Valid()) {
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
parentScale = Transform::AbsoluteScale(parent);
}
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation / parentScale;
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
glm::vec3 parentScale(1.f);
EntityWrapper parent = m_CurrentSelection.Parent();
if (parent.Valid()) {
parentScale = Transform::AbsoluteScale(parent);
}
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
glm::vec3 localTranslation = selectionOri * e.Translation;
glm::vec3 localTranslation = selectionOri * e.Translation / parentScale;
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
}
m_EditorGUI->SetDirty(m_CurrentSelection);
+1 -1
View File
@@ -494,7 +494,7 @@ bool Server::OnEntityDeleted(const Events::EntityDeleted & e)
{
if (!e.Cascaded) {
Packet packet = Packet(MessageType::EntityDeleted);
packet.WritePrimitive<EntityID>(e.DeletedEntity);
packet.WritePrimitive<EntityID>(e.DeletedEntity.ID);
reliableBroadcast(packet);
}
return false;
+1 -1
View File
@@ -283,7 +283,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
bool AnimationSystem::OnEntityDeleted(Events::EntityDeleted& e)
{
EntityWrapper entity = EntityWrapper(m_World, e.DeletedEntity);
EntityWrapper entity = e.DeletedEntity;
if (entity.HasComponent("Model")) {
Model* model;
+3 -1
View File
@@ -7,7 +7,7 @@
#include "Systems/RaptorCopterSystem.h"
#include "Systems/HealthSystem.h"
#include "Systems/PlayerMovementSystem.h"
#include "Systems/SpawnerSystem.h"
#include "Core/SpawnerSystem.h"
#include "Systems/PlayerSpawnSystem.h"
#include "Systems/PlayerDeathSystem.h"
#include "Systems/FloatingEffectSystem.h"
@@ -40,6 +40,7 @@
#include "Game/Systems/MainMenuSystem.h"
#include "Game/Systems/ServerListSystem.h"
#include "Game/Systems/StartSystem.h"
#include "Core/RespawnSystem.h"
#include "Rendering/TextureSprite.h"
@@ -135,6 +136,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<RespawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AssaultWeaponBehaviour>(updateOrderLevel, m_Renderer, m_OctreeCollision);
m_SystemPipeline->AddSystem<DefenderWeaponBehaviour>(updateOrderLevel, m_Renderer, m_OctreeCollision);
+1 -1
View File
@@ -67,7 +67,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
{
// We only care about when the local players death effect is removed.
if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) {
if (m_LocalPlayerDeathEffect != e.DeletedEntity) {
return false;
}
-12
View File
@@ -208,18 +208,6 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
m_EventBroker->Publish(lock);
}
// HACK: Set the player model color to team color
EntityWrapper playerModel = e.Player.FirstChildByName("PlayerModel");
if (playerModel.Valid() && e.Player.HasComponent("Team")) {
ComponentWrapper cTeam = e.Player["Team"];
ComponentWrapper cModel = playerModel["Model"];
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Red")) {
cModel["Color"] = glm::vec3(1.f, 0.f, 0.f);
} else if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Blue")) {
cModel["Color"] = glm::vec3(0.f, 0.25f, 1.f);
}
}
return true;
}