2025-10-03 14:30:36 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
|
|
2025-10-04 17:24:30 +01:00
|
|
|
#define STB_IMAGE_IMPLEMENTATION 1
|
|
|
|
|
#include <stb_image.h>
|
|
|
|
|
|
2025-10-04 00:46:26 +01:00
|
|
|
#include "core/core.h"
|
2025-10-04 14:57:09 +01:00
|
|
|
#include "core/types.h"
|
2025-10-05 00:25:37 +01:00
|
|
|
#include "game/npc.h"
|
2025-10-04 00:46:26 +01:00
|
|
|
#include "os/core.h"
|
2025-10-03 20:04:40 +01:00
|
|
|
|
|
|
|
|
#include "vulkan/core.h"
|
2025-10-04 17:24:30 +01:00
|
|
|
#include "game/core.h"
|
2025-10-03 20:04:40 +01:00
|
|
|
|
2025-10-05 00:25:37 +01:00
|
|
|
#include "game/world.h"
|
|
|
|
|
#include "game/impl/npc.c"
|
|
|
|
|
#include "game/testnavmesh.h"
|
2025-10-03 20:04:40 +01:00
|
|
|
|
2025-10-03 14:30:36 +01:00
|
|
|
int main(int argc, char **argv) {
|
2025-10-03 20:04:40 +01:00
|
|
|
(void) argc;
|
|
|
|
|
(void) argv;
|
2025-10-04 15:53:55 +01:00
|
|
|
|
|
|
|
|
if (!SDL_Init(SDL_INIT_VIDEO))
|
|
|
|
|
{
|
2025-10-03 14:30:36 +01:00
|
|
|
printf("[Error] :: Failed to initialise SDL3 (%s)\n", SDL_GetError());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_Window *window = SDL_CreateWindow("Ludum", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
2025-10-04 15:53:55 +01:00
|
|
|
if (!window)
|
|
|
|
|
{
|
2025-10-03 14:30:36 +01:00
|
|
|
printf("[Error] :: Failed to create window (%s)\n", SDL_GetError());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 20:04:40 +01:00
|
|
|
Vk_Setup(window);
|
|
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
G_State *game = 0;
|
|
|
|
|
{
|
|
|
|
|
M_Arena *arena = M_ArenaAlloc(GB(64), .initial = MB(4));
|
|
|
|
|
game = M_ArenaPush(arena, G_State);
|
2025-10-04 17:24:30 +01:00
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
game->arena = arena;
|
|
|
|
|
|
|
|
|
|
G_ImagesLoad(game);
|
|
|
|
|
G_PipelinesLoad(game);
|
|
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
G_Camera *camera = &game->camera;
|
|
|
|
|
|
|
|
|
|
camera->x = (V3f) { 1, 0, 0 };
|
|
|
|
|
camera->y = (V3f) { 0, 1, 0 };
|
|
|
|
|
camera->z = (V3f) { 0, 0, 1 };
|
|
|
|
|
camera->p = (V3f) { 0, 0, 8 };
|
|
|
|
|
|
|
|
|
|
camera->fov = 60.0f;
|
2025-10-04 23:46:13 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
camera->nearp = 0.01f;
|
|
|
|
|
camera->farp = 1000.0f;
|
2025-10-04 23:46:13 +01:00
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
Vk_Buffer *vbo = &game->vbo;
|
|
|
|
|
vbo->size = KB(4096);
|
|
|
|
|
vbo->usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
|
|
|
|
vbo->host_visible = true;
|
|
|
|
|
|
|
|
|
|
Vk_BufferCreate(vbo);
|
|
|
|
|
|
|
|
|
|
G_Vertex *vertices = cast(G_Vertex *) vbo->data;
|
|
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
vertices[0] = (G_Vertex) { -0.25f, -0.625f, 1.0f, 1.0f, 0.0f, 0.0f, 0xFFFFFFFF, 1};
|
|
|
|
|
vertices[1] = (G_Vertex) { 0.25f, -0.625f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 1};
|
|
|
|
|
vertices[2] = (G_Vertex) { -0.25f, 0.625f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1};
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
vertices[3] = (G_Vertex) { 0.25f, -0.625f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 1};
|
|
|
|
|
vertices[4] = (G_Vertex) { 0.25f, 0.625f, 1.0f, 1.0f, 1.0f, 1.0f, 0xFFFFFFFF, 1};
|
|
|
|
|
vertices[5] = (G_Vertex) { -0.25f, 0.625f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1};
|
2025-10-04 21:42:04 +01:00
|
|
|
}
|
2025-10-04 17:24:30 +01:00
|
|
|
|
2025-10-03 14:30:36 +01:00
|
|
|
bool running = true;
|
2025-10-04 15:53:55 +01:00
|
|
|
Player player;
|
|
|
|
|
player.pos.x = 0;
|
|
|
|
|
player.pos.y = 0;
|
2025-10-05 00:25:37 +01:00
|
|
|
World world = {
|
|
|
|
|
.npcCount = 2,
|
|
|
|
|
.npcs = {
|
|
|
|
|
{
|
|
|
|
|
.collision = {{10, 10}, {10, 10}},
|
|
|
|
|
.name = S("Matt"),
|
|
|
|
|
.mode = NPC_ACTION_WAITING,
|
|
|
|
|
.waitTime = 0,
|
|
|
|
|
.maxWaitTime = 5,
|
|
|
|
|
.currentNavNode = 87
|
|
|
|
|
},{
|
|
|
|
|
.collision = {{15, 15}, {10, 10}},
|
|
|
|
|
.name = S("James"),
|
|
|
|
|
.mode = NPC_ACTION_WAITING,
|
|
|
|
|
.waitTime = 0,
|
|
|
|
|
.maxWaitTime = 10,
|
|
|
|
|
.currentNavNode = 0
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-10-05 02:40:59 +01:00
|
|
|
.navMesh = &TestNavMesh,
|
2025-10-05 00:25:37 +01:00
|
|
|
.npcPOI = {100}
|
|
|
|
|
};
|
2025-10-05 01:31:39 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
printf("%zu size in bytes\n", sizeof(TestNavMesh));
|
|
|
|
|
|
2025-10-04 15:53:55 +01:00
|
|
|
while (running)
|
|
|
|
|
{
|
2025-10-03 14:30:36 +01:00
|
|
|
SDL_Event e;
|
2025-10-04 15:53:55 +01:00
|
|
|
while (SDL_PollEvent(&e))
|
|
|
|
|
{
|
|
|
|
|
PlayerUpdate(&e, &player);
|
|
|
|
|
if (e.type == SDL_EVENT_QUIT)
|
|
|
|
|
{
|
|
|
|
|
running = false;
|
|
|
|
|
}
|
2025-10-03 14:30:36 +01:00
|
|
|
}
|
2025-10-05 01:31:39 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
updateNPCs(1.0f / 60.0f, &world);
|
2025-10-03 20:04:40 +01:00
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
|
SDL_GetWindowSizeInPixels(window, &w, &h);
|
|
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
G_CalulateCamera(&game->camera, (F32) w / (F32) h);
|
|
|
|
|
|
2025-10-03 20:04:40 +01:00
|
|
|
Vk_Frame *frame = Vk_FrameBegin(window);
|
|
|
|
|
VkCommandBuffer cmd = frame->cmd;
|
|
|
|
|
|
|
|
|
|
VkClearValue clear_colour;
|
|
|
|
|
clear_colour.color.float32[0] = 1.0f;
|
|
|
|
|
clear_colour.color.float32[1] = 0.0f;
|
|
|
|
|
clear_colour.color.float32[2] = 0.0f;
|
|
|
|
|
clear_colour.color.float32[3] = 1.0f;
|
|
|
|
|
|
2025-10-04 15:53:55 +01:00
|
|
|
VkRenderingAttachmentInfo colour_attachment = {0};
|
2025-10-05 02:40:59 +01:00
|
|
|
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
|
|
|
|
colour_attachment.imageView = vk.swapchain.views[frame->image];
|
2025-10-03 20:04:40 +01:00
|
|
|
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
2025-10-05 02:40:59 +01:00
|
|
|
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
|
colour_attachment.clearValue = clear_colour;
|
2025-10-04 15:53:55 +01:00
|
|
|
|
|
|
|
|
VkRenderingInfo rendering_info = {0};
|
2025-10-05 02:40:59 +01:00
|
|
|
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
|
|
|
|
rendering_info.renderArea = (VkRect2D) { 0, 0, w, h };
|
|
|
|
|
rendering_info.layerCount = 1;
|
2025-10-03 20:04:40 +01:00
|
|
|
rendering_info.colorAttachmentCount = 1;
|
2025-10-05 02:40:59 +01:00
|
|
|
rendering_info.pColorAttachments = &colour_attachment;
|
2025-10-03 20:04:40 +01:00
|
|
|
|
|
|
|
|
vk.CmdBeginRendering(cmd, &rendering_info);
|
|
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
Vk_Pipeline *basic = &game->pipelines[0];
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet set;
|
|
|
|
|
VkDescriptorSetAllocateInfo alloc_info = { 0 };
|
|
|
|
|
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
|
|
|
alloc_info.descriptorPool = frame->descriptors;
|
|
|
|
|
alloc_info.descriptorSetCount = 1;
|
|
|
|
|
alloc_info.pSetLayouts = &basic->layout.set;
|
|
|
|
|
|
|
|
|
|
vk.AllocateDescriptorSets(vk.device, &alloc_info, &set);
|
2025-10-03 20:04:40 +01:00
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
// 'update' the descriptor sets for binding
|
2025-10-05 01:31:39 +01:00
|
|
|
M_TempScope(0, 0) {
|
2025-10-04 21:42:04 +01:00
|
|
|
VkWriteDescriptorSet writes[2] = { 0 };
|
|
|
|
|
|
|
|
|
|
VkDescriptorBufferInfo vbo_info = { 0 };
|
|
|
|
|
vbo_info.buffer = game->vbo.handle;
|
|
|
|
|
vbo_info.offset = 0;
|
|
|
|
|
vbo_info.range = 256;
|
|
|
|
|
|
2025-10-05 01:31:39 +01:00
|
|
|
VkDescriptorImageInfo *image_info = M_ArenaPush(temp.arena, VkDescriptorImageInfo, .count = game->n_images);
|
|
|
|
|
|
|
|
|
|
for (U32 it = 0; it < game->n_images; ++it) {
|
|
|
|
|
image_info[it].imageView = game->images[it].image.view;
|
|
|
|
|
image_info[it].sampler = vk.sampler;
|
|
|
|
|
image_info[it].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
}
|
2025-10-04 21:42:04 +01:00
|
|
|
|
|
|
|
|
writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
|
writes[0].dstSet = set;
|
|
|
|
|
writes[0].dstBinding = 0;
|
|
|
|
|
writes[0].descriptorCount = 1;
|
|
|
|
|
writes[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
|
|
|
|
writes[0].pBufferInfo = &vbo_info;
|
|
|
|
|
|
|
|
|
|
writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
|
|
|
|
writes[1].dstSet = set;
|
|
|
|
|
writes[1].dstBinding = 1;
|
2025-10-05 01:31:39 +01:00
|
|
|
writes[1].descriptorCount = game->n_images;
|
2025-10-04 21:42:04 +01:00
|
|
|
writes[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
2025-10-05 01:31:39 +01:00
|
|
|
writes[1].pImageInfo = image_info;
|
2025-10-04 21:42:04 +01:00
|
|
|
|
|
|
|
|
vk.UpdateDescriptorSets(vk.device, ArraySize(writes), writes, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, basic->handle);
|
|
|
|
|
vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, basic->layout.pipeline, 0, 1, &set, 0, 0);
|
2025-10-05 02:40:59 +01:00
|
|
|
vk.CmdPushConstants(cmd, basic->layout.pipeline, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(Mat4x4F), &game->camera.proj.fwd);
|
2025-10-03 20:04:40 +01:00
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
VkViewport viewport = { 0, 0, (F32) w, (F32) h, 0.0f, 1.0f };
|
|
|
|
|
VkRect2D scissor = { 0, 0, w, h };
|
2025-10-03 20:04:40 +01:00
|
|
|
|
2025-10-04 21:42:04 +01:00
|
|
|
vk.CmdSetViewport(cmd, 0, 1, &viewport);
|
|
|
|
|
vk.CmdSetScissor(cmd, 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
vk.CmdDraw(cmd, 6, 1, 0, 0);
|
|
|
|
|
|
2025-10-03 20:04:40 +01:00
|
|
|
vk.CmdEndRendering(cmd);
|
|
|
|
|
|
|
|
|
|
Vk_FrameEnd();
|
2025-10-03 14:30:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-10-03 20:04:40 +01:00
|
|
|
|
2025-10-04 00:46:26 +01:00
|
|
|
#include "core/core.c"
|
|
|
|
|
#include "os/core.c"
|
2025-10-03 20:04:40 +01:00
|
|
|
#include "vulkan/core.c"
|
2025-10-04 17:24:30 +01:00
|
|
|
#include "game/core.c"
|