X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.h;h=454fccc67427786e61fd3db7b8d22bc074938786;hb=4aca5f02e6edfc3ace1862b4639198a89004b4fd;hp=c2fc25f84b6a1b6cb09edf1492e046f1e13c50d2;hpb=107b78b720db69ad402c09c0b1d9beb3b88a1952;p=l2e.git diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index c2fc25f..454fccc 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -1,58 +1,104 @@ -/* - * Interpreter.h - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #ifndef LOADER_INTERPRETER_H_ #define LOADER_INTERPRETER_H_ +#include "PagedAllocator.h" +#include "ParsedSource.h" +#include "../common/Script.h" + #include +#include #include #include #include - -namespace battle { - class Monster; -} +#include namespace loader { -class Definition; -class ParsedSource; -class PropertyList; - 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) { } - ~Interpreter() { } + explicit Interpreter(const ParsedSource &source) : source(source), alloc(4096) { } + ~Interpreter(); private: Interpreter(const Interpreter &); Interpreter &operator =(const Interpreter &); public: void ReadSource(); + 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, 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::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 &); - void ReadMonster(battle::Monster &, 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(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined); private: const ParsedSource &source; - std::vector monsters; + + PagedAllocator alloc; + + std::map parsedDefinitions; + std::vector postponedDefinitions; + std::map imageCache; + std::map > values; }; } -#endif /* LOADER_INTERPRETER_H_ */ +#endif