diff options
| author | Indrajith K L | 2025-11-09 16:12:20 +0530 |
|---|---|---|
| committer | Indrajith K L | 2025-11-09 16:12:20 +0530 |
| commit | 8c9367f3689aee05d33fc1cae8a5d1aa6d2b5fb8 (patch) | |
| tree | 94ab60d8a0dd939478f9b2838bdc6c1d693cb9a8 /src | |
| parent | 0fbc961bb8e7b9864c0982bb86b0de2e25d6f4aa (diff) | |
| download | reilua-enhanced-8c9367f3689aee05d33fc1cae8a5d1aa6d2b5fb8.tar.gz reilua-enhanced-8c9367f3689aee05d33fc1cae8a5d1aa6d2b5fb8.tar.bz2 reilua-enhanced-8c9367f3689aee05d33fc1cae8a5d1aa6d2b5fb8.zip | |
Add game folder workflow, custom executable names, cross-platform tasks, and logging controls
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 42 | ||||
| -rw-r--r-- | src/state.c | 16 |
2 files changed, 47 insertions, 11 deletions
@@ -33,12 +33,14 @@ int main( int argn, const char** argc ) { bool interpret_mode = false; bool show_console = false; bool skip_splash = false; + bool enable_logging = false; #ifdef _WIN32 /* Check for --log and --no-logo arguments */ for ( int i = 1; i < argn; i++ ) { if ( strcmp( argc[i], "--log" ) == 0 ) { show_console = true; + enable_logging = true; } if ( strcmp( argc[i], "--no-logo" ) == 0 ) { skip_splash = true; @@ -59,11 +61,13 @@ int main( int argn, const char** argc ) { FreeConsole(); } #else - /* Check for --no-logo on non-Windows platforms */ + /* Check for --no-logo and --log on non-Windows platforms */ for ( int i = 1; i < argn; i++ ) { if ( strcmp( argc[i], "--no-logo" ) == 0 ) { skip_splash = true; - break; + } + if ( strcmp( argc[i], "--log" ) == 0 ) { + enable_logging = true; } } #endif @@ -96,26 +100,44 @@ int main( int argn, const char** argc ) { else { /* Only flags were provided, use default path search */ char testPath[ STRING_LEN ] = { '\0' }; - sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + /* Check for game/main.lua in working directory */ + sprintf( testPath, "%s/game/main.lua", GetWorkingDirectory() ); if ( FileExists( testPath ) ) { - sprintf( basePath, "%s", GetWorkingDirectory() ); + sprintf( basePath, "%s/game/", GetWorkingDirectory() ); } + /* Check for main.lua in working directory */ else { - sprintf( basePath, "%s", GetApplicationDirectory() ); + sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + if ( FileExists( testPath ) ) { + sprintf( basePath, "%s", GetWorkingDirectory() ); + } + /* Check exe directory */ + else { + sprintf( basePath, "%s", GetApplicationDirectory() ); + } } } } - /* If no argument given, check current directory first, then exe directory. */ + /* If no argument given, check game folder first, then current directory, then exe directory. */ else { char testPath[ STRING_LEN ] = { '\0' }; - sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + /* Check for game/main.lua in working directory */ + sprintf( testPath, "%s/game/main.lua", GetWorkingDirectory() ); if ( FileExists( testPath ) ) { - sprintf( basePath, "%s", GetWorkingDirectory() ); + sprintf( basePath, "%s/game/", GetWorkingDirectory() ); } + /* Check for main.lua in working directory */ else { - sprintf( basePath, "%s", GetApplicationDirectory() ); + sprintf( testPath, "%s/main.lua", GetWorkingDirectory() ); + if ( FileExists( testPath ) ) { + sprintf( basePath, "%s", GetWorkingDirectory() ); + } + /* Check exe directory */ + else { + sprintf( basePath, "%s", GetApplicationDirectory() ); + } } } @@ -135,7 +157,7 @@ int main( int argn, const char** argc ) { } else { printVersion(); - stateInit( argn, argc, basePath ); + stateInit( argn, argc, basePath, enable_logging ); /* Show splash screens if not skipped */ if ( !skip_splash ) { diff --git a/src/state.c b/src/state.c index 4fdc729..2e946ea 100644 --- a/src/state.c +++ b/src/state.c @@ -10,7 +10,7 @@ State* state; -bool stateInit( int argn, const char** argc, const char* basePath ) { +bool stateInit( int argn, const char** argc, const char* basePath, bool enable_logging ) { state = malloc( sizeof( State ) ); state->basePath = malloc( STRING_LEN * sizeof( char ) ); @@ -36,6 +36,20 @@ bool stateInit( int argn, const char** argc, const char* basePath ) { state->mouseScale = (Vector2){ 1, 1 }; state->customFontLoaded = false; + /* Set log level based on build type and --log flag */ +#ifdef NDEBUG + /* Release build - only show warnings/errors unless --log is specified */ + if ( enable_logging ) { + SetTraceLogLevel( LOG_INFO ); + } + else { + SetTraceLogLevel( LOG_WARNING ); + } +#else + /* Debug/Dev build - always show all logs */ + SetTraceLogLevel( LOG_INFO ); +#endif + InitWindow( state->resolution.x, state->resolution.y, "ReiLua" ); if ( !IsWindowReady() ) { |
