Files
ld58/code/first.c

176 lines
4.0 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdbool.h>
#include <SDL3/SDL.h>
#define STB_IMAGE_IMPLEMENTATION 1
#include <stb_image.h>
#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"
#include "os/core.h"
#include "vulkan/core.h"
#include "draw/core.h"
#include "game/core.h"
#include "game/impl/world.c"
2025-10-05 00:25:37 +01:00
#include "game/impl/npc.c"
#include "game/testnavmesh.h"
2025-10-04 17:36:47 +01:00
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
2025-10-04 15:53:55 +01:00
if (!SDL_Init(SDL_INIT_VIDEO))
{
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)
{
printf("[Error] :: Failed to create window (%s)\n", SDL_GetError());
return 1;
}
Vk_Setup(window);
G_State *game = 0;
{
M_Arena *arena = M_ArenaAlloc(GB(64), .initial = MB(4));
game = M_ArenaPush(arena, G_State);
game->arena = arena;
G_ImagesLoad(game);
G_PipelinesLoad(game);
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, 48);
camera->fov = 60.0f;
camera->nearp = 0.01f;
2025-10-04 17:36:47 +01:00
camera->farp = 1000.0f;
game->draw.camera = camera;
2025-10-05 15:21:23 +01:00
World *world = M_ArenaPush(arena, World);
2025-10-04 17:36:47 +01:00
game->world = world;
world->random = Random_Seed(29237489723847);
world->npcCount = 2;
NPC *npc1 = &world->npcs[0];
npc1->collision.pos.x = 15;
npc1->collision.pos.y = 15;
npc1->collision.size.x = 10;
npc1->collision.size.y = 10;
npc1->name = S("Matt");
npc1->mode = NPC_ACTION_WAITING;
npc1->waitTime = 0;
npc1->maxWaitTime = 5;
npc1->currentNavNode = 87;
npc1->collision.pos.x = 15;
npc1->collision.pos.y = 15;
npc1->collision.size.x = 10;
npc1->collision.size.y = 10;
NPC *npc2 = &world->npcs[1];
npc2->collision.pos.x = 15;
npc2->collision.pos.y = 15;
npc2->collision.size.x = 10;
npc2->collision.size.y = 10;
npc2->name = S("James");
npc2->mode = NPC_ACTION_WAITING;
npc2->waitTime = 0;
npc2->maxWaitTime = 10;
npc2->currentNavNode = 0;
world->navMesh = &TestNavMesh;
world->npcPOI[0] = 100;
world->player.pos.x = 0;
world->player.pos.y = 0;
}
bool running = true;
printf("%zu size in bytes\n", sizeof(TestNavMesh));
2025-10-04 15:53:55 +01:00
while (running)
{
SDL_Event e;
2025-10-04 15:53:55 +01:00
while (SDL_PollEvent(&e))
{
if (e.type == SDL_EVENT_QUIT)
{
running = false;
}
2025-10-04 17:36:47 +01:00
ProcessEvents(&e, game->world);
}
2025-10-04 17:36:47 +01:00
UpdateWorld(1.0 / 60.0, game->world);
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
2025-10-04 17:36:47 +01:00
game->draw.window_width = w;
game->draw.window_height = h;
2025-10-04 17:36:47 +01:00
G_CalculateCamera(&game->camera, (F32)w / (F32)h);
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-04 17:36:47 +01:00
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
colour_attachment.imageView = vk.swapchain.views[frame->image];
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2025-10-04 17:36:47 +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-04 17:36:47 +01:00
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
rendering_info.renderArea = (VkRect2D){0, 0, w, h};
rendering_info.layerCount = 1;
rendering_info.colorAttachmentCount = 1;
2025-10-04 17:36:47 +01:00
rendering_info.pColorAttachments = &colour_attachment;
vk.CmdBeginRendering(cmd, &rendering_info);
D_Begin(&game->draw, frame, D_MAX_RECTS);
2025-10-04 17:36:47 +01:00
D_Rect(&game->draw, 0.0f, 0.0f, .texture = 1);
D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f);
2025-10-04 17:36:47 +01:00
D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3);
D_End(&game->draw, frame);
vk.CmdEndRendering(cmd);
Vk_FrameEnd();
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
#include "core/core.c"
#include "os/core.c"
#include "vulkan/core.c"
#include "draw/core.c"
#include "game/core.c"