From f76b95f200bb37a52ce4e7574ddb5aed9c725fd5 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 26 Jan 2011 14:49:51 +0000 Subject: [PATCH] Rename Float3 to float3, Int3 to int3 etc. and add the 4-member versions. --- src/debugfps.cpp | 2 +- src/emitter.cpp | 10 +++++----- src/emitter.h | 4 ++-- src/input.cpp | 14 +++++++------- src/input.h | 8 ++++---- src/matrix.h | 26 ++++++++++++++++++++++---- src/sdlinput.cpp | 2 +- src/text.cpp | 6 +++--- src/text.h | 2 +- 9 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/debugfps.cpp b/src/debugfps.cpp index 8ede59df..274a8c1c 100644 --- a/src/debugfps.cpp +++ b/src/debugfps.cpp @@ -39,7 +39,7 @@ DebugFps::DebugFps(int x, int y) for (int i = 0; i < 5; i ++) { data->lines[i] = new Text(NULL, "gfx/font/ascii.png"); - data->lines[i]->SetPos(Int3(x, y + (i ? 8 : 0) + 16 * i, 0)); + data->lines[i]->SetPos(int3(x, y + (i ? 8 : 0) + 16 * i, 0)); Ticker::Ref(data->lines[i]); } } diff --git a/src/emitter.cpp b/src/emitter.cpp index c489add5..5471225f 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -27,10 +27,10 @@ class EmitterData private: int tiler; - Float3 gravity; + float3 gravity; int particles[100]; - Float3 positions[100]; - Float3 velocities[100]; + float3 positions[100]; + float3 velocities[100]; int nparticles; }; @@ -38,7 +38,7 @@ private: * Public Emitter class */ -Emitter::Emitter(int tiler, Float3 gravity) +Emitter::Emitter(int tiler, float3 gravity) : data(new EmitterData()) { data->tiler = tiler; @@ -75,7 +75,7 @@ void Emitter::TickDraw(float deltams) data->positions[i].z, 0); } -void Emitter::AddParticle(int id, Float3 pos, Float3 vel) +void Emitter::AddParticle(int id, float3 pos, float3 vel) { if (data->nparticles >= 100) return; diff --git a/src/emitter.h b/src/emitter.h index 35da6906..5fc5b509 100644 --- a/src/emitter.h +++ b/src/emitter.h @@ -23,10 +23,10 @@ class EmitterData; class Emitter : public Entity { public: - Emitter(int tiler, Float3 gravity); + Emitter(int tiler, float3 gravity); virtual ~Emitter(); - void AddParticle(int id, Float3 pos, Float3 vel); + void AddParticle(int id, float3 pos, float3 vel); protected: virtual void TickGame(float deltams); diff --git a/src/input.cpp b/src/input.cpp index cbe831ca..1f2a40dc 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -34,8 +34,8 @@ public: buttons(0, 0, 0) { } - Int2 mouse; - Int3 buttons; + int2 mouse; + int3 buttons; } inputdata; @@ -45,10 +45,10 @@ static InputData * const data = &inputdata; * Public Input class */ -Float2 Input::GetAxis(int axis) +float2 Input::GetAxis(int axis) { float invsqrt2 = sqrtf(0.5f); - Float2 f; + float2 f; /* Simulate a joystick using the keyboard. This SDL call is free. */ Uint8 *keystate = SDL_GetKeyState(NULL); @@ -65,12 +65,12 @@ Float2 Input::GetAxis(int axis) return f; } -void Input::SetMousePos(Int2 coord) +void Input::SetMousePos(int2 coord) { data->mouse = coord; } -Int2 Input::GetMousePos() +int2 Input::GetMousePos() { return data->mouse; } @@ -85,7 +85,7 @@ void Input::UnsetMouseButton(int index) data->buttons[index] = 0; } -Int3 Input::GetMouseButtons() +int3 Input::GetMouseButtons() { return data->buttons; } diff --git a/src/input.h b/src/input.h index 830cca7a..b3ee8172 100644 --- a/src/input.h +++ b/src/input.h @@ -21,12 +21,12 @@ class Input { public: - static Float2 GetAxis(int axis); - static void SetMousePos(Int2 coord); - static Int2 GetMousePos(); + static float2 GetAxis(int axis); + static void SetMousePos(int2 coord); + static int2 GetMousePos(); static void SetMouseButton(int index); static void UnsetMouseButton(int index); - static Int3 GetMouseButtons(); + static int3 GetMouseButtons(); }; #endif // __DH_INPUT_H__ diff --git a/src/matrix.h b/src/matrix.h index 9bde380e..0e0c91de 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -97,8 +97,8 @@ template struct Vec2 union { T y; T b; T j; }; }; -typedef Vec2 Float2; -typedef Vec2 Int2; +typedef Vec2 float2; +typedef Vec2 int2; template struct Vec3 { @@ -113,8 +113,25 @@ template struct Vec3 union { T z; T c; T k; }; }; -typedef Vec3 Float3; -typedef Vec3 Int3; +typedef Vec3 float3; +typedef Vec3 int3; + +template struct Vec4 +{ + inline Vec4() { x = y = z = w = 0; } + inline Vec4(T val) { x = y = z = w = val; } + inline Vec4(T _x, T _y, T _z, T _w) { x = _x; y = _y; z = _z; w = _w; } + + OPERATORS(4) + + union { T x; T a; T i; }; + union { T y; T b; T j; }; + union { T z; T c; T k; }; + union { T w; T d; T l; }; +}; + +typedef Vec4 float4; +typedef Vec4 int4; #define SCALAR_GLOBAL(elems, op, U) \ template \ @@ -139,6 +156,7 @@ typedef Vec3 Int3; GLOBALS(2) GLOBALS(3) +GLOBALS(4) #endif // __DH_MATRIX_H__ diff --git a/src/sdlinput.cpp b/src/sdlinput.cpp index be991011..ca70cf41 100644 --- a/src/sdlinput.cpp +++ b/src/sdlinput.cpp @@ -48,7 +48,7 @@ void SdlInput::TickGame(float deltams) Entity::TickGame(deltams); /* Handle mouse input */ - Int2 mouse; + int2 mouse; if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { SDL_GetMouseState(&mouse.x, &mouse.y); diff --git a/src/text.cpp b/src/text.cpp index bf6d85ab..e32e5d28 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -29,7 +29,7 @@ class TextData private: int font; char *text; - Int3 pos; + int3 pos; }; /* @@ -41,7 +41,7 @@ Text::Text(char const *text, char const *font) { data->font = Forge::Register(font); data->text = text ? strdup(text) : NULL; - data->pos = Int3(0, 0, 0); + data->pos = int3(0, 0, 0); drawgroup = DRAWGROUP_HUD; } @@ -53,7 +53,7 @@ void Text::SetText(char const *text) data->text = text ? strdup(text) : NULL; } -void Text::SetPos(Int3 pos) +void Text::SetPos(int3 pos) { data->pos = pos; } diff --git a/src/text.h b/src/text.h index 6f4a32ec..c398814e 100644 --- a/src/text.h +++ b/src/text.h @@ -27,7 +27,7 @@ public: virtual ~Text(); void SetText(char const *text); - void SetPos(Int3 pos); + void SetPos(int3 pos); protected: virtual void TickDraw(float deltams);