X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.h;h=9795a6062961b283d7efcb1e38fe1a2b8756538a;hb=7c43158af1abf38fa896a442cb3c6d8a5bc630e7;hp=2748c63bdadfa44e80539fca52d9517cb4636822;hpb=ebd72885587d606677e35129e418dbe6321082d1;p=l2e.git diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 2748c63..9795a60 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -8,8 +8,16 @@ #ifndef LOADER_INTERPRETER_H_ #define LOADER_INTERPRETER_H_ +#include "fwd.h" +#include "PagedAllocator.h" +#include "ParsedSource.h" +#include "TypeDescription.h" +#include "../battle/fwd.h" +#include "../common/fwd.h" #include "../geometry/Vector.h" +#include "../graphics/Color.h" #include "../graphics/ComplexAnimation.h" +#include "../graphics/fwd.h" #include #include @@ -18,25 +26,8 @@ #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: @@ -46,55 +37,69 @@ public: }; 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; + }; -public: - graphics::Animation *GetAnimation(const std::string &name); - 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 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 &); - const std::vector &GetValueArray(const Value &); - const std::vector &GetPropertyListArray(const Value &); - bool GetBoolean(const Value &); - SDL_Surface *GetImage(const Value &); - int GetNumber(const Value &); - const PropertyList *GetPropertyList(const Value &); - graphics::Sprite *GetSprite(const Value &); - const char *GetString(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 &); + void ReadScriptAddress(const ScriptToken &t, unsigned char *dest); + void ReadScriptInteger(const ScriptToken &t, unsigned char *dest); + void ReadScriptVector(const ScriptToken &t, unsigned 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::set parsedDefinitions; - std::map animations; - std::map heroes; - std::map monsters; - std::map numbers; - std::map sprites; + PagedAllocator alloc; + + std::map parsedDefinitions; + std::vector postponedDefinitions; + std::map imageCache; + std::map > values; };