X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.cpp;h=8b54fc177913de18a1266f885cc8e959b6eb4eef;hb=eb2ad5ffd08128d31af32f3929a3295fcfa251e9;hp=5da1ff35a194f194606c573be575d797643e5486;hpb=754442d4502b743a46831055484c3fa9fa621ec2;p=l2e.git diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 5da1ff3..8b54fc1 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -1,19 +1,14 @@ -/* - * Interpreter.cpp - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #include "Interpreter.h" #include "ParsedSource.h" +#include "TypeDescription.h" #include "../battle/Hero.h" #include "../battle/Monster.h" #include "../battle/PartyLayout.h" #include "../battle/Resources.h" #include "../common/Ikari.h" #include "../common/Item.h" +#include "../common/Script.h" #include "../common/Spell.h" #include "../common/Stats.h" #include "../common/TargetingMode.h" @@ -34,6 +29,7 @@ using battle::Monster; using battle::PartyLayout; using common::Ikari; using common::Item; +using common::Script; using common::Spell; using common::Stats; using common::TargetingMode; @@ -45,7 +41,7 @@ using graphics::Gauge; using graphics::ComplexAnimation; using graphics::SimpleAnimation; using graphics::Sprite; -using geometry::Vector; +using math::Vector; using std::make_pair; using std::set; using std::string; @@ -60,8 +56,16 @@ Interpreter::~Interpreter() { } -const Interpreter::ParsedDefinition &Interpreter::GetDefinition(const string &identifier) const { - return parsedDefinitions.at(identifier); +const Interpreter::ParsedDefinition &Interpreter::GetDefinition(const string &identifier) { + std::map::const_iterator i(parsedDefinitions.find(identifier)); + if (i != parsedDefinitions.end()) { + return i->second; + } else if (source.IsDefined(identifier)) { + ReadDefinition(source.GetDefinition(identifier)); + return parsedDefinitions.at(identifier); + } else { + throw Error("access to undefined object " + identifier); + } } @@ -112,22 +116,21 @@ void Interpreter::ReadLiteral(const Definition &dfn) { || dfn.GetLiteral()->GetType() == Literal::STRING) ? dfn.GetLiteral()->GetString().size() : td.Size()); char *object(alloc.Alloc(size)); + values[typeId].push_back(object); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, id))); if (dfn.GetLiteral()->GetType() == Literal::OBJECT) { ReadObject(typeId, id, object, *dfn.GetLiteral()->GetProperties()); } else { ReadLiteral(typeId, id, object, *dfn.GetLiteral()); } - values[typeId].push_back(object); - parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, id))); } void Interpreter::ReadLiteral(int typeId, int id, char *object, const Literal &literal) { switch (literal.GetType()) { case Literal::ARRAY_VALUES: - throw Error("named value arrays are not supported, sorry"); - break; case Literal::ARRAY_PROPS: - throw Error("named property list arrays are not supported, sorry"); + case Literal::ARRAY_IDENTS: + throw Error("named arrays are not supported, sorry"); break; case Literal::BOOLEAN: new (object) bool(literal.GetBoolean()); @@ -142,6 +145,10 @@ void Interpreter::ReadLiteral(int typeId, int id, char *object, const Literal &l std::memcpy(object, literal.GetString().c_str(), literal.GetString().size()); object[literal.GetString().size()] = '\0'; break; + case Literal::SCRIPT: + new (object) Script; + ReadScript(literal.GetScript(), reinterpret_cast