From 2fc295a8e11b2b286dcd10d257b1cebe68dd10d0 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Thu, 9 Aug 2018 20:56:32 -0400 Subject: [PATCH] move utility functions to new header file --- src/gooey.cpp | 1 + src/hexgame.cpp | 1 + src/hexgame.h | 49 +---------------------------------------- src/render_group.h | 3 +-- src/renderer.cpp | 1 + src/renderer.h | 1 + src/util.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 60 insertions(+), 50 deletions(-) create mode 100644 src/util.h diff --git a/src/gooey.cpp b/src/gooey.cpp index 7180bc9..eb9712b 100644 --- a/src/gooey.cpp +++ b/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 diff --git a/src/hexgame.cpp b/src/hexgame.cpp index 40c882e..f5f5c6a 100644 --- a/src/hexgame.cpp +++ b/src/hexgame.cpp @@ -33,6 +33,7 @@ #include "aixlog.hpp" +#include "util.h" #include "hexgame.h" #include "hexlib.h" #include "renderer.h" diff --git a/src/hexgame.h b/src/hexgame.h index a8dfcbf..736c429 100644 --- a/src/hexgame.h +++ b/src/hexgame.h @@ -2,7 +2,6 @@ #pragma once #include -#include #if defined (_WIN32) #include @@ -13,39 +12,9 @@ #include // 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; -} - diff --git a/src/render_group.h b/src/render_group.h index a5ee1b7..0d18bd6 100644 --- a/src/render_group.h +++ b/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" diff --git a/src/renderer.cpp b/src/renderer.cpp index b08b725..1d0ef7b 100644 --- a/src/renderer.cpp +++ b/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" diff --git a/src/renderer.h b/src/renderer.h index 47be02f..b2d2fe1 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -3,6 +3,7 @@ #include +#include "util.h" #include "hexgame.h" bool initRenderer(SDL_Handles &handles, v2i vpDims); diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..5b5ccf3 --- /dev/null +++ b/src/util.h @@ -0,0 +1,54 @@ + +#pragma once + +#include + + +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; +} +