|
|
|
|
@ -91,9 +91,19 @@ hgAddHex(hexgrid& hg, v3f hex_coords, render_group* rg_filled, render_group* rg_
|
|
|
|
|
Hex h = hex_round(pixel_to_hex(hg.hexlib_layout, Point(hex_coords.x, hex_coords.y))); |
|
|
|
|
hex_info new_hex = createHexInfo(hg, h.q, h.r); |
|
|
|
|
hg.hex_map.insert({h, new_hex}); |
|
|
|
|
#if 0 |
|
|
|
|
// NOTE: have to repopulate all the buffers, and re-index
|
|
|
|
|
uint i = 0; |
|
|
|
|
for (auto it : hg.hex_map) { |
|
|
|
|
it.second.hexID = i; |
|
|
|
|
populateFilledHexGLBuffers(hg, it.second, rg_filled); |
|
|
|
|
populateLineGLBuffers(hg, it.second, rg_lines); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
populateFilledHexGLBuffers(hg, new_hex, rg_filled); |
|
|
|
|
populateLineGLBuffers(hg, new_hex, rg_lines); |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
// NOTE: we could send just a part of the buffer if performance ends up being bad here
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vb_f.buffer_id); |
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, vb_f.count * sizeof(GLfloat), vb_f.buffer); |
|
|
|
|
@ -145,7 +155,7 @@ hgRemoveHex(hexgrid& hg, v3f hex_coords, render_group* rg_filled, render_group*
|
|
|
|
|
|
|
|
|
|
// NOTE: have to repopulate all the buffers, and re-index
|
|
|
|
|
uint i = 0; |
|
|
|
|
for (auto it : hg.hex_map) { |
|
|
|
|
for (auto& it : hg.hex_map) { |
|
|
|
|
it.second.hexID = i; |
|
|
|
|
populateFilledHexGLBuffers(hg, it.second, rg_filled); |
|
|
|
|
populateLineGLBuffers(hg, it.second, rg_lines); |
|
|
|
|
@ -286,9 +296,10 @@ hgUpdateHexConeFill(hexgrid& hg, int32 x, int32 y, float cone_angle, std::vector
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
hgUpdateUVBuffer(hexgrid& hg, float* uv_buffer, uint buf_len) |
|
|
|
|
hgUpdateUVBuffer(hexgrid& hg, render_group* rg) |
|
|
|
|
{ |
|
|
|
|
assert(buf_len == hg.hex_map.size() * IDX_PER_HEX_FILLED); |
|
|
|
|
gl_buffer& uv_buf = rg->render_objects[0]->uv_buffer; |
|
|
|
|
assert(uv_buf.count == hg.hex_map.size() * IDX_PER_HEX_FILLED); |
|
|
|
|
|
|
|
|
|
for (auto& it : hg.hex_map) { |
|
|
|
|
hex_info hxi = it.second; |
|
|
|
|
@ -296,11 +307,14 @@ hgUpdateUVBuffer(hexgrid& hg, float* uv_buffer, uint buf_len)
|
|
|
|
|
uint buf_idx = hxi.hexID * IDX_PER_HEX_FILLED; |
|
|
|
|
|
|
|
|
|
for (uint j = 0; j < IDX_PER_HEX_FILLED; j +=3) { |
|
|
|
|
uv_buffer[buf_idx + j + 0] = uv_coords.x; |
|
|
|
|
uv_buffer[buf_idx + j + 1] = uv_coords.y; |
|
|
|
|
uv_buffer[buf_idx + j + 2] = 0; |
|
|
|
|
uv_buf.buffer[buf_idx + j + 0] = uv_coords.x; |
|
|
|
|
uv_buf.buffer[buf_idx + j + 1] = uv_coords.y; |
|
|
|
|
uv_buf.buffer[buf_idx + j + 2] = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, uv_buf.buffer_id); |
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, uv_buf.count * sizeof(GLfloat), uv_buf.buffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// internal
|
|
|
|
|
@ -333,14 +347,7 @@ createHexagonGrid(hexgrid& hg)
|
|
|
|
|
|
|
|
|
|
for (int r = r1; r <= r2; r++) { |
|
|
|
|
hex_info hxi = createHexInfo(hg, q, r); |
|
|
|
|
|
|
|
|
|
// NOTE: testing sparse grid
|
|
|
|
|
if ((q > -2 && q < 2) && (r > -2 && r < 2)) { |
|
|
|
|
// skip
|
|
|
|
|
} else { |
|
|
|
|
hg.hex_map.insert({hxi.hex, hxi}); |
|
|
|
|
} |
|
|
|
|
/////////////
|
|
|
|
|
hg.hex_map.insert({hxi.hex, hxi}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|