Merge remote-tracking branch 'origin'
This commit is contained in:
93
code/first.c
93
code/first.c
@@ -8,17 +8,22 @@
|
|||||||
|
|
||||||
#include "vulkan/core.h"
|
#include "vulkan/core.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
#include "game/impl/player.c"
|
||||||
(void) argc;
|
|
||||||
(void) argv;
|
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
|
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||||
|
{
|
||||||
printf("[Error] :: Failed to initialise SDL3 (%s)\n", SDL_GetError());
|
printf("[Error] :: Failed to initialise SDL3 (%s)\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Window *window = SDL_CreateWindow("Ludum", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
SDL_Window *window = SDL_CreateWindow("Ludum", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
||||||
if (!window) {
|
if (!window)
|
||||||
|
{
|
||||||
printf("[Error] :: Failed to create window (%s)\n", SDL_GetError());
|
printf("[Error] :: Failed to create window (%s)\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -26,10 +31,19 @@ int main(int argc, char **argv) {
|
|||||||
Vk_Setup(window);
|
Vk_Setup(window);
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
Player player;
|
||||||
|
player.pos.x = 0;
|
||||||
|
player.pos.y = 0;
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e))
|
||||||
if (e.type == SDL_EVENT_QUIT) { running = false; }
|
{
|
||||||
|
PlayerUpdate(&e, &player);
|
||||||
|
if (e.type == SDL_EVENT_QUIT)
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
@@ -37,25 +51,24 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
Vk_Frame *frame = Vk_FrameBegin(window);
|
Vk_Frame *frame = Vk_FrameBegin(window);
|
||||||
VkCommandBuffer cmd = frame->cmd;
|
VkCommandBuffer cmd = frame->cmd;
|
||||||
|
VkImageMemoryBarrier2 colour_optimal = {0};
|
||||||
VkImageMemoryBarrier2 colour_optimal = { 0 };
|
colour_optimal.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
||||||
colour_optimal.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
colour_optimal.srcStageMask = VK_PIPELINE_STAGE_2_NONE;
|
||||||
colour_optimal.srcStageMask = VK_PIPELINE_STAGE_2_NONE;
|
|
||||||
colour_optimal.srcAccessMask = VK_ACCESS_2_NONE;
|
colour_optimal.srcAccessMask = VK_ACCESS_2_NONE;
|
||||||
colour_optimal.dstStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
colour_optimal.dstStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
colour_optimal.dstAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
colour_optimal.dstAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
colour_optimal.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
colour_optimal.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
colour_optimal.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colour_optimal.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
colour_optimal.image = vk.swapchain.images[frame->image];
|
colour_optimal.image = vk.swapchain.images[frame->image];
|
||||||
|
|
||||||
colour_optimal.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
colour_optimal.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
colour_optimal.subresourceRange.layerCount = 1;
|
colour_optimal.subresourceRange.layerCount = 1;
|
||||||
colour_optimal.subresourceRange.levelCount = 1;
|
colour_optimal.subresourceRange.levelCount = 1;
|
||||||
|
|
||||||
VkDependencyInfo colour_barrier = { 0 };
|
VkDependencyInfo colour_barrier = {0};
|
||||||
colour_barrier.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
colour_barrier.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||||
colour_barrier.imageMemoryBarrierCount = 1;
|
colour_barrier.imageMemoryBarrierCount = 1;
|
||||||
colour_barrier.pImageMemoryBarriers = &colour_optimal;
|
colour_barrier.pImageMemoryBarriers = &colour_optimal;
|
||||||
|
|
||||||
vk.CmdPipelineBarrier2(cmd, &colour_barrier);
|
vk.CmdPipelineBarrier2(cmd, &colour_barrier);
|
||||||
|
|
||||||
@@ -65,43 +78,43 @@ int main(int argc, char **argv) {
|
|||||||
clear_colour.color.float32[2] = 0.0f;
|
clear_colour.color.float32[2] = 0.0f;
|
||||||
clear_colour.color.float32[3] = 1.0f;
|
clear_colour.color.float32[3] = 1.0f;
|
||||||
|
|
||||||
VkRenderingAttachmentInfo colour_attachment = { 0 };
|
VkRenderingAttachmentInfo colour_attachment = {0};
|
||||||
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
||||||
colour_attachment.imageView = vk.swapchain.views[frame->image];
|
colour_attachment.imageView = vk.swapchain.views[frame->image];
|
||||||
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
colour_attachment.clearValue = clear_colour;
|
colour_attachment.clearValue = clear_colour;
|
||||||
|
|
||||||
VkRenderingInfo rendering_info = { 0 };
|
VkRenderingInfo rendering_info = {0};
|
||||||
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
||||||
rendering_info.renderArea = (VkRect2D) { 0, 0, w, h };
|
rendering_info.renderArea = (VkRect2D){0, 0, w, h};
|
||||||
rendering_info.layerCount = 1;
|
rendering_info.layerCount = 1;
|
||||||
rendering_info.colorAttachmentCount = 1;
|
rendering_info.colorAttachmentCount = 1;
|
||||||
rendering_info.pColorAttachments = &colour_attachment;
|
rendering_info.pColorAttachments = &colour_attachment;
|
||||||
|
|
||||||
vk.CmdBeginRendering(cmd, &rendering_info);
|
vk.CmdBeginRendering(cmd, &rendering_info);
|
||||||
|
|
||||||
vk.CmdEndRendering(cmd);
|
vk.CmdEndRendering(cmd);
|
||||||
|
|
||||||
VkImageMemoryBarrier2 present_src = { 0 };
|
VkImageMemoryBarrier2 present_src = {0};
|
||||||
present_src.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
present_src.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
||||||
present_src.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
present_src.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
present_src.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
present_src.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
present_src.dstStageMask = VK_PIPELINE_STAGE_2_NONE;
|
present_src.dstStageMask = VK_PIPELINE_STAGE_2_NONE;
|
||||||
present_src.dstAccessMask = VK_ACCESS_2_NONE;
|
present_src.dstAccessMask = VK_ACCESS_2_NONE;
|
||||||
present_src.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
present_src.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
present_src.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
present_src.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
present_src.image = vk.swapchain.images[frame->image];
|
present_src.image = vk.swapchain.images[frame->image];
|
||||||
|
|
||||||
present_src.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
present_src.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
present_src.subresourceRange.layerCount = 1;
|
present_src.subresourceRange.layerCount = 1;
|
||||||
present_src.subresourceRange.levelCount = 1;
|
present_src.subresourceRange.levelCount = 1;
|
||||||
|
|
||||||
VkDependencyInfo to_present = { 0 };
|
VkDependencyInfo to_present = {0};
|
||||||
to_present.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
to_present.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||||
to_present.imageMemoryBarrierCount = 1;
|
to_present.imageMemoryBarrierCount = 1;
|
||||||
to_present.pImageMemoryBarriers = &present_src;
|
to_present.pImageMemoryBarriers = &present_src;
|
||||||
|
|
||||||
vk.CmdPipelineBarrier2(cmd, &to_present);
|
vk.CmdPipelineBarrier2(cmd, &to_present);
|
||||||
|
|
||||||
|
|||||||
22
code/game/impl/player.c
Normal file
22
code/game/impl/player.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "../player.h"
|
||||||
|
|
||||||
|
void PlayerUpdate(SDL_Event *event, Player *player)
|
||||||
|
{
|
||||||
|
SDL_KeyboardEvent key = event->key;
|
||||||
|
if (key.key == SDLK_W)
|
||||||
|
{
|
||||||
|
player->pos.y += 10;
|
||||||
|
}
|
||||||
|
if (key.key == SDLK_A)
|
||||||
|
{
|
||||||
|
player->pos.x -= 10;
|
||||||
|
}
|
||||||
|
if (key.key == SDLK_D)
|
||||||
|
{
|
||||||
|
player->pos.x += 10;
|
||||||
|
}
|
||||||
|
if (key.key == SDLK_S)
|
||||||
|
{
|
||||||
|
player->pos.y -= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
code/game/player.h
Normal file
11
code/game/player.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "core/types.h"
|
||||||
|
#include <SDL3/SDL_events.h>
|
||||||
|
#include "../core/macros.h"
|
||||||
|
|
||||||
|
typedef struct Player Player;
|
||||||
|
struct Player
|
||||||
|
{
|
||||||
|
V2f pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
function void PlayerUpdate(SDL_Event *event, Player *player);
|
||||||
Reference in New Issue
Block a user