2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 waker@users.sourceforge.net
23 #ifndef __F_MATHEXPRESSION_H
24 #define __F_MATHEXPRESSION_H
28 #include "f_baseobject.h"
30 #include "f_helpers.h"
35 class mathExpression
: public baseObject
38 // FIXME: do we need more than 2?
39 // FIXME: hi-level expressions never use more than 2
40 // FIXME: but if we allow user to write something more complex (and optimized) in assembly - 2 regs are insufficient
41 // FIXME: increment maxregisters to whatever required when assembly programs support is available
42 enum { maxregisters
= 2 };
44 enum operator_t
{ op_no
, op_add
, op_sub
, op_mul
, op_div
, op_dot
, op_mov
, op_lookup
, op_max
};
46 enum { parmtypemask
= (0x0003 << 14), constmask
= (0x0000 << 14), regmask
= (0x0001 << 14), varmask
= (0x0002 << 14), resmask
= (0x0003 << 14) };
74 std::vector
< float > mConstants
;
75 std::vector
< command_t
> mCommands
;
77 void getwords (const cStr
&in
, std::vector
< cStr
> &expression
);
78 bool validate (const std::vector
<cStr
> &expr
);
79 cStr
opstring (int op
);
80 operator_t
getoperator (const std::vector
<cStr
> &expression
, size_t curword
);
81 int getparamidx (const char *name
) const;
82 float* getvarvalueptr (int v
) const;
83 bool iscomplex (const cStr
&s
);
84 node
* buildtree (std::vector
<cStr
> &expr
);
85 cStr
strop (operator_t op
) const;
86 bool isconst (const char *s
);
87 void traverse (node
*n
, std::vector
< mathExpression::command_t
> &commands
, std::vector
< float > &constants
, int reg
= 0);
88 void deltree (node
*n
);
90 void printProgram (const std::vector
< mathExpression::command_t
> &commands
, const std::vector
< float > &constants
) const;
95 mathExpression (void);
96 mathExpression (const char *expr
);
98 ~mathExpression (void);
100 float evaluate (void);
103 typedef smartPtr
<mathExpression
> mathExpressionPtr
;
107 #endif // __F_MATHEXPRESSION_H