Use GetApplicationDirectory instead of GetWorkingDirectory for basePath if no path argument given.

This commit is contained in:
jussi
2024-05-20 15:45:31 +03:00
parent e84be85254
commit 9edaf7a47b
9 changed files with 25 additions and 23 deletions

6
API.md
View File

@@ -5385,9 +5385,9 @@ Note: angle must be provided in radians
> RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp ) > RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp )
Rotates the camera around it's right vector, pitch is "looking up and down" Rotates the camera around it's right vector, pitch is "looking up and down"
- lockView prevents camera overrotation (aka "somersaults") - lockView prevents camera overrotation (aka "somersaults")
- rotateAroundTarget defines if rotation is around target or around it's position - rotateAroundTarget defines if rotation is around target or around it's position
- rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE) - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
NOTE: angle must be provided in radians NOTE: angle must be provided in radians
--- ---

View File

@@ -2559,9 +2559,9 @@ function RL.Camera3DMoveToTarget( camera, delta ) end
function RL.Camera3DYaw( camera, angle, rotateAroundTarget ) end function RL.Camera3DYaw( camera, angle, rotateAroundTarget ) end
---Rotates the camera around it's right vector, pitch is "looking up and down" ---Rotates the camera around it's right vector, pitch is "looking up and down"
--- - lockView prevents camera overrotation (aka "somersaults") ---- lockView prevents camera overrotation (aka "somersaults")
--- - rotateAroundTarget defines if rotation is around target or around it's position ---- rotateAroundTarget defines if rotation is around target or around it's position
--- - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE) ---- rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
---NOTE: angle must be provided in radians ---NOTE: angle must be provided in radians
---@param camera any ---@param camera any
---@param angle number ---@param angle number

View File

@@ -9,6 +9,7 @@ KEY CHANGES:
- ADDED OpenGL Stencil management functions. - ADDED OpenGL Stencil management functions.
- CHANGE: Object libraries like Vector2 optimizations. Separated table argument style for new and set methods. - CHANGE: Object libraries like Vector2 optimizations. Separated table argument style for new and set methods.
Option for pre generated temp objects. There was a lot of overhead on old new method. Option for pre generated temp objects. There was a lot of overhead on old new method.
- CHANGE: Use GetApplicationDirectory instead of GetWorkingDirectory for basePath if no path argument given.
DETAILED CHANGES: DETAILED CHANGES:
- ADDED: GetBufferElementSize and GetBufferLength. - ADDED: GetBufferElementSize and GetBufferLength.

View File

@@ -5,7 +5,7 @@
#endif #endif
typedef struct { typedef struct {
char* exePath; char* basePath;
bool hasWindow; bool hasWindow;
bool run; bool run;
bool gcUnload; bool gcUnload;
@@ -45,6 +45,6 @@ typedef struct {
extern State* state; extern State* state;
bool stateInit( int argn, const char** argc, const char* exePath ); bool stateInit( int argn, const char** argc, const char* basePath );
void stateInitInterpret( int argn, const char** argc ); void stateInitInterpret( int argn, const char** argc );
void stateFree(); void stateFree();

View File

@@ -1591,7 +1591,7 @@ Return game directory (where main.lua is located)
- Success return string - Success return string
*/ */
int lcoreGetBasePath( lua_State* L ) { int lcoreGetBasePath( lua_State* L ) {
lua_pushstring( L, state->exePath ); lua_pushstring( L, state->basePath );
return 1; return 1;
} }

View File

@@ -32,7 +32,7 @@ Copy a block of pixels from one framebuffer object to another.
Use nil RenderTexture for window framebuffer Use nil RenderTexture for window framebuffer
*/ */
int lglBlitFramebuffer( lua_State* L ) { int lglBlitFramebuffer( lua_State* L ) {
// #if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL ) #if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL )
if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) { if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) {
TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" ); TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" );
lua_pushnil( L ); lua_pushnil( L );
@@ -70,7 +70,7 @@ int lglBlitFramebuffer( lua_State* L ) {
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
return 1; return 1;
// #endif #endif
} }
/* /*

View File

@@ -1160,10 +1160,10 @@ bool luaCallMain() {
snprintf( path, STRING_LEN, "main" ); snprintf( path, STRING_LEN, "main" );
} }
#else #else
snprintf( path, STRING_LEN, "%smain.lua", state->exePath ); snprintf( path, STRING_LEN, "%smain.lua", state->basePath );
/* Alternatively look for main. Could be precompiled binary file. */ /* Alternatively look for main. Could be precompiled binary file. */
if ( !FileExists( path ) ) { if ( !FileExists( path ) ) {
snprintf( path, STRING_LEN, "%smain", state->exePath ); snprintf( path, STRING_LEN, "%smain", state->basePath );
} }
#endif #endif
luaL_dofile( L, path ); luaL_dofile( L, path );

View File

@@ -20,7 +20,7 @@ inline static void printVersion() {
} }
int main( int argn, const char** argc ) { int main( int argn, const char** argc ) {
char exePath[ STRING_LEN ] = { '\0' }; char basePath[ STRING_LEN ] = { '\0' };
bool interpret_mode = false; bool interpret_mode = false;
if ( 1 < argn ) { if ( 1 < argn ) {
@@ -36,15 +36,16 @@ int main( int argn, const char** argc ) {
interpret_mode = true; interpret_mode = true;
if ( 2 < argn ) { if ( 2 < argn ) {
sprintf( exePath, "%s/%s", GetWorkingDirectory(), argc[2] ); sprintf( basePath, "%s/%s", GetWorkingDirectory(), argc[2] );
} }
} }
else{ else{
sprintf( exePath, "%s/%s", GetWorkingDirectory(), argc[1] ); sprintf( basePath, "%s/%s", GetWorkingDirectory(), argc[1] );
} }
} }
/* If no argument given, assume main.lua is in exe directory. */
else { else {
sprintf( exePath, "%s/", GetWorkingDirectory() ); sprintf( basePath, "%s", GetApplicationDirectory() );
} }
if ( interpret_mode ) { if ( interpret_mode ) {
@@ -54,7 +55,7 @@ int main( int argn, const char** argc ) {
lua_pushcfunction( L, luaTraceback ); lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L ); int tracebackidx = lua_gettop( L );
luaL_loadfile( L, exePath ); luaL_loadfile( L, basePath );
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
@@ -63,7 +64,7 @@ int main( int argn, const char** argc ) {
} }
else { else {
printVersion(); printVersion();
stateInit( argn, argc, exePath ); stateInit( argn, argc, basePath );
state->run = luaCallMain(); state->run = luaCallMain();
while ( state->run ) { while ( state->run ) {

View File

@@ -6,11 +6,11 @@
State* state; State* state;
bool stateInit( int argn, const char** argc, const char* exePath ) { bool stateInit( int argn, const char** argc, const char* basePath ) {
state = malloc( sizeof( State ) ); state = malloc( sizeof( State ) );
state->exePath = malloc( STRING_LEN * sizeof( char ) ); state->basePath = malloc( STRING_LEN * sizeof( char ) );
strncpy( state->exePath, exePath, STRING_LEN - 1 ); strncpy( state->basePath, basePath, STRING_LEN - 1 );
state->hasWindow = true; state->hasWindow = true;
state->run = true; state->run = true;
@@ -65,7 +65,7 @@ void stateFree() {
#ifdef PLATFORM_DESKTOP_SDL #ifdef PLATFORM_DESKTOP_SDL
free( state->SDL_eventQueue ); free( state->SDL_eventQueue );
#endif #endif
free( state->exePath ); free( state->basePath );
free( state->RLGLcurrentShaderLocs ); free( state->RLGLcurrentShaderLocs );
free( state ); free( state );
} }