Browse Source

merging windows fix and local changes

master
cinnaboot 8 years ago
parent
commit
1b2c1afb51
  1. 122
      src/hexgame.cpp
  2. 227
      src/hexgame.h
  3. 5
      src/imgui.ini
  4. 2
      src/renderer.h

122
src/hexgame.cpp

@ -88,9 +88,7 @@ getSingleHex(int32 x, int32 y)
for (hex_info &hxi : *g_game_state->hex_array) for (hex_info &hxi : *g_game_state->hex_array)
{ {
if (hex_equal(h, hxi.hex)) if (hex_equal(h, hxi.hex))
{
return &hxi; return &hxi;
}
} }
return 0; return 0;
@ -111,34 +109,29 @@ startHexFill(int32 x, int32 y)
resetHexes(); resetHexes();
hex_info *hex = getSingleHex(x, y); hex_info *hex = getSingleHex(x, y);
if (hex) if (hex)
{
setStartHex(hex); setStartHex(hex);
}
} }
void void
updateHexFill(int32 x, int32 y) updateHexFill(int32 x, int32 y)
{ {
if (g_game_state->is_selecting) hex_info *hxi = getSingleHex(x, y);
if (hxi && (hxi != g_game_state->current_hex))
{ {
hex_info *hxi = getSingleHex(x, y); g_game_state->current_hex = hxi;
if (hxi && (hxi != g_game_state->current_hex)) int l = hex_distance(g_game_state->start_hex->hex, g_game_state->current_hex->hex);
for (hex_info &h : *g_game_state->hex_array)
{ {
g_game_state->current_hex = hxi; if (hex_distance(g_game_state->start_hex->hex, h.hex) <= l)
int l = hex_distance(g_game_state->start_hex->hex, g_game_state->current_hex->hex);
for (hex_info &h : *g_game_state->hex_array)
{ {
if (hex_distance(g_game_state->start_hex->hex, h.hex) <= l) h.selected = true;
{ h.current_color = g_render_state->selected_fill_color;
h.selected = true; }
h.current_color = g_render_state->selected_fill_color; else
} {
else h.selected = false;
{ h.current_color = h.stored_color;
h.selected = false;
h.current_color = h.stored_color;
}
} }
} }
} }
@ -150,38 +143,33 @@ startHexLineDraw(int32 x, int32 y)
resetHexes(); resetHexes();
hex_info *hex = getSingleHex(x, y); hex_info *hex = getSingleHex(x, y);
if (hex) if (hex)
{
setStartHex(hex); setStartHex(hex);
}
} }
void void
updateHexLineDraw(int32 x, int32 y) updateHexLineDraw(int32 x, int32 y)
{ {
if (g_game_state->is_selecting) hex_info *hxi = getSingleHex(x, y);
if (hxi && (hxi != g_game_state->current_hex))
{ {
hex_info *hxi = getSingleHex(x, y); g_game_state->current_hex = hxi;
if (hxi && (hxi != g_game_state->current_hex)) vector<Hex> hexLine = hex_linedraw(g_game_state->start_hex->hex, hxi->hex);
for (hex_info &h1 : *g_game_state->hex_array)
{ {
g_game_state->current_hex = hxi; for (uint i = 0; i < hexLine.size(); i++)
vector<Hex> hexLine = hex_linedraw(g_game_state->start_hex->hex, hxi->hex); {
Hex h2 = hexLine[i];
for (hex_info &h1 : *g_game_state->hex_array) if (hex_equal(h1.hex, h2))
{ {
for (uint32 i = 0; i < hexLine.size(); i++) h1.selected = true;
{ h1.current_color = g_render_state->selected_fill_color;
Hex h2 = hexLine[i]; break;
if (hex_equal(h1.hex, h2)) }
{ else if (i == hexLine.size() - 1)
h1.selected = true; {
h1.current_color = g_render_state->selected_fill_color; h1.selected = false;
break; h1.current_color = h1.stored_color;
}
else if (i == hexLine.size() - 1)
{
h1.selected = false;
h1.current_color = h1.stored_color;
}
} }
} }
} }
@ -194,39 +182,33 @@ startHexConeFill(int32 x, int32 y)
resetHexes(); resetHexes();
hex_info *hex = getSingleHex(x, y); hex_info *hex = getSingleHex(x, y);
if (hex) if (hex)
{
setStartHex(hex); setStartHex(hex);
}
} }
void void
updateHexConeFill(int32 x, int32 y) updateHexConeFill(int32 x, int32 y)
{ {
if (g_game_state->is_selecting) hex_info *hxi = getSingleHex(x, y);
if (hxi && (hxi != g_game_state->current_hex))
{ {
hex_info *hxi = getSingleHex(x, y); g_game_state->current_hex = hxi;
if (hxi && (hxi != g_game_state->current_hex))
for (hex_info &h : *g_game_state->hex_array)
{ {
g_game_state->current_hex = hxi; // TODO: define a system of linear inequalities in hex-space to represent
// cones/arbitrary polygons
for (hex_info &h : *g_game_state->hex_array) if (&h == g_game_state->start_hex)
continue;
if (hex_equal(h.hex, hxi->hex))
{ {
// TODO: define a system of linear inequalities in hex-space to represent h.selected = true;
// cones/arbitrary polygons h.current_color = g_render_state->selected_fill_color;
if (&h == g_game_state->start_hex) }
{ else
continue; {
} h.selected = false;
if (hex_equal(h.hex, hxi->hex)) h.current_color = h.stored_color;
{
h.selected = true;
h.current_color = g_render_state->selected_fill_color;
}
else
{
h.selected = false;
h.current_color = h.stored_color;
}
} }
} }
} }
@ -370,7 +352,7 @@ processSDLEvents(SDL_Handles &handles)
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (!gooey_wants) if (!gooey_wants && g_game_state->is_selecting)
handleMouseMove(e.motion); handleMouseMove(e.motion);
break; break;
default: default:

227
src/hexgame.h

@ -1,111 +1,116 @@
#ifndef HEXGAME_H #ifndef HEXGAME_H
#define HEXGAME_H #define HEXGAME_H
#include <vector> #include <vector>
#include <cassert> #include <cassert>
#include <SDL.h> #if defined (_WIN32)
#include "aixlog.hpp" #include <SDL.h>
#else
#include "hexlib.h" #include <SDL2/SDL.h>
#endif
typedef float real32; #include "aixlog.hpp"
typedef double real64;
typedef int32_t bool32; #include "hexlib.h"
typedef int32_t int32;
typedef int64_t int64; typedef float real32;
typedef uint8_t uint8; typedef double real64;
typedef uint32_t uint32; typedef int32_t bool32;
typedef int32_t int32;
struct v2f typedef int64_t int64;
{ typedef uint8_t uint8;
v2f(): x(0), y(0) {} typedef uint32_t uint32;
v2f(real64 a, real64 b): x(a), y(b) {}
real64 x; struct v2f
real64 y; {
}; v2f(): x(0), y(0) {}
v2f(real64 a, real64 b): x(a), y(b) {}
struct v2i real64 x;
{ real64 y;
v2i(int a, int b): x(a), y(b) {} };
v2i() : x(0), y(0) {}
int32 x; struct v2i
int32 y; {
}; v2i(int a, int b): x(a), y(b) {}
v2i() : x(0), y(0) {}
struct v4i int32 x;
{ int32 y;
int32 x0; };
int32 y0;
int32 x1; struct v4i
int32 y1; {
}; int32 x0;
int32 y0;
struct SDL_Handles int32 x1;
{ int32 y1;
SDL_Window *window; };
SDL_GLContext glContext;
SDL_DisplayMode currentDisplayMode; struct SDL_Handles
std::vector<SDL_Surface*> texSurfaces; {
}; SDL_Window *window;
SDL_GLContext glContext;
struct hex_info SDL_DisplayMode currentDisplayMode;
{ std::vector<SDL_Surface*> texSurfaces;
int32 hexID = 0; };
Hex hex = {};
real64 XPos = 0; struct hex_info
real64 YPos = 0; {
uint32 current_color = 0; // RGBA int32 hexID = 0;
uint32 stored_color = 0; // RGBA Hex hex = {};
bool selected = false; real64 XPos = 0;
std::vector<Point> vertices; real64 YPos = 0;
}; uint32 current_color = 0; // RGBA
uint32 stored_color = 0; // RGBA
enum HexDrawMode bool selected = false;
{ std::vector<Point> vertices;
NONE, };
FILL,
LINE, enum HexDrawMode
CONE_FILL, {
PATHFINDING NONE,
}; FILL,
LINE,
struct render_state CONE_FILL,
{ PATHFINDING
v2i viewport_dims; };
bool is_debug_draw;
uint32 fill_color; struct render_state
uint32 selected_fill_color; {
}; v2i viewport_dims;
bool is_debug_draw;
struct game_state uint32 fill_color;
{ uint32 selected_fill_color;
bool is_selecting; };
std::vector<hex_info> *hex_array;
hex_info *start_hex; struct game_state
hex_info *current_hex; {
vector<hex_info> selected_hexes; bool is_selecting;
HexDrawMode draw_mode; std::vector<hex_info> *hex_array;
const Layout hex_layout; hex_info *start_hex;
hex_info *current_hex;
game_state(Layout &l) : hex_layout(l) {} vector<hex_info> selected_hexes;
}; HexDrawMode draw_mode;
const Layout hex_layout;
real32
SafeRatio(real32 dividend, real32 divisor) game_state(Layout &l) : hex_layout(l) {}
{ };
if (divisor == 0)
return dividend; real32
else SafeRatio(real32 dividend, real32 divisor)
return dividend / divisor; {
} if (divisor == 0)
return dividend;
int32 else
SafeTruncateToInt32(int64 val) return dividend / divisor;
{ }
assert(val <= INT32_MAX && val >= INT32_MIN);
return (int32) val; int32
} SafeTruncateToInt32(int64 val)
{
#endif // HEXGAME_H assert(val <= INT32_MAX && val >= INT32_MIN);
return (int32) val;
}
#endif // HEXGAME_H

5
src/imgui.ini

@ -0,0 +1,5 @@
[Window][Debug##Default]
Pos=0,5
Size=400,400
Collapsed=0

2
src/renderer.h

@ -493,7 +493,7 @@ renderDebug(hex_info *start_hex, hex_info *current_hex)
Point p2(current_hex->XPos, current_hex->YPos); Point p2(current_hex->XPos, current_hex->YPos);
real64 angle = std::atan2(p2.y - p1.y, p2.x - p1.x); real64 angle = std::atan2(p2.y - p1.y, p2.x - p1.x);
real64 len = std::hypot(p2.y - p1.y, p2.x - p1.x); real64 len = std::hypot(p2.y - p1.y, p2.x - p1.x);
real64 coneAngle = 24.5f * M_PI / 180; // M_PI is non-standard and may not be portable real64 coneAngle = 30.f * M_PI / 180; // M_PI is non-standard and may not be portable
// TODO: add matrix math library for rotation transform? // TODO: add matrix math library for rotation transform?
// |x| | cos(a + b) -sin(a + b) 0 | // |x| | cos(a + b) -sin(a + b) 0 |

Loading…
Cancel
Save