From 48c7e3f86d9f3b37c2bda0e9f613e9ed4df7c80e Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 3 Mar 2025 23:40:54 +1100 Subject: [PATCH] started work on windows platform layer --- .gitignore | 2 +- build.bat | 11 +++++++ src/platform.c | 2 +- src/platform.h | 2 +- src/platform_linux.h | 8 ----- src/platform_windows.c | 42 ++++++++++++++++++++++++++ src/platform_windows.h | 68 ++++++++++++++++++++++++++++++++++++++++++ src/util.h | 8 +++++ 8 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 build.bat create mode 100644 src/platform_windows.c create mode 100644 src/platform_windows.h diff --git a/.gitignore b/.gitignore index 378eac2..567609b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -build +build/ diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..27d20b1 --- /dev/null +++ b/build.bat @@ -0,0 +1,11 @@ +@echo off +setlocal enabledelayedexpansion + +set vulkan_include=C:\VulkanSDK\1.4.304.1\Include + + +mkdir build +pushd build +cl /c /I ..\external\vma /I %vulkan_include% ..\external\vma\vma.cpp +cl /I ..\external ..\src\main.c +popd diff --git a/src/platform.c b/src/platform.c index 39e4679..4d47dbe 100644 --- a/src/platform.c +++ b/src/platform.c @@ -3,7 +3,7 @@ #endif #if _WIN32 -#error Not yet implemented +#include "platform_windows.c" #endif #if __APPLE__ || __MACH__ diff --git a/src/platform.h b/src/platform.h index 5d70a86..9557b23 100644 --- a/src/platform.h +++ b/src/platform.h @@ -9,7 +9,7 @@ typedef struct WindowSize WindowSize; #endif #if _WIN32 -#error Not yet implemented +#include "platform_windows.h" #endif #if __APPLE__ || __MACH__ diff --git a/src/platform_linux.h b/src/platform_linux.h index fd0fc0e..044e8a1 100644 --- a/src/platform_linux.h +++ b/src/platform_linux.h @@ -12,14 +12,6 @@ #include #include -#define Assert(condition, message) do { assert(condition && message); } while(0) - -// generic defines -#define KB(n) n * 1024LL -#define MB(n) KB(n) * 1024LL -#define GB(n) MB(n) * 1024LL -#define TB(n) GB(n) * 1024LL - // syscall defines #define SYS_ERR -1 diff --git a/src/platform_windows.c b/src/platform_windows.c new file mode 100644 index 0000000..62251eb --- /dev/null +++ b/src/platform_windows.c @@ -0,0 +1,42 @@ +LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param) +{ + LRESULT result = 0; + + switch (message) + { + case WM_SIZE: + { + OutputDebugStringA("WM_SIZE\n"); + } break; + case WM_DESTROY: + { + OutputDebugStringA("WM_DESTROY\n"); + } break; + case WM_CLOSE: + { + OutputDebugStringA("WM_CLOSE\n"); + } break; + case WM_ACTIVATEAPP: + { + OutputDebugStringA("WM_ACTIVATEAPP\n"); + } break; + default: + { + result = DefWindowProc(window, message, w_param, l_param); + } break; + } + + return result; +} + +int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line, int show_code) +{ + WNDCLASS window_class = { + .style = CS_OWNDC|CS_HREDREAW|CS_VREDRAW, + .lpfnWndProc = , + .hInstance = instance, + .lpszClassName = "GearsWindowClass", + }; + + +} diff --git a/src/platform_windows.h b/src/platform_windows.h new file mode 100644 index 0000000..0ce2b46 --- /dev/null +++ b/src/platform_windows.h @@ -0,0 +1,68 @@ +#pragma once +#include + +#include +#include + +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef intptr_t intptr; +typedef uintptr_t uintptr; + +#if defined ( _WIN64 ) +typedef int64_t isize; +typedef uint64_t usize; +#elif defined ( _WIN32 ) +typedef int32_t isize; +typedef uint32_t usize; +#endif + +typedef float f32; +typedef double f64; + +typedef uint8_t b8; +typedef uint32_t b32; + +typedef void * rawptr; + +typedef struct +{ + i32 lib; +} Library; + +typedef struct +{ + i32 win; +} Window; + +typedef struct +{ + i32 fn; +} Function; + +b32 _LoadLib(const char *name, Library *out_lib); +b32 _LoadFn(const char *name, Library *lib, Function *out_fn); + +b32 _InitPlatform(); +rawptr _MemAlloc(isize size); +rawptr _MemAllocZeroed(isize size); +isize _GetPageSize(); + +i32 _EPrint(void const *str); +i32 _Printf(const char *fmt, ...); +i32 _Printfln(const char *fmt, ...); +i32 _EPrintf(const char *fmt, ...); + +b32 _CreateWindow(); +Window *_GetWindow(); +b32 _GetWindowEvent(WindowEvent *event); +void _WaitForWindowEvent(WindowEvent *event); +WindowSize _GetWindowSize(); diff --git a/src/util.h b/src/util.h index 19cd140..a76d12a 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,14 @@ #include +#define Assert(condition, message) do { assert(condition && message); } while(0) + +// generic defines +#define KB(n) n * 1024LL +#define MB(n) KB(n) * 1024LL +#define GB(n) MB(n) * 1024LL +#define TB(n) GB(n) * 1024LL + #define DEFAULT_ALIGNMENT (2*sizeof(rawptr)) #define Len(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))