Added system path stuff on Windows
Fixed typo in image loading
This commit is contained in:
@@ -68,6 +68,7 @@
|
|||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <shlobj_core.h>
|
||||||
#pragma warning(disable : 4201)
|
#pragma warning(disable : 4201)
|
||||||
#elif OS_LINUX
|
#elif OS_LINUX
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_GetWindowSizeInPixels(window, &w, &h);
|
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
void G_ImagesLoad(G_State *game) {
|
void G_ImagesLoad(G_State *game) {
|
||||||
M_TempScope(0, 0) {
|
M_TempScope(0, 0) {
|
||||||
Str8 exe_path = FS_SystemPath(temp.arena, FS_SYSTEM_PATH_EXE);
|
Str8 exe_path = FS_SystemPath(temp.arena, FS_SYSTEM_PATH_EXE);
|
||||||
Str8 path = Sf(temp.arena, "%.*s/assets", exe_path);
|
Str8 path = Sf(temp.arena, "%.*s/assets", Sv(exe_path));
|
||||||
|
|
||||||
FS_List assets = FS_PathList(temp.arena, path);
|
FS_List assets = FS_PathList(temp.arena, path);
|
||||||
|
|
||||||
|
|||||||
@@ -132,3 +132,78 @@ FS_List FS_PathList(M_Arena *arena, Str8 path) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Str8 FS_SystemPath(M_Arena *arena, FS_SystemPathType path) {
|
||||||
|
Str8 result = { 0 };
|
||||||
|
|
||||||
|
M_TempScope(1, &arena) {
|
||||||
|
switch (path) {
|
||||||
|
case FS_SYSTEM_PATH_EXE: {
|
||||||
|
U64 offset = M_ArenaOffset(temp.arena);
|
||||||
|
|
||||||
|
DWORD err, nchars;
|
||||||
|
|
||||||
|
DWORD nSize = 1024;
|
||||||
|
LPWSTR lpFilename = M_ArenaPush(temp.arena, WCHAR, .count = nSize, .flags = M_ARENA_NO_ZERO);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
nchars = GetModuleFileNameW(0, lpFilename, nSize);
|
||||||
|
|
||||||
|
err = GetLastError();
|
||||||
|
if (err != ERROR_INSUFFICIENT_BUFFER) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
M_ArenaPop(temp.arena, offset);
|
||||||
|
|
||||||
|
nSize *= 2;
|
||||||
|
lpFilename = M_ArenaPush(temp.arena, WCHAR, .count = nSize, .flags = M_ARENA_NO_ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == ERROR_SUCCESS) {
|
||||||
|
while (lpFilename[nchars] != '\\') { nchars -= 1; }
|
||||||
|
lpFilename[nchars] = 0;
|
||||||
|
|
||||||
|
result = Win32_MultiByteStr(arena, lpFilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FS_SYSTEM_PATH_WORKING: {
|
||||||
|
DWORD nSize = GetCurrentDirectoryW(0, 0);
|
||||||
|
|
||||||
|
if (nSize != 0) {
|
||||||
|
LPWSTR lpBuffer = M_ArenaPush(temp.arena, WCHAR, .count = nSize, .flags = M_ARENA_NO_ZERO);
|
||||||
|
GetCurrentDirectoryW(nSize, lpBuffer);
|
||||||
|
|
||||||
|
result = Win32_MultiByteStr(arena, lpBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FS_SYSTEM_PATH_USER: {
|
||||||
|
LPWSTR wpath;
|
||||||
|
HRESULT hResult = SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, 0, &wpath);
|
||||||
|
if (hResult == S_OK) {
|
||||||
|
result = Win32_MultiByteStr(arena, wpath);
|
||||||
|
CoTaskMemFree(wpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FS_SYSTEM_PATH_TEMP: {
|
||||||
|
DWORD nSize = MAX_PATH + 1;
|
||||||
|
LPWSTR lpBuffer = M_ArenaPush(temp.arena, WCHAR, .count = nSize);
|
||||||
|
|
||||||
|
DWORD nchars = GetTempPathW(nSize, lpBuffer);
|
||||||
|
if (nchars != 0) {
|
||||||
|
lpBuffer[nchars - 1] = 0; // Strip trailing backslash
|
||||||
|
result = Win32_MultiByteStr(arena, lpBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ glslangValidator -o "assets\shaders\basic.frag.spv" --target-env vulkan1.3 "..\c
|
|||||||
ECHO [Building source]
|
ECHO [Building source]
|
||||||
|
|
||||||
SET COMPILER_OPTS=-nologo -W4 -I"deps\SDL3\include" -I"deps\stb" -I"%VULKAN_SDK%\Include" -I"..\code"
|
SET COMPILER_OPTS=-nologo -W4 -I"deps\SDL3\include" -I"deps\stb" -I"%VULKAN_SDK%\Include" -I"..\code"
|
||||||
SET LINKER_OPTS=-LIBPATH:"deps\SDL3\lib" SDL3.lib
|
SET LINKER_OPTS=-LIBPATH:"deps\SDL3\lib" SDL3.lib Ole32.lib Shell32.lib
|
||||||
|
|
||||||
IF %release% equ 1 (
|
IF %release% equ 1 (
|
||||||
ECHO [Release build]
|
ECHO [Release build]
|
||||||
|
|||||||
Reference in New Issue
Block a user