]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Interpreter.h
removed stupid file headers that eclipse put in
[l2e.git] / src / loader / Interpreter.h
index a32b3cad6d4c8a90cd8401f25c868955c2dd23fc..fc1499dbd807c10eff793ee7b34a3506db8df640 100644 (file)
@@ -1,51 +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 <map>
+#include <set>
 #include <stdexcept>
 #include <string>
 #include <vector>
 #include <SDL.h>
 
-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,65 +48,62 @@ private:
 
 public:
        void ReadSource();
+       void *GetObject(int typeId, const std::string &name);
 
-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);
+       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<std::string> &ExportedIdentifiers() const { return source.Exports(); }
+       const ParsedDefinition &GetDefinition(const std::string &identifier);
+       const std::map<std::string, SDL_Surface *> &Images() const { return imageCache; }
+       const std::vector<PostponedDefinition> &PostponedDefinitions() const { return postponedDefinitions; }
+       const std::map<int, std::vector<void *> > &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<Value *> &GetValueArray(const Value &);
-       const std::vector<PropertyList *> &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<int> 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<ScriptToken *> &, common::Script *);
+       char *ReadScript(const std::vector<ScriptToken *> &);
+       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 DynamicType {
-               ANIMATION,
-               COMPLEX_ANIMATION,
-               HERO,
-               MONSTER,
-               NUMBER,
-               SIMPLE_ANIMATION,
-               SPRITE,
-       };
-       struct ParsedDefinition {
-               ParsedDefinition(const Definition *dfn, DynamicType type, int index)
-               : dfn(dfn), type(type), index(index) { }
-               bool IsCompatible(DynamicType with) const;
-               const Definition *dfn;
-               DynamicType type;
-               int index;
-       };
-       std::map<std::string, ParsedDefinition> parsedDefinitions;
 
-       std::vector<graphics::Animation *> animations;
-       std::vector<battle::Hero> heroes;
-       std::vector<SDL_Surface *> images;
-       std::vector<battle::Monster> monsters;
-       std::vector<int> numbers;
-       std::vector<graphics::Sprite> sprites;
+       PagedAllocator alloc;
+
+       std::map<std::string, ParsedDefinition> parsedDefinitions;
+       std::vector<PostponedDefinition> postponedDefinitions;
+       std::map<std::string, SDL_Surface *> imageCache;
+       std::map<int, std::vector<void *> > values;
 
 };