X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.h;h=5f66c0f954e55243f018eb9065783359801e206b;hb=092a2dd175a4001a495c84ee85211734fb928c83;hp=8d5c1e31aadf7ca70ad042501baa2317d074fbd3;hpb=401785f03e9d56fb28d9e29cdb74dbbf5664c342;p=l2e.git diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 8d5c1e3..5f66c0f 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -1,67 +1,38 @@ -/* - * Interpreter.h - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #ifndef LOADER_INTERPRETER_H_ #define LOADER_INTERPRETER_H_ -#include "TypeDescription.h" -#include "../geometry/Vector.h" -#include "../graphics/Color.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 PartyLayout; - struct Resources; - class Stats; -} - -namespace common { - class Ikari; - class Item; - class Spell; - class TargetingMode; -} - -namespace graphics { - class Animation; - class Font; - class Frame; - class Gauge; - struct MenuProperties; - class SimpleAnimation; - class Sprite; -} - namespace loader { -class Definition; -class Literal; -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 &); @@ -72,17 +43,29 @@ public: void *GetObject(int typeId, const std::string &name); 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(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType) - : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType) { } + PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType, bool inlined) + : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType), inlined(inlined) { } int type; int id; std::ptrdiff_t offset; const char *identifier; int linkedType; + bool inlined; }; - const std::vector &PostponedDefinitions() { return postponedDefinitions; } + 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 &); @@ -92,24 +75,26 @@ private: 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(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined); private: const ParsedSource &source; - struct ParsedDefinition { - ParsedDefinition(const Definition *dfn, int type, int id) - : dfn(dfn), type(type), id(id) { } - const Definition *dfn; - int type; - int id; - }; - std::map parsedDefinitions; - bool CanLink(const Value &) const; - void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType); - std::vector postponedDefinitions; + PagedAllocator alloc; + std::map parsedDefinitions; + std::vector postponedDefinitions; std::map imageCache; - std::map > values; };