Added highlighted hex

main
noah metz 2024-11-05 20:07:11 -07:00
parent ba4bd9bc85
commit 034ee66224
3 changed files with 29 additions and 3 deletions

@ -12,12 +12,12 @@ void main() {
if(gl_InstanceIndex == 0) { if(gl_InstanceIndex == 0) {
hex_index = pc.context.clicked_hex; hex_index = pc.context.clicked_hex;
region = pc.context.regions[pc.context.clicked_region]; region = pc.context.regions[pc.context.clicked_region];
color = vec4(0.3, 0.3, 0.3, 0.3); color = vec4(0.5, 0.5, 0.5, 0.3);
raise = 0.015; raise = 0.015;
} else { } else {
hex_index = pc.context.hovered_hex; hex_index = pc.context.hovered_hex;
region = pc.context.regions[pc.context.hovered_region]; region = pc.context.regions[pc.context.hovered_region];
color = vec4(0.8, 0.8, 0.8, 0.3); color = vec4(0.25, 0.25, 0.25, 0.3);
raise = 0.01; raise = 0.01;
} }

@ -1292,6 +1292,16 @@ VkResult add_transfer(
FrameContext* frame = &gpu->frame[frame_index]; FrameContext* frame = &gpu->frame[frame_index];
TransferBuffer* transfer = &frame->transfers[frame->transfer_index % 2]; TransferBuffer* transfer = &frame->transfers[frame->transfer_index % 2];
VkDeviceSize src_offset = 0;
for(uint32_t i = 0; i < transfer->count; i++) {
if(transfer->infos[i].buffer == buffer && transfer->infos[i].size == size && transfer->infos[i].offset == offset) {
memcpy(transfer->mapped + src_offset, data, size);
return VK_SUCCESS;
} else {
src_offset += transfer->infos[i].size;
}
}
if(transfer->written + size >= transfer->max_size) { if(transfer->written + size >= transfer->max_size) {
uint32_t new_size = 2*transfer->max_size; uint32_t new_size = 2*transfer->max_size;
while(transfer->written + size >= new_size) { while(transfer->written + size >= new_size) {

@ -288,8 +288,8 @@ VkResult main_thread(ClientContext* context) {
context->zoom = 0; context->zoom = 0;
context->cur_spin[0] = 0; context->cur_spin[0] = 0;
context->cur_spin[1] = 0; context->cur_spin[1] = 0;
glfwPollEvents();
glfwPollEvents();
if((context->key_spin[0] != 0 || context->key_spin[1] != 0 || if((context->key_spin[0] != 0 || context->key_spin[1] != 0 ||
context->zoom != 0 || context->zoom != 0 ||
context->cur_spin[0] != 0 || context->cur_spin[1] != 0 || context->cur_spin[0] != 0 || context->cur_spin[1] != 0 ||
@ -535,6 +535,22 @@ void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) {
cursor_to_world_ray(context, context->cursor, context->hex->data.hover_start, context->hex->data.hover_end); cursor_to_world_ray(context, context->cursor, context->hex->data.hover_start, context->hex->data.hover_end);
add_transfer(&context->hex->data.hover_start, context->hex->context, offsetof(GPUHexContext, hover_start), sizeof(vec4)*2, context->render->current_frame, context->render); add_transfer(&context->hex->data.hover_start, context->hex->context, offsetof(GPUHexContext, hover_start), sizeof(vec4)*2, context->render->current_frame, context->render);
// Hex intersections
float distance;
for(uint32_t r = 0; r < MAX_LOADED_REGIONS; r++) {
if(context->hex->regions[r] == NULL) {
continue;
} else if(context->hex->regions[r]->data.map != context->hex->data.current_map) {
continue;
}
for(uint32_t h = 0; h < REGION_HEX_COUNT; h++) {
if(ray_hex_intersect(&distance, context->hex->data.hover_start, context->hex->data.hover_end, r, h, context->hex)) {
context->hex->data.hovered_region = r;
context->hex->data.hovered_hex = h;
add_transfer(&context->hex->data.hovered_region, context->hex->context, offsetof(GPUHexContext, hovered_region), sizeof(uint32_t)*2, context->render->current_frame, context->render);
}
}
}
} }
int main() { int main() {