diff options
| author | jussi | 2023-04-09 22:19:47 +0300 |
|---|---|---|
| committer | jussi | 2023-04-09 22:19:47 +0300 |
| commit | f4ae19ca7d62a2bc6b125a1ddb678300b30790d2 (patch) | |
| tree | 057373c6d815aacfc5127bdba274b848ccbd93be /src/lights.c | |
| parent | 6dad6544d7196905668b4863487daa00ac9843f7 (diff) | |
| download | reilua-enhanced-f4ae19ca7d62a2bc6b125a1ddb678300b30790d2.tar.gz reilua-enhanced-f4ae19ca7d62a2bc6b125a1ddb678300b30790d2.tar.bz2 reilua-enhanced-f4ae19ca7d62a2bc6b125a1ddb678300b30790d2.zip | |
New argument style for rlgl, text, lights and math.
Diffstat (limited to 'src/lights.c')
| -rw-r--r-- | src/lights.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/lights.c b/src/lights.c index b82ba8d..180cbd1 100644 --- a/src/lights.c +++ b/src/lights.c @@ -32,6 +32,20 @@ bool validLight( size_t id ) { } } +static int newLight() { + int i = 0; + + for ( i = 0; i < state->lightCount; i++ ) { + if ( state->lights[i] == NULL ) { + break; + } + } + state->lights[i] = malloc( sizeof( Light ) ); + checkLightRealloc( i ); + + return i; +} + /* ## Lights - Basics */ @@ -45,32 +59,21 @@ Create a light and get shader locations - Success return int */ int llightsCreateLight( lua_State *L ) { - if ( !lua_isnumber( L, -5 ) || !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) + || !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.CreateLight( int type, Vector3 position, Vector3 target, Color color, Shader shader )" ); lua_pushinteger( L, -1 ); return 1; } - size_t shaderId = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - Color color = uluaGetColor( L ); - lua_pop( L, 1 ); - Vector3 target = uluaGetVector3( L ); - lua_pop( L, 1 ); - Vector3 position = uluaGetVector3( L ); - lua_pop( L, 1 ); - int type = lua_tointeger( L, -1 ); - - int i = 0; + int type = lua_tointeger( L, 1 ); + Vector3 position = uluaGetVector3Index( L, 2 ); + Vector3 target = uluaGetVector3Index( L, 3 ); + Color color = uluaGetColorIndex( L, 4 ); + size_t shaderId = lua_tointeger( L, 5 ); - for ( i = 0; i < state->lightCount; i++ ) { - if ( state->lights[i] == NULL ) { - break; - } - } - state->lights[i] = malloc( sizeof( Light ) ); + int i = newLight(); *state->lights[i] = CreateLight( type, position, target, color, *state->shaders[ shaderId ] ); lua_pushinteger( L, i ); - checkLightRealloc( i ); return 1; } @@ -84,14 +87,13 @@ Send light properties to shader - Success return true */ int llightsUpdateLightValues( lua_State *L ) { - if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.UpdateLightValues( Shader shader, Light light )" ); lua_pushboolean( L, false ); return 1; } - size_t lightId = lua_tointeger( L, -1 ); - lua_pop( L, 1 ); - size_t shaderId = lua_tointeger( L, -1 ); + size_t shaderId = lua_tointeger( L, 1 ); + size_t lightId = lua_tointeger( L, 2 ); if ( !validLight( lightId ) ) { lua_pushboolean( L, false ); |
