Added region manipulation

main
noah metz 2024-11-10 21:45:39 -07:00
parent 2a6b96a274
commit 8321fb0510
1 changed files with 154 additions and 53 deletions

@ -54,12 +54,10 @@ void* network_thread(void* data) {
return NULL; return NULL;
} }
VkResult add_hex_region(ClientContext* context) { uint32_t add_hex_region(ClientContext* context) {
VkResult result;
HexRegion* region; HexRegion* region;
VK_RESULT(allocate_hex_region(0, 0, 0, context->hex->data.current_map, &region, context->hex, context->render)); allocate_hex_region(0, 0, 0, context->hex->data.current_map, &region, context->hex, context->render);
for(uint32_t hex = 0; hex < REGION_HEX_COUNT; hex++) { for(uint32_t hex = 0; hex < REGION_HEX_COUNT; hex++) {
region->data.hexes[hex].color[0] = 0xFFFFFFFF; region->data.hexes[hex].color[0] = 0xFFFFFFFF;
@ -78,9 +76,16 @@ VkResult add_hex_region(ClientContext* context) {
region->data.hexes[hex].height[5] = 0; region->data.hexes[hex].height[5] = 0;
} }
VK_RESULT(set_hex_region(region, context->hex, context->render)); set_hex_region(region, context->hex, context->render);
return VK_SUCCESS; uint32_t i = 0;
for(; i < MAX_LOADED_REGIONS; i++) {
if(region == context->hex->regions[i]) {
break;
}
}
return i;
} }
char region_info_strs[][20] = { char region_info_strs[][20] = {
@ -172,6 +177,56 @@ VkResult region_info_ui(ClientContext* context) {
return create_container(&region_info, context->render, context->ui); return create_container(&region_info, context->render, context->ui);
} }
VkResult update_region_info_ui(ClientContext* context) {
VkResult result;
HexRegion* selected_region = context->hex->regions[context->selected_region];
snprintf(region_info_strs[0],
sizeof(region_info_strs[0]),
"Region %4d", context->selected_region);
VK_RESULT(update_ui_string(region_info_strs[0], 0, 0, 0, context->ui, context->render));
if(selected_region == NULL) {
snprintf(
region_info_strs[1],
sizeof(region_info_strs[1]),
"");
VK_RESULT(update_ui_string(region_info_strs[1], 0, 0, 1, context->ui, context->render));
snprintf(
region_info_strs[2],
sizeof(region_info_strs[2]),
"");
VK_RESULT(update_ui_string(region_info_strs[2], 0, 0, 2, context->ui, context->render));
snprintf(
region_info_strs[3],
sizeof(region_info_strs[3]),
"");
VK_RESULT(update_ui_string(region_info_strs[3], 0, 0, 3, context->ui, context->render));
} else {
snprintf(
region_info_strs[1],
sizeof(region_info_strs[1]),
"Q: %4d", selected_region->data.q);
VK_RESULT(update_ui_string(region_info_strs[1], 0, 0, 1, context->ui, context->render));
snprintf(
region_info_strs[2],
sizeof(region_info_strs[2]),
"R: %4d", selected_region->data.r);
VK_RESULT(update_ui_string(region_info_strs[2], 0, 0, 2, context->ui, context->render));
snprintf(
region_info_strs[3],
sizeof(region_info_strs[3]),
"Y: %4d", selected_region->data.y);
VK_RESULT(update_ui_string(region_info_strs[3], 0, 0, 3, context->ui, context->render));
}
return VK_SUCCESS;
}
VkResult main_thread(ClientContext* context) { VkResult main_thread(ClientContext* context) {
VkResult result; VkResult result;
@ -194,52 +249,7 @@ VkResult main_thread(ClientContext* context) {
if(context->selected_region != context->last_selected_region) { if(context->selected_region != context->last_selected_region) {
context->last_selected_region = context->selected_region; context->last_selected_region = context->selected_region;
update_region_info_ui(context);
HexRegion* selected_region = context->hex->regions[context->selected_region];
snprintf(region_info_strs[0],
sizeof(region_info_strs[0]),
"Region %4d", context->selected_region);
VK_RESULT(update_ui_string(region_info_strs[0], 0, 0, 0, context->ui, context->render));
if(selected_region == NULL) {
snprintf(
region_info_strs[1],
sizeof(region_info_strs[1]),
"");
VK_RESULT(update_ui_string(region_info_strs[1], 0, 0, 1, context->ui, context->render));
snprintf(
region_info_strs[2],
sizeof(region_info_strs[2]),
"");
VK_RESULT(update_ui_string(region_info_strs[2], 0, 0, 2, context->ui, context->render));
snprintf(
region_info_strs[3],
sizeof(region_info_strs[3]),
"");
VK_RESULT(update_ui_string(region_info_strs[3], 0, 0, 3, context->ui, context->render));
} else {
snprintf(
region_info_strs[1],
sizeof(region_info_strs[1]),
"Q: %4d", selected_region->data.q);
VK_RESULT(update_ui_string(region_info_strs[1], 0, 0, 1, context->ui, context->render));
snprintf(
region_info_strs[2],
sizeof(region_info_strs[2]),
"R: %4d", selected_region->data.r);
VK_RESULT(update_ui_string(region_info_strs[2], 0, 0, 2, context->ui, context->render));
snprintf(
region_info_strs[3],
sizeof(region_info_strs[3]),
"Y: %4d", selected_region->data.y);
VK_RESULT(update_ui_string(region_info_strs[3], 0, 0, 3, context->ui, context->render));
}
} }
if((context->key_spin[0] != 0 || context->key_spin[1] != 0 || if((context->key_spin[0] != 0 || context->key_spin[1] != 0 ||
@ -387,7 +397,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
case GLFW_KEY_EQUAL: case GLFW_KEY_EQUAL:
if(action == GLFW_PRESS) { if(action == GLFW_PRESS) {
add_hex_region(context); context->selected_region = add_hex_region(context);
} }
break; break;
@ -407,6 +417,97 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
} }
} }
break; break;
case GLFW_KEY_I:
if(action == GLFW_PRESS) {
if(context->hex->regions[context->selected_region] != NULL) {
context->hex->regions[context->selected_region]->data.q += 1;
add_transfer(
&context->hex->regions[context->selected_region]->data.q,
context->hex->regions[context->selected_region]->region,
offsetof(GPUHexRegion, q),
sizeof(uint32_t),
context->render->current_frame,
context->render);
}
update_region_info_ui(context);
}
break;
case GLFW_KEY_K:
if(action == GLFW_PRESS) {
if(context->hex->regions[context->selected_region] != NULL) {
context->hex->regions[context->selected_region]->data.q -= 1;
add_transfer(
&context->hex->regions[context->selected_region]->data.q,
context->hex->regions[context->selected_region]->region,
offsetof(GPUHexRegion, q),
sizeof(uint32_t),
context->render->current_frame,
context->render);
}
update_region_info_ui(context);
}
break;
case GLFW_KEY_J:
if(action == GLFW_PRESS) {
if(context->hex->regions[context->selected_region] != NULL) {
context->hex->regions[context->selected_region]->data.r += 1;
add_transfer(
&context->hex->regions[context->selected_region]->data.r,
context->hex->regions[context->selected_region]->region,
offsetof(GPUHexRegion, r),
sizeof(uint32_t),
context->render->current_frame,
context->render);
}
update_region_info_ui(context);
}
break;
case GLFW_KEY_L:
if(action == GLFW_PRESS) {
if(context->hex->regions[context->selected_region] != NULL) {
context->hex->regions[context->selected_region]->data.r -= 1;
add_transfer(
&context->hex->regions[context->selected_region]->data.r,
context->hex->regions[context->selected_region]->region,
offsetof(GPUHexRegion, r),
sizeof(uint32_t),
context->render->current_frame,
context->render);
}
update_region_info_ui(context);
}
break;
case GLFW_KEY_O:
if(action == GLFW_PRESS) {
if(context->hex->regions[context->selected_region] != NULL) {
context->hex->regions[context->selected_region]->data.y += 1;
add_transfer(
&context->hex->regions[context->selected_region]->data.y,
context->hex->regions[context->selected_region]->region,
offsetof(GPUHexRegion, y),
sizeof(int32_t),
context->render->current_frame,
context->render);
}
update_region_info_ui(context);
}
break;
case GLFW_KEY_U:
if(action == GLFW_PRESS) {
if(context->hex->regions[context->selected_region] != NULL) {
context->hex->regions[context->selected_region]->data.y -= 1;
add_transfer(
&context->hex->regions[context->selected_region]->data.y,
context->hex->regions[context->selected_region]->region,
offsetof(GPUHexRegion, y),
sizeof(int32_t),
context->render->current_frame,
context->render);
}
update_region_info_ui(context);
}
break;
} }
} }