]> git.localhorst.tv Git - l2e.git/blob - src/common/ScriptRunner.h
879877d8467a2463f1680863a78ad1bbb8178328
[l2e.git] / src / common / ScriptRunner.h
1 /*
2  * ScriptRunner.h
3  *
4  *  Created on: Oct 13, 2012
5  *      Author: holy
6  */
7
8 #ifndef COMMON_SCRIPTRUNNER_H_
9 #define COMMON_SCRIPTRUNNER_H_
10
11 #include "fwd.h"
12 #include "Script.h"
13 #include "../geometry/Vector.h"
14
15 #include <SDL.h>
16
17 namespace common {
18
19 class ScriptRunner {
20
21 public:
22         ScriptRunner();
23         ~ScriptRunner();
24
25 public:
26         void Run(ScriptHost &, const Script &);
27         bool Running() const;
28
29         void *AddressRegister(int n) const { return address[n]; }
30         int IntegerRegister(int n) const { return integer[n]; }
31         const geometry::Vector<int> &VectorRegister(int n) const { return vector[n]; }
32
33 private:
34         void Reset();
35         void Exec(Script::Code code);
36
37         void *PopAddress();
38         Script::Code PopCode();
39         int PopInt();
40         const geometry::Vector<int> &PopVector();
41
42         void Compare(int, int);
43
44         enum CompareFlags {
45                 COMPARE_EQUAL = 0,
46                 COMPARE_LESS = 1,
47                 COMPARE_GREATER = 2,
48         };
49
50 private:
51         ScriptHost *host;
52         const Script *script;
53         int cursor;
54
55         static const int numRegisters = 7;
56         void *address[numRegisters];
57         int integer[numRegisters];
58         geometry::Vector<int> vector[numRegisters];
59
60         Uint8 compare;
61
62 };
63
64 }
65
66 #endif /* COMMON_SCRIPTRUNNER_H_ */