started work on windows platform layer

This commit is contained in:
Matthew 2025-03-03 23:40:54 +11:00
parent b627a30675
commit 48c7e3f86d
8 changed files with 132 additions and 11 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
build
build/

11
build.bat Normal file
View File

@ -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

View File

@ -3,7 +3,7 @@
#endif
#if _WIN32
#error Not yet implemented
#include "platform_windows.c"
#endif
#if __APPLE__ || __MACH__

View File

@ -9,7 +9,7 @@ typedef struct WindowSize WindowSize;
#endif
#if _WIN32
#error Not yet implemented
#include "platform_windows.h"
#endif
#if __APPLE__ || __MACH__

View File

@ -12,14 +12,6 @@
#include <stdlib.h>
#include <dlfcn.h>
#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

42
src/platform_windows.c Normal file
View File

@ -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",
};
}

68
src/platform_windows.h Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#include <windows.h>
#include <stdint.h>
#include <stdbool.h>
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();

View File

@ -2,6 +2,14 @@
#include <assert.h>
#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])))))