medfall

A super great game engine
Log | Files | Refs

commit c61d3093499f77e62a6e4348a4e3723299707eb4
parent 0479a9a3a3dbbbbd138c371fd024377e5dfff419
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed May 10 03:00:06 +0300

Strip out the module hotloading code

Diffstat:
main.cc | 98-------------------------------------------------------------------------------
scripts/gen_makefile.lua | 4++--
2 files changed, 2 insertions(+), 100 deletions(-)
diff --git a/main.cc b/main.cc @@ -1,7 +1,4 @@ #include <stdio.h> -#include <time.h> -#include <sys/stat.h> -#include <sys/types.h> #include <xmmintrin.h> #include <pmmintrin.h> @@ -12,73 +9,12 @@ #include "keys.h" #include "work_queue.h" #include "text_renderer.h" -#include "platform_library.h" #define GLFW_INCLUDE_NONE #include "libs/glfw/include/GLFW/glfw3.h" -struct Game { - Library lib; - GameInit * init; - GameFrame * frame; - - time_t lib_write_time; -}; - -static time_t file_last_write_time( const char * path ) { - struct stat buf; - if( stat( path, &buf ) == -1 ) { - return 0; - } - - return buf.st_mtime; -} - -static Game load_game( const char * path ) { - Game game = { }; - - game.lib = library_open( path ); - if( game.lib ) { - game.init = ( GameInit * ) library_function( game.lib, "game_init" ); - game.frame = ( GameFrame * ) library_function( game.lib, "game_frame" ); - - if( !game.init || !game.frame ) { - WARN( "load_game: couldn't find game functions (init = {}, frame = {})", - game.init == NULL ? "NULL" : "ok", - game.frame == NULL ? "NULL" : "ok" ); - - game.init = NULL; - game.frame = NULL; - } - } - - game.lib_write_time = file_last_write_time( path ); - - const char * error = library_last_error(); - if( error ) { - WARN( "load_game: {}", error ); - } - - return game; -} - -static void unload_game( Game * game ) { - if( game->lib ) { - library_close( game->lib ); - } - - game->init = NULL; - game->frame = NULL; -} - -static bool should_reload_game( const char * path, time_t lib_write_time ) { - return file_last_write_time( path ) > lib_write_time; -} - -#if STATIC_GAME extern "C" GameInit game_init; extern "C" GameFrame game_frame; -#endif #if PLATFORM_LINUX #include "autogdb.h" @@ -91,14 +27,6 @@ int main( int argc, char ** argv ) { install_debug_signal_handlers( true ); #endif -#if !STATIC_GAME -#if PLATFORM_UNIX - const char * game_library_path = argc == 2 ? argv[ 1 ] : "./hm.so"; -#elif PLATFORM_WINDOWS - const char * game_library_path = argc == 2 ? argv[ 1 ] : "./hm.dll"; -#endif -#endif - size_t persistent_size = megabytes( 64 ); u8 * persistent_memory = ( u8 * ) malloc( persistent_size ); if( persistent_memory == NULL ) { @@ -113,15 +41,8 @@ int main( int argc, char ** argv ) { GLFWwindow * window = gl_init(); text_renderer_init(); - workqueue_init( &state.background_tasks, &mem.persistent_arena, 2 ); - -#if STATIC_GAME game_init( &state, &mem ); -#else - Game game = load_game( game_library_path ); - game.init( &state, &mem ); -#endif glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); @@ -143,15 +64,6 @@ int main( int argc, char ** argv ) { break; } -#if !STATIC_GAME - if( ( s32 ) current_frame_time != ( s32 ) last_frame_time ) { - if( should_reload_game( game_library_path, game.lib_write_time ) ) { - unload_game( &game ); - game = load_game( game_library_path ); - } - } -#endif - // TODO: do this properly GameInput input = { }; input.keys[ KEY_A ] = glfwGetKey( window, GLFW_KEY_A ) == GLFW_PRESS; @@ -182,13 +94,7 @@ int main( int argc, char ** argv ) { last_xpos = xpos; last_ypos = ypos; -#if STATIC_GAME game_frame( &state, &mem, &input, current_frame_time, dt ); -#else - if( game.frame ) { - game.frame( &state, &mem, &input, current_frame_time, dt ); - } -#endif glfwSwapBuffers( window ); glfwPollEvents(); @@ -206,10 +112,6 @@ int main( int argc, char ** argv ) { workqueue_term( &state.background_tasks ); -#if !STATIC_GAME - unload_game( &game ); -#endif - text_renderer_term(); gl_term(); diff --git a/scripts/gen_makefile.lua b/scripts/gen_makefile.lua @@ -7,7 +7,7 @@ local configs = { cxx = "...", lib = "...", - cxxflags = "/I . /c /Oi /Gm- /GR- /EHa- /nologo /DNOMINMAX /D_USE_MATH_DEFINES /DWIN32_LEAN_AND_MEAN /DSTATIC_GAME", + cxxflags = "/I . /c /Oi /Gm- /GR- /EHa- /nologo /DNOMINMAX /D_USE_MATH_DEFINES /DWIN32_LEAN_AND_MEAN", -- ldflags = "user32.lib shell32.lib opengl32.lib gdi32.lib Ws2_32.lib", ldflags = "user32.lib shell32.lib dbghelp.lib /nologo", warnings = "/W4 /wd4100 /wd4201 /wd4189 /wd4351 /wd4505 /wd4127 /wd4530 /wd4702 /D_CRT_SECURE_NO_WARNINGS", @@ -29,7 +29,7 @@ local configs = { lib_prefix = "lib", lib_suffix = ".a", - cxxflags = "-I . -c -x c++ -std=c++11 -msse2 -fno-exceptions -fno-rtti -fno-strict-aliasing -fno-strict-overflow -D_USE_MATH_DEFINES -DSTATIC_GAME", + cxxflags = "-I . -c -x c++ -std=c++11 -msse2 -fno-exceptions -fno-rtti -fno-strict-aliasing -fno-strict-overflow -D_USE_MATH_DEFINES", ldflags = "-lm -lpthread -ldl", warnings = "-Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wshadow -Wcast-align -Wstrict-overflow ", -- -Wconversion },