From 9eca26db4ecf3b08d3d2fe35d75ae6f35fcb353b Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 4 Nov 2024 21:02:48 -0700 Subject: [PATCH] Added support for multiple regions on the same q,r but different y, added map ID to region --- client/include/hex.h | 7 +++++-- client/shader/hex.vert | 10 +++++++--- client/shader/hex_common.glsl | 2 ++ client/shader/hex_highlight.vert | 4 ++-- client/src/hex.c | 6 ++++-- client/src/main.c | 22 ++++++++++++---------- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/client/include/hex.h b/client/include/hex.h index 17d44f5..fdd35f1 100644 --- a/client/include/hex.h +++ b/client/include/hex.h @@ -15,6 +15,8 @@ typedef struct GPUHexStruct { typedef struct GPUHexRegionStruct { int32_t q; int32_t r; + int32_t y; + uint32_t map; GPUHex hexes[REGION_HEX_COUNT]; } GPUHexRegion; @@ -64,8 +66,9 @@ VkResult create_hex_context( RenderContext* gpu, HexContext* context); -VkResult create_hex_region( - int32_t q, int32_t r, +VkResult set_hex_region( + int32_t q, int32_t r, int32_t y, + uint32_t map, HexRegion** region, HexContext* hex, RenderContext* gpu); diff --git a/client/shader/hex.vert b/client/shader/hex.vert index e1e27ba..1e566f8 100644 --- a/client/shader/hex.vert +++ b/client/shader/hex.vert @@ -15,9 +15,13 @@ vec4 int2color(uint color_int) { void main() { int region_index = gl_InstanceIndex/region_hex_count; - int hex_index = gl_InstanceIndex - (region_index*region_hex_count); Region region = pc.context.regions[region_index]; + if(region.map == 0) { + gl_Position = vec4(0, 0, 0, 0); + return; + } + int hex_index = gl_InstanceIndex - (region_index*region_hex_count); vec2 region_qr = vec2(region.q, region.r); vec4 region_pos = vec4(0, 0, 0, 0); @@ -40,9 +44,9 @@ void main() { region.hexes[hex_index].heights[2] + region.hexes[hex_index].heights[3] + region.hexes[hex_index].heights[4] + - region.hexes[hex_index].heights[5])/6; + region.hexes[hex_index].heights[5])/6 + region.y; } else { - position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1]; + position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1] + region.y; } color = int2color(region.hexes[hex_index].colors[indices[gl_VertexIndex]]); diff --git a/client/shader/hex_common.glsl b/client/shader/hex_common.glsl index 03df02c..eb56d1e 100644 --- a/client/shader/hex_common.glsl +++ b/client/shader/hex_common.glsl @@ -6,6 +6,8 @@ struct Hex { layout(std430, buffer_reference) readonly buffer Region { int q; int r; + int y; + uint map; Hex hexes[]; }; diff --git a/client/shader/hex_highlight.vert b/client/shader/hex_highlight.vert index 40dec01..6adff12 100644 --- a/client/shader/hex_highlight.vert +++ b/client/shader/hex_highlight.vert @@ -47,9 +47,9 @@ void main() { region.hexes[hex_index].heights[2] + region.hexes[hex_index].heights[3] + region.hexes[hex_index].heights[4] + - region.hexes[hex_index].heights[5])/6; + region.hexes[hex_index].heights[5])/6 + region.y; } else { - position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1]; + position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1] + region.y; } position.y += raise; diff --git a/client/src/hex.c b/client/src/hex.c index 9d1bfb2..b0d10ce 100644 --- a/client/src/hex.c +++ b/client/src/hex.c @@ -492,7 +492,7 @@ VkResult create_hex_context( return VK_SUCCESS; } -VkResult create_hex_region(int32_t q, int32_t r, HexRegion** region, HexContext* hex, RenderContext* gpu) { +VkResult set_hex_region(int32_t q, int32_t r, int32_t y, uint32_t map, HexRegion** region, HexContext* hex, RenderContext* gpu) { VkResult result; uint32_t i = 0; @@ -509,13 +509,15 @@ VkResult create_hex_region(int32_t q, int32_t r, HexRegion** region, HexContext* (*region)->data.q = q; (*region)->data.r = r; + (*region)->data.y = y; + (*region)->data.map = map; VK_RESULT(create_storage_buffer( gpu->allocator, 0, sizeof(GPUHexRegion), &(*region)->region, &(*region)->region_memory)); - VK_RESULT(add_transfer(&(*region)->data.q, (*region)->region, offsetof(GPUHexRegion, q), sizeof(uint32_t)*2, gpu->current_frame, gpu)); + VK_RESULT(add_transfer(&(*region)->data.q, (*region)->region, offsetof(GPUHexRegion, q), sizeof(int32_t)*3 + sizeof(uint32_t), gpu->current_frame, gpu)); (*region)->address = buffer_address(gpu->device, (*region)->region); diff --git a/client/src/main.c b/client/src/main.c index 75cb0c7..3165d2a 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -100,18 +100,20 @@ VkResult main_thread(ClientContext* context) { }; uint32_t region = 0; - for(int32_t q = -10; q < 10; q++) { - for(int32_t r = -10; r < 10; r++) { - 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 h = 0; h < 6; h++) { - regions[region]->data.hexes[i].color[h] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))]; - regions[region]->data.hexes[i].height[h] = (float)i/REGION_HEX_COUNT; + for(int32_t y = -2; y < 2; y++) { + for(int32_t q = -5; q < 5; q++) { + for(int32_t r = -5; r < 5; r++) { + VK_RESULT(set_hex_region(q, r, y, 0x01, ®ions[region], context->hex, context->render)); + for(uint32_t i = 0; i < REGION_HEX_COUNT; i++) { + for(uint32_t h = 0; h < 6; h++) { + regions[region]->data.hexes[i].color[h] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))]; + regions[region]->data.hexes[i].height[h] = (float)i/REGION_HEX_COUNT; + } + regions[region]->data.hexes[i].color[6] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))]; } - regions[region]->data.hexes[i].color[6] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))]; + VK_RESULT(add_transfer(®ions[region]->data.hexes, regions[region]->region, offsetof(GPUHexRegion, hexes), sizeof(GPUHex)*REGION_HEX_COUNT, 0, context->render)); + region++; } - VK_RESULT(add_transfer(®ions[region]->data.hexes, regions[region]->region, offsetof(GPUHexRegion, hexes), sizeof(GPUHex)*REGION_HEX_COUNT, 0, context->render)); - region++; } }