X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FInterpreter.h;h=fc1499dbd807c10eff793ee7b34a3506db8df640;hb=cc3d698b8c1ad09d7a3f9e3f28bc84e0ac1735ea;hp=044a3c0848c0dd51bb0df8a3124fb48e1c0457f2;hpb=d5959073b2c413ba1bd6f3d14bc8bcf59304e488;p=l2e.git diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 044a3c0..fc1499d 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -1,65 +1,46 @@ -/* - * Interpreter.h - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #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 "../common/Script.h" #include "../geometry/Vector.h" #include "../graphics/Color.h" #include "../graphics/ComplexAnimation.h" +#include "../graphics/fwd.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 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 &); @@ -67,163 +48,62 @@ private: public: void ReadSource(); + void *GetObject(int typeId, const std::string &name); -public: - graphics::Animation *GetAnimation(const std::string &name); - battle::Resources *GetBattleResources(const std::string &name); - bool GetBoolean(const std::string &name) const; - const graphics::Color &GetColor(const std::string &name) const; - graphics::Font *GetFont(const std::string &name); - graphics::Frame *GetFrame(const std::string &name); - graphics::Gauge *GetGauge(const std::string &name); - battle::Hero *GetHero(const std::string &name); - common::Ikari *GetIkari(const std::string &name); - common::Item *GetItem(const std::string &name); - graphics::MenuProperties *GetMenuProperties(const std::string &name); - battle::Monster *GetMonster(const std::string &name); - int GetNumber(const std::string &name) const; - battle::PartyLayout *GetPartyLayout(const std::string &name); - const char *GetPath(const std::string &name) const; - common::Spell *GetSpell(const std::string &name); - graphics::Sprite *GetSprite(const std::string &name); - const char *GetString(const std::string &name) const; - common::TargetingMode *GetTargetingMode(const std::string &name); - 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(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: - const std::vector &BattleResources() const { return battleResources; } - const std::vector &Booleans() const { return booleans; } - const std::vector &Colors() const { return colors; } - const std::vector &ComplexAnimations() const { return complexAnimations; } - const std::vector &Fonts() const { return fonts; } - const std::vector &Frames() const { return frames; } - const std::vector &Gauges() const { return gauges; } - const std::vector &Heroes() const { return heroes; } - const std::vector &Ikaris() const { return ikaris; } - const std::vector &Images() const { return images; } - const std::vector &Items() const { return items; } - const std::vector &MenuProperties() const { return menuProperties; } - const std::vector &Monsters() const { return monsters; } - const std::vector &Numbers() const { return numbers; } - const std::vector &PartyLayouts() const { return partyLayouts; } - const std::vector &SimpleAnimations() const { return simpleAnimations; } - const std::vector &Spells() const { return spells; } - const std::vector &Sprites() const { return sprites; } - const std::vector &Strings() const { return strings; } - const std::vector &TargetingModes() const { return targetingModes; } - 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 &); - battle::Resources *GetBattleResources(const Value &); - graphics::Color GetColor(const Value &); - bool GetBoolean(const Value &); - graphics::Font *GetFont(const Value &); - graphics::Frame *GetFrame(const Value &); - graphics::Gauge *GetGauge(const Value &); - battle::Hero *GetHero(const Value &); - common::Ikari *GetIkari(const Value &); - SDL_Surface *GetImage(const Value &); - common::Item *GetItem(const Value &); - graphics::MenuProperties *GetMenuProperties(const Value &); - battle::Monster *GetMonster(const Value &); - int GetNumber(const Value &); - battle::PartyLayout *GetPartyLayout(const Value &); - const PropertyList *GetPropertyList(const Value &); - const std::vector &GetPropertyListArray(const Value &); - const char *GetPath(const Value &); - common::Spell *GetSpell(const Value &); - graphics::Sprite *GetSprite(const Value &); - const char *GetString(const Value &); - common::TargetingMode *GetTargetingMode(const Value &); - const std::vector &GetValueArray(const Value &); - geometry::Vector GetVector(const Value &); - - void ReadBattleResources(battle::Resources &, const PropertyList &); - void ReadComplexAnimation(graphics::ComplexAnimation &, const PropertyList &); - void ReadComplexAnimationFrame(graphics::ComplexAnimation::FrameProp &, const PropertyList &); - void ReadFont(graphics::Font &, const PropertyList &); - void ReadFrame(graphics::Frame &, const PropertyList &); - void ReadGauge(graphics::Gauge &, const PropertyList &); - void ReadHero(battle::Hero &, const PropertyList &); - void ReadIkari(common::Ikari &, const PropertyList &); - void ReadItem(common::Item &, const PropertyList &); - void ReadMenuProperties(graphics::MenuProperties &, const PropertyList &); - void ReadMonster(battle::Monster &, const PropertyList &); - void ReadPartyLayout(battle::PartyLayout &, const PropertyList &); - void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &); - void ReadSpell(common::Spell &, const PropertyList &); - void ReadSprite(graphics::Sprite &, const PropertyList &); - void ReadStats(battle::Stats &, const PropertyList &); - void ReadTargetingMode(common::TargetingMode &, 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; - enum Type { - BATTLE_RESOURCES, - BOOLEAN, - COLOR, - COMPLEX_ANIMATION, - FONT, - FRAME, - GAUGE, - HERO, - IKARI, - IMAGE, - ITEM, - MENU_PROPERTIES, - MONSTER, - NUMBER, - PARTY_LAYOUT, - PATH, - PROPERTY_LIST_ARRAY, - SIMPLE_ANIMATION, - SPELL, - SPRITE, - STRING, - TARGETING_MODE, - 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::map imageCache; + PagedAllocator alloc; - std::vector battleResources; - std::vector booleans; - std::vector colors; - std::vector complexAnimations; - std::vector fonts; - std::vector frames; - std::vector gauges; - std::vector heroes; - std::vector ikaris; - std::vector images; - std::vector items; - std::vector menuProperties; - std::vector monsters; - std::vector numbers; - std::vector partyLayouts; - std::vector propertyLists; - std::vector > propertyListArrays; - std::vector simpleAnimations; - std::vector spells; - std::vector sprites; - std::vector strings; - std::vector targetingModes; - std::vector > valueArrays; - std::vector > vectors; + std::map parsedDefinitions; + std::vector postponedDefinitions; + std::map imageCache; + std::map > values; };