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;
}
VkResult add_hex_region(ClientContext* context) {
VkResult result;
uint32_t add_hex_region(ClientContext* context) {
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++) {
region->data.hexes[hex].color[0] = 0xFFFFFFFF;
@ -78,9 +76,16 @@ VkResult add_hex_region(ClientContext* context) {
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] = {
@ -172,31 +177,10 @@ VkResult region_info_ui(ClientContext* context) {
return create_container(&region_info, context->render, context->ui);
}
VkResult main_thread(ClientContext* context) {
VkResult update_region_info_ui(ClientContext* context) {
VkResult result;
VK_RESULT(region_info_ui(context));
//
double last_frame_time = 0;
while(glfwWindowShouldClose(context->window) == 0) {
double frame_time = glfwGetTime();
double delta_time = (frame_time - last_frame_time);
// Reset callback variables
context->clicked_element = 0x00000000;
context->clicked_container = 0x00000000;
context->zoom = 0;
context->cur_spin[0] = 0;
context->cur_spin[1] = 0;
glfwPollEvents();
if(context->selected_region != context->last_selected_region) {
context->last_selected_region = context->selected_region;
HexRegion* selected_region = context->hex->regions[context->selected_region];
snprintf(region_info_strs[0],
sizeof(region_info_strs[0]),
"Region %4d", context->selected_region);
@ -240,6 +224,32 @@ VkResult main_thread(ClientContext* context) {
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 result;
VK_RESULT(region_info_ui(context));
//
double last_frame_time = 0;
while(glfwWindowShouldClose(context->window) == 0) {
double frame_time = glfwGetTime();
double delta_time = (frame_time - last_frame_time);
// Reset callback variables
context->clicked_element = 0x00000000;
context->clicked_container = 0x00000000;
context->zoom = 0;
context->cur_spin[0] = 0;
context->cur_spin[1] = 0;
glfwPollEvents();
if(context->selected_region != context->last_selected_region) {
context->last_selected_region = context->selected_region;
update_region_info_ui(context);
}
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:
if(action == GLFW_PRESS) {
add_hex_region(context);
context->selected_region = add_hex_region(context);
}
break;
@ -407,6 +417,97 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
}
}
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;
}
}