Browse Source

move utility functions to new header file

master
cinnaboot 8 years ago
parent
commit
2fc295a8e1
  1. 1
      src/gooey.cpp
  2. 1
      src/hexgame.cpp
  3. 49
      src/hexgame.h
  4. 3
      src/render_group.h
  5. 1
      src/renderer.cpp
  6. 1
      src/renderer.h
  7. 54
      src/util.h

1
src/gooey.cpp

@ -8,6 +8,7 @@
#include "imgui.h"
#include "examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h"
#include "util.h"
#include "gooey.h"
bool

1
src/hexgame.cpp

@ -33,6 +33,7 @@
#include "aixlog.hpp"
#include "util.h"
#include "hexgame.h"
#include "hexlib.h"
#include "renderer.h"

49
src/hexgame.h

@ -2,7 +2,6 @@
#pragma once
#include <vector>
#include <cassert>
#if defined (_WIN32)
#include <SDL.h>
@ -13,39 +12,9 @@
#include <glm/glm.hpp> // vec3
#include "hexlib.h"
#include "util.h"
#include "mesh.h"
typedef float real32;
typedef double real64;
typedef int32_t bool32;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint32_t uint32;
struct v2f
{
v2f(): x(0), y(0) {}
v2f(real64 a, real64 b): x(a), y(b) {}
real64 x;
real64 y;
};
struct v2i
{
v2i(int a, int b): x(a), y(b) {}
v2i() : x(0), y(0) {}
int32 x;
int32 y;
};
struct v4i
{
int32 x0;
int32 y0;
int32 x1;
int32 y1;
};
struct SDL_Handles
{
@ -116,19 +85,3 @@ struct game_state
game_state(Layout &l) : hex_layout(l) {}
};
inline real32
SafeRatio(real32 dividend, real32 divisor)
{
if (divisor == 0)
return dividend;
else
return dividend / divisor;
}
inline int32
SafeTruncateToInt32(int64 val)
{
assert(val <= INT32_MAX && val >= INT32_MIN);
return (int32) val;
}

3
src/render_group.h

@ -1,6 +1,5 @@
// TODO: put type info into seperate header from hexgame.h
//#include "types.h"
#include "util.h"
#include "hexgame.h"

1
src/renderer.cpp

@ -20,6 +20,7 @@
#include "aixlog.hpp"
#include "hexlib.h"
#include "util.h"
#include "hexgame.h"
#include "renderer.h"
#include "render_group.h"

1
src/renderer.h

@ -3,6 +3,7 @@
#include <vector>
#include "util.h"
#include "hexgame.h"
bool initRenderer(SDL_Handles &handles, v2i vpDims);

54
src/util.h

@ -0,0 +1,54 @@
#pragma once
#include <cassert>
typedef float real32;
typedef double real64;
typedef int32_t bool32;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint32_t uint32;
struct v2f
{
v2f(): x(0), y(0) {}
v2f(real64 a, real64 b): x(a), y(b) {}
real64 x;
real64 y;
};
struct v2i
{
v2i(int a, int b): x(a), y(b) {}
v2i() : x(0), y(0) {}
int32 x;
int32 y;
};
struct v4i
{
int32 x0;
int32 y0;
int32 x1;
int32 y1;
};
inline real32
SafeRatio(real32 dividend, real32 divisor)
{
if (divisor == 0)
return dividend;
else
return dividend / divisor;
}
inline int32
SafeTruncateToInt32(int64 val)
{
assert(val <= INT32_MAX && val >= INT32_MIN);
return (int32) val;
}
Loading…
Cancel
Save