try to change to working directory on startup so assets can be found
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#include "change_directory.h"
|
||||
#include <SDL3/SDL_platform.h>
|
||||
|
||||
#if SDL_PLATFORM_LINUX
|
||||
#include <unistd.h>
|
||||
#elif SDL_PLATFORM_WINDOWS
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
void change_directory(const char *path) {
|
||||
#if SDL_PLATFORM_LINUX
|
||||
chdir(path);
|
||||
#elif SDL_PLATFORM_WINDOWS
|
||||
_chdir(path);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INCLUDE_CHANGE_DIRECTORY_H
|
||||
#define INCLUDE_CHANGE_DIRECTORY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
void change_directory(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // INCLUDE_CHANGE_DIRECTORY_H
|
||||
+17
-1
@@ -15,12 +15,13 @@
|
||||
#include "log.h"
|
||||
#include "math_graphics.h"
|
||||
#include "stb_image.h"
|
||||
#include "change_directory.h"
|
||||
|
||||
#include "shaders/shaders.h"
|
||||
|
||||
using namespace M;
|
||||
|
||||
#define ASSETS_PATH "../assets/"
|
||||
#define ASSETS_PATH "./assets/"
|
||||
|
||||
#define NEAR_PLANE (0.01f)
|
||||
#define TILE_SIZE (32)
|
||||
@@ -1365,8 +1366,23 @@ WGPUSurface create_wgpu_surface_for_SDL_window(SDL_Window *window) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void setup_working_directory() {
|
||||
if (SDL_GetPathInfo(ASSETS_PATH, NULL)) return;
|
||||
|
||||
const char *current_directory = SDL_GetCurrentDirectory();
|
||||
|
||||
change_directory(SDL_GetBasePath());
|
||||
if (SDL_GetPathInfo(ASSETS_PATH, NULL)) return;
|
||||
|
||||
change_directory("..");
|
||||
if (SDL_GetPathInfo(ASSETS_PATH, NULL)) return;
|
||||
|
||||
change_directory(current_directory);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
setup_memory_functions();
|
||||
setup_working_directory();
|
||||
|
||||
#ifdef SDL_PLATFORM_LINUX
|
||||
if (getenv("ENABLE_VULKAN_RENDERDOC_CAPTURE"))
|
||||
|
||||
Reference in New Issue
Block a user