| 1 |
/* |
| 2 |
* interpreters interpretating module vectors |
| 3 |
*/ |
| 4 |
|
| 5 |
#ifndef INTERP_H |
| 6 |
#define INTERP_H |
| 7 |
|
| 8 |
#include <stack> |
| 9 |
|
| 10 |
#include "lsys.h" |
| 11 |
#include "interface.h" |
| 12 |
#include "util.h" |
| 13 |
#include "matrix.h" |
| 14 |
|
| 15 |
#include <iostream> // FIXME only for simple_interpreter |
| 16 |
|
| 17 |
using namespace std; |
| 18 |
|
| 19 |
class interpreter { |
| 20 |
protected: |
| 21 |
virtual void execute (const module_vec &v, const lsys &l) t_err abstract; |
| 22 |
virtual bool execute_child (const module &m, const lsys &l) t_err; |
| 23 |
public: |
| 24 |
virtual ~interpreter () t_no {}; |
| 25 |
virtual void operator ()(const module_vec &v, const lsys &l) t_err { execute (v, l); }; |
| 26 |
}; |
| 27 |
|
| 28 |
class simple_interpreter : public interpreter { |
| 29 |
int maxdepth; |
| 30 |
int depth; |
| 31 |
|
| 32 |
void execute(const module_vec &v, const lsys &l) t_err; |
| 33 |
public: |
| 34 |
simple_interpreter (int depth) t_no : maxdepth (depth) {}; |
| 35 |
void operator ()(const module_vec &v, const lsys &l) t_err; |
| 36 |
}; |
| 37 |
|
| 38 |
class turtle_interpreter : public interpreter { |
| 39 |
gfx_int &iface; |
| 40 |
bool flat; |
| 41 |
|
| 42 |
double delta, distance; |
| 43 |
struct state { |
| 44 |
vec pos; |
| 45 |
mat dir; /* H L U, up = normal */ |
| 46 |
attribute_set attr; |
| 47 |
}; |
| 48 |
state cur; |
| 49 |
stack<state> state_stack; |
| 50 |
|
| 51 |
points cur_obj; |
| 52 |
stack<points> obj_stack; |
| 53 |
|
| 54 |
void rotate_tl (double phi) t_no; |
| 55 |
void rotate_pd (double phi) t_no; |
| 56 |
void rotate_rl (double phi) t_no; |
| 57 |
void forward (double d) t_no; |
| 58 |
|
| 59 |
void attrs_changed () t_err; |
| 60 |
protected: |
| 61 |
void execute (const module_vec &v, const lsys &l) t_err; |
| 62 |
public: |
| 63 |
turtle_interpreter (gfx_int &interface, bool flat_world = false) t_no; |
| 64 |
~turtle_interpreter () t_no {}; |
| 65 |
void operator ()(const module_vec &v, const lsys &l) t_err; |
| 66 |
}; |
| 67 |
|
| 68 |
#endif |