From 39b9b3c2a77de5e21d7743b91d05cb0c92cd1703 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 12 Jan 2016 11:35:32 +0100 Subject: [PATCH] Semi-working entity references (no editor support) --- include/Engine/Core/EntityFile.h | 46 +++++++++++++-------- resources/Schema/Entities/EntityRefTest.xml | 18 ++++++++ resources/Schema/Types/Entity.xsd | 8 +--- resources/Shaders/.gitkeep | 0 src/Engine/Core/EntityFile.cpp | 2 +- src/Engine/Core/EntityFileParser.cpp | 2 +- src/Engine/Input/InputProxy.cpp | 4 +- 7 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 resources/Schema/Entities/EntityRefTest.xml delete mode 100644 resources/Shaders/.gitkeep diff --git a/include/Engine/Core/EntityFile.h b/include/Engine/Core/EntityFile.h index 27115264..706e1c04 100644 --- a/include/Engine/Core/EntityFile.h +++ b/include/Engine/Core/EntityFile.h @@ -69,6 +69,7 @@ public: { Unknown, Entity, + EntityRef, Component, ComponentField }; @@ -77,29 +78,32 @@ public: : m_Handler(handler) , m_Reader(reader) { - // 0 is imaginary world entity - m_EntityStack.push(0); + // Push first parent + m_EntityStack.push(EntityID_Invalid); m_StateStack.push(State::Unknown); } void startElement(const XMLCh* const _uri, const XMLCh* const _localName, const XMLCh* const _qname, const xercesc::Attributes& attrs) override { std::string name = XS::ToString(_localName); - - if (m_StateStack.top() == State::Unknown || m_StateStack.top() == State::Entity) { + if (m_StateStack.top() == State::Unknown || m_StateStack.top() == State::Entity || m_StateStack.top() == State::EntityRef) { if (name == "Entity") { - m_StateStack.push(State::Entity); - onStartEntity(attrs); - return; - } - if (name == "EntityRef") { - onStartEntityRef(attrs); + // Handle entity references + const XMLCh* refAttr = attrs.getValue(XS::ToXMLCh("ref")); + std::string ref = XS::ToString(refAttr); + if (ref.empty()) { + m_StateStack.push(State::Entity); + onStartEntity(attrs); + } else { + m_StateStack.push(State::EntityRef); + onStartEntityRef(ref, attrs); + } return; } } std::string uri = XS::ToString(_uri); - if (m_StateStack.top() == State::Entity) { + if (m_StateStack.top() == State::Entity || m_StateStack.top() == State::EntityRef) { if (uri == "components") { m_StateStack.push(State::Component); onStartComponent(name); @@ -125,10 +129,16 @@ public: void endElement(const XMLCh* const _uri, const XMLCh* const _localName, const XMLCh* const _qname) override { std::string name = XS::ToString(_localName); - if (m_StateStack.top() == State::Entity) { + if (m_StateStack.top() == State::Entity || m_StateStack.top() == State::EntityRef) { if (name == "Entity") { - m_StateStack.pop(); - onEndEntity(); + if (m_StateStack.top() == State::Entity) { + m_StateStack.pop(); + if (m_StateStack.top() == State::EntityRef) { + onEndEntityRef(); + } else { + onEndEntity(); + } + } return; } } @@ -188,16 +198,16 @@ private: { m_EntityStack.pop(); } - void onStartEntityRef(const xercesc::Attributes& attrs) + void onStartEntityRef(const std::string& ref, const xercesc::Attributes& attrs) { - std::string path = XS::ToString(attrs.getValue(XS::ToXMLCh("file"))); - xercesc::SAX2XMLReader* parser = xercesc::XMLReaderFactory::createXMLReader(); parser->setContentHandler(this); parser->setErrorHandler(this); - parser->parse(path.c_str()); + parser->parse(ref.c_str()); delete parser; + //m_StateStack.push(State::Entity); } + void onEndEntityRef() { } void onStartComponent(const std::string& name) { //LOG_DEBUG(" Component: %s", name.c_str()); diff --git a/resources/Schema/Entities/EntityRefTest.xml b/resources/Schema/Entities/EntityRefTest.xml new file mode 100644 index 00000000..bf3507f9 --- /dev/null +++ b/resources/Schema/Entities/EntityRefTest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 6562f3ed..60dc748d 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -24,19 +24,13 @@ - - - - - - - + \ No newline at end of file diff --git a/resources/Shaders/.gitkeep b/resources/Shaders/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Engine/Core/EntityFile.cpp b/src/Engine/Core/EntityFile.cpp index 1e381df5..3e4ca83f 100644 --- a/src/Engine/Core/EntityFile.cpp +++ b/src/Engine/Core/EntityFile.cpp @@ -20,7 +20,7 @@ void EntityFile::Parse(const EntityFileHandler* handler) const { using namespace xercesc; - EntityFileSAXHandler saxHandler(handler, nullptr); + EntityFileSAXHandler saxHandler(handler, m_SAX2XMLReader); m_SAX2XMLReader->setFeature(XMLUni::fgXercesCacheGrammarFromParse, true); m_SAX2XMLReader->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true); m_SAX2XMLReader->setContentHandler(&saxHandler); diff --git a/src/Engine/Core/EntityFileParser.cpp b/src/Engine/Core/EntityFileParser.cpp index 541da01d..0240fb73 100644 --- a/src/Engine/Core/EntityFileParser.cpp +++ b/src/Engine/Core/EntityFileParser.cpp @@ -12,7 +12,7 @@ EntityFileParser::EntityFileParser(const EntityFile* entityFile) void EntityFileParser::MergeEntities(World* world) { m_World = world; - m_EntityIDMapper[0] = 0; + m_EntityIDMapper[EntityID_Invalid] = EntityID_Invalid; m_EntityFile->Parse(&m_Handler); } diff --git a/src/Engine/Input/InputProxy.cpp b/src/Engine/Input/InputProxy.cpp index c3e4d669..ad589df3 100644 --- a/src/Engine/Input/InputProxy.cpp +++ b/src/Engine/Input/InputProxy.cpp @@ -62,7 +62,7 @@ void InputProxy::Process() e.Command = command; e.Value = currentValue; m_EventBroker->Publish(e); - LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID); + //LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID); m_LastCommandValues[command] = currentValue; } } @@ -78,7 +78,7 @@ void InputProxy::Process() } //e.Value = std::max(-1.f, std::min(e.Value, 1.f)); m_EventBroker->Publish(e); - LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID); + //LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID); } m_CommandQueue.clear(); }