diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-02-02 12:38:36 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-02-02 12:38:36 +0000 |
| commit | 1fe3202f0b7e2f52e50c430caa744b029fd5bcef (patch) | |
| tree | e238b0f211badb35fecdc3f87fe32978fd512b5e /src/game/g_math.h | |
| parent | 307c2cfae8fd678b10235bdc0c1a8cfc7da6adae (diff) | |
| download | zcatch-1fe3202f0b7e2f52e50c430caa744b029fd5bcef.tar.gz zcatch-1fe3202f0b7e2f52e50c430caa744b029fd5bcef.zip | |
cleaned up the console code. added the ability to tune the game in runtime.
Diffstat (limited to 'src/game/g_math.h')
| -rw-r--r-- | src/game/g_math.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/game/g_math.h b/src/game/g_math.h index 54c23ac9..5e3f7ede 100644 --- a/src/game/g_math.h +++ b/src/game/g_math.h @@ -27,6 +27,32 @@ inline T mix(const T a, const T b, TB amount) inline float frandom() { return rand()/(float)(RAND_MAX); } +// float to fixed +inline int f2fx(float v) { return (int)(v*(float)(1<<10)); } +inline float fx2f(int v) { return v*(1.0f/(1<<10)); } + +class fxp +{ + int value; +public: + void set(int v) { value = v; } + int get() const { return value; } + fxp &operator = (int v) { value = v<<10; return *this; } + fxp &operator = (float v) { value = (int)(v*(float)(1<<10)); return *this; } + operator float() const { return value/(float)(1<<10); } +}; + +class tune_param +{ + int value; +public: + void set(int v) { value = v; } + int get() const { return value; } + tune_param &operator = (int v) { value = (int)(v*100.0f); return *this; } + tune_param &operator = (float v) { value = (int)(v*100.0f); return *this; } + operator float() const { return value/100.0f; } +}; + const float pi = 3.1415926535897932384626433f; template <typename T> inline T min(T a, T b) { return a<b?a:b; } |