4 changed files with 174 additions and 182 deletions
@ -1,111 +1,116 @@
|
||||
|
||||
#ifndef HEXGAME_H |
||||
#define HEXGAME_H |
||||
|
||||
#include <vector> |
||||
#include <cassert> |
||||
|
||||
#include <SDL.h> |
||||
#include "aixlog.hpp" |
||||
|
||||
#include "hexlib.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 |
||||
{ |
||||
SDL_Window *window; |
||||
SDL_GLContext glContext; |
||||
SDL_DisplayMode currentDisplayMode; |
||||
std::vector<SDL_Surface*> texSurfaces; |
||||
}; |
||||
|
||||
struct hex_info |
||||
{ |
||||
int32 hexID = 0; |
||||
Hex hex = {}; |
||||
real64 XPos = 0; |
||||
real64 YPos = 0; |
||||
uint32 current_color = 0; // RGBA
|
||||
uint32 stored_color = 0; // RGBA
|
||||
bool selected = false; |
||||
std::vector<Point> vertices; |
||||
}; |
||||
|
||||
enum HexDrawMode |
||||
{ |
||||
NONE, |
||||
FILL, |
||||
LINE, |
||||
CONE_FILL, |
||||
PATHFINDING |
||||
}; |
||||
|
||||
struct render_state |
||||
{ |
||||
v2i viewport_dims; |
||||
bool is_debug_draw; |
||||
uint32 fill_color; |
||||
uint32 selected_fill_color; |
||||
}; |
||||
|
||||
struct game_state |
||||
{ |
||||
bool is_selecting; |
||||
std::vector<hex_info> *hex_array; |
||||
hex_info *start_hex; |
||||
hex_info *current_hex; |
||||
vector<hex_info> selected_hexes; |
||||
HexDrawMode draw_mode; |
||||
const Layout hex_layout; |
||||
|
||||
game_state(Layout &l) : hex_layout(l) {} |
||||
}; |
||||
|
||||
real32 |
||||
SafeRatio(real32 dividend, real32 divisor) |
||||
{ |
||||
if (divisor == 0) |
||||
return dividend; |
||||
else |
||||
return dividend / divisor; |
||||
} |
||||
|
||||
int32 |
||||
SafeTruncateToInt32(int64 val) |
||||
{ |
||||
assert(val <= INT32_MAX && val >= INT32_MIN); |
||||
return (int32) val; |
||||
} |
||||
|
||||
#endif // HEXGAME_H
|
||||
|
||||
#ifndef HEXGAME_H |
||||
#define HEXGAME_H |
||||
|
||||
#include <vector> |
||||
#include <cassert> |
||||
|
||||
#if defined (_WIN32) |
||||
#include <SDL.h> |
||||
#else |
||||
#include <SDL2/SDL.h> |
||||
#endif |
||||
#include "aixlog.hpp" |
||||
|
||||
#include "hexlib.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 |
||||
{ |
||||
SDL_Window *window; |
||||
SDL_GLContext glContext; |
||||
SDL_DisplayMode currentDisplayMode; |
||||
std::vector<SDL_Surface*> texSurfaces; |
||||
}; |
||||
|
||||
struct hex_info |
||||
{ |
||||
int32 hexID = 0; |
||||
Hex hex = {}; |
||||
real64 XPos = 0; |
||||
real64 YPos = 0; |
||||
uint32 current_color = 0; // RGBA
|
||||
uint32 stored_color = 0; // RGBA
|
||||
bool selected = false; |
||||
std::vector<Point> vertices; |
||||
}; |
||||
|
||||
enum HexDrawMode |
||||
{ |
||||
NONE, |
||||
FILL, |
||||
LINE, |
||||
CONE_FILL, |
||||
PATHFINDING |
||||
}; |
||||
|
||||
struct render_state |
||||
{ |
||||
v2i viewport_dims; |
||||
bool is_debug_draw; |
||||
uint32 fill_color; |
||||
uint32 selected_fill_color; |
||||
}; |
||||
|
||||
struct game_state |
||||
{ |
||||
bool is_selecting; |
||||
std::vector<hex_info> *hex_array; |
||||
hex_info *start_hex; |
||||
hex_info *current_hex; |
||||
vector<hex_info> selected_hexes; |
||||
HexDrawMode draw_mode; |
||||
const Layout hex_layout; |
||||
|
||||
game_state(Layout &l) : hex_layout(l) {} |
||||
}; |
||||
|
||||
real32 |
||||
SafeRatio(real32 dividend, real32 divisor) |
||||
{ |
||||
if (divisor == 0) |
||||
return dividend; |
||||
else |
||||
return dividend / divisor; |
||||
} |
||||
|
||||
int32 |
||||
SafeTruncateToInt32(int64 val) |
||||
{ |
||||
assert(val <= INT32_MAX && val >= INT32_MIN); |
||||
return (int32) val; |
||||
} |
||||
|
||||
#endif // HEXGAME_H
|
||||
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
[Window][Debug##Default] |
||||
Pos=0,5 |
||||
Size=400,400 |
||||
Collapsed=0 |
||||
|
||||
Loading…
Reference in new issue