GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Expression.hh
Go to the documentation of this file.
1#include "Effect.hh"
2#include <vector>
3
4
5template<class T, class K>
7{
8public:
9 Duplicate(T t) : t(t) { }
10 std::vector<K> Elem()
11 {
12 std::vector<K> vec;
13 int s=funcs.size();
14 for(int i=0;i<s;i++)
15 {
16 Function<T,K> *func = funcs[i];
17 vec.push_back(func->Index(t));
18 }
19 return vec;
20 }
21 void push_back(Function<T,K> *func) { funcs.push_back(func); }
22private:
23 T t;
24 std::vector<Function<T,K>*> funcs;
25};
26
27template<class T, class K>
28class Duplicate2Array : public Array<int,K>
29{
30public:
31 Duplicate2Array(T t, Array<int,Function<T,K>*> &arr) : t(t), arr(arr) { }
32 int Size() const
33 {
34 return arr.Size();
35 }
36 K Index(int i) const
37 {
38 Function<T,K>* func = arr.Index(i);
39 return func->Index(t);
40 }
41
42private:
43 T t;
45};
46
47template<class T, class K>
49{
50public:
51 Duplicate2(T t, Array<int, Function<T,K>*> &funcarr) : t(t), arr(t, funcarr) { }
53 {
54 return &arr;
55 }
56private:
58};
59
60template<class T, class K>
62{
63public:
64 Duplicate3(T t) : dup(t,vec) { }
65 void push_back(Function<T,K> *func) { vec.push_back(func); }
67 {
68 return dup.Elem();
69 }
70priate:
71 VectorArray vec;
73};
74
75class Duplicate4Array : public Array<int,T>
76{
77public:
78 Duplicate4Array(int s, T t) : t(t), s(s) { }
79 int Size() const { return s; }
80 T Index(int i) const { return t; }
81private:
82 T t;
83 int s;
84};
85
86template<class T>
88{
89public:
90 Duplicate4(int s, T t) : arr(s,t) { }
92 {
93 return &arr;
94 }
95private:
97};
98
99//
100//
101// NEW EXPRESSION STUFF
102//
103template<class T>
104class Value
105{
106public:
107 virtual T get() const=0;
108 virtual bool valid_get() const=0;
109 virtual void set(T t)=0;
110 virtual bool valid_set(T t) const=0;
111};
112
113template<class T, class K>
114class X_choose_first : public Value<T>
115{ // (x) |- (x,y)
116public:
117 X_choose_first(Value<std::pair<T,K> > &p) : p(p) { }
118 virtual T get() const { return p.get().first; }
119 bool valid_get() const { return p.valid_get(); }
120 virtual void set(T t)
121 {
122 p.set(std::make_pair(t, p.get().second));
123 }
124 virtual bool valid_set(T t) const
125 {
126 return p.valid_set(std::make_pair(t, p.get().second));
127 }
128
129private:
131};
132
133template<class T, class K>
134class X_choose_second : public Value<K>
135{ // (y) |- (x,y)
136public:
137 X_choose_second(Value<std::pair<T,K> > &p) : p(p) { }
138 virtual K get() const { return p.get().first; }
139 bool valid_get() const { return p.valid_get(); }
140 virtual void set(K k)
141 {
142 p.set(std::make_pair(p.get().first, k));
143 }
144 virtual bool valid_set(K k) const
145 {
146 return p.valid_set(std::make_pair(p.get().first,k));
147 }
148
149private:
151};
152
153
154class X_X_Value_Int : public Value<std::pair<int,int> >
155{ // (x,x) : (int,int)
156public:
157
158 virtual std::pair<T,T> get() const { return p; }
159 bool valid_get() const { return true; }
160 virtual void set(std::pair<T,T> t) { p = t; }
161 virtual bool valid_set(std::pair<T,T> t) const
162 {
163 return t.first == t.second;
164 }
165private:
166 std::pair<T,T> p;
167};
168
169
170template<class T>
171class X_Value : public Value<T>
172{ // x |- (x)
173public:
174 X_Value() : m_t(0.0) { }
175 X_Value(T t) : m_t(t) { }
176 virtual T get() const { return m_t; }
177 bool valid_get() const { return true; }
178 virtual void set(T t) { m_t = t; }
179 virtual bool valid_set(T t) const { return true; }
180private:
181 T m_t;
182};
183
184template<class T>
185class ConstantValue : public Value<T>
186{
187public:
188 ConstantValue(T t) : t(t) { }
189 virtual T get() const { return t; }
190 bool valid_get() const { return true; }
191 virtual void set(T t) { }
192 virtual bool valid_set(T t) const { return true; }
193private:
194 T t;
195};
196
197template<class T>
198class PlusValue : public Value<T>
199{ // (x,y) |- (x+y)
200public:
201 PlusValue(Value<T> &t1, Value<T> &t2) : t1(t1), t2(t2) { }
202 bool valid_get() const { return t1.valid_get() && t2.valid_get(); }
203 virtual T get() const
204 {
205 return t1.get() + t2.get();
206 }
207 virtual void set(T t)
208 {
209 T tt = 0;
210 for(T i=0;i<t;i++)
211 {
212 if (t1.valid_set(i) && t2.valid_set(t-i))
213 {
214 break;
215 }
216 }
217 t1.set(i); t2.set(t-i);
218 }
219 virtual bool valid_set(T t) const
220 {
221 T tt = 0;
222 bool b = false;
223 for(T i=0;i<t;i++)
224 {
225 if (t1.valid_set(i) && t2.valid_set(t-i))
226 {
227 b = true;
228 break;
229 }
230 }
231 return b;
232 }
233
234private:
235 Value<T> &t1, &t2;
236};
237
238template<class T>
239class Unit : public Value<T>
240{ // u |- (u)
241public:
242 Unit(T &ref) : ref(ref) { }
243 virtual T get() const { return ref; }
244 bool valid_get() const { return true; }
245 virtual void set(T t) { }
246 virtual bool valid_set(T t) const
247 {
248 return true;
249 }
250private:
251 T &ref;
252};
253
254class T_Int_to_Float_conversion : public Value<float>
255{ //(x) |- (y), F : Int->Float
256public:
258 virtual float get() const { return (float)val.get(); }
259 bool valid_get() const { return true; }
260
261 virtual void set(float t)
262 {
263 val.set((int)t);
264 }
265 virtual bool valid_set(float t) const
266 {
267 int v = (int)t;
268 float vf = (float) v;
269 float delta = t - vf;
270 return fabs(delta) < 0.001;
271 }
272private:
273 Value<int> &val;
274};
275
277{ //(x) |- (y), F : Float->Int
278public:
280 virtual int get() const { return (int)val.get(); }
281 bool valid_get() const
282 {
283 int v = (int)val.get();
284 float vf = (float) v;
285 float delta = val.get() - vf;
286 return fabs(delta) < 0.001;
287 }
288
289 virtual void set(int t)
290 {
291 val.set((float)t);
292 }
293 virtual bool valid_set(int t) const
294 {
295 return true;
296 }
297private:
298 Value<float> &val;
299};
300
301
302class T_power_2_float : public Value<float>
303{ // x |- (x^2)
304public:
305 T_power_2(Value<float> &val) : val(val) { }
306 virtual float get() const { float t = val.get(); float t2 = t*t; return t2; }
307 virtual void set(float t) { val.set(sqrt(t)); }
308 virtual bool valid_set(float t) const
309 {
310 return val.valid_set(t);
311 }
312private:
313 Value<float> &val;
314};
315
316template<class T>
318{ // x |- (k*x)
319public:
321 virtual T get() const { return k.get()*x.get(); }
322 virtual void set(T t) { x.set(t/k.get()); }
323 virtual bool valid_set(T t) const { return x.valid_set(t/k.get()); }
324private:
325 Value<T> &x;
326 Value<T> &k;
327};
328
329void test_expr();
P func(int c, EveryApi &ev)
Definition test.cpp:59
void test_expr()
Definition Expression.cc:2
Definition EffectI.hh:22
virtual bool valid_set(T t) const
Definition Expression.hh:192
ConstantValue(T t)
Definition Expression.hh:188
virtual void set(T t)
Definition Expression.hh:191
bool valid_get() const
Definition Expression.hh:190
virtual T get() const
Definition Expression.hh:189
Definition Expression.hh:29
K Index(int i) const
Definition Expression.hh:36
Duplicate2Array(T t, Array< int, Function< T, K > * > &arr)
Definition Expression.hh:31
int Size() const
Definition Expression.hh:32
Definition Expression.hh:49
Array< int, K > * Elem()
Definition Expression.hh:52
Duplicate2(T t, Array< int, Function< T, K > * > &funcarr)
Definition Expression.hh:51
Array< int, K > * Elem()
Definition Expression.hh:66
Duplicate3(T t)
Definition Expression.hh:64
void push_back(Function< T, K > *func)
Definition Expression.hh:65
Duplicate2< T, K > dup
Definition Expression.hh:72
Definition Expression.hh:76
T Index(int i) const
Definition Expression.hh:80
int Size() const
Definition Expression.hh:79
Duplicate4Array(int s, T t)
Definition Expression.hh:78
Duplicate4(int s, T t)
Definition Expression.hh:90
Array< int, T > * Elem() const
Definition Expression.hh:91
Duplicate(T t)
Definition Expression.hh:9
std::vector< K > Elem()
Definition Expression.hh:10
void push_back(Function< T, K > *func)
Definition Expression.hh:21
Definition EffectI.hh:11
bool valid_get() const
Definition Expression.hh:202
virtual bool valid_set(T t) const
Definition Expression.hh:219
virtual void set(T t)
Definition Expression.hh:207
PlusValue(Value< T > &t1, Value< T > &t2)
Definition Expression.hh:201
virtual T get() const
Definition Expression.hh:203
virtual void set(int t)
Definition Expression.hh:289
T_Float_to_Int_conversion(Value< float > &val)
Definition Expression.hh:279
bool valid_get() const
Definition Expression.hh:281
virtual int get() const
Definition Expression.hh:280
virtual bool valid_set(int t) const
Definition Expression.hh:293
virtual bool valid_set(float t) const
Definition Expression.hh:265
virtual float get() const
Definition Expression.hh:258
T_Int_to_Float_conversion(Value< int > &val)
Definition Expression.hh:257
bool valid_get() const
Definition Expression.hh:259
virtual void set(float t)
Definition Expression.hh:261
virtual bool valid_set(T t) const
Definition Expression.hh:323
virtual void set(T t)
Definition Expression.hh:322
T_constant_multiplication(Value< T > &x, Value< T > &k)
Definition Expression.hh:320
virtual T get() const
Definition Expression.hh:321
Definition Expression.hh:303
virtual void set(float t)
Definition Expression.hh:307
virtual bool valid_set(float t) const
Definition Expression.hh:308
T_power_2(Value< float > &val)
Definition Expression.hh:305
virtual float get() const
Definition Expression.hh:306
virtual bool valid_set(T t) const
Definition Expression.hh:246
virtual void set(T t)
Definition Expression.hh:245
Unit(T &ref)
Definition Expression.hh:242
virtual T get() const
Definition Expression.hh:243
bool valid_get() const
Definition Expression.hh:244
Definition Expression.hh:105
virtual bool valid_get() const =0
virtual void set(T t)=0
virtual T get() const =0
virtual bool valid_set(T t) const =0
Definition Effect.hh:1122
virtual void set(T t)
Definition Expression.hh:178
bool valid_get() const
Definition Expression.hh:177
virtual bool valid_set(T t) const
Definition Expression.hh:179
X_Value(T t)
Definition Expression.hh:175
virtual T get() const
Definition Expression.hh:176
X_Value()
Definition Expression.hh:174
Definition Expression.hh:155
bool valid_get() const
Definition Expression.hh:159
virtual std::pair< T, T > get() const
Definition Expression.hh:158
virtual void set(std::pair< T, T > t)
Definition Expression.hh:160
virtual bool valid_set(std::pair< T, T > t) const
Definition Expression.hh:161
virtual T get() const
Definition Expression.hh:118
X_choose_first(Value< std::pair< T, K > > &p)
Definition Expression.hh:117
virtual bool valid_set(T t) const
Definition Expression.hh:124
bool valid_get() const
Definition Expression.hh:119
virtual void set(T t)
Definition Expression.hh:120
virtual void set(K k)
Definition Expression.hh:140
bool valid_get() const
Definition Expression.hh:139
virtual bool valid_set(K k) const
Definition Expression.hh:144
virtual K get() const
Definition Expression.hh:138
X_choose_second(Value< std::pair< T, K > > &p)
Definition Expression.hh:137
Definition FreeType2.cc:432
Definition GameApi.h:42