summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c42
-rw-r--r--src/state.c16
2 files changed, 47 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c
index 72dbdca..19a49a3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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() ) {