Remove int v2 type, change V2i to cast i32 to f32

Mixing and matching V2 int and float types in the code creates too much
necessary work when an integer implementation has to interact with float
implementation. Let V2i create the cast for us and use floats for all
vector operations since they are mostly mathematic.
This commit is contained in:
2016-07-17 23:45:59 +10:00
parent 2745a8e25a
commit 7971b10b74
7 changed files with 44 additions and 59 deletions
+4 -4
View File
@@ -60,8 +60,8 @@ typedef struct CharMetrics
i32 leftSideBearing;
// TODO(doyle): Utilise kerning
i32 *kerning;
v2i offset;
v2i trueSize;
v2 offset;
v2 trueSize;
} CharMetrics;
typedef struct Font
@@ -72,8 +72,8 @@ typedef struct Font
FontMetrics metrics;
CharMetrics *charMetrics;
v2i codepointRange;
v2i maxSize;
v2 codepointRange;
v2 maxSize;
} Font;
#endif
+2 -19
View File
@@ -11,13 +11,6 @@
#define SQRT(x) (sqrtf(x))
/* VECTORS */
typedef union v2i
{
struct { i32 x, y; };
struct { i32 w, h; };
i32 e[2];
} v2i;
typedef union v2
{
struct { f32 x, y; };
@@ -39,9 +32,9 @@ typedef union v4
f32 e[4];
} v4;
INTERNAL inline v2i V2i(const i32 x, const i32 y)
INTERNAL inline v2 V2i(const i32 x, const i32 y)
{
v2i result = {x, y};
v2 result = {CAST(f32)x, CAST(f32)y};
return result;
}
INTERNAL inline v2 V2(const f32 x, const f32 y)
@@ -127,16 +120,6 @@ DEFINE_VECTOR_FLOAT_MATH(2);
DEFINE_VECTOR_FLOAT_MATH(3);
DEFINE_VECTOR_FLOAT_MATH(4);
#define DEFINE_VECTOR_INT_MATH(num) \
INTERNAL inline v##num##i v##num##i_add(const v##num##i a, const v##num##i b) \
{ \
v##num##i result; \
for (i32 i = 0; i < ##num; i++) { result.e[i] = a.e[i] + b.e[i]; } \
return result; \
} \
DEFINE_VECTOR_INT_MATH(2);
INTERNAL inline f32 v2_magnitude(const v2 a, const v2 b)
{
f32 x = b.x - a.x;
+1 -1
View File
@@ -40,6 +40,6 @@ typedef struct GameState
AssetManager assetManager;
} GameState;
void worldTraveller_gameInit(GameState *state, v2i windowSize);
void worldTraveller_gameInit(GameState *state, v2 windowSize);
void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt);
#endif