]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
handle special case of Image type objects
[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         SDL_Surface *GetImage(const std::string &);
97
98 private:
99         const ParsedSource &source;
100         struct ParsedDefinition {
101                 ParsedDefinition(const Definition *dfn, int type, int id)
102                 : dfn(dfn), type(type), id(id) { }
103                 const Definition *dfn;
104                 int type;
105                 int id;
106         };
107         std::map<std::string, ParsedDefinition> parsedDefinitions;
108
109         bool CanLink(const Value &) const;
110         void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType);
111         std::vector<PostponedDefinition> postponedDefinitions;
112
113         std::map<std::string, SDL_Surface *> imageCache;
114
115         std::map<int, std::vector<void *> > values;
116
117 };
118
119 }
120
121 #endif /* LOADER_INTERPRETER_H_ */