|
|
@ -17,6 +17,7 @@ typedef struct ClientContextStruct {
|
|
|
|
GLFWwindow* window;
|
|
|
|
GLFWwindow* window;
|
|
|
|
RenderContext render;
|
|
|
|
RenderContext render;
|
|
|
|
UIContext ui;
|
|
|
|
UIContext ui;
|
|
|
|
|
|
|
|
HexContext hex;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t clicked_container;
|
|
|
|
uint32_t clicked_container;
|
|
|
|
uint32_t clicked_element;
|
|
|
|
uint32_t clicked_element;
|
|
|
@ -51,9 +52,6 @@ vec3 up = {0, 1, 0};
|
|
|
|
VkResult main_thread(ClientContext* context) {
|
|
|
|
VkResult main_thread(ClientContext* context) {
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsPipeline graphics;
|
|
|
|
|
|
|
|
ComputePipeline compute;
|
|
|
|
|
|
|
|
VK_RESULT(create_hex_pipeline(context->render.device, context->render.render_pass, &graphics, &compute));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GPUString strings[] = {
|
|
|
|
GPUString strings[] = {
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -124,17 +122,13 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
4*sizeof(uint32_t),
|
|
|
|
4*sizeof(uint32_t),
|
|
|
|
&context->render));
|
|
|
|
&context->render));
|
|
|
|
|
|
|
|
|
|
|
|
VkBuffer hex_context;
|
|
|
|
HexRegion region;
|
|
|
|
VmaAllocation hex_context_memory;
|
|
|
|
VK_RESULT(create_hex_region(0, 0, ®ion, &context->render));
|
|
|
|
GPUHexContext hex;
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(context->render.allocator, 0, sizeof(GPUHexContext), &hex_context, &hex_context_memory));
|
|
|
|
|
|
|
|
VkDeviceAddress hex_context_address = buffer_address(context->render.device, hex_context);
|
|
|
|
|
|
|
|
glm_perspective(30.0, (float)context->render.swapchain_extent.width/(float)context->render.swapchain_extent.height, 0.01, 99.9, hex.proj);
|
|
|
|
|
|
|
|
context->position[0] = 0;
|
|
|
|
context->position[0] = 0;
|
|
|
|
context->position[1] = 0;
|
|
|
|
context->position[1] = 0;
|
|
|
|
context->position[2] = 0;
|
|
|
|
context->position[2] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
context->rotation[0] = 0;
|
|
|
|
context->rotation[0] = 3*M_PI/2;
|
|
|
|
context->rotation[1] = 0;
|
|
|
|
context->rotation[1] = 0;
|
|
|
|
context->cur_spin[0] = 0;
|
|
|
|
context->cur_spin[0] = 0;
|
|
|
|
context->cur_spin[1] = 0;
|
|
|
|
context->cur_spin[1] = 0;
|
|
|
@ -143,7 +137,7 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
context->key_spin[1] = 0;
|
|
|
|
context->key_spin[1] = 0;
|
|
|
|
context->cur_spin[0] = 0;
|
|
|
|
context->cur_spin[0] = 0;
|
|
|
|
context->cur_spin[1] = 0;
|
|
|
|
context->cur_spin[1] = 0;
|
|
|
|
context->distance = 1;
|
|
|
|
context->distance = 10;
|
|
|
|
context->zoom = 0;
|
|
|
|
context->zoom = 0;
|
|
|
|
context->camera_mode = false;
|
|
|
|
context->camera_mode = false;
|
|
|
|
context->key_spin_speed = 1.0;
|
|
|
|
context->key_spin_speed = 1.0;
|
|
|
@ -154,7 +148,6 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
uint32_t* mapped_codes = context->ui.containers[0].layers[0].codes_buffer;
|
|
|
|
uint32_t* mapped_codes = context->ui.containers[0].layers[0].codes_buffer;
|
|
|
|
GPUString* mapped_string = context->ui.containers[0].layers[0].strings_buffer;
|
|
|
|
GPUString* mapped_string = context->ui.containers[0].layers[0].strings_buffer;
|
|
|
|
char str[21];
|
|
|
|
char str[21];
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double last_frame_time = glfwGetTime();
|
|
|
|
double last_frame_time = glfwGetTime();
|
|
|
|
while(glfwWindowShouldClose(context->window) == 0) {
|
|
|
|
while(glfwWindowShouldClose(context->window) == 0) {
|
|
|
@ -183,8 +176,8 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
|
|
|
|
|
|
|
|
context->rotation[1] += (float)context->key_spin[1]*delta_time*context->key_spin_speed;
|
|
|
|
context->rotation[1] += (float)context->key_spin[1]*delta_time*context->key_spin_speed;
|
|
|
|
context->rotation[1] += (float)context->cur_spin[1]*delta_time*context->cur_spin_speed;
|
|
|
|
context->rotation[1] += (float)context->cur_spin[1]*delta_time*context->cur_spin_speed;
|
|
|
|
if(context->rotation[1] > M_PI/2) {
|
|
|
|
if(context->rotation[1] > (M_PI/2 - 0.1)) {
|
|
|
|
context->rotation[1] = M_PI/2;
|
|
|
|
context->rotation[1] = (M_PI/2 - 0.1);
|
|
|
|
} else if(context->rotation[1] < 0) {
|
|
|
|
} else if(context->rotation[1] < 0) {
|
|
|
|
context->rotation[1] = 0;
|
|
|
|
context->rotation[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -198,9 +191,9 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
camera[0] = context->position[0] + context->distance*cos(context->rotation[1])*cos(context->rotation[0]);
|
|
|
|
camera[0] = context->position[0] + context->distance*cos(context->rotation[1])*cos(context->rotation[0]);
|
|
|
|
camera[1] = context->position[1] + context->distance*sin(context->rotation[1]);
|
|
|
|
camera[1] = context->position[1] + context->distance*sin(context->rotation[1]);
|
|
|
|
camera[2] = context->position[2] + context->distance*cos(context->rotation[1])*sin(context->rotation[0]);
|
|
|
|
camera[2] = context->position[2] + context->distance*cos(context->rotation[1])*sin(context->rotation[0]);
|
|
|
|
glm_lookat(camera, context->position, up, hex.view);
|
|
|
|
glm_lookat(camera, context->position, up, context->hex.data.view);
|
|
|
|
|
|
|
|
add_transfer(&context->hex.data, context->hex.context, 0, sizeof(GPUHexContext), 0, &context->render);
|
|
|
|
add_transfer(&hex, hex_context, 0, sizeof(GPUHexContext), (context->render.current_frame + 1) % MAX_FRAMES_IN_FLIGHT, &context->render);
|
|
|
|
add_transfer(&context->hex.data, context->hex.context, 0, sizeof(GPUHexContext), 1, &context->render);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(context->clicked_container != 0) {
|
|
|
|
if(context->clicked_container != 0) {
|
|
|
@ -223,7 +216,7 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
VkResult result = draw_frame(&context->render, &context->ui, &graphics, hex_context_address, frame_time);
|
|
|
|
VkResult result = draw_frame(&context->render, &context->ui, &context->hex, frame_time);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
fprintf(stderr, "draw_frame error: %s\n", string_VkResult(result));
|
|
|
|
fprintf(stderr, "draw_frame error: %s\n", string_VkResult(result));
|
|
|
|
glfwDestroyWindow(context->window);
|
|
|
|
glfwDestroyWindow(context->window);
|
|
|
@ -365,6 +358,7 @@ int main() {
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: make # of fonts/textures/containers scaling, recreate GPU buffers as necessary
|
|
|
|
// TODO: make # of fonts/textures/containers scaling, recreate GPU buffers as necessary
|
|
|
|
VK_RESULT(create_ui_context(10, 10, 10, &context.render, &context.ui));
|
|
|
|
VK_RESULT(create_ui_context(10, 10, 10, &context.render, &context.ui));
|
|
|
|
|
|
|
|
VK_RESULT(create_hex_context(&context.render, &context.hex));
|
|
|
|
|
|
|
|
|
|
|
|
pthread_t network_thread_handle;
|
|
|
|
pthread_t network_thread_handle;
|
|
|
|
|
|
|
|
|
|
|
|