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 "material.h"
|
||||||
#include "object_sphere.h"
|
#include "object_sphere.h"
|
||||||
#include "yaml/objectParser.hh"
|
#include "yaml/objectParser.hh"
|
||||||
#include "yaml/vector_parser.hh"
|
#include "yaml/vectorParser.hh"
|
||||||
|
|
||||||
|
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
|
@ -79,20 +79,16 @@ ObjectParser::HandleColorEvent(yaml_event_t& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto onDone = [this](std::vector<double> color) {
|
auto onDone = [this](Color color) {
|
||||||
if (color.size() < 3) {
|
|
||||||
assert(color.size() < 3);
|
|
||||||
}
|
|
||||||
if (!mObject->get_material()) {
|
if (!mObject->get_material()) {
|
||||||
mObject->set_material(new 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;
|
mSection = NoSection;
|
||||||
SetShouldExpectKey(true);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto onDone = [this](std::vector<double> origin) {
|
auto onDone = [this](Vector3 origin) {
|
||||||
if (origin.size() < 3) {
|
mObject->set_origin(origin);
|
||||||
assert(origin.size() < 3);
|
|
||||||
}
|
|
||||||
mObject->set_origin(Vector3(origin[0], origin[1], origin[2]));
|
|
||||||
|
|
||||||
mSection = NoSection;
|
mSection = NoSection;
|
||||||
SetShouldExpectKey(true);
|
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;
|
typedef std::function<void (T)> CallbackFunction;
|
||||||
|
|
||||||
|
UtilityParser(Scene& scene,
|
||||||
|
ParserStack& parsers)
|
||||||
|
: Parser(scene, parsers),
|
||||||
|
mCallback()
|
||||||
|
{ }
|
||||||
|
|
||||||
UtilityParser(Scene& scene,
|
UtilityParser(Scene& scene,
|
||||||
ParserStack& parsers,
|
ParserStack& parsers,
|
||||||
CallbackFunction callback)
|
CallbackFunction callback)
|
||||||
|
|
@ -94,7 +100,15 @@ struct UtilityParser
|
||||||
void
|
void
|
||||||
Notify(T value)
|
Notify(T value)
|
||||||
{
|
{
|
||||||
mCallback(value);
|
if (mCallback) {
|
||||||
|
mCallback(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SetCallback(CallbackFunction callback)
|
||||||
|
{
|
||||||
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "objectParser.hh"
|
#include "objectParser.hh"
|
||||||
#include "sceneParser.hh"
|
#include "sceneParser.hh"
|
||||||
#include "vector_parser.hh"
|
#include "vectorParser.hh"
|
||||||
|
|
||||||
|
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
|
@ -82,7 +82,8 @@ SceneParser::HandleDimensionsEvent(yaml_event_t& event)
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case YAML_SEQUENCE_START_EVENT:
|
case YAML_SEQUENCE_START_EVENT:
|
||||||
GetParsers().push(new VectorParser<int>(GetScene(), GetParsers(), onDone));
|
GetParsers().push(new ScalarSequenceParser<int>(GetScene(), GetParsers(),
|
||||||
|
onDone));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* TODO: Fail gracefully. */
|
/* TODO: Fail gracefully. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue