Update call sites and instantiation for Vector3 and Color parsers
This commit is contained in:
parent
2c4f6a4d29
commit
76a13e61de
3 changed files with 25 additions and 18 deletions
|
@ -13,7 +13,7 @@
|
|||
#include "material.h"
|
||||
#include "object_sphere.h"
|
||||
#include "yaml/objectParser.hh"
|
||||
#include "yaml/vector_parser.hh"
|
||||
#include "yaml/vectorParser.hh"
|
||||
|
||||
|
||||
namespace yaml {
|
||||
|
@ -79,20 +79,16 @@ ObjectParser::HandleColorEvent(yaml_event_t& event)
|
|||
return;
|
||||
}
|
||||
|
||||
auto onDone = [this](std::vector<double> color) {
|
||||
if (color.size() < 3) {
|
||||
assert(color.size() < 3);
|
||||
}
|
||||
auto onDone = [this](Color color) {
|
||||
if (!mObject->get_material()) {
|
||||
mObject->set_material(new Material());
|
||||
}
|
||||
mObject->get_material()->set_diffuse_color(Color(color[0], color[1], color[2]));
|
||||
|
||||
mObject->get_material()->set_diffuse_color(color);
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
};
|
||||
|
||||
GetParsers().push(new VectorParser<double>(GetScene(), GetParsers(), onDone));
|
||||
GetParsers().push(new ColorParser(GetScene(), GetParsers(), onDone));
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,17 +101,13 @@ ObjectParser::HandleOriginEvent(yaml_event_t& event)
|
|||
return;
|
||||
}
|
||||
|
||||
auto onDone = [this](std::vector<double> origin) {
|
||||
if (origin.size() < 3) {
|
||||
assert(origin.size() < 3);
|
||||
}
|
||||
mObject->set_origin(Vector3(origin[0], origin[1], origin[2]));
|
||||
|
||||
auto onDone = [this](Vector3 origin) {
|
||||
mObject->set_origin(origin);
|
||||
mSection = NoSection;
|
||||
SetShouldExpectKey(true);
|
||||
};
|
||||
|
||||
GetParsers().push(new VectorParser<double>(GetScene(), GetParsers(), onDone));
|
||||
GetParsers().push(new Vector3Parser(GetScene(), GetParsers(), onDone));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,6 +80,12 @@ struct UtilityParser
|
|||
{
|
||||
typedef std::function<void (T)> CallbackFunction;
|
||||
|
||||
UtilityParser(Scene& scene,
|
||||
ParserStack& parsers)
|
||||
: Parser(scene, parsers),
|
||||
mCallback()
|
||||
{ }
|
||||
|
||||
UtilityParser(Scene& scene,
|
||||
ParserStack& parsers,
|
||||
CallbackFunction callback)
|
||||
|
@ -94,7 +100,15 @@ struct UtilityParser
|
|||
void
|
||||
Notify(T value)
|
||||
{
|
||||
mCallback(value);
|
||||
if (mCallback) {
|
||||
mCallback(value);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SetCallback(CallbackFunction callback)
|
||||
{
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "objectParser.hh"
|
||||
#include "sceneParser.hh"
|
||||
#include "vector_parser.hh"
|
||||
#include "vectorParser.hh"
|
||||
|
||||
|
||||
namespace yaml {
|
||||
|
@ -82,7 +82,8 @@ SceneParser::HandleDimensionsEvent(yaml_event_t& event)
|
|||
|
||||
switch (event.type) {
|
||||
case YAML_SEQUENCE_START_EVENT:
|
||||
GetParsers().push(new VectorParser<int>(GetScene(), GetParsers(), onDone));
|
||||
GetParsers().push(new ScalarSequenceParser<int>(GetScene(), GetParsers(),
|
||||
onDone));
|
||||
break;
|
||||
default:
|
||||
/* TODO: Fail gracefully. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue