|
|
|
@ -1,9 +1,6 @@ |
|
|
|
/*******************************************************************************
|
|
|
|
/*******************************************************************************
|
|
|
|
* TODO: |
|
|
|
* TODO: |
|
|
|
* - renderer |
|
|
|
* - renderer |
|
|
|
* - move hexgrid buffer functions from renderer to hexgrid |
|
|
|
|
|
|
|
* - remove references to hexes from renderer functions |
|
|
|
|
|
|
|
* - move hex functions from hexgame.cpp to hexgrid |
|
|
|
|
|
|
|
* - add prefix to interface function names for eg) gooey.h, renderer.h |
|
|
|
* - add prefix to interface function names for eg) gooey.h, renderer.h |
|
|
|
* - clean up main(), split out initialization and scene loading to new functions |
|
|
|
* - clean up main(), split out initialization and scene loading to new functions |
|
|
|
* - check over renderer, camera, gooey init after changes |
|
|
|
* - check over renderer, camera, gooey init after changes |
|
|
|
@ -87,35 +84,6 @@ mapMouseToViewport(int32 x, int32 y) |
|
|
|
return coords; |
|
|
|
return coords; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
resetHexes() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
g_game_state->grid.start_hex = g_game_state->grid.current_hex = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &hxi : *g_game_state->grid.hex_array) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
hxi.selected = false; |
|
|
|
|
|
|
|
hxi.current_color = hxi.stored_color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hex_info * |
|
|
|
|
|
|
|
getSingleHex(int32 x, int32 y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
|
|
|
|
v2f v = cameraUnproject(g_render_state->cam, x, y, dims.x, dims.y); |
|
|
|
|
|
|
|
Point p(v.x, v.y); |
|
|
|
|
|
|
|
Hex h = hex_round(pixel_to_hex(g_game_state->grid.hexlib_layout, p)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &hxi : *g_game_state->grid.hex_array) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (hex_equal(h, hxi.hex)) |
|
|
|
|
|
|
|
return &hxi; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
setStartHex(hex_info *hex) |
|
|
|
setStartHex(hex_info *hex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -128,120 +96,14 @@ setStartHex(hex_info *hex) |
|
|
|
void |
|
|
|
void |
|
|
|
startDrawHelper(int32 x, int32 y) |
|
|
|
startDrawHelper(int32 x, int32 y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
resetHexes(); |
|
|
|
hgResetHexes(g_game_state->grid); |
|
|
|
hex_info *hex = getSingleHex(x, y); |
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
|
|
|
|
v2f v = cameraUnproject(g_render_state->cam, x, y, dims.x, dims.y); |
|
|
|
|
|
|
|
hex_info *hex = hgGetSingleHex(g_game_state->grid, v.x, v.y); |
|
|
|
if (hex) |
|
|
|
if (hex) |
|
|
|
setStartHex(hex); |
|
|
|
setStartHex(hex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
updateHexFill(int32 x, int32 y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
hex_info *hxi = getSingleHex(x, y); |
|
|
|
|
|
|
|
if (hxi && (hxi != g_game_state->grid.current_hex) && g_game_state->grid.start_hex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
g_game_state->grid.current_hex = hxi; |
|
|
|
|
|
|
|
int l = hex_distance(g_game_state->grid.start_hex->hex, g_game_state->grid.current_hex->hex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &h : *g_game_state->grid.hex_array) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (hex_distance(g_game_state->grid.start_hex->hex, h.hex) <= l) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
h.selected = true; |
|
|
|
|
|
|
|
h.current_color = g_game_state->grid.selected_fill_color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
h.selected = false; |
|
|
|
|
|
|
|
h.current_color = h.stored_color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
updateHexLineDraw(int32 x, int32 y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
hex_info *hxi = getSingleHex(x, y); |
|
|
|
|
|
|
|
if (hxi && (hxi != g_game_state->grid.current_hex) && g_game_state->grid.start_hex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
g_game_state->grid.current_hex = hxi; |
|
|
|
|
|
|
|
vector<Hex> hexLine = hex_linedraw(g_game_state->grid.start_hex->hex, hxi->hex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &h1 : *g_game_state->grid.hex_array) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (uint i = 0; i < hexLine.size(); i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Hex h2 = hexLine[i]; |
|
|
|
|
|
|
|
if (hex_equal(h1.hex, h2)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
h1.selected = true; |
|
|
|
|
|
|
|
h1.current_color = g_game_state->grid.selected_fill_color; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (i == hexLine.size() - 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
h1.selected = false; |
|
|
|
|
|
|
|
h1.current_color = h1.stored_color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
updateHexConeFill(int32 x, int32 y) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
hex_info *hxi = getSingleHex(x, y); |
|
|
|
|
|
|
|
if (hxi && (hxi != g_game_state->grid.current_hex) && g_game_state->grid.start_hex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
g_game_state->grid.current_hex = hxi; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Remove debug code here and from gooey.h
|
|
|
|
|
|
|
|
Point p1(g_game_state->grid.start_hex->XPos, g_game_state->grid.start_hex->YPos); |
|
|
|
|
|
|
|
Point p2(g_game_state->grid.current_hex->XPos, g_game_state->grid.current_hex->YPos); |
|
|
|
|
|
|
|
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 coneAngle = CONE_ANGLE * M_PI / 180; // M_PI is non-standard and may not be portable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real64 x1 = len * std::cos(angle); |
|
|
|
|
|
|
|
real64 y1 = len * std::sin(angle); |
|
|
|
|
|
|
|
// top of cone
|
|
|
|
|
|
|
|
real64 topX = x1 * std::cos(coneAngle) - y1 * std::sin(coneAngle) + p1.x; |
|
|
|
|
|
|
|
real64 topY = x1 * std::sin(coneAngle) + y1 * std::cos(coneAngle) + p1.y; |
|
|
|
|
|
|
|
// bottom of cone
|
|
|
|
|
|
|
|
real64 botX = x1 * std::cos(coneAngle) + y1 * std::sin(coneAngle) + p1.x; |
|
|
|
|
|
|
|
real64 botY = x1 * std::sin(-1 * coneAngle) + y1 * std::cos(coneAngle) + p1.y; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Point test_p; |
|
|
|
|
|
|
|
Point vert2 = Point(botX, botY); |
|
|
|
|
|
|
|
Point vert4 = Point(topX, topY); |
|
|
|
|
|
|
|
std::vector<Point> vertices = {p1, vert2, p2, vert4}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &h : *g_game_state->grid.hex_array) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
test_p.x = h.XPos; |
|
|
|
|
|
|
|
test_p.y = h.YPos; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (crossingTest(vertices, test_p)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
h.selected = true; |
|
|
|
|
|
|
|
h.current_color = g_game_state->grid.selected_fill_color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
h.selected = false; |
|
|
|
|
|
|
|
h.current_color = h.stored_color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_polygon_select_vertices[0] = p1; |
|
|
|
|
|
|
|
g_polygon_select_vertices[1] = vert2; |
|
|
|
|
|
|
|
g_polygon_select_vertices[2] = p2; |
|
|
|
|
|
|
|
g_polygon_select_vertices[3] = vert4; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -268,7 +130,9 @@ handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
// fall through
|
|
|
|
// fall through
|
|
|
|
default: |
|
|
|
default: |
|
|
|
{ |
|
|
|
{ |
|
|
|
hex_info *hex = getSingleHex(coords.x, coords.y); |
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
|
|
|
|
v2f v = cameraUnproject(g_render_state->cam, coords.x, coords.y, dims.x, dims.y); |
|
|
|
|
|
|
|
hex_info *hex = hgGetSingleHex(g_game_state->grid, v.x, v.y); |
|
|
|
if (hex) |
|
|
|
if (hex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
hex->selected = !hex->selected; |
|
|
|
hex->selected = !hex->selected; |
|
|
|
@ -289,48 +153,21 @@ void |
|
|
|
handleMouseMove(SDL_MouseMotionEvent &e) |
|
|
|
handleMouseMove(SDL_MouseMotionEvent &e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
v2i coords = mapMouseToViewport(e.x, e.y); |
|
|
|
v2i coords = mapMouseToViewport(e.x, e.y); |
|
|
|
|
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
|
|
|
|
v2f v = cameraUnproject(g_render_state->cam, coords.x, coords.y, dims.x, dims.y); |
|
|
|
|
|
|
|
|
|
|
|
switch (g_game_state->grid.draw_mode) |
|
|
|
switch (g_game_state->grid.draw_mode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case FILL: |
|
|
|
case FILL: |
|
|
|
updateHexFill(coords.x, coords.y); |
|
|
|
hgUpdateHexFill(g_game_state->grid, v.x, v.y); |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
|
|
|
|
updateHexLineDraw(coords.x, coords.y); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
|
|
|
|
updateHexConeFill(coords.x, coords.y); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case NONE: |
|
|
|
|
|
|
|
// fall through
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
handleMouseUp(SDL_MouseButtonEvent &e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//v2i coords = mapMouseToViewport(e.x, e.y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (g_game_state->grid.draw_mode) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case FILL: |
|
|
|
|
|
|
|
g_game_state->grid.is_selecting = false; |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
case LINE: |
|
|
|
g_game_state->grid.is_selecting = false; |
|
|
|
hgUpdateHexLineDraw(g_game_state->grid, v.x, v.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
case CONE_FILL: |
|
|
|
g_game_state->grid.is_selecting = false; |
|
|
|
hgUpdateHexConeFill(g_game_state->grid, v.x, v.y, CONE_ANGLE, g_polygon_select_vertices); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
case PATHFINDING: |
|
|
|
@ -407,15 +244,10 @@ processSDLEvents() |
|
|
|
if (!gooey_wants) |
|
|
|
if (!gooey_wants) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) |
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) |
|
|
|
{ |
|
|
|
|
|
|
|
g->grid.is_selecting = false; |
|
|
|
g->grid.is_selecting = false; |
|
|
|
handleMouseUp(e.button); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (e.button.button == SDL_BUTTON_RIGHT) |
|
|
|
else if (e.button.button == SDL_BUTTON_RIGHT) |
|
|
|
{ |
|
|
|
|
|
|
|
g->is_camera_rotate = false; |
|
|
|
g->is_camera_rotate = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case SDL_MOUSEMOTION: |
|
|
|
case SDL_MOUSEMOTION: |
|
|
|
if (!gooey_wants && g->grid.is_selecting) |
|
|
|
if (!gooey_wants && g->grid.is_selecting) |
|
|
|
|