|
|
|
@ -36,6 +36,9 @@ |
|
|
|
#define CONE_ANGLE 30 |
|
|
|
#define CONE_ANGLE 30 |
|
|
|
#define VSYNC_ENABLED true |
|
|
|
#define VSYNC_ENABLED true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//testing
|
|
|
|
|
|
|
|
#define DEFAULT_SCENE_FILE "../data/test_scene.json" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
@ -62,6 +65,7 @@ |
|
|
|
#include "mesh.h" |
|
|
|
#include "mesh.h" |
|
|
|
#include "platform_wait_for_vblank.h" |
|
|
|
#include "platform_wait_for_vblank.h" |
|
|
|
#include "renderer.h" |
|
|
|
#include "renderer.h" |
|
|
|
|
|
|
|
#include "scene_loader.h" |
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
|
|
using std::vector; |
|
|
|
using std::vector; |
|
|
|
@ -79,7 +83,7 @@ createHexes(vector<hex_info> *hxi_array, const Layout &layout, uint32 color) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int r1 = std::max(-map_radius, -q - map_radius); |
|
|
|
int r1 = std::max(-map_radius, -q - map_radius); |
|
|
|
int r2 = std::min(map_radius, -q + map_radius); |
|
|
|
int r2 = std::min(map_radius, -q + map_radius); |
|
|
|
|
|
|
|
|
|
|
|
for (int r = r1; r <= r2; r++) |
|
|
|
for (int r = r1; r <= r2; r++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
hex_info hxi; |
|
|
|
hex_info hxi; |
|
|
|
@ -110,7 +114,7 @@ void |
|
|
|
resetHexes() |
|
|
|
resetHexes() |
|
|
|
{ |
|
|
|
{ |
|
|
|
g_game_state->start_hex = g_game_state->current_hex = 0; |
|
|
|
g_game_state->start_hex = g_game_state->current_hex = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &hxi : *g_game_state->hex_array) |
|
|
|
for (hex_info &hxi : *g_game_state->hex_array) |
|
|
|
{ |
|
|
|
{ |
|
|
|
hxi.selected = false; |
|
|
|
hxi.selected = false; |
|
|
|
@ -125,13 +129,13 @@ getSingleHex(int32 x, int32 y) |
|
|
|
v2f v = getUnprojectedCoords(x, y, dims.x, dims.y); |
|
|
|
v2f v = getUnprojectedCoords(x, y, dims.x, dims.y); |
|
|
|
Point p(v.x, v.y); |
|
|
|
Point p(v.x, v.y); |
|
|
|
Hex h = hex_round(pixel_to_hex(g_game_state->hex_layout, p)); |
|
|
|
Hex h = hex_round(pixel_to_hex(g_game_state->hex_layout, p)); |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -161,7 +165,7 @@ updateHexFill(int32 x, int32 y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
int l = hex_distance(g_game_state->start_hex->hex, g_game_state->current_hex->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) |
|
|
|
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) |
|
|
|
@ -186,11 +190,11 @@ updateHexLineDraw(int32 x, int32 y) |
|
|
|
{ |
|
|
|
{ |
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
vector<Hex> hexLine = hex_linedraw(g_game_state->start_hex->hex, hxi->hex); |
|
|
|
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 (uint i = 0; i < hexLine.size(); i++) |
|
|
|
{
|
|
|
|
{ |
|
|
|
Hex h2 = hexLine[i]; |
|
|
|
Hex h2 = hexLine[i]; |
|
|
|
if (hex_equal(h1.hex, h2)) |
|
|
|
if (hex_equal(h1.hex, h2)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -215,14 +219,14 @@ updateHexConeFill(int32 x, int32 y) |
|
|
|
if (hxi && (hxi != g_game_state->current_hex) && g_game_state->start_hex) |
|
|
|
if (hxi && (hxi != g_game_state->current_hex) && g_game_state->start_hex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Remove debug code here and from gooey.h
|
|
|
|
// TODO: Remove debug code here and from gooey.h
|
|
|
|
Point p1(g_game_state->start_hex->XPos, g_game_state->start_hex->YPos); |
|
|
|
Point p1(g_game_state->start_hex->XPos, g_game_state->start_hex->YPos); |
|
|
|
Point p2(g_game_state->current_hex->XPos, g_game_state->current_hex->YPos); |
|
|
|
Point p2(g_game_state->current_hex->XPos, g_game_state->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 = CONE_ANGLE * M_PI / 180; // M_PI is non-standard and may not be portable
|
|
|
|
real64 coneAngle = CONE_ANGLE * M_PI / 180; // M_PI is non-standard and may not be portable
|
|
|
|
|
|
|
|
|
|
|
|
real64 x1 = len * std::cos(angle); |
|
|
|
real64 x1 = len * std::cos(angle); |
|
|
|
real64 y1 = len * std::sin(angle); |
|
|
|
real64 y1 = len * std::sin(angle); |
|
|
|
// top of cone
|
|
|
|
// top of cone
|
|
|
|
@ -271,18 +275,18 @@ handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
case FILL: |
|
|
|
case FILL: |
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
case LINE: |
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
case CONE_FILL: |
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
case PATHFINDING: |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case NONE: |
|
|
|
case NONE: |
|
|
|
// fall through
|
|
|
|
// fall through
|
|
|
|
default: |
|
|
|
default: |
|
|
|
@ -298,7 +302,7 @@ handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
hex->current_color = hex->stored_color; |
|
|
|
hex->current_color = hex->stored_color; |
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -308,24 +312,24 @@ void |
|
|
|
handleMouseMove(SDL_MouseMotionEvent &e) |
|
|
|
handleMouseMove(SDL_MouseMotionEvent &e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
v2i coords = mapMouseToViewport(e.x, e.y); |
|
|
|
v2i coords = mapMouseToViewport(e.x, e.y); |
|
|
|
|
|
|
|
|
|
|
|
switch (g_game_state->draw_mode) |
|
|
|
switch (g_game_state->draw_mode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case FILL: |
|
|
|
case FILL: |
|
|
|
updateHexFill(coords.x, coords.y); |
|
|
|
updateHexFill(coords.x, coords.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
case LINE: |
|
|
|
updateHexLineDraw(coords.x, coords.y); |
|
|
|
updateHexLineDraw(coords.x, coords.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
case CONE_FILL: |
|
|
|
updateHexConeFill(coords.x, coords.y); |
|
|
|
updateHexConeFill(coords.x, coords.y); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
case PATHFINDING: |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case NONE: |
|
|
|
case NONE: |
|
|
|
// fall through
|
|
|
|
// fall through
|
|
|
|
default: |
|
|
|
default: |
|
|
|
@ -337,24 +341,24 @@ void |
|
|
|
handleMouseUp(SDL_MouseButtonEvent &e) |
|
|
|
handleMouseUp(SDL_MouseButtonEvent &e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//v2i coords = mapMouseToViewport(e.x, e.y);
|
|
|
|
//v2i coords = mapMouseToViewport(e.x, e.y);
|
|
|
|
|
|
|
|
|
|
|
|
switch (g_game_state->draw_mode) |
|
|
|
switch (g_game_state->draw_mode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case FILL: |
|
|
|
case FILL: |
|
|
|
g_game_state->is_selecting = false; |
|
|
|
g_game_state->is_selecting = false; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
case LINE: |
|
|
|
g_game_state->is_selecting = false; |
|
|
|
g_game_state->is_selecting = false; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
case CONE_FILL: |
|
|
|
g_game_state->is_selecting = false; |
|
|
|
g_game_state->is_selecting = false; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
case PATHFINDING: |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case NONE: |
|
|
|
case NONE: |
|
|
|
// fall through
|
|
|
|
// fall through
|
|
|
|
default: |
|
|
|
default: |
|
|
|
@ -446,7 +450,7 @@ processSDLEvents() |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return run; |
|
|
|
return run; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -482,7 +486,7 @@ cleanUp(SDL_Handles &handles) |
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) |
|
|
|
#if defined(_WIN32) |
|
|
|
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
|
|
|
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
|
|
|
LPSTR lpCmdLine, int nShowCmd) |
|
|
|
LPSTR lpCmdLine, int nShowCmd) |
|
|
|
#else |
|
|
|
#else |
|
|
|
int main(int argc, char* argv[]) |
|
|
|
int main(int argc, char* argv[]) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
@ -513,7 +517,7 @@ int main(int argc, char* argv[]) |
|
|
|
|
|
|
|
|
|
|
|
createHexes(g_game_state->hex_array, g_game_state->hex_layout, g_render_state->fill_color); |
|
|
|
createHexes(g_game_state->hex_array, g_game_state->hex_layout, g_render_state->fill_color); |
|
|
|
SDL_Handles handles; |
|
|
|
SDL_Handles handles; |
|
|
|
|
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) { |
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) { |
|
|
|
LOG(ERROR) << "Error, SDL_Init: " << SDL_GetError() << "\n"; |
|
|
|
LOG(ERROR) << "Error, SDL_Init: " << SDL_GetError() << "\n"; |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
@ -550,6 +554,7 @@ int main(int argc, char* argv[]) |
|
|
|
game_state* g = g_game_state; |
|
|
|
game_state* g = g_game_state; |
|
|
|
g->entities = (Entity*) std::calloc(1000, sizeof(Entity)); |
|
|
|
g->entities = (Entity*) std::calloc(1000, sizeof(Entity)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
meMeshGroup mg1, mg2; |
|
|
|
meMeshGroup mg1, mg2; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: store these meMeshGroups serperately from entities to re-use them,
|
|
|
|
// TODO: store these meMeshGroups serperately from entities to re-use them,
|
|
|
|
@ -577,12 +582,22 @@ int main(int argc, char* argv[]) |
|
|
|
LOG(ERROR) << "Error loading file, exiting\n"; |
|
|
|
LOG(ERROR) << "Error loading file, exiting\n"; |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LOG(ERROR) << "Error initializing assimp\n"; |
|
|
|
LOG(ERROR) << "Error initializing assimp\n"; |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// testing scene_loader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (slLoadFile(DEFAULT_SCENE_FILE, g_game_state->entities, g_game_state->entity_count, 1000)) { |
|
|
|
|
|
|
|
// ???
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
LOG(ERROR) << "Error reading scene file, exiting\n"; |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!createScene(g_game_state->hex_array, g_game_state->entities, g_game_state->entity_count)) { |
|
|
|
if (!createScene(g_game_state->hex_array, g_game_state->entities, g_game_state->entity_count)) { |
|
|
|
LOG(ERROR) << "Error in vertex data, exiting\n"; |
|
|
|
LOG(ERROR) << "Error in vertex data, exiting\n"; |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
@ -611,18 +626,18 @@ int main(int argc, char* argv[]) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
game_state* g = g_game_state; |
|
|
|
game_state* g = g_game_state; |
|
|
|
render_state* r = g_render_state; |
|
|
|
render_state* r = g_render_state; |
|
|
|
|
|
|
|
|
|
|
|
moveCamera(g->is_moveup, g->is_moveleft, g->is_movedown, g->is_moveright, |
|
|
|
moveCamera(g->is_moveup, g->is_moveleft, g->is_movedown, g->is_moveright, |
|
|
|
g->is_moveforward, g->is_movebackward); |
|
|
|
g->is_moveforward, g->is_movebackward); |
|
|
|
|
|
|
|
|
|
|
|
renderFrame(g->hex_array, g->entities, g->entity_count); |
|
|
|
renderFrame(g->hex_array, g->entities, g->entity_count); |
|
|
|
|
|
|
|
|
|
|
|
if (r->is_debug_draw && g->draw_mode == CONE_FILL) |
|
|
|
if (r->is_debug_draw && g->draw_mode == CONE_FILL) |
|
|
|
renderDebug(g_polygon_select_vertices); |
|
|
|
renderDebug(g_polygon_select_vertices); |
|
|
|
|
|
|
|
|
|
|
|
renderGooey(handles, g->draw_mode, r->is_debug_draw, g->start_hex, |
|
|
|
renderGooey(handles, g->draw_mode, r->is_debug_draw, g->start_hex, |
|
|
|
g->current_hex, g->is_selecting, getCameraPosition()); |
|
|
|
g->current_hex, g->is_selecting, getCameraPosition()); |
|
|
|
|
|
|
|
|
|
|
|
SDL_GL_SwapWindow(handles.window); |
|
|
|
SDL_GL_SwapWindow(handles.window); |
|
|
|
|
|
|
|
|
|
|
|
platform_wait_for_vblank(VSYNC_ENABLED); |
|
|
|
platform_wait_for_vblank(VSYNC_ENABLED); |
|
|
|
|