]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
8d5c1e31aadf7ca70ad042501baa2317d074fbd3
[l2e.git] / src / loader / Interpreter.h
1 /*
2  * Interpreter.h
3  *
4  *  Created on: Aug 26, 2012
5  *      Author: holy
6  */
7
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
10
11 #include "TypeDescription.h"
12 #include "../geometry/Vector.h"
13 #include "../graphics/Color.h"
14 #include "../graphics/ComplexAnimation.h"
15
16 #include <map>
17 #include <stdexcept>
18 #include <string>
19 #include <vector>
20 #include <SDL.h>
21
22 namespace battle {
23         class Hero;
24         class Monster;
25         class PartyLayout;
26         struct Resources;
27         class Stats;
28 }
29
30 namespace common {
31         class Ikari;
32         class Item;
33         class Spell;
34         class TargetingMode;
35 }
36
37 namespace graphics {
38         class Animation;
39         class Font;
40         class Frame;
41         class Gauge;
42         struct MenuProperties;
43         class SimpleAnimation;
44         class Sprite;
45 }
46
47 namespace loader {
48
49 class Definition;
50 class Literal;
51 class ParsedSource;
52 class PropertyList;
53 class Value;
54
55 class Interpreter {
56
57 public:
58         class Error: public std::runtime_error {
59         public:
60                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
61         };
62
63 public:
64         Interpreter(const ParsedSource &source) : source(source) { }
65         ~Interpreter();
66 private:
67         Interpreter(const Interpreter &);
68         Interpreter &operator =(const Interpreter &);
69
70 public:
71         void ReadSource();
72         void *GetObject(int typeId, const std::string &name);
73
74         static void CreateTypeDescriptions();
75         struct PostponedDefinition {
76                 PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType)
77                 : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType) { }
78                 int type;
79                 int id;
80                 std::ptrdiff_t offset;
81                 const char *identifier;
82                 int linkedType;
83         };
84
85         const std::vector<PostponedDefinition> &PostponedDefinitions() { return postponedDefinitions; }
86
87 private:
88         void ReadDefinition(const Definition &);
89         void ReadLiteral(const Definition &);
90         void ReadObject(const Definition &);
91
92         void ReadLiteral(int typeId, int id, char *dest, const Literal &);
93         void *GetObject(int typeId, const Value &value);
94         void ReadObject(int typeId, int id, char *dest, const PropertyList &);
95
96 private:
97         const ParsedSource &source;
98         struct ParsedDefinition {
99                 ParsedDefinition(const Definition *dfn, int type, int id)
100                 : dfn(dfn), type(type), id(id) { }
101                 const Definition *dfn;
102                 int type;
103                 int id;
104         };
105         std::map<std::string, ParsedDefinition> parsedDefinitions;
106
107         bool CanLink(const Value &) const;
108         void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType);
109         std::vector<PostponedDefinition> postponedDefinitions;
110
111         std::map<std::string, SDL_Surface *> imageCache;
112
113         std::map<int, std::vector<void *> > values;
114
115 };
116
117 }
118
119 #endif /* LOADER_INTERPRETER_H_ */