2024-10-30 17:36:53 -06:00
|
|
|
#ifndef HEX_H
|
|
|
|
#define HEX_H
|
|
|
|
|
|
|
|
#include "gpu.h"
|
2024-11-24 21:44:36 -07:00
|
|
|
#include "vulkan/vulkan_core.h"
|
2024-10-30 17:36:53 -06:00
|
|
|
|
2024-11-24 21:44:36 -07:00
|
|
|
#define MAX_RAYS 10
|
|
|
|
#define MAX_HIGHLIGHTS 10
|
|
|
|
#define MAX_POINTS 10
|
|
|
|
|
|
|
|
#define MAX_LOADED_REGIONS 2500
|
2024-11-05 16:34:10 -07:00
|
|
|
#define REGION_SIZE 10
|
2024-11-01 17:34:41 -06:00
|
|
|
#define REGION_HEX_COUNT (3*REGION_SIZE*(REGION_SIZE-1)+1)
|
2024-11-05 16:34:10 -07:00
|
|
|
#define HEX_X 0.75
|
|
|
|
#define SQRT3 1.732050807568877193176604123436845839023590087890625
|
|
|
|
#define HEX_Z (SQRT3/2)
|
|
|
|
#define REGION_DIAMETER (2*REGION_SIZE-1)
|
|
|
|
#define REGION_WIDTH (HEX_X*REGION_DIAMETER)
|
|
|
|
#define REGION_HEIGHT (HEX_Z*REGION_DIAMETER)
|
2024-10-30 21:24:03 -06:00
|
|
|
|
2024-11-06 18:13:32 -07:00
|
|
|
#define max(a, b) ((a > b) ? a : b)
|
|
|
|
#define min(a, b) ((a < b) ? a : b)
|
|
|
|
|
2024-11-22 19:36:14 -07:00
|
|
|
typedef struct HexCoordStruct {
|
|
|
|
int32_t q;
|
|
|
|
int32_t r;
|
|
|
|
} HexCoord;
|
|
|
|
|
2024-11-06 17:50:42 -07:00
|
|
|
extern vec3 hex_vertices[];
|
|
|
|
extern vec3 hex_starts[];
|
|
|
|
extern vec3 hex_directions[];
|
2024-11-22 19:36:14 -07:00
|
|
|
extern HexCoord hex_starts_qr[];
|
|
|
|
extern HexCoord hex_directions_qr[];
|
2024-11-06 17:50:42 -07:00
|
|
|
extern int hex_indices[];
|
|
|
|
|
2024-11-01 17:34:41 -06:00
|
|
|
typedef struct GPUHexStruct {
|
|
|
|
float height[6];
|
2024-11-02 22:02:32 -06:00
|
|
|
uint32_t color[7];
|
2024-11-01 17:34:41 -06:00
|
|
|
} GPUHex;
|
|
|
|
|
|
|
|
typedef struct GPUHexRegionStruct {
|
2024-11-24 19:40:49 -07:00
|
|
|
HexCoord position;
|
2024-11-04 21:02:48 -07:00
|
|
|
int32_t y;
|
|
|
|
uint32_t map;
|
2024-11-01 17:34:41 -06:00
|
|
|
|
|
|
|
GPUHex hexes[REGION_HEX_COUNT];
|
|
|
|
} GPUHexRegion;
|
|
|
|
|
|
|
|
typedef struct HexRegionStruct {
|
|
|
|
VkDeviceAddress address;
|
|
|
|
VkBuffer region;
|
|
|
|
VmaAllocation region_memory;
|
2024-11-02 23:25:21 -06:00
|
|
|
|
2024-11-04 17:51:10 -07:00
|
|
|
GPUHexRegion data;
|
2024-11-01 17:34:41 -06:00
|
|
|
} HexRegion;
|
2024-10-30 17:36:53 -06:00
|
|
|
|
2024-11-24 21:44:36 -07:00
|
|
|
typedef struct GPURayStruct {
|
|
|
|
vec4 start;
|
|
|
|
vec4 end;
|
|
|
|
vec4 color;
|
|
|
|
} GPURay;
|
|
|
|
|
|
|
|
typedef struct GPUHighlightStruct {
|
|
|
|
vec4 color;
|
|
|
|
uint32_t region;
|
|
|
|
uint32_t hex;
|
|
|
|
float offset;
|
|
|
|
} GPUHighlight;
|
|
|
|
|
|
|
|
typedef struct GPUPointStruct {
|
|
|
|
vec4 color;
|
|
|
|
uint32_t region;
|
|
|
|
uint32_t hex;
|
|
|
|
uint32_t vertex;
|
|
|
|
float size;
|
|
|
|
float offset;
|
|
|
|
} GPUPoint;
|
|
|
|
|
2024-11-01 15:46:27 -06:00
|
|
|
typedef struct GPUHexContextStruct {
|
|
|
|
mat4 proj;
|
|
|
|
mat4 view;
|
2024-11-04 21:04:51 -07:00
|
|
|
uint32_t current_map;
|
2024-11-24 21:44:36 -07:00
|
|
|
VkDeviceAddress rays;
|
|
|
|
VkDeviceAddress points;
|
|
|
|
VkDeviceAddress highlights;
|
2024-11-01 17:34:41 -06:00
|
|
|
VkDeviceAddress regions[MAX_LOADED_REGIONS];
|
2024-11-01 15:46:27 -06:00
|
|
|
} GPUHexContext;
|
|
|
|
|
|
|
|
typedef struct HexContextStruct {
|
2024-11-06 17:50:42 -07:00
|
|
|
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VkBuffer context[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VmaAllocation context_memory[MAX_FRAMES_IN_FLIGHT];
|
2024-11-01 15:46:27 -06:00
|
|
|
|
2024-11-24 21:44:36 -07:00
|
|
|
VkBuffer rays[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VkBuffer points[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VkBuffer highlights[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VmaAllocation rays_memory[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VmaAllocation points_memory[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VmaAllocation highlights_memory[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
|
|
|
|
GPURay rays_buffer[MAX_RAYS];
|
|
|
|
GPUHighlight highlights_buffer[MAX_HIGHLIGHTS];
|
|
|
|
GPUPoint points_buffer[MAX_POINTS];
|
|
|
|
|
2024-11-07 20:01:31 -07:00
|
|
|
mat4 inverse;
|
|
|
|
|
2024-11-01 15:46:27 -06:00
|
|
|
GraphicsPipeline graphics;
|
2024-11-04 20:42:58 -07:00
|
|
|
GraphicsPipeline highlight_pipeline;
|
2024-11-09 21:51:23 -07:00
|
|
|
GraphicsPipeline point_pipeline;
|
2024-11-06 17:50:42 -07:00
|
|
|
GraphicsPipeline ray_pipeline;
|
2024-11-01 15:46:27 -06:00
|
|
|
|
2024-11-05 16:34:10 -07:00
|
|
|
HexRegion* regions[MAX_LOADED_REGIONS];
|
2024-11-01 15:46:27 -06:00
|
|
|
GPUHexContext data;
|
|
|
|
} HexContext;
|
|
|
|
|
2024-11-01 17:34:41 -06:00
|
|
|
typedef struct HexPushConstantStruct {
|
|
|
|
VkDeviceAddress context;
|
|
|
|
double time;
|
|
|
|
} HexPushConstant;
|
2024-11-01 15:46:27 -06:00
|
|
|
|
|
|
|
VkResult create_hex_context(
|
2024-11-06 18:13:32 -07:00
|
|
|
RenderContext* gpu,
|
|
|
|
HexContext* context);
|
2024-11-01 15:46:27 -06:00
|
|
|
|
2024-11-04 21:02:48 -07:00
|
|
|
VkResult set_hex_region(
|
2024-11-06 18:13:32 -07:00
|
|
|
HexRegion* region,
|
|
|
|
HexContext* hex,
|
|
|
|
RenderContext* gpu);
|
|
|
|
|
|
|
|
VkResult allocate_hex_region(
|
|
|
|
int32_t q, int32_t r, int32_t y,
|
|
|
|
uint32_t map,
|
|
|
|
HexRegion** region,
|
|
|
|
HexContext* hex,
|
|
|
|
RenderContext* gpu);
|
|
|
|
|
2024-11-24 19:40:49 -07:00
|
|
|
VkResult free_hex_region(
|
|
|
|
uint32_t region_index,
|
|
|
|
HexContext* hex,
|
|
|
|
RenderContext* gpu);
|
|
|
|
|
2024-11-06 18:13:32 -07:00
|
|
|
bool ray_world_intersect(
|
|
|
|
float* distance,
|
2024-11-09 21:51:23 -07:00
|
|
|
uint32_t* vertex,
|
2024-11-06 18:13:32 -07:00
|
|
|
uint32_t* rid,
|
|
|
|
uint32_t* hid,
|
|
|
|
vec4 ray_start,
|
|
|
|
vec4 ray_end,
|
|
|
|
HexContext* context);
|
|
|
|
|
|
|
|
VkResult update_hex_proj(
|
|
|
|
RenderContext* gpu,
|
|
|
|
HexContext* hex);
|
|
|
|
|
|
|
|
VkResult update_hex_view(
|
|
|
|
vec3 position,
|
|
|
|
vec2 rotation,
|
|
|
|
double distance,
|
|
|
|
RenderContext* gpu,
|
|
|
|
HexContext* hex);
|
2024-10-30 17:36:53 -06:00
|
|
|
|
2024-11-22 19:36:14 -07:00
|
|
|
void hex_qr(uint32_t hex, HexCoord* world);
|
|
|
|
|
|
|
|
void region_qr(HexCoord region, HexCoord* world);
|
|
|
|
|
|
|
|
void hex_add(HexCoord from, HexCoord* to);
|
|
|
|
|
|
|
|
void hex_index(HexCoord world, HexCoord* region, uint32_t* hex);
|
|
|
|
|
2024-11-24 19:40:49 -07:00
|
|
|
void hex_vertex_neighbors(
|
|
|
|
uint32_t vertex, HexCoord hex,
|
|
|
|
uint32_t n_vertex[2], HexCoord n_region[2], uint32_t n_hex[2]);
|
|
|
|
|
|
|
|
void first_matching_region(HexCoord coord, int y, uint32_t* region, HexContext* context);
|
|
|
|
|
2024-10-30 17:36:53 -06:00
|
|
|
#endif
|