2025-10-03 14:30:36 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <SDL3/SDL.h>
|
2025-10-05 16:49:18 +01:00
|
|
|
#include <SDL3/SDL_keycode.h>
|
2025-10-03 14:30:36 +01:00
|
|
|
|
2025-10-04 17:24:30 +01:00
|
|
|
#define STB_IMAGE_IMPLEMENTATION 1
|
|
|
|
|
#include <stb_image.h>
|
|
|
|
|
|
2025-10-05 21:11:18 +01:00
|
|
|
#define STB_RECT_PACK_IMPLEMENTATION 1
|
|
|
|
|
#include <stb_rect_pack.h>
|
|
|
|
|
|
|
|
|
|
#define STB_TRUETYPE_IMPLEMENTATION 1
|
|
|
|
|
#include <stb_truetype.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-05 14:27:05 +01:00
|
|
|
#include "draw/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 14:42:19 +01:00
|
|
|
#include "game/impl/world.c"
|
2025-10-05 00:25:37 +01:00
|
|
|
#include "game/impl/npc.c"
|
2025-10-05 21:05:29 +01:00
|
|
|
#include "game/impl/bandit.c"
|
2025-10-05 00:25:37 +01:00
|
|
|
#include "game/testnavmesh.h"
|
2025-10-03 20:04:40 +01:00
|
|
|
|
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
|
|
|
|
2025-10-06 00:52:16 +01:00
|
|
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO))
|
2025-10-04 15:53:55 +01:00
|
|
|
{
|
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-06 00:52:16 +01:00
|
|
|
SDL_AudioStream *austream;
|
|
|
|
|
Str8 audio_data;
|
|
|
|
|
M_TempScope(0, 0) {
|
|
|
|
|
SDL_AudioSpec spec;
|
|
|
|
|
spec.format = SDL_AUDIO_S16LE;
|
|
|
|
|
spec.channels = 2;
|
|
|
|
|
spec.freq = 44100;
|
|
|
|
|
|
|
|
|
|
austream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, 0, 0);
|
|
|
|
|
|
|
|
|
|
if (!austream) {
|
|
|
|
|
printf("Failed to open audio stream (%s)\n", SDL_GetError());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Str8 exec = FS_SystemPath(temp.arena, FS_SYSTEM_PATH_EXE);
|
|
|
|
|
Str8 path = Sf(temp.arena, "%.*s/assets/outside_ambience.wav", Sv(exec));
|
|
|
|
|
|
|
|
|
|
SDL_AudioSpec wav_spec;
|
|
|
|
|
U32 count;
|
|
|
|
|
|
|
|
|
|
SDL_LoadWAV((const char *) path.data, &wav_spec, &audio_data.data, &count);
|
|
|
|
|
audio_data.count = count;
|
|
|
|
|
}
|
|
|
|
|
|
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-06 00:52:16 +01:00
|
|
|
game->arena = arena;
|
2025-10-05 21:11:18 +01:00
|
|
|
game->draw.arena = arena;
|
2025-10-04 21:42:04 +01:00
|
|
|
|
|
|
|
|
G_ImagesLoad(game);
|
|
|
|
|
G_PipelinesLoad(game);
|
2025-10-06 00:52:16 +01:00
|
|
|
G_AudioLoad(game);
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
G_Camera *camera = &game->camera;
|
2025-10-04 23:46:13 +01:00
|
|
|
|
2025-10-05 14:27:05 +01:00
|
|
|
camera->x = V3F(1, 0, 0);
|
|
|
|
|
camera->y = V3F(0, 1, 0);
|
|
|
|
|
camera->z = V3F(0, 0, 1);
|
|
|
|
|
camera->p = V3F(0, 0, 48);
|
2025-10-04 23:46:13 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
camera->fov = 60.0f;
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-05 02:40:59 +01:00
|
|
|
camera->nearp = 0.01f;
|
2025-10-04 17:36:47 +01:00
|
|
|
camera->farp = 1000.0f;
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-05 14:27:05 +01:00
|
|
|
game->draw.camera = camera;
|
2025-10-05 15:21:23 +01:00
|
|
|
World *world = M_ArenaPush(arena, World);
|
|
|
|
|
game->world = world;
|
2025-10-05 15:32:57 +01:00
|
|
|
world->random = Random_Seed(29237489723847);
|
2025-10-05 21:05:29 +01:00
|
|
|
world->npcCount = 1;
|
2025-10-05 21:19:14 +01:00
|
|
|
for(U32 i = 0; i < world->npcCount; i++) {
|
2025-10-05 16:49:18 +01:00
|
|
|
NPC *npc1 = &world->npcs[i];
|
|
|
|
|
npc1->collision.pos.x = 15;
|
|
|
|
|
npc1->collision.pos.y = 15;
|
2025-10-05 21:05:29 +01:00
|
|
|
npc1->collision.size.x = 1;
|
|
|
|
|
npc1->collision.size.y = 1;
|
2025-10-05 16:49:18 +01:00
|
|
|
npc1->name = S("Matt");
|
|
|
|
|
npc1->mode = NPC_ACTION_WAITING;
|
|
|
|
|
npc1->waitTime = 0;
|
|
|
|
|
npc1->maxWaitTime = 5;
|
|
|
|
|
npc1->currentNavNode = 0;
|
|
|
|
|
npc1->collision.pos.x = 15;
|
|
|
|
|
npc1->collision.pos.y = 15;
|
|
|
|
|
npc1->collision.size.x = 10;
|
|
|
|
|
npc1->collision.size.y = 10;
|
|
|
|
|
}
|
2025-10-05 15:21:23 +01:00
|
|
|
|
2025-10-05 21:05:29 +01:00
|
|
|
Bandit *badman = &world->bandit;
|
|
|
|
|
badman->collision.pos.x = 15;
|
|
|
|
|
badman->collision.pos.y = 15;
|
|
|
|
|
badman->collision.size.x = 10;
|
|
|
|
|
badman->collision.size.y = 10;
|
|
|
|
|
badman->name = S("Leroy Brown");
|
|
|
|
|
badman->mode = BANDIT_WAITING;
|
|
|
|
|
badman->waitTime = 0;
|
|
|
|
|
badman->maxWaitTime = 2;
|
|
|
|
|
badman->poiCount = 2;
|
|
|
|
|
badman->pointsOfInterest[0] = 937;
|
|
|
|
|
badman->pointsOfInterest[1] = 12;
|
2025-10-04 17:36:47 +01:00
|
|
|
|
|
|
|
|
world->navMesh = &TestNavMesh;
|
|
|
|
|
world->npcPOI[0] = 100;
|
|
|
|
|
world->player.pos.x = 0;
|
|
|
|
|
world->player.pos.y = 0;
|
2025-10-05 21:05:29 +01:00
|
|
|
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
|
|
|
|
|
world->player.reloadTimer = 0;
|
2025-10-05 14:27:05 +01:00
|
|
|
}
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-06 00:52:16 +01:00
|
|
|
|
|
|
|
|
D_Animation animation;
|
|
|
|
|
{
|
|
|
|
|
U32 id = D_ImageHandle(&game->draw, S("npc_front_base_white"));
|
|
|
|
|
D_AnimationInit(&animation, id, 1, 4, 1.0f / 20.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 14:30:36 +01:00
|
|
|
bool running = true;
|
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))
|
|
|
|
|
{
|
|
|
|
|
if (e.type == SDL_EVENT_QUIT)
|
|
|
|
|
{
|
|
|
|
|
running = false;
|
|
|
|
|
}
|
2025-10-05 21:11:18 +01:00
|
|
|
|
2025-10-05 15:21:23 +01:00
|
|
|
ProcessEvents(&e, game->world);
|
2025-10-03 14:30:36 +01:00
|
|
|
}
|
2025-10-05 15:17:37 +01:00
|
|
|
|
2025-10-05 21:19:14 +01:00
|
|
|
UpdateWorld(1.0f / 60.0f, game->world);
|
2025-10-06 00:52:16 +01:00
|
|
|
D_AnimationUpdate(&animation, 1.0f / 250.0f);
|
2025-10-05 18:05:01 +01:00
|
|
|
game->camera.p.x = game->world->player.pos.x;
|
|
|
|
|
game->camera.p.y = game->world->player.pos.y;
|
2025-10-03 20:04:40 +01:00
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
|
SDL_GetWindowSizeInPixels(window, &w, &h);
|
|
|
|
|
|
2025-10-04 17:36:47 +01:00
|
|
|
game->draw.window_width = w;
|
2025-10-05 14:27:05 +01:00
|
|
|
game->draw.window_height = h;
|
|
|
|
|
|
2025-10-04 17:36:47 +01:00
|
|
|
G_CalculateCamera(&game->camera, (F32)w / (F32)h);
|
2025-10-05 02:40:59 +01:00
|
|
|
|
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-04 17:36:47 +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-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;
|
2025-10-03 20:04:40 +01:00
|
|
|
rendering_info.colorAttachmentCount = 1;
|
2025-10-04 17:36:47 +01:00
|
|
|
rendering_info.pColorAttachments = &colour_attachment;
|
2025-10-03 20:04:40 +01:00
|
|
|
|
|
|
|
|
vk.CmdBeginRendering(cmd, &rendering_info);
|
|
|
|
|
|
2025-10-05 14:27:05 +01:00
|
|
|
D_Begin(&game->draw, frame, D_MAX_RECTS);
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-06 00:52:16 +01:00
|
|
|
//RenderWorld(game->world, &game->draw);
|
|
|
|
|
// D_Rect(&game->draw, 0.0f, 0.0f, .texture = D_ImageHandle(&game->draw, S("saloon_ext")), .scale = 4.0f);
|
|
|
|
|
// D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f);
|
|
|
|
|
// D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3);
|
|
|
|
|
|
|
|
|
|
G_WorldDraw(game, game->world);
|
|
|
|
|
|
|
|
|
|
R2f aframe = D_AnimationFrame(&animation);
|
|
|
|
|
D_Rect(&game->draw, 0, 0, .texture = animation.id, .uv = aframe, .flags = D_RECT_UV_ASPECT);
|
2025-10-04 21:42:04 +01:00
|
|
|
|
2025-10-05 14:27:05 +01:00
|
|
|
D_End(&game->draw, frame);
|
2025-10-04 21:42:04 +01:00
|
|
|
|
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-05 14:27:05 +01:00
|
|
|
#include "draw/core.c"
|
2025-10-04 17:24:30 +01:00
|
|
|
#include "game/core.c"
|