|
|
@ -12,6 +12,9 @@
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "pthread.h"
|
|
|
|
#include "pthread.h"
|
|
|
|
#include <math.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define max(a, b) ((a > b) ? a : b)
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct ClientContextStruct {
|
|
|
|
typedef struct ClientContextStruct {
|
|
|
|
GLFWwindow* window;
|
|
|
|
GLFWwindow* window;
|
|
|
@ -21,6 +24,7 @@ typedef struct ClientContextStruct {
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t clicked_container;
|
|
|
|
uint32_t clicked_container;
|
|
|
|
uint32_t clicked_element;
|
|
|
|
uint32_t clicked_element;
|
|
|
|
|
|
|
|
int32_t clicked_hex[2];
|
|
|
|
|
|
|
|
|
|
|
|
vec2 cursor;
|
|
|
|
vec2 cursor;
|
|
|
|
|
|
|
|
|
|
|
@ -62,45 +66,14 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
.length = 0,
|
|
|
|
.length = 0,
|
|
|
|
.font = 0,
|
|
|
|
.font = 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
.pos = {110, 138},
|
|
|
|
|
|
|
|
.size = 32,
|
|
|
|
|
|
|
|
.color = {1.0, 1.0, 1.0, 1.0},
|
|
|
|
|
|
|
|
.offset = 20,
|
|
|
|
|
|
|
|
.length = 1,
|
|
|
|
|
|
|
|
.font = 0,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
.pos = {210, 138},
|
|
|
|
|
|
|
|
.size = 32,
|
|
|
|
|
|
|
|
.color = {1.0, 1.0, 1.0, 1.0},
|
|
|
|
|
|
|
|
.offset = 21,
|
|
|
|
|
|
|
|
.length = 1,
|
|
|
|
|
|
|
|
.font = 0,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GPUDrawable drawables[] = {
|
|
|
|
GPUDrawable drawables[] = {};
|
|
|
|
{
|
|
|
|
|
|
|
|
.pos = {100, 100},
|
|
|
|
|
|
|
|
.size = {50, 50},
|
|
|
|
|
|
|
|
.color = {1, 0, 0, 1},
|
|
|
|
|
|
|
|
.type = 0,
|
|
|
|
|
|
|
|
.id = 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
.pos = {200, 100},
|
|
|
|
|
|
|
|
.size = {50, 50},
|
|
|
|
|
|
|
|
.color = {0, 1, 0, 1},
|
|
|
|
|
|
|
|
.type = 0,
|
|
|
|
|
|
|
|
.id = 2,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LayerInput layer = {
|
|
|
|
LayerInput layer = {
|
|
|
|
.strings = strings,
|
|
|
|
.strings = strings,
|
|
|
|
.num_strings = sizeof(strings)/sizeof(GPUString),
|
|
|
|
.num_strings = sizeof(strings)/sizeof(GPUString),
|
|
|
|
.max_codes = 24,
|
|
|
|
.max_codes = 50,
|
|
|
|
|
|
|
|
|
|
|
|
.drawables = drawables,
|
|
|
|
.drawables = drawables,
|
|
|
|
.num_drawables = sizeof(drawables)/sizeof(GPUDrawable),
|
|
|
|
.num_drawables = sizeof(drawables)/sizeof(GPUDrawable),
|
|
|
@ -114,57 +87,30 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
create_container(&container, &context->render, &context->ui);
|
|
|
|
create_container(&container, &context->render, &context->ui);
|
|
|
|
map_string("1234", context->ui.containers[0].layers[0].codes_buffer, 20, 0, &context->ui);
|
|
|
|
|
|
|
|
VK_RESULT(add_transfers(
|
|
|
|
|
|
|
|
&context->ui.containers[0].layers[0].codes_buffer[20],
|
|
|
|
|
|
|
|
context->ui.containers[0].layers[0].codes,
|
|
|
|
|
|
|
|
20*sizeof(uint32_t),
|
|
|
|
|
|
|
|
4*sizeof(uint32_t),
|
|
|
|
|
|
|
|
&context->render));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HexRegion* regions[MAX_LOADED_REGIONS];
|
|
|
|
HexRegion* regions[MAX_LOADED_REGIONS];
|
|
|
|
uint32_t colors[] = {
|
|
|
|
uint32_t colors[] = {
|
|
|
|
0xFF0000FF,
|
|
|
|
0xFF0000FF,
|
|
|
|
0x00FF00FF,
|
|
|
|
0x00FF00FF,
|
|
|
|
0x00FF00FF,
|
|
|
|
|
|
|
|
0x00FF00FF,
|
|
|
|
|
|
|
|
0x00FF00FF,
|
|
|
|
|
|
|
|
0x00FF00FF,
|
|
|
|
|
|
|
|
0x00FF00FF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
|
|
|
|
0x0000FFFF,
|
|
|
|
0x0000FFFF,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GPUHex* temp_hexes = malloc(sizeof(GPUHex)*REGION_HEX_COUNT);
|
|
|
|
|
|
|
|
uint32_t region = 0;
|
|
|
|
uint32_t region = 0;
|
|
|
|
for(int32_t q = -5; q < 5; q++) {
|
|
|
|
for(int32_t q = -10; q < 10; q++) {
|
|
|
|
for(int32_t r = -5; r < 5; r++) {
|
|
|
|
for(int32_t r = -10; r < 10; r++) {
|
|
|
|
VK_RESULT(create_hex_region(q, r, ®ions[region], &context->hex, &context->render));
|
|
|
|
VK_RESULT(create_hex_region(q, r, ®ions[region], &context->hex, &context->render));
|
|
|
|
for(uint32_t i = 0; i < REGION_HEX_COUNT; i++) {
|
|
|
|
for(uint32_t i = 0; i < REGION_HEX_COUNT; i++) {
|
|
|
|
for(uint32_t h = 0; h < 6; h++) {
|
|
|
|
for(uint32_t h = 0; h < 6; h++) {
|
|
|
|
temp_hexes[i].color[h] = colors[r % (sizeof(colors)/sizeof(uint32_t))];
|
|
|
|
regions[region]->data[i].color[h] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))];
|
|
|
|
temp_hexes[i].height[h] = 0;
|
|
|
|
regions[region]->data[i].height[h] = (float)i/REGION_HEX_COUNT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp_hexes[i].color[6] = colors[r % (sizeof(colors)/sizeof(uint32_t))];
|
|
|
|
regions[region]->data[i].color[6] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VK_RESULT(add_transfer(temp_hexes, regions[region]->region, offsetof(GPUHexRegion, hexes), sizeof(GPUHex)*REGION_HEX_COUNT, 0, &context->render));
|
|
|
|
VK_RESULT(add_transfer(®ions[region]->data, regions[region]->region, offsetof(GPUHexRegion, hexes), sizeof(GPUHex)*REGION_HEX_COUNT, 0, &context->render));
|
|
|
|
region++;
|
|
|
|
region++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(temp_hexes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context->position[0] = 0;
|
|
|
|
context->position[0] = 0;
|
|
|
|
context->position[1] = 0;
|
|
|
|
context->position[1] = 0;
|
|
|
|
context->position[2] = 0;
|
|
|
|
context->position[2] = 0;
|
|
|
@ -178,7 +124,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 = 50;
|
|
|
|
context->distance = 25;
|
|
|
|
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;
|
|
|
@ -188,15 +134,18 @@ 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[51];
|
|
|
|
|
|
|
|
|
|
|
|
double last_frame_time = 0;
|
|
|
|
double last_frame_time = 0;
|
|
|
|
|
|
|
|
int frame = 0;
|
|
|
|
while(glfwWindowShouldClose(context->window) == 0) {
|
|
|
|
while(glfwWindowShouldClose(context->window) == 0) {
|
|
|
|
double frame_time = glfwGetTime();
|
|
|
|
double frame_time = glfwGetTime();
|
|
|
|
double delta_time = (frame_time - last_frame_time);
|
|
|
|
double delta_time = (frame_time - last_frame_time);
|
|
|
|
|
|
|
|
|
|
|
|
context->clicked_element = 0x00000000;
|
|
|
|
context->clicked_element = 0x00000000;
|
|
|
|
context->clicked_container = 0x00000000;
|
|
|
|
context->clicked_container = 0x00000000;
|
|
|
|
|
|
|
|
context->clicked_hex[0] = 0;
|
|
|
|
|
|
|
|
context->clicked_hex[1] = 0;
|
|
|
|
context->zoom = 0;
|
|
|
|
context->zoom = 0;
|
|
|
|
context->cur_spin[0] = 0;
|
|
|
|
context->cur_spin[0] = 0;
|
|
|
|
context->cur_spin[1] = 0;
|
|
|
|
context->cur_spin[1] = 0;
|
|
|
@ -205,8 +154,7 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
|
|
|
|
|
|
|
|
if(context->key_spin[0] != 0 || context->key_spin[1] != 0 ||
|
|
|
|
if(context->key_spin[0] != 0 || context->key_spin[1] != 0 ||
|
|
|
|
context->zoom != 0 ||
|
|
|
|
context->zoom != 0 ||
|
|
|
|
context->cur_spin[0] != 0 || context->cur_spin[1] != 0 ||
|
|
|
|
context->cur_spin[0] != 0 || context->cur_spin[1] != 0 || frame == 1) {
|
|
|
|
last_frame_time == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context->rotation[0] += (float)context->key_spin[0]*delta_time*context->key_spin_speed;
|
|
|
|
context->rotation[0] += (float)context->key_spin[0]*delta_time*context->key_spin_speed;
|
|
|
|
context->rotation[0] += (float)context->cur_spin[0]*delta_time*context->cur_spin_speed;
|
|
|
|
context->rotation[0] += (float)context->cur_spin[0]*delta_time*context->cur_spin_speed;
|
|
|
@ -238,7 +186,9 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
vec2 hex_forward = {};
|
|
|
|
vec2 hex_forward = {};
|
|
|
|
|
|
|
|
|
|
|
|
hex_pos[0] = camera[0];
|
|
|
|
hex_pos[0] = camera[0];
|
|
|
|
hex_pos[1] = camera[2] - camera[0]/2;
|
|
|
|
hex_pos[1] = -camera[2] + camera[0]/2;
|
|
|
|
|
|
|
|
hex_forward[0] = 0;
|
|
|
|
|
|
|
|
hex_forward[1] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
glm_lookat(camera, context->position, up, context->hex.data.view);
|
|
|
|
glm_lookat(camera, context->position, up, context->hex.data.view);
|
|
|
|
add_transfer(&context->hex.data, context->hex.context, 0, 2*sizeof(mat4), context->render.current_frame, &context->render);
|
|
|
|
add_transfer(&context->hex.data, context->hex.context, 0, 2*sizeof(mat4), context->render.current_frame, &context->render);
|
|
|
@ -246,8 +196,8 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
add_transfer(hex_forward, context->hex.context, offsetof(GPUHexContext, forward), sizeof(vec2), context->render.current_frame, &context->render);
|
|
|
|
add_transfer(hex_forward, context->hex.context, offsetof(GPUHexContext, forward), sizeof(vec2), context->render.current_frame, &context->render);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(context->clicked_container != 0) {
|
|
|
|
if(context->clicked_hex[0] != 0 || context->clicked_hex[1] != 0) {
|
|
|
|
snprintf(str, 21, "Clicked: %d.%d", context->clicked_container, context->clicked_element);
|
|
|
|
snprintf(str, 50, "Clicked: (%d,%d)", context->clicked_hex[0], context->clicked_hex[1]);
|
|
|
|
map_string(str, mapped_codes, 0, 0, &context->ui);
|
|
|
|
map_string(str, mapped_codes, 0, 0, &context->ui);
|
|
|
|
VK_RESULT(add_transfers(
|
|
|
|
VK_RESULT(add_transfers(
|
|
|
|
context->ui.containers[0].layers[0].codes_buffer,
|
|
|
|
context->ui.containers[0].layers[0].codes_buffer,
|
|
|
@ -264,6 +214,7 @@ VkResult main_thread(ClientContext* context) {
|
|
|
|
&context->render));
|
|
|
|
&context->render));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame += 1;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
VkResult result = draw_frame(&context->render, &context->ui, &context->hex, frame_time);
|
|
|
|
VkResult result = draw_frame(&context->render, &context->ui, &context->hex, frame_time);
|
|
|
|