Compare commits

...

2 Commits

Author SHA1 Message Date
Jace 3678bf6d18 Entity parenting on parse 2016-01-12 12:50:31 +01:00
Jace 39b9b3c2a7 Semi-working entity references (no editor support) 2016-01-12 11:35:52 +01:00
9 changed files with 54 additions and 31 deletions
+23 -13
View File
@@ -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") {
// 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);
return;
} else {
m_StateStack.push(State::EntityRef);
onStartEntityRef(ref, attrs);
}
if (name == "EntityRef") {
onStartEntityRef(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") {
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());
+1 -1
View File
@@ -9,7 +9,7 @@ class EntityFileParser
public:
EntityFileParser(const EntityFile* entityFile);
void MergeEntities(World* world);
void MergeEntities(World* world, EntityID parent = EntityID_Invalid);
private:
const EntityFile* m_EntityFile;
+1
View File
@@ -31,6 +31,7 @@ private:
bool m_Visible;
boost::filesystem::path m_DefaultEntityDir;
boost::filesystem::path m_CurrentFile;
std::map<boost::filesystem::path, EntityID> m_CurrentFiles;
std::vector<glm::vec2> m_PickingQueue;
enum class WidgetMode
@@ -0,0 +1,18 @@
<?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/>
</Components>
<Children>
<Entity ref="Schema/Entities/RaptorCopter.xml">
<Components>
<c:Transform>
<Position X="1" Y="2" Z="3" />
</c:Transform>
</Components>
</Entity>
</Children>
</Entity>
+1 -7
View File
@@ -24,19 +24,13 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="Entity" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="EntityRef" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:attribute name="file" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute ref="xml:base"/>
<xs:attribute name="name" type="xs:string" minOccurs="0" default=""/>
<xs:attribute name="ref" type="xs:string" minOccurs="0" default=""/>
</xs:complexType>
</xs:element>
</xs:schema>
View File
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -9,10 +9,10 @@ EntityFileParser::EntityFileParser(const EntityFile* entityFile)
m_Handler.SetStartFieldDataCallback(std::bind(&EntityFileParser::onFieldData, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
}
void EntityFileParser::MergeEntities(World* world)
void EntityFileParser::MergeEntities(World* world, EntityID parent /*= EntityID_Invalid*/)
{
m_World = world;
m_EntityIDMapper[0] = 0;
m_EntityIDMapper[EntityID_Invalid] = parent;
m_EntityFile->Parse(&m_Handler);
}
+2 -2
View File
@@ -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();
}