|
|
|
@ -1,11 +1,8 @@ |
|
|
|
/*******************************************************************************
|
|
|
|
/*******************************************************************************
|
|
|
|
* TODO: |
|
|
|
* TODO: |
|
|
|
* - add a color buffer to hex_line and debug render groups to re-use |
|
|
|
* - add 3d orientation widget to gooey |
|
|
|
* fragment shaders and simplify draw rgDraw() |
|
|
|
|
|
|
|
* - need to add normal buffer too |
|
|
|
|
|
|
|
* - lighting |
|
|
|
* - lighting |
|
|
|
* - add light struct
|
|
|
|
* - test adding more lights |
|
|
|
* - pass all lights to render groups/shaders every frame |
|
|
|
|
|
|
|
* - map generation |
|
|
|
* - map generation |
|
|
|
* - pathfinding |
|
|
|
* - pathfinding |
|
|
|
* - assimp animation |
|
|
|
* - assimp animation |
|
|
|
@ -20,17 +17,20 @@ |
|
|
|
* - actually don't need to save the vertex/normal buffers after passing |
|
|
|
* - actually don't need to save the vertex/normal buffers after passing |
|
|
|
* to opengl |
|
|
|
* to opengl |
|
|
|
* - use a storage pool for assimp meshes allowing reuse across entities |
|
|
|
* - use a storage pool for assimp meshes allowing reuse across entities |
|
|
|
* - replace calls to malloc/free with safe(r) function in util.h |
|
|
|
* - replace remaining calls to malloc/free with safe(r) function in util.h |
|
|
|
* - add cpu perforcmace counters in render loop |
|
|
|
* - add cpu perforcmace counters in render loop |
|
|
|
* - check for memory leaks w/ valgrind |
|
|
|
* - check for memory leaks w/ valgrind |
|
|
|
******************************************************************************/ |
|
|
|
******************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
// Some defaults for the game layout
|
|
|
|
// Some defaults for the game layout
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
#define HEX_SIZE 10 |
|
|
|
#define HEX_SIZE 10 |
|
|
|
#define HEX_RADIUS 19 |
|
|
|
#define HEX_RADIUS 19 |
|
|
|
#define HEX_ORIENTATION layout_flat |
|
|
|
#define HEX_ORIENTATION layout_flat |
|
|
|
#define FILL_COLOR 0x565656FF |
|
|
|
#define FILL_COLOR 0x565656FF |
|
|
|
#define SELECTED_FILL_COLOR 0xF46000FF |
|
|
|
#define SELECTED_FILL_COLOR 0xF46000FF |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG_DRAW true |
|
|
|
#define DEBUG_DRAW true |
|
|
|
#define VIEWPORT_WIDTH 1920 |
|
|
|
#define VIEWPORT_WIDTH 1920 |
|
|
|
#define VIEWPORT_HEIGHT 1080 |
|
|
|
#define VIEWPORT_HEIGHT 1080 |
|
|
|
@ -77,32 +77,6 @@ static game_state* g_game_state; |
|
|
|
static render_state* g_render_state; |
|
|
|
static render_state* g_render_state; |
|
|
|
static vector<Point> g_polygon_select_vertices = {Point(), Point(), Point(), Point()}; |
|
|
|
static vector<Point> g_polygon_select_vertices = {Point(), Point(), Point(), Point()}; |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
createHexes(vector<hex_info> *hxi_array, const Layout &layout, uint32 color) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// create a hexagonal grid of hexagons
|
|
|
|
|
|
|
|
int map_radius = HEX_RADIUS; |
|
|
|
|
|
|
|
for (int q = -map_radius; q <= map_radius; q++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int r1 = std::max(-map_radius, -q - map_radius); |
|
|
|
|
|
|
|
int r2 = std::min(map_radius, -q + map_radius); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int r = r1; r <= r2; r++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
hex_info hxi; |
|
|
|
|
|
|
|
hxi.hexID = (int32) hxi_array->size(); |
|
|
|
|
|
|
|
hxi.hex.q = q; hxi.hex.r = r; hxi.hex.s = -q-r; |
|
|
|
|
|
|
|
Point p = hex_to_pixel(layout, hxi.hex); |
|
|
|
|
|
|
|
hxi.XPos = p.x; |
|
|
|
|
|
|
|
hxi.YPos = p.y; |
|
|
|
|
|
|
|
hxi.current_color = color; |
|
|
|
|
|
|
|
hxi.stored_color = color; |
|
|
|
|
|
|
|
hxi.vertices = polygon_corners(layout, hxi.hex); |
|
|
|
|
|
|
|
hxi.vertices.shrink_to_fit(); |
|
|
|
|
|
|
|
hxi_array->push_back(hxi); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v2i |
|
|
|
v2i |
|
|
|
mapMouseToViewport(int32 x, int32 y) |
|
|
|
mapMouseToViewport(int32 x, int32 y) |
|
|
|
@ -131,7 +105,7 @@ getSingleHex(int32 x, int32 y) |
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
v2i dims = g_render_state->viewport_dims; |
|
|
|
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->grid.hex_layout, p)); |
|
|
|
Hex h = hex_round(pixel_to_hex(g_game_state->grid.hexlib_layout, p)); |
|
|
|
|
|
|
|
|
|
|
|
for (hex_info &hxi : *g_game_state->grid.hex_array) |
|
|
|
for (hex_info &hxi : *g_game_state->grid.hex_array) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -502,9 +476,7 @@ int main(int argc, char* argv[]) |
|
|
|
LOG(INFO) << "Application started\n"; |
|
|
|
LOG(INFO) << "Application started\n"; |
|
|
|
|
|
|
|
|
|
|
|
// init global game state
|
|
|
|
// init global game state
|
|
|
|
Layout layout(HEX_ORIENTATION, Point(HEX_SIZE, HEX_SIZE), Point(VIEWPORT_WIDTH / 2, VIEWPORT_HEIGHT / 2)); |
|
|
|
|
|
|
|
g_game_state = UTIL_ALLOC(1, game_state); |
|
|
|
g_game_state = UTIL_ALLOC(1, game_state); |
|
|
|
g_game_state->grid.hex_layout = layout; |
|
|
|
|
|
|
|
g_game_state->grid.hex_array = new vector<hex_info>; |
|
|
|
g_game_state->grid.hex_array = new vector<hex_info>; |
|
|
|
g_game_state->entities = UTIL_ALLOC(MAX_ENTITIES, Entity); |
|
|
|
g_game_state->entities = UTIL_ALLOC(MAX_ENTITIES, Entity); |
|
|
|
|
|
|
|
|
|
|
|
@ -512,11 +484,7 @@ int main(int argc, char* argv[]) |
|
|
|
g_render_state = UTIL_ALLOC(1, render_state); |
|
|
|
g_render_state = UTIL_ALLOC(1, render_state); |
|
|
|
g_render_state->is_debug_draw = DEBUG_DRAW; |
|
|
|
g_render_state->is_debug_draw = DEBUG_DRAW; |
|
|
|
g_render_state->viewport_dims = v2i(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); |
|
|
|
g_render_state->viewport_dims = v2i(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); |
|
|
|
g_render_state->fill_color = FILL_COLOR; |
|
|
|
|
|
|
|
g_render_state->selected_fill_color = SELECTED_FILL_COLOR; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createHexes(g_game_state->grid.hex_array, g_game_state->grid.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) { |
|
|
|
@ -559,10 +527,11 @@ int main(int argc, char* argv[]) |
|
|
|
|
|
|
|
|
|
|
|
slSceneDoc* sd = slLoadFile(DATA_DIR, DEFAULT_SCENE_FILE, SCENE_SCHEMA_FILE); |
|
|
|
slSceneDoc* sd = slLoadFile(DATA_DIR, DEFAULT_SCENE_FILE, SCENE_SCHEMA_FILE); |
|
|
|
if (sd != nullptr) { |
|
|
|
if (sd != nullptr) { |
|
|
|
slParseEntities(sd, g_game_state->entities, g_game_state->entity_count, MAX_ENTITIES, |
|
|
|
game_state* g = g_game_state; |
|
|
|
DATA_DIR); |
|
|
|
render_state* r = g_render_state; |
|
|
|
|
|
|
|
slParseEntities(sd, g->entities, g->entity_count, MAX_ENTITIES, DATA_DIR); |
|
|
|
slParseCamera(sd, renGetCamera()); |
|
|
|
slParseCamera(sd, renGetCamera()); |
|
|
|
slParseHexGrid(sd, g_game_state->grid); |
|
|
|
slParseHexGrid(sd, g->grid, r->fill_color, r->selected_fill_color); |
|
|
|
slFreeSceneDoc(sd); |
|
|
|
slFreeSceneDoc(sd); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LOG(ERROR) << "Error loading scene, exiting\n"; |
|
|
|
LOG(ERROR) << "Error loading scene, exiting\n"; |
|
|
|
|