diff --git a/client/src/main.c b/client/src/main.c index d9fca10..3b2c71b 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -15,6 +15,15 @@ #include #include +typedef struct EditorContextStruct { + uint32_t selected_region; + uint32_t last_selected_region; + + uint32_t last_clicked_region; + uint32_t last_clicked_hex; + uint32_t last_clicked_vertex; +} EditorContext; + typedef struct ClientContextStruct { GLFWwindow* window; RenderContext* render; @@ -43,12 +52,7 @@ typedef struct ClientContextStruct { float zoom_speed; float move_speed; - uint32_t selected_region; - uint32_t last_selected_region; - - uint32_t last_clicked_region; - uint32_t last_clicked_hex; - uint32_t last_clicked_vertex; + EditorContext editor; } ClientContext; void* network_thread(void* data) { @@ -252,11 +256,11 @@ VkResult region_info_ui(ClientContext* context) { VkResult update_region_info_ui(ClientContext* context) { char temp[20]; VkResult result; - HexRegion* selected_region = context->hex->regions[context->selected_region]; + HexRegion* selected_region = context->hex->regions[context->editor.selected_region]; snprintf(temp, sizeof(temp), - "Region %4d", context->selected_region); + "Region %4d", context->editor.selected_region); VK_RESULT(update_ui_string(temp, 0, 0, 0, context->ui, context->render)); if(selected_region == NULL) { @@ -418,17 +422,17 @@ VkResult main_thread(ClientContext* context) { glfwPollEvents(); - if(context->last_clicked_region != context->hex->data.clicked_region || - context->last_clicked_hex != context->hex->data.clicked_hex || - context->last_clicked_vertex != context->hex->data.clicked_vertex) { - context->last_clicked_region = context->hex->data.clicked_region; - context->last_clicked_hex = context->hex->data.clicked_hex; - context->last_clicked_vertex = context->hex->data.clicked_vertex; + if(context->editor.last_clicked_region != context->hex->data.clicked_region || + context->editor.last_clicked_hex != context->hex->data.clicked_hex || + context->editor.last_clicked_vertex != context->hex->data.clicked_vertex) { + context->editor.last_clicked_region = context->hex->data.clicked_region; + context->editor.last_clicked_hex = context->hex->data.clicked_hex; + context->editor.last_clicked_vertex = context->hex->data.clicked_vertex; update_hex_info_ui(context); } - if(context->selected_region != context->last_selected_region) { - context->last_selected_region = context->selected_region; + if(context->editor.selected_region != context->editor.last_selected_region) { + context->editor.last_selected_region = context->editor.selected_region; update_region_info_ui(context); } @@ -577,34 +581,34 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod case GLFW_KEY_EQUAL: if(action == GLFW_PRESS) { - context->selected_region = add_hex_region(context); + context->editor.selected_region = add_hex_region(context); } break; case GLFW_KEY_LEFT_BRACKET: if(action == GLFW_PRESS) { - context->selected_region -= 1; - if(context->selected_region > MAX_LOADED_REGIONS) { - context->selected_region = MAX_LOADED_REGIONS; + context->editor.selected_region -= 1; + if(context->editor.selected_region > MAX_LOADED_REGIONS) { + context->editor.selected_region = MAX_LOADED_REGIONS; } } break; case GLFW_KEY_RIGHT_BRACKET: if(action == GLFW_PRESS) { - context->selected_region += 1; - if(context->selected_region > MAX_LOADED_REGIONS) { - context->selected_region = 0; + context->editor.selected_region += 1; + if(context->editor.selected_region > MAX_LOADED_REGIONS) { + context->editor.selected_region = 0; } } 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; + if(context->hex->regions[context->editor.selected_region] != NULL) { + context->hex->regions[context->editor.selected_region]->data.q += 1; add_transfer( - &context->hex->regions[context->selected_region]->data.q, - context->hex->regions[context->selected_region]->region, + &context->hex->regions[context->editor.selected_region]->data.q, + context->hex->regions[context->editor.selected_region]->region, offsetof(GPUHexRegion, q), sizeof(uint32_t), context->render->current_frame, @@ -615,11 +619,11 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod 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; + if(context->hex->regions[context->editor.selected_region] != NULL) { + context->hex->regions[context->editor.selected_region]->data.q -= 1; add_transfer( - &context->hex->regions[context->selected_region]->data.q, - context->hex->regions[context->selected_region]->region, + &context->hex->regions[context->editor.selected_region]->data.q, + context->hex->regions[context->editor.selected_region]->region, offsetof(GPUHexRegion, q), sizeof(uint32_t), context->render->current_frame, @@ -630,11 +634,11 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod 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; + if(context->hex->regions[context->editor.selected_region] != NULL) { + context->hex->regions[context->editor.selected_region]->data.r += 1; add_transfer( - &context->hex->regions[context->selected_region]->data.r, - context->hex->regions[context->selected_region]->region, + &context->hex->regions[context->editor.selected_region]->data.r, + context->hex->regions[context->editor.selected_region]->region, offsetof(GPUHexRegion, r), sizeof(uint32_t), context->render->current_frame, @@ -645,11 +649,11 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod 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; + if(context->hex->regions[context->editor.selected_region] != NULL) { + context->hex->regions[context->editor.selected_region]->data.r -= 1; add_transfer( - &context->hex->regions[context->selected_region]->data.r, - context->hex->regions[context->selected_region]->region, + &context->hex->regions[context->editor.selected_region]->data.r, + context->hex->regions[context->editor.selected_region]->region, offsetof(GPUHexRegion, r), sizeof(uint32_t), context->render->current_frame, @@ -660,11 +664,11 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod 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; + if(context->hex->regions[context->editor.selected_region] != NULL) { + context->hex->regions[context->editor.selected_region]->data.y += 1; add_transfer( - &context->hex->regions[context->selected_region]->data.y, - context->hex->regions[context->selected_region]->region, + &context->hex->regions[context->editor.selected_region]->data.y, + context->hex->regions[context->editor.selected_region]->region, offsetof(GPUHexRegion, y), sizeof(int32_t), context->render->current_frame, @@ -675,11 +679,11 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod 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; + if(context->hex->regions[context->editor.selected_region] != NULL) { + context->hex->regions[context->editor.selected_region]->data.y -= 1; add_transfer( - &context->hex->regions[context->selected_region]->data.y, - context->hex->regions[context->selected_region]->region, + &context->hex->regions[context->editor.selected_region]->data.y, + context->hex->regions[context->editor.selected_region]->region, offsetof(GPUHexRegion, y), sizeof(int32_t), context->render->current_frame, @@ -826,10 +830,12 @@ int main() { .zoom_speed = 1.0, .move_speed = 0.1, - .selected_region = MAX_LOADED_REGIONS, - .last_selected_region = 0, + .editor = { + .selected_region = MAX_LOADED_REGIONS, + .last_selected_region = 0, - .last_clicked_region = MAX_LOADED_REGIONS, + .last_clicked_region = MAX_LOADED_REGIONS, + }, }; if(context.window == NULL || context.render == NULL || context.ui == NULL || context.hex == NULL) { return VK_ERROR_OUT_OF_HOST_MEMORY;