Updated all uses of EntityXMLFile to use the new EntityFile to load entities into a world.
This commit is contained in:
@@ -6,12 +6,13 @@
|
|||||||
|
|
||||||
class EntityXMLFileParser
|
class EntityXMLFileParser
|
||||||
{
|
{
|
||||||
|
friend class EntityFile;
|
||||||
public:
|
public:
|
||||||
EntityXMLFileParser(const EntityXMLFile* entityFile);
|
EntityXMLFileParser(const EntityXMLFile* entityFile);
|
||||||
|
|
||||||
|
private:
|
||||||
EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid);
|
EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid);
|
||||||
|
|
||||||
private:
|
|
||||||
const EntityXMLFile* m_EntityFile;
|
const EntityXMLFile* m_EntityFile;
|
||||||
EntityFileHandler m_Handler;
|
EntityFileHandler m_Handler;
|
||||||
World* m_World = nullptr;
|
World* m_World = nullptr;
|
||||||
|
|||||||
@@ -21,12 +21,13 @@
|
|||||||
|
|
||||||
class EntityXMLFilePreprocessor
|
class EntityXMLFilePreprocessor
|
||||||
{
|
{
|
||||||
|
friend class EntityFile;
|
||||||
public:
|
public:
|
||||||
EntityXMLFilePreprocessor(const EntityXMLFile* entityFile);
|
EntityXMLFilePreprocessor(const EntityXMLFile* entityFile);
|
||||||
|
|
||||||
|
private:
|
||||||
void RegisterComponents(World* world);
|
void RegisterComponents(World* world);
|
||||||
|
|
||||||
private:
|
|
||||||
const EntityXMLFile* m_EntityFile;
|
const EntityXMLFile* m_EntityFile;
|
||||||
std::map<std::string, unsigned int> m_ComponentCounts;
|
std::map<std::string, unsigned int> m_ComponentCounts;
|
||||||
std::map<std::string, ComponentInfo> m_ComponentInfo;
|
std::map<std::string, ComponentInfo> m_ComponentInfo;
|
||||||
|
|||||||
@@ -5,8 +5,7 @@
|
|||||||
#include "../Core/World.h"
|
#include "../Core/World.h"
|
||||||
#include "../Core/SystemPipeline.h"
|
#include "../Core/SystemPipeline.h"
|
||||||
#include "../Core/ResourceManager.h"
|
#include "../Core/ResourceManager.h"
|
||||||
#include "../Core/EntityXMLFilePreprocessor.h"
|
#include "../Core/EntityFile.h"
|
||||||
#include "../Core/EntityXMLFileParser.h"
|
|
||||||
#include "../Core/EntityXMLFileWriter.h"
|
#include "../Core/EntityXMLFileWriter.h"
|
||||||
#include "../Core/EMousePress.h"
|
#include "../Core/EMousePress.h"
|
||||||
#include "../Input/EInputCommand.h"
|
#include "../Input/EInputCommand.h"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/Transform.h"
|
#include "Core/Transform.h"
|
||||||
#include "Core/ResourceManager.h"
|
#include "Core/ResourceManager.h"
|
||||||
#include "Core/EntityXMLFileParser.h"
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EPickupSpawned.h"
|
#include "Core/EPickupSpawned.h"
|
||||||
#include "Core/EAmmoPickup.h"
|
#include "Core/EAmmoPickup.h"
|
||||||
#include "Engine/Collision/ETrigger.h"
|
#include "Engine/Collision/ETrigger.h"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/ResourceManager.h"
|
#include "Core/ResourceManager.h"
|
||||||
#include "Core/EntityXMLFileParser.h"
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EPlayerDamage.h"
|
#include "Core/EPlayerDamage.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/Transform.h"
|
#include "Core/Transform.h"
|
||||||
#include "Core/ResourceManager.h"
|
#include "Core/ResourceManager.h"
|
||||||
#include "Core/EntityXMLFileParser.h"
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EPlayerDamage.h"
|
#include "Core/EPlayerDamage.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "Core/Transform.h"
|
#include "Core/Transform.h"
|
||||||
#include "Core/ResourceManager.h"
|
#include "Core/ResourceManager.h"
|
||||||
#include "Core/EntityXMLFileParser.h"
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EPickupSpawned.h"
|
#include "Core/EPickupSpawned.h"
|
||||||
#include "Core/EPlayerHealthPickup.h"
|
#include "Core/EPlayerHealthPickup.h"
|
||||||
#include "Engine/Collision/ETrigger.h"
|
#include "Engine/Collision/ETrigger.h"
|
||||||
|
|||||||
@@ -6,10 +6,7 @@
|
|||||||
#include "GLM.h"
|
#include "GLM.h"
|
||||||
#include "Rendering/ESetCamera.h"
|
#include "Rendering/ESetCamera.h"
|
||||||
#include "Core/ConfigFile.h"
|
#include "Core/ConfigFile.h"
|
||||||
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EntityXMLFile.h"
|
|
||||||
#include "Core/EntityXMLFileParser.h"
|
|
||||||
|
|
||||||
#include "Core/EPlayerDeath.h"
|
#include "Core/EPlayerDeath.h"
|
||||||
#include "Core/EEntityDeleted.h"
|
#include "Core/EEntityDeleted.h"
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
#include "Events/EDoubleJump.h"
|
#include "Events/EDoubleJump.h"
|
||||||
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||||
|
#include "Core/EntityFile.h"
|
||||||
#include "Core/EntityXMLFile.h"
|
|
||||||
#include "Core/EntityXMLFileParser.h"
|
|
||||||
|
|
||||||
class PlayerMovementSystem : public ImpureSystem
|
class PlayerMovementSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Core/UniformScaleSystem.h"
|
#include "Core/UniformScaleSystem.h"
|
||||||
#include "Editor/EditorRenderSystem.h"
|
#include "Editor/EditorRenderSystem.h"
|
||||||
#include "Editor/EditorWidgetSystem.h"
|
#include "Editor/EditorWidgetSystem.h"
|
||||||
|
#include "Core/EntityFile.h"
|
||||||
|
|
||||||
EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame)
|
EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame* renderFrame)
|
||||||
: System(params)
|
: System(params)
|
||||||
@@ -259,12 +260,10 @@ EntityWrapper EditorSystem::importEntity(EntityWrapper parent, boost::filesystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto entityFile = ResourceManager::Load<EntityXMLFile>(filePath.string());
|
auto entityFile = ResourceManager::Load<EntityFile>(filePath.string());
|
||||||
EntityXMLFilePreprocessor fpp(entityFile);
|
EntityWrapper newEntity = entityFile->MergeInto(parent.World);
|
||||||
fpp.RegisterComponents(parent.World);
|
parent.World->SetParent(newEntity.ID, parent.ID);
|
||||||
EntityXMLFileParser fp(entityFile);
|
return newEntity;
|
||||||
EntityID newEntity = fp.MergeEntities(parent.World, parent.ID);
|
|
||||||
return EntityWrapper(parent.World, newEntity);
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LOG_ERROR("Failed to import entity \"%s\": \"%s\"", filePath.string().c_str(), e.what());
|
LOG_ERROR("Failed to import entity \"%s\": \"%s\"", filePath.string().c_str(), e.what());
|
||||||
return EntityWrapper::Invalid;
|
return EntityWrapper::Invalid;
|
||||||
|
|||||||
+2
-5
@@ -82,11 +82,8 @@ Game::Game(int argc, char* argv[])
|
|||||||
m_World = new World(m_EventBroker);
|
m_World = new World(m_EventBroker);
|
||||||
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
|
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
|
||||||
if (!mapToLoad.empty()) {
|
if (!mapToLoad.empty()) {
|
||||||
auto file = ResourceManager::Load<EntityXMLFile>(mapToLoad);
|
auto file = ResourceManager::Load<EntityFile>(mapToLoad);
|
||||||
EntityXMLFilePreprocessor fpp(file);
|
file->MergeInto(m_World);
|
||||||
fpp.RegisterComponents(m_World);
|
|
||||||
EntityXMLFileParser fp(file);
|
|
||||||
fp.MergeEntities(m_World);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the sound manager
|
// Create the sound manager
|
||||||
|
|||||||
@@ -20,17 +20,16 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
auto& somePickup = *it;
|
auto& somePickup = *it;
|
||||||
somePickup.DecreaseThisRespawnTimer -= dt;
|
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||||
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
||||||
auto entityFile = ResourceManager::Load<EntityXMLFile>("Schema/Entities/AmmoPickup.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/AmmoPickup.xml");
|
||||||
EntityXMLFileParser parser(entityFile);
|
EntityWrapper ammoPickup = entityFile->MergeInto(m_World);
|
||||||
EntityID ammoPickupID = parser.MergeEntities(m_World);
|
|
||||||
|
|
||||||
//let the world know a pickup has spawned
|
//let the world know a pickup has spawned
|
||||||
Events::PickupSpawned ePickupSpawned;
|
Events::PickupSpawned ePickupSpawned;
|
||||||
ePickupSpawned.Pickup = EntityWrapper(m_World, ammoPickupID);
|
ePickupSpawned.Pickup = ammoPickup;
|
||||||
m_EventBroker->Publish(ePickupSpawned);
|
m_EventBroker->Publish(ePickupSpawned);
|
||||||
|
|
||||||
//copy values from the old entity to the new entity
|
//copy values from the old entity to the new entity
|
||||||
auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
auto& newAmmoPickupEntity = ammoPickup;
|
||||||
newAmmoPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
newAmmoPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||||
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain;
|
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain;
|
||||||
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||||
|
|||||||
@@ -38,11 +38,10 @@ bool BoostSystem::OnPlayerDamage(Events::PlayerDamage& e)
|
|||||||
m_World->DeleteEntity(playerBoostAssaultEntity.ID);
|
m_World->DeleteEntity(playerBoostAssaultEntity.ID);
|
||||||
}
|
}
|
||||||
//load boost XML file, set it entity parented with the victim player
|
//load boost XML file, set it entity parented with the victim player
|
||||||
auto entityFile = ResourceManager::Load<EntityXMLFile>(classXML);
|
auto entityFile = ResourceManager::Load<EntityFile>(classXML);
|
||||||
EntityXMLFileParser parser(entityFile);
|
EntityWrapper boostAssaultEntity = entityFile->MergeInto(m_World);
|
||||||
EntityID boostAssaultEntity = parser.MergeEntities(m_World);
|
m_World->SetName(boostAssaultEntity.ID, className);
|
||||||
m_World->SetName(boostAssaultEntity, className);
|
m_World->SetParent(boostAssaultEntity.ID, e.Victim.ID);
|
||||||
m_World->SetParent(boostAssaultEntity, e.Victim.ID);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,16 +49,14 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
|
|||||||
float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos);
|
float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos);
|
||||||
|
|
||||||
//load & set the "2d" sprite
|
//load & set the "2d" sprite
|
||||||
auto entityFile = ResourceManager::Load<EntityXMLFile>("Schema/Entities/DamageIndicator.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DamageIndicator.xml");
|
||||||
EntityXMLFileParser parser(entityFile);
|
EntityWrapper sprite = entityFile->MergeInto(m_World);
|
||||||
EntityID spriteID = parser.MergeEntities(m_World);
|
m_World->SetParent(sprite.ID, m_CurrentCamera);
|
||||||
m_World->SetParent(spriteID, m_CurrentCamera);
|
|
||||||
auto spriteWrapper = EntityWrapper(m_World, spriteID);
|
|
||||||
//simply set the rotation z-wise to the angleBetweenVectors
|
//simply set the rotation z-wise to the angleBetweenVectors
|
||||||
spriteWrapper["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
|
sprite["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
|
||||||
|
|
||||||
if (!IsServer) {
|
if (!IsServer) {
|
||||||
updateDamageIndicatorVector.emplace_back(spriteWrapper, inflictorPos);
|
updateDamageIndicatorVector.emplace_back(sprite, inflictorPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -18,17 +18,16 @@ void PickupSpawnSystem::Update(double dt)
|
|||||||
somePickup.DecreaseThisRespawnTimer -= dt;
|
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||||
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
||||||
//spawn the new healthPickup
|
//spawn the new healthPickup
|
||||||
auto entityFile = ResourceManager::Load<EntityXMLFile>("Schema/Entities/HealthPickup.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
|
||||||
EntityXMLFileParser parser(entityFile);
|
EntityWrapper healthPickup = entityFile->MergeInto(m_World);
|
||||||
EntityID healthPickupID = parser.MergeEntities(m_World);
|
|
||||||
|
|
||||||
//let the world know a pickup has spawned (graphics effects, etc)
|
//let the world know a pickup has spawned (graphics effects, etc)
|
||||||
Events::PickupSpawned ePickupSpawned;
|
Events::PickupSpawned ePickupSpawned;
|
||||||
ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID);
|
ePickupSpawned.Pickup = healthPickup;
|
||||||
m_EventBroker->Publish(ePickupSpawned);
|
m_EventBroker->Publish(ePickupSpawned);
|
||||||
|
|
||||||
//copy values from the old entity to the new entity
|
//copy values from the old entity to the new entity
|
||||||
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
|
auto& newHealthPickupEntity = healthPickup;
|
||||||
newHealthPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
newHealthPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||||
newHealthPickupEntity["HealthPickup"]["HealthGain"] = somePickup.HealthGain;
|
newHealthPickupEntity["HealthPickup"]["HealthGain"] = somePickup.HealthGain;
|
||||||
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
|||||||
void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||||
{
|
{
|
||||||
//load the explosioneffect XML
|
//load the explosioneffect XML
|
||||||
auto deathEffect = ResourceManager::Load<EntityXMLFile>("Schema/Entities/PlayerDeathExplosionWithCamera.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/PlayerDeathExplosionWithCamera.xml");
|
||||||
EntityXMLFileParser parser(deathEffect);
|
EntityWrapper deathEffectEW = entityFile->MergeInto(m_World);
|
||||||
EntityID deathEffectID = parser.MergeEntities(m_World);
|
|
||||||
EntityWrapper deathEffectEW = EntityWrapper(m_World, deathEffectID);
|
|
||||||
|
|
||||||
//components that we need from player
|
//components that we need from player
|
||||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||||
|
|||||||
@@ -328,10 +328,8 @@ bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e)
|
|||||||
void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
|
void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
|
||||||
{
|
{
|
||||||
//put a hexagon at the entitys... feet?
|
//put a hexagon at the entitys... feet?
|
||||||
auto hexagonEffect = ResourceManager::Load<EntityXMLFile>("Schema/Entities/DoubleJumpHexagon.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DoubleJumpHexagon.xml");
|
||||||
EntityXMLFileParser parser(hexagonEffect);
|
EntityWrapper hexagonEW = entityFile->MergeInto(m_World);
|
||||||
EntityID hexagonEffectID = parser.MergeEntities(m_World);
|
|
||||||
EntityWrapper hexagonEW = EntityWrapper(m_World, hexagonEffectID);
|
|
||||||
hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"];
|
hexagonEW["Transform"]["Position"] = (glm::vec3)target["Transform"]["Position"];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,10 +340,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dashEffectResource = ResourceManager::Load<EntityXMLFile>("Schema/Entities/DashEffect.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
|
||||||
EntityXMLFileParser parser(dashEffectResource);
|
EntityWrapper dashEffect = entityFile->MergeInto(m_World);
|
||||||
EntityID dashEffectID = parser.MergeEntities(m_World);
|
|
||||||
EntityWrapper dashEffect(m_World, dashEffectID);
|
|
||||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||||
auto playerEntityModel = playerModel["Model"];
|
auto playerEntityModel = playerModel["Model"];
|
||||||
auto playerEntityAnimation = playerModel["Animation"];
|
auto playerEntityAnimation = playerModel["Animation"];
|
||||||
|
|||||||
Reference in New Issue
Block a user