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