|
|
|
|
@ -90,6 +90,10 @@ init()
|
|
|
|
|
// TODO: I think this is necessary because we're using calloc to initialize gamestate
|
|
|
|
|
// which contains the hashtable.
|
|
|
|
|
g_game_state->grid.hex_map = std::unordered_map<Hex, hex_info, hex_hashfunc>(); |
|
|
|
|
// NOTE: testing hex_add
|
|
|
|
|
g_game_state->grid.draw_mode = ADD_HEXES; |
|
|
|
|
// TODO: maybe add this as an option to scene json?
|
|
|
|
|
g_game_state->grid.normal = v3f(0.f, 0.f, 1.f); |
|
|
|
|
|
|
|
|
|
// init global render state
|
|
|
|
|
g_render_state = UTIL_ALLOC(1, render_state); |
|
|
|
|
@ -170,37 +174,41 @@ startDrawHelper(int32 x, int32 y)
|
|
|
|
|
void |
|
|
|
|
handleMouseDown(SDL_MouseButtonEvent &e) |
|
|
|
|
{ |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
render_state* rs = g_render_state; |
|
|
|
|
v2i coords = mapMouseToViewport(e.x, e.y); |
|
|
|
|
v2i dims = rs->viewport_dims; |
|
|
|
|
|
|
|
|
|
switch (g_game_state->grid.draw_mode) |
|
|
|
|
{ |
|
|
|
|
switch (gs->grid.draw_mode) { |
|
|
|
|
case FILL: |
|
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
|
startDrawHelper(coords.x, coords.y); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case ADD_HEXES: { |
|
|
|
|
v3f ray = cameraCreateRay(rs->cam, coords, dims); |
|
|
|
|
v3f xsect; |
|
|
|
|
if (cameraIntersectPlane(rs->cam, ray, gs->grid.position, gs->grid.normal, xsect)) |
|
|
|
|
hgAddHex(gs->grid, xsect); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case NONE: |
|
|
|
|
// fall through
|
|
|
|
|
default: |
|
|
|
|
{ |
|
|
|
|
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); |
|
|
|
|
v2f v = cameraUnproject(rs->cam, coords.x, coords.y, dims.x, dims.y); |
|
|
|
|
hex_info *hex = hgGetSingleHex(gs->grid, v.x, v.y); |
|
|
|
|
|
|
|
|
|
if (hex) { |
|
|
|
|
hex->selected = !hex->selected; |
|
|
|
|
g_game_state->grid.start_hex = g_game_state->grid.current_hex = hex; |
|
|
|
|
gs->grid.start_hex = gs->grid.current_hex = hex; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -211,25 +219,19 @@ handleMouseMove(SDL_MouseMotionEvent &e)
|
|
|
|
|
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: |
|
|
|
|
hgUpdateHexFill(g_game_state->grid, v.x, v.y); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case LINE: |
|
|
|
|
hgUpdateHexLineDraw(g_game_state->grid, v.x, v.y); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case CONE_FILL: |
|
|
|
|
hgUpdateHexConeFill(g_game_state->grid, v.x, v.y, CONE_ANGLE, g_polygon_select_vertices); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case PATHFINDING: |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case NONE: |
|
|
|
|
// fall through
|
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
@ -241,22 +243,19 @@ processSDLEvents()
|
|
|
|
|
SDL_Event e; |
|
|
|
|
bool run = true; |
|
|
|
|
|
|
|
|
|
while (SDL_PollEvent(&e)) |
|
|
|
|
{ |
|
|
|
|
while (SDL_PollEvent(&e)) { |
|
|
|
|
// let gooey have event
|
|
|
|
|
// TODO: need to check for both io.WantCaptureKeyboard and io.WantCaptureMouse
|
|
|
|
|
// to fix bug with 'ESC' not passing through while in imgui
|
|
|
|
|
bool gooey_wants = gooProcessEvent(e); |
|
|
|
|
game_state* gs = g_game_state; |
|
|
|
|
|
|
|
|
|
switch (e.type) |
|
|
|
|
{ |
|
|
|
|
switch (e.type) { |
|
|
|
|
case SDL_QUIT: |
|
|
|
|
run = false; |
|
|
|
|
break; |
|
|
|
|
case SDL_KEYDOWN: |
|
|
|
|
switch (e.key.keysym.sym) |
|
|
|
|
{ |
|
|
|
|
switch (e.key.keysym.sym) { |
|
|
|
|
case SDLK_ESCAPE: run = false; break; |
|
|
|
|
case SDLK_e: gs->is_moveforward = true; break; |
|
|
|
|
case SDLK_s: gs->is_moveleft = true; break; |
|
|
|
|
@ -269,8 +268,7 @@ processSDLEvents()
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case SDL_KEYUP: |
|
|
|
|
switch (e.key.keysym.sym) |
|
|
|
|
{ |
|
|
|
|
switch (e.key.keysym.sym) { |
|
|
|
|
case SDLK_e: gs->is_moveforward = false; break; |
|
|
|
|
case SDLK_s: gs->is_moveleft = false; break; |
|
|
|
|
case SDLK_d: gs->is_movebackward = false; break; |
|
|
|
|
@ -282,22 +280,17 @@ processSDLEvents()
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case SDL_MOUSEBUTTONDOWN: |
|
|
|
|
if (!gooey_wants) |
|
|
|
|
{ |
|
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) |
|
|
|
|
{ |
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) { |
|
|
|
|
gs->grid.is_selecting = true; |
|
|
|
|
handleMouseDown(e.button); |
|
|
|
|
} |
|
|
|
|
else if (e.button.button == SDL_BUTTON_RIGHT) |
|
|
|
|
{ |
|
|
|
|
} else if (e.button.button == SDL_BUTTON_RIGHT) { |
|
|
|
|
gs->is_camera_rotate = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case SDL_MOUSEBUTTONUP: |
|
|
|
|
if (!gooey_wants) |
|
|
|
|
{ |
|
|
|
|
if (!gooey_wants) { |
|
|
|
|
if (e.button.button == SDL_BUTTON_LEFT) |
|
|
|
|
gs->grid.is_selecting = false; |
|
|
|
|
else if (e.button.button == SDL_BUTTON_RIGHT) |
|
|
|
|
|