X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.h;h=5a8e3ab8aa424ed4db977e0c471c475cea05b8af;hb=eb2ad5ffd08128d31af32f3929a3295fcfa251e9;hp=8824a14ecfb2e36eb428519c9268d328d5a3230f;hpb=774c652e18456863dc1ae03e3a5bb4a75f40a956;p=l2e.git diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 8824a14..5a8e3ab 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -1,51 +1,38 @@ -/* - * Interpreter.h - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #ifndef LOADER_INTERPRETER_H_ #define LOADER_INTERPRETER_H_ -#include "../geometry/Vector.h" -#include "../graphics/ComplexAnimation.h" +#include "PagedAllocator.h" +#include "ParsedSource.h" +#include "../common/Script.h" #include +#include #include #include #include #include -namespace battle { - class Hero; - class Monster; - class Stats; -} - -namespace graphics { - class Animation; - class SimpleAnimation; - class Sprite; -} - namespace loader { -class Definition; -class ParsedSource; -class PropertyList; -class Value; - class Interpreter { public: + static const int BOOLEAN_ID = 1; + static const int COLOR_ID = 2; + static const int IMAGE_ID = 3; + static const int NUMBER_ID = 4; + static const int PATH_ID = 5; + static const int SCRIPT_ID = 6; + static const int STRING_ID = 7; + static const int VECTOR_ID = 8; + class Error: public std::runtime_error { public: Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { } }; public: - Interpreter(const ParsedSource &source) : source(source) { } + explicit Interpreter(const ParsedSource &source) : source(source), alloc(4096) { } ~Interpreter(); private: Interpreter(const Interpreter &); @@ -53,94 +40,78 @@ private: public: void ReadSource(); + void *GetObject(int typeId, const std::string &name); -public: - graphics::Animation *GetAnimation(const std::string &name); - bool GetBoolean(const std::string &name) const; - battle::Hero *GetHero(const std::string &name); - battle::Monster *GetMonster(const std::string &name); - int GetNumber(const std::string &name) const; - graphics::Sprite *GetSprite(const std::string &name); - const char *GetString(const std::string &name) const; - geometry::Vector GetVector(const std::string &name) const; + static void CreateTypeDescriptions(); + struct ParsedDefinition { + ParsedDefinition(const Definition *dfn, int type, int id) + : dfn(dfn), type(type), id(id) { } + const Definition *dfn; + int type; + int id; + }; + struct PostponedDefinition { + PostponedDefinition( + char *dest, + const char *identifier, + int type, + bool inlined, + bool aggregate) + : dest(dest) + , identifier(identifier) + , type(type) + , inlined(inlined) + , aggregate(aggregate) { } + char *dest; + const char *identifier; + int type; + bool inlined; + bool aggregate; + }; -public: - const std::vector &Booleans() const { return booleans; } - const std::vector &ComplexAnimations() const { return complexAnimations; } - const std::vector &Heroes() const { return heroes; } - const std::vector &Images() const { return images; } - const std::vector &Monsters() const { return monsters; } - const std::vector &Numbers() const { return numbers; } - const std::vector &SimpleAnimations() const { return simpleAnimations; } - const std::vector &Sprites() const { return sprites; } - const std::vector &Strings() const { return strings; } - const std::vector > &Vectors() const { return vectors; } + const std::set &ExportedIdentifiers() const { return source.Exports(); } + const ParsedDefinition &GetDefinition(const std::string &identifier); + const std::map &Images() const { return imageCache; } + const std::vector &PostponedDefinitions() const { return postponedDefinitions; } + const std::map > &Values() const { return values; } private: void ReadDefinition(const Definition &); void ReadLiteral(const Definition &); void ReadObject(const Definition &); - graphics::Animation *GetAnimation(const Value &); - bool GetBoolean(const Value &); - SDL_Surface *GetImage(const Value &); - int GetNumber(const Value &); - const PropertyList *GetPropertyList(const Value &); - const std::vector &GetPropertyListArray(const Value &); - graphics::Sprite *GetSprite(const Value &); - const char *GetString(const Value &); - const std::vector &GetValueArray(const Value &); - geometry::Vector GetVector(const Value &); - - void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &); - void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &); - void ReadHero(battle::Hero &, const PropertyList &); - void ReadMonster(battle::Monster &, const PropertyList &); - void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &); - void ReadSprite(graphics::Sprite &, const PropertyList &); - void ReadStats(battle::Stats &, const PropertyList &); + void ReadLiteral(int typeId, int id, char *dest, const Literal &); + void *GetObject(int typeId, const Value &value); + void ReadObject(int typeId, int id, char *dest, const PropertyList &); + void ReadScript(const std::vector &, common::Script *); + char *ReadScript(const std::vector &); + common::Script::Code &CreateScriptCode(common::Script::Command c, char *dest); + void ReadScriptAddress(const ScriptToken &t, char *dest); + void ReadScriptInteger(const ScriptToken &t, char *dest); + void ReadScriptVector(const ScriptToken &t, char *dest); + + SDL_Surface *GetImage(const std::string &); + + bool CanLink(const Value &) const; + void Postpone( + char *dest, + const std::string &identifier, + int type, + bool inlined = true, + bool aggregate = false); private: const ParsedSource &source; - enum Type { - BOOLEAN, - COMPLEX_ANIMATION, - HERO, - IMAGE, - MONSTER, - NUMBER, - PROPERTY_LIST_ARRAY, - SIMPLE_ANIMATION, - SPRITE, - STRING, - VECTOR, - VALUE_ARRAY, - }; - struct ParsedDefinition { - ParsedDefinition(const Definition *dfn, Type type, int index) - : dfn(dfn), type(type), index(index) { } - const Definition *dfn; - Type type; - int index; - }; - std::map parsedDefinitions; - std::vector booleans; - std::vector complexAnimations; - std::vector heroes; - std::vector images; - std::vector monsters; - std::vector numbers; - std::vector propertyLists; - std::vector > propertyListArrays; - std::vector simpleAnimations; - std::vector sprites; - std::vector strings; - std::vector > valueArrays; - std::vector > vectors; + PagedAllocator alloc; + + std::map parsedDefinitions; + std::vector postponedDefinitions; + std::map imageCache; + std::map > values; }; } -#endif /* LOADER_INTERPRETER_H_ */ +#endif