Semi-working entity references (no editor support)
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user