try to change to working directory on startup so assets can be found
This commit is contained in:
parent
c3c0f8adf7
commit
5a77a4aacb
@ -60,6 +60,7 @@ add_executable(mikemon
|
|||||||
src/log.cpp
|
src/log.cpp
|
||||||
src/smol-atlas.cpp
|
src/smol-atlas.cpp
|
||||||
src/math_graphics.cpp
|
src/math_graphics.cpp
|
||||||
|
src/change_directory.c
|
||||||
src/shaders/shaders.c
|
src/shaders/shaders.c
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
16
src/change_directory.c
Normal file
16
src/change_directory.c
Normal file
@ -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
|
||||||
|
}
|
||||||
14
src/change_directory.h
Normal file
14
src/change_directory.h
Normal file
@ -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
|
||||||
18
src/main.cpp
18
src/main.cpp
@ -15,12 +15,13 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "math_graphics.h"
|
#include "math_graphics.h"
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
#include "change_directory.h"
|
||||||
|
|
||||||
#include "shaders/shaders.h"
|
#include "shaders/shaders.h"
|
||||||
|
|
||||||
using namespace M;
|
using namespace M;
|
||||||
|
|
||||||
#define ASSETS_PATH "../assets/"
|
#define ASSETS_PATH "./assets/"
|
||||||
|
|
||||||
#define NEAR_PLANE (0.01f)
|
#define NEAR_PLANE (0.01f)
|
||||||
#define TILE_SIZE (32)
|
#define TILE_SIZE (32)
|
||||||
@ -1365,8 +1366,23 @@ WGPUSurface create_wgpu_surface_for_SDL_window(SDL_Window *window) {
|
|||||||
return NULL;
|
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) {
|
int main(int argc, char **argv) {
|
||||||
setup_memory_functions();
|
setup_memory_functions();
|
||||||
|
setup_working_directory();
|
||||||
|
|
||||||
#ifdef SDL_PLATFORM_LINUX
|
#ifdef SDL_PLATFORM_LINUX
|
||||||
if (getenv("ENABLE_VULKAN_RENDERDOC_CAPTURE"))
|
if (getenv("ENABLE_VULKAN_RENDERDOC_CAPTURE"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user