From 1d85024a6a97a1d713c19c95b412ffa98eaf8549 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 4 Nov 2024 00:44:21 -0700 Subject: [PATCH] Cleanup --- client/include/hex.h | 1 - client/src/hex.c | 54 +++++++------------------------------------- client/src/main.c | 28 +++++++---------------- 3 files changed, 16 insertions(+), 67 deletions(-) diff --git a/client/include/hex.h b/client/include/hex.h index a2f98bd..8293911 100644 --- a/client/include/hex.h +++ b/client/include/hex.h @@ -44,7 +44,6 @@ typedef struct HexContextStruct { VmaAllocation context_memory; GraphicsPipeline graphics; - ComputePipeline compute; HexRegion regions[MAX_LOADED_REGIONS]; diff --git a/client/src/hex.c b/client/src/hex.c index afe406c..eeb251e 100644 --- a/client/src/hex.c +++ b/client/src/hex.c @@ -8,49 +8,11 @@ VkResult create_hex_context( RenderContext* gpu, HexContext* context) { VkResult result; - - // Compute Pipeline - - VkShaderModule compute_shader = load_shader_file("shader/hex.comp.spv", gpu->device); - if(compute_shader == VK_NULL_HANDLE) { - return VK_ERROR_UNKNOWN; - } - - VkPipelineShaderStageCreateInfo compute_shader_stage = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .pName = "main", - .module = compute_shader, - }; - - VkPushConstantRange compute_push = { - .size = sizeof(HexPushConstant), - .offset = 0, - .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, - }; - - VkPipelineLayoutCreateInfo compute_layout_info = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .pPushConstantRanges = &compute_push, - .pushConstantRangeCount = 1, - }; - - VK_RESULT(vkCreatePipelineLayout(gpu->device, &compute_layout_info, NULL, &context->compute.layout)); - - VkComputePipelineCreateInfo compute_pipeline_info = { - .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, - .stage = compute_shader_stage, - .layout = context->compute.layout, - }; - - VK_RESULT(vkCreateComputePipelines(gpu->device, VK_NULL_HANDLE, 1, &compute_pipeline_info, NULL, &context->compute.pipeline)); - - // Graphics Pipeline - + VkShaderModule vert_shader = load_shader_file("shader/hex.vert.spv", gpu->device); VkShaderModule frag_shader = load_shader_file("shader/hex.frag.spv", gpu->device); - VkPipelineShaderStageCreateInfo graphics_stages[] = { + VkPipelineShaderStageCreateInfo stages[] = { { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, @@ -65,19 +27,19 @@ VkResult create_hex_context( }, }; - VkPushConstantRange graphics_push = { + VkPushConstantRange push = { .size = sizeof(HexPushConstant), .offset = 0, .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, }; - VkPipelineLayoutCreateInfo graphics_layout_info = { + VkPipelineLayoutCreateInfo layout_info = { .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .pPushConstantRanges = &graphics_push, + .pPushConstantRanges = &push, .pushConstantRangeCount = 1, }; - VK_RESULT(vkCreatePipelineLayout(gpu->device, &graphics_layout_info, NULL, &context->graphics.layout)); + VK_RESULT(vkCreatePipelineLayout(gpu->device, &layout_info, NULL, &context->graphics.layout)); VkPipelineVertexInputStateCreateInfo vertex_info = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, @@ -177,8 +139,8 @@ VkResult create_hex_context( VkGraphicsPipelineCreateInfo graphics_pipeline_info = { .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .layout = context->graphics.layout, - .stageCount = sizeof(graphics_stages)/sizeof(VkPipelineShaderStageCreateInfo), - .pStages = graphics_stages, + .stageCount = sizeof(stages)/sizeof(VkPipelineShaderStageCreateInfo), + .pStages = stages, .pVertexInputState = &vertex_info, .pInputAssemblyState = &input_info, .pViewportState = &viewport_info, diff --git a/client/src/main.c b/client/src/main.c index 116dd7d..cc8f007 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -117,26 +117,6 @@ VkResult main_thread(ClientContext* context) { } } - context->position[0] = 0; - context->position[1] = 0; - context->position[2] = 0; - - context->rotation[0] = 3*M_PI/2; - context->rotation[1] = M_PI/4; - context->cur_spin[0] = 0; - context->cur_spin[1] = 0; - - context->key_spin[0] = 0; - context->key_spin[1] = 0; - context->cur_spin[0] = 0; - context->cur_spin[1] = 0; - context->distance = 25; - context->zoom = 0; - context->camera_mode = false; - context->key_spin_speed = 1.0; - context->cur_spin_speed = 1.0; - context->zoom_speed = 1.0; - // uint32_t* mapped_codes = context->ui->containers[0].layers[0].codes_buffer; GPUString* mapped_string = context->ui->containers[0].layers[0].strings_buffer; @@ -148,6 +128,7 @@ VkResult main_thread(ClientContext* context) { double frame_time = glfwGetTime(); double delta_time = (frame_time - last_frame_time); + // Reset callback variables context->clicked_element = 0x00000000; context->clicked_container = 0x00000000; context->clicked_hex[0] = 0; @@ -395,6 +376,13 @@ int main() { .ui = malloc(sizeof(UIContext)), .hex = malloc(sizeof(HexContext)), .window = init_window(), + + .position = {0, 0, 0}, + .rotation = {3*M_PI/2, M_PI/4}, + .distance = 25, + .key_spin_speed = 1.0, + .cur_spin_speed = 1.0, + .zoom_speed = 1.0, }; if(context.window == NULL || context.render == NULL || context.ui == NULL || context.hex == NULL) { return VK_ERROR_OUT_OF_HOST_MEMORY;