Parallel event processing
This commit is contained in:
@ -6,7 +6,10 @@
|
||||
# Sources
|
||||
target_sources(vnscenetool
|
||||
PRIVATE
|
||||
VNSceneEventsParser.cpp
|
||||
VNPositionEventParser.cpp
|
||||
VNTextEventParser.cpp
|
||||
VNSetEventParser.cpp
|
||||
VNWaitEventParser.cpp
|
||||
VNParallelEventParser.cpp
|
||||
)
|
27
src/dawntools/vnscenetool/events/VNParallelEventParser.cpp
Normal file
27
src/dawntools/vnscenetool/events/VNParallelEventParser.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNParallelEventParser.hpp"
|
||||
#include "VNSceneEventsParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNParallelEventParser::getRequiredAttributes() {
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNParallelEventParser::getOptionalAttributes() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t VNParallelEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNParallelEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
// Parse all children
|
||||
return (VNSceneEventsParser()).parse(node, &out->events, error);
|
||||
}
|
23
src/dawntools/vnscenetool/events/VNParallelEventParser.hpp
Normal file
23
src/dawntools/vnscenetool/events/VNParallelEventParser.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/XmlParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNParallelEvent;
|
||||
|
||||
class VNParallelEventParser : public XmlParser<struct VNParallelEvent> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNParallelEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
69
src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
Normal file
69
src/dawntools/vnscenetool/events/VNSceneEventsParser.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNSceneEventsParser.hpp"
|
||||
#include "VNParallelEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNSceneEventsParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNSceneEventsParser::getOptionalAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
int32_t VNSceneEventsParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneEventList *out,
|
||||
std::string *error
|
||||
) {
|
||||
int32_t ret;
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
Xml *child = *itChildren;
|
||||
struct VNSceneEvent event;
|
||||
|
||||
// Parse event(s)
|
||||
if(child->node == "text") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_TEXT;
|
||||
ret = (VNTextEventParser()).parse(child, &event.text, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "position") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_POSITION;
|
||||
ret = (VNPositionEventParser()).parse(child, &event.position, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "set") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_SET;
|
||||
ret = (VNSetEventParser()).parse(child, &event.set, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "wait") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_WAIT;
|
||||
ret = (VNWaitEventParser()).parse(child, &event.wait, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else if(child->node == "parallel") {
|
||||
event.type = VN_SCENE_EVENT_TYPE_PARALLEL;
|
||||
ret = (VNParallelEventParser()).parse(child, &event.parallel, error);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
} else {
|
||||
*error = "Unknown child node '" + child->node + "'";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ret != 0) return ret;
|
||||
out->events.push_back(event);
|
||||
itChildren++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
53
src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
Normal file
53
src/dawntools/vnscenetool/events/VNSceneEventsParser.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "VNTextEventParser.hpp"
|
||||
#include "VNPositionEventParser.hpp"
|
||||
#include "VNSetEventParser.hpp"
|
||||
#include "VNWaitEventParser.hpp"
|
||||
#include "VNParallelEventParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNSceneEvent;
|
||||
|
||||
struct VNSceneEventList {
|
||||
std::vector<struct VNSceneEvent> events;
|
||||
};
|
||||
|
||||
enum VNSceneEventType {
|
||||
VN_SCENE_EVENT_TYPE_TEXT,
|
||||
VN_SCENE_EVENT_TYPE_POSITION,
|
||||
VN_SCENE_EVENT_TYPE_SET,
|
||||
VN_SCENE_EVENT_TYPE_WAIT,
|
||||
VN_SCENE_EVENT_TYPE_PARALLEL
|
||||
};
|
||||
|
||||
struct VNParallelEvent {
|
||||
struct VNSceneEventList events;
|
||||
};
|
||||
|
||||
struct VNSceneEvent {
|
||||
enum VNSceneEventType type;
|
||||
|
||||
struct VNTextEvent text;
|
||||
struct VNPositionEvent position;
|
||||
struct VNSetEvent set;
|
||||
struct VNWaitEvent wait;
|
||||
struct VNParallelEvent parallel;
|
||||
};
|
||||
|
||||
class VNSceneEventsParser : public XmlParser<struct VNSceneEventList> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct VNSceneEventList *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
35
src/dawntools/vnscenetool/events/VNWaitEventParser.cpp
Normal file
35
src/dawntools/vnscenetool/events/VNWaitEventParser.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VNWaitEventParser.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VNWaitEventParser::getRequiredAttributes() {
|
||||
return { };
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> VNWaitEventParser::getOptionalAttributes() {
|
||||
return { { "duration", "" }, { "time", "" } };
|
||||
}
|
||||
|
||||
int32_t VNWaitEventParser::onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
VNWaitEvent *out,
|
||||
std::string *error
|
||||
) {
|
||||
//Get the duration
|
||||
if(!values["duration"].empty()) {
|
||||
out->duration = values["duration"];
|
||||
} else if(!values["time"].empty()) {
|
||||
out->duration = values["time"];
|
||||
} else {
|
||||
*error = "No duration specified.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
25
src/dawntools/vnscenetool/events/VNWaitEventParser.hpp
Normal file
25
src/dawntools/vnscenetool/events/VNWaitEventParser.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/XmlParser.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VNWaitEvent {
|
||||
std::string duration;
|
||||
};
|
||||
|
||||
class VNWaitEventParser : public XmlParser<VNWaitEvent> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() override;
|
||||
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
VNWaitEvent *out,
|
||||
std::string *error
|
||||
) override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user