summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-11-13 09:30:55 -0800
committerAmin Mesbah <mesbahamin@gmail.com>2017-12-15 09:39:53 -0800
commit70e9d76b4b9174dba759192f049efe431ac93449 (patch)
tree65c31cd98579b6fbfc428bfafbb29fa95692acf8
parente77b9aef0d6480380dd162a5d4c55c3942d83f12 (diff)
downloadohsp-features/windows-compat.zip
ohsp-features/windows-compat.tar.gz
WIP: windows code reloadingfeatures/windows-compat
-rw-r--r--ohsp.vcxproj1
-rw-r--r--src/platform_sdl.c3
-rw-r--r--src/util_win32.h83
3 files changed, 86 insertions, 1 deletions
diff --git a/ohsp.vcxproj b/ohsp.vcxproj
index 6ee7988..21f577f 100644
--- a/ohsp.vcxproj
+++ b/ohsp.vcxproj
@@ -120,6 +120,7 @@
<ClInclude Include="src\entity.h" />
<ClInclude Include="src\game.h" />
<ClInclude Include="src\platform_sdl.h" />
+ <ClInclude Include="src\util_win32.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\entity.c" />
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
index 038e67b..2badc33 100644
--- a/src/platform_sdl.c
+++ b/src/platform_sdl.c
@@ -2,7 +2,8 @@
#ifdef __linux__
#include "util_linux.h"
-#elif __WIN32
+#elif _WIN32
+#include "util_win32.h"
#endif
#include <stdbool.h>
diff --git a/src/util_win32.h b/src/util_win32.h
new file mode 100644
index 0000000..d3fb79c
--- /dev/null
+++ b/src/util_win32.h
@@ -0,0 +1,83 @@
+#ifndef UTIL_WIN32_H
+#define UTIL_WIN32_H
+
+#include <stdio.h>
+#include <time.h>
+
+time_t file_get_modified_time(char *file_path)
+{
+ time_t mtime = 0;
+ /*
+ struct stat file_status = {0};
+ if (stat(file_path, &file_status) == 0)
+ {
+ //printf("File: %s last modified: %s\n", file_path, ctime(&file_status.st_mtime));
+ mtime = file_status.st_mtime;
+ }
+ else
+ {
+ fprintf(stderr, "ERROR: Failed to stat file: %s\n", file_path);
+ }
+ */
+ return mtime;
+}
+
+
+void unload_game_code(struct SDLGameCode *game_code)
+{
+ /*
+ if (!game_code)
+ {
+ printf("Invalid pointer *game_code\n");
+ return;
+ }
+
+ if (game_code->game_code_library)
+ {
+ //dlclose(game_code->game_code_library);
+ game_code->game_code_library = 0;
+ }
+ game_code->is_valid = false;
+ game_code->game_update = 0;
+ game_code->game_render = 0;
+ */
+}
+
+
+// TODO: Add backup dll in case loading fails
+struct SDLGameCode load_game_code(char *source_lib_path)
+{
+ struct SDLGameCode game_code = {0};
+
+ /*
+ game_code.last_write_time = file_get_modified_time(source_lib_path);
+ if (game_code.last_write_time)
+ {
+ game_code.game_code_library = dlopen(source_lib_path, RTLD_LAZY);
+ if (game_code.game_code_library)
+ {
+ // NOTE: The C standard (as of C99) distinguishes function pointers
+ // from object pointers (`void *` is an object pointer). Technically it
+ // is undefined behavior to cast between these two pointer types. In
+ // practice, it works on most modern platforms.
+ //
+ // In this case, we are protected by POSIX, which specifies that
+ // function and data pointers must be the same size. We will only ever
+ // be using dlsym on POSIX-compliant platforms.
+ game_code.game_update = (game_update_t *) dlsym(game_code.game_code_library, "game_update");
+ game_code.game_render = (game_render_t *) dlsym(game_code.game_code_library, "game_render");
+ game_code.is_valid = (game_code.game_update && game_code.game_render);
+ }
+ }
+
+ if (!game_code.is_valid)
+ {
+ fprintf(stderr, "ERROR: Game code is not valid: %s\n", dlerror());
+ }
+ */
+
+ return game_code;
+}
+
+
+#endif