New argument style for rlgl, text, lights and math.

This commit is contained in:
jussi
2023-04-09 22:19:47 +03:00
parent 6dad6544d7
commit f4ae19ca7d
6 changed files with 433 additions and 515 deletions

View File

@@ -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 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 );
int i = 0;
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 );