Browse Source

merging windows fix and local changes

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

116
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);
{
g_game_state->current_hex = hxi;
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) for (hex_info &h : *g_game_state->hex_array)
{
if (hex_distance(g_game_state->start_hex->hex, h.hex) <= l)
{ {
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);
{
g_game_state->current_hex = hxi;
vector<Hex> hexLine = hex_linedraw(g_game_state->start_hex->hex, hxi->hex);
for (hex_info &h1 : *g_game_state->hex_array) for (hex_info &h1 : *g_game_state->hex_array)
{
for (uint i = 0; i < hexLine.size(); i++)
{ {
for (uint32 i = 0; i < hexLine.size(); i++) Hex h2 = hexLine[i];
if (hex_equal(h1.hex, h2))
{
h1.selected = true;
h1.current_color = g_render_state->selected_fill_color;
break;
}
else if (i == hexLine.size() - 1)
{ {
Hex h2 = hexLine[i]; h1.selected = false;
if (hex_equal(h1.hex, h2)) h1.current_color = h1.stored_color;
{
h1.selected = true;
h1.current_color = g_render_state->selected_fill_color;
break;
}
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
if (&h == g_game_state->start_hex)
continue;
for (hex_info &h : *g_game_state->hex_array) 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:

7
src/hexgame.h

@ -5,7 +5,11 @@
#include <vector> #include <vector>
#include <cassert> #include <cassert>
#include <SDL.h> #if defined (_WIN32)
#include <SDL.h>
#else
#include <SDL2/SDL.h>
#endif
#include "aixlog.hpp" #include "aixlog.hpp"
#include "hexlib.h" #include "hexlib.h"
@ -109,3 +113,4 @@ SafeTruncateToInt32(int64 val)
} }
#endif // HEXGAME_H #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