diff options
| author | jussi | 2023-10-28 16:42:49 +0300 |
|---|---|---|
| committer | jussi | 2023-10-28 16:42:49 +0300 |
| commit | fd49d806cf1f54fb86c3ed7b9db499f473a3ef1d (patch) | |
| tree | a9c3e8ea40a4b6d2b1104bad4cff998ae7f4d4ca | |
| parent | af03c7364ea0dfe2c8bb269eb8a8f9b580f39633 (diff) | |
| download | reilua-enhanced-fd49d806cf1f54fb86c3ed7b9db499f473a3ef1d.tar.gz reilua-enhanced-fd49d806cf1f54fb86c3ed7b9db499f473a3ef1d.tar.bz2 reilua-enhanced-fd49d806cf1f54fb86c3ed7b9db499f473a3ef1d.zip | |
New object types for Wave, Sound, Music and Light.
| -rw-r--r-- | API.md | 201 | ||||
| -rw-r--r-- | ReiLua_API.lua | 222 | ||||
| -rw-r--r-- | changelog | 2 | ||||
| -rw-r--r-- | include/audio.h | 2 | ||||
| -rw-r--r-- | include/lights.h | 2 | ||||
| -rw-r--r-- | include/lua_core.h | 4 | ||||
| -rw-r--r-- | include/state.h | 16 | ||||
| -rw-r--r-- | src/audio.c | 834 | ||||
| -rw-r--r-- | src/gl.c | 2 | ||||
| -rw-r--r-- | src/lights.c | 247 | ||||
| -rw-r--r-- | src/lua_core.c | 93 | ||||
| -rw-r--r-- | src/state.c | 48 | ||||
| -rw-r--r-- | src/text.c | 6 | ||||
| -rw-r--r-- | src/textures.c | 4 |
14 files changed, 409 insertions, 1274 deletions
@@ -3879,7 +3879,7 @@ Load font from file with extended parameters. Loading the default character set > font = RL.LoadFontFromImage( Image image, Color key, int firstChar ) -Load font from Image ( XNA style ) +Load font from Image ( XNA style) - Success return Font @@ -4646,12 +4646,9 @@ Get collision info between ray and quad --- -> success = RL.SetMasterVolume( float volume ) +> RL.SetMasterVolume( float volume ) -Set master volume ( listener ) - -- Failure return false -- Success return true +Set master volume (listener) --- @@ -4663,8 +4660,8 @@ Set master volume ( listener ) Load sound from file -- Failure return -1 -- Success return int +- Failure return nil +- Success return Sound --- @@ -4672,8 +4669,8 @@ Load sound from file Load wave data from file -- Failure return -1 -- Success return int +- Failure return nil +- Success return Wave --- @@ -4681,26 +4678,7 @@ Load wave data from file Load sound from wave data -- Failure return -1 -- Success return int - ---- - -> success = RL.UnloadSound( Sound sound ) - -Unload sound - -- Failure return false -- Success return true - ---- - -> success = RL.UnloadWave( Wave wave ) - -Unload wave data - -- Failure return false -- Success return true +- Success return Sound --- @@ -4708,8 +4686,7 @@ Unload wave data Export wave data to file, returns true on success -- Failure return false -- Success return true +- Success return bool --- @@ -4717,7 +4694,6 @@ Export wave data to file, returns true on success Export wave sample data to code (.h), returns true on success -- Failure return false - Success return true --- @@ -4726,103 +4702,74 @@ Export wave sample data to code (.h), returns true on success --- -> success = RL.PlaySound( Sound sound ) +> RL.PlaySound( Sound sound ) Play a sound -- Failure return false -- Success return true - --- -> success = RL.StopSound( Sound sound ) +> RL.StopSound( Sound sound ) Stop playing a sound -- Failure return false -- Success return true - --- -> success = RL.PauseSound( Sound sound ) +> RL.PauseSound( Sound sound ) Pause a sound -- Failure return false -- Success return true - --- -> success = RL.ResumeSound( Sound sound ) +> RL.ResumeSound( Sound sound ) Resume a paused sound -- Failure return false -- Success return true - --- > playing = RL.IsSoundPlaying( Sound sound ) Check if a sound is currently playing -- Failure return nil - Success return bool --- -> success = RL.SetSoundVolume( Sound sound, float volume ) +> RL.SetSoundVolume( Sound sound, float volume ) -Set volume for a sound ( 1.0 is max level ) - -- Failure return false -- Success return true +Set volume for a sound (1.0 is max level) --- -> success = RL.SetSoundPitch( Sound sound, float pitch ) +> RL.SetSoundPitch( Sound sound, float pitch ) -Set pitch for a sound ( 1.0 is base level ) - -- Failure return false -- Success return true +Set pitch for a sound (1.0 is base level) --- -> success = RL.SetSoundPan( Sound sound, float pan ) +> RL.SetSoundPan( Sound sound, float pan ) -Set pan for a sound ( 0.5 is center ) - -- Failure return false -- Success return true +Set pan for a sound (0.5 is center) --- -> success = RL.WaveFormat( Wave wave, int sampleRate, int sampleSize, int channels ) +> RL.WaveFormat( Wave wave, int sampleRate, int sampleSize, int channels ) Convert wave data to desired format -- Failure return false -- Success return true - --- > wave = RL.WaveCopy( Wave wave ) Copy a wave to a new wave -- Failure return -1 -- Success return int +- Success return Wave --- -> success = RL.WaveCrop( Wave wave, int initSample, int finalSample ) +> RL.WaveCrop( Wave wave, int initSample, int finalSample ) Crop a wave to defined samples range -- Failure return false -- Success return true - --- ## Audio - Music management @@ -4833,133 +4780,98 @@ Crop a wave to defined samples range Load music stream from file -- Failure return -1 -- Success return int +- Success return Music --- -> success = RL.PlayMusicStream( Music music ) +> RL.PlayMusicStream( Music music ) Start music playing -- Failure return false -- Success return true - --- > playing = RL.IsMusicStreamPlaying( Music music ) Check if music is playing -- Failure return nil - Success return bool --- -> success = RL.UpdateMusicStream( Music music ) +> RL.UpdateMusicStream( Music music ) Updates buffers for music streaming -- Failure return false -- Success return true - --- -> success = RL.StopMusicStream( Music music ) +> RL.StopMusicStream( Music music ) Stop music playing -- Failure return false -- Success return true - --- -> success = RL.PauseMusicStream( Music music ) +> RL.PauseMusicStream( Music music ) Pause music playing -- Failure return false -- Success return true - --- -> success = RL.ResumeMusicStream( Music music ) +> RL.ResumeMusicStream( Music music ) Resume playing paused music -- Failure return false -- Success return true - --- -> success = RL.SeekMusicStream( Music music, float position ) +> RL.SeekMusicStream( Music music, float position ) -Seek music to a position ( in seconds ) - -- Failure return false -- Success return true +Seek music to a position (in seconds) --- -> success = RL.SetMusicVolume( Music music, float volume ) - -Set volume for music ( 1.0 is max level ) +> RL.SetMusicVolume( Music music, float volume ) -- Failure return false -- Success return true +Set volume for music (1.0 is max level) --- -> success = RL.SetMusicPitch( Music music, float pitch ) +> RL.SetMusicPitch( Music music, float pitch ) -Set pitch for a music ( 1.0 is base level ) - -- Failure return false -- Success return true +Set pitch for a music (1.0 is base level) --- -> success = RL.SetMusicPan( Music music, float pan ) - -Set pan for a music ( 0.5 is center ) +> RL.SetMusicPan( Music music, float pan ) -- Failure return false -- Success return true +Set pan for a music (0.5 is center) --- -> success = RL.SetMusicLooping( Music music, bool looping ) +> RL.SetMusicLooping( Music music, bool looping ) Set looping for a music -- Failure return false -- Success return true - --- > looping = RL.GetMusicLooping( Music music ) Get looping of a music -- Failure return nil - Success return bool --- > length = RL.GetMusicTimeLength( Music music ) -Get music time length ( in seconds ) +Get music time length (in seconds) -- Failure return false - Success return float --- -> played = RL.GetMusicTimePlayed( Music music ) +> timePlayed = RL.GetMusicTimePlayed( Music music ) -Get current music time played ( in seconds ) +Get current music time played (in seconds) -- Failure return false - Success return float --- @@ -6466,8 +6378,7 @@ Check icon pixel value Create a light and get shader locations -- Failure return -1 -- Success return int +- Success return Light --- @@ -6477,56 +6388,40 @@ Send light properties to shader --- -> success = RL.SetLightType( Light light, int type ) +> RL.SetLightType( Light light, int type ) Set light type -- Failure return false -- Success return true - --- -> success = RL.SetLightPosition( Light light, Vector3 position ) +> RL.SetLightPosition( Light light, Vector3 position ) Set light position -- Failure return false -- Success return true - --- -> success = RL.SetLightTarget( Light light, Vector3 target ) +> RL.SetLightTarget( Light light, Vector3 target ) Set light target -- Failure return false -- Success return true - --- -> success = RL.SetLightColor( Light light, Color color ) +> RL.SetLightColor( Light light, Color color ) Set light color -- Failure return false -- Success return true - --- -> success = RL.SetLightEnabled( Light light, bool enabled ) +> RL.SetLightEnabled( Light light, bool enabled ) Set light enabled -- Failure return false -- Success return true - --- > type = RL.GetLightType( Light light ) Get light type -- Failure return false - Success return int --- @@ -6535,7 +6430,6 @@ Get light type Get light position -- Failure return false - Success return Vector3 --- @@ -6544,7 +6438,6 @@ Get light position Get light target -- Failure return false - Success return Vector3 --- @@ -6553,7 +6446,6 @@ Get light target Get light color -- Failure return false - Success return Color --- @@ -6562,7 +6454,6 @@ Get light color Get light enabled -- Failure return nil - Success return boolean --- diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 8b5a5f1..254dd16 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -2814,7 +2814,7 @@ function RL.LoadFont( fileName ) end ---@return any font function RL.LoadFontEx( fileName, fontSize, fontChars{} ) end ----Load font from Image ( XNA style ) +---Load font from Image ( XNA style) ---- Success return Font ---@param image any ---@param key table @@ -3573,60 +3573,41 @@ function RL.GetRayCollisionQuad( ray, p1, p2, p3, p4 ) end -- Audio - Audio device management ----Set master volume ( listener ) ----- Failure return false ----- Success return true +---Set master volume (listener) ---@param volume number ----@return any success -function RL.SetMasterVolume( volume ) end +---@return any RL.SetMasterVolume +function RL.SetMasterVolume( volume ) end -- Audio - Wave/Sound Loading ---Load sound from file ----- Failure return -1 ----- Success return int +---- Failure return nil +---- Success return Sound ---@param fileName string ---@return any sound function RL.LoadSound( fileName ) end ---Load wave data from file ----- Failure return -1 ----- Success return int +---- Failure return nil +---- Success return Wave ---@param fileName string ---@return any wave function RL.LoadWave( fileName ) end ---Load sound from wave data ----- Failure return -1 ----- Success return int +---- Success return Sound ---@param wave any ---@return any sound function RL.LoadSoundFromWave( wave ) end ----Unload sound ----- Failure return false ----- Success return true ----@param sound any ----@return any success -function RL.UnloadSound( sound ) end - ----Unload wave data ----- Failure return false ----- Success return true ----@param wave any ----@return any success -function RL.UnloadWave( wave ) end - ---Export wave data to file, returns true on success ----- Failure return false ----- Success return true +---- Success return bool ---@param wave any ---@param fileName string ---@return any success function RL.ExportWave( wave, fileName ) end ---Export wave sample data to code (.h), returns true on success ----- Failure return false ---- Success return true ---@param wave any ---@param fileName string @@ -3636,200 +3617,155 @@ function RL.ExportWaveAsCode( wave, fileName ) end -- Audio - Wave/Sound management ---Play a sound ----- Failure return false ----- Success return true ---@param sound any ----@return any success -function RL.PlaySound( sound ) end +---@return any RL.PlaySound +function RL.PlaySound( sound ) end ---Stop playing a sound ----- Failure return false ----- Success return true ---@param sound any ----@return any success -function RL.StopSound( sound ) end +---@return any RL.StopSound +function RL.StopSound( sound ) end ---Pause a sound ----- Failure return false ----- Success return true ---@param sound any ----@return any success -function RL.PauseSound( sound ) end +---@return any RL.PauseSound +function RL.PauseSound( sound ) end ---Resume a paused sound ----- Failure return false ----- Success return true ---@param sound any ----@return any success -function RL.ResumeSound( sound ) end +---@return any RL.ResumeSound +function RL.ResumeSound( sound ) end ---Check if a sound is currently playing ----- Failure return nil ---- Success return bool ---@param sound any ---@return any playing function RL.IsSoundPlaying( sound ) end ----Set volume for a sound ( 1.0 is max level ) ----- Failure return false ----- Success return true +---Set volume for a sound (1.0 is max level) ---@param sound any ---@param volume number ----@return any success -function RL.SetSoundVolume( sound, volume ) end +---@return any RL.SetSoundVolume +function RL.SetSoundVolume( sound, volume ) end ----Set pitch for a sound ( 1.0 is base level ) ----- Failure return false ----- Success return true +---Set pitch for a sound (1.0 is base level) ---@param sound any ---@param pitch number ----@return any success -function RL.SetSoundPitch( sound, pitch ) end +---@return any RL.SetSoundPitch +function RL.SetSoundPitch( sound, pitch ) end ----Set pan for a sound ( 0.5 is center ) ----- Failure return false ----- Success return true +---Set pan for a sound (0.5 is center) ---@param sound any ---@param pan number ----@return any success -function RL.SetSoundPan( sound, pan ) end +---@return any RL.SetSoundPan +function RL.SetSoundPan( sound, pan ) end ---Convert wave data to desired format ----- Failure return false ----- Success return true ---@param wave any ---@param sampleRate integer ---@param sampleSize integer ---@param channels integer ----@return any success -function RL.WaveFormat( wave, sampleRate, sampleSize, channels ) end +---@return any RL.WaveFormat +function RL.WaveFormat( wave, sampleRate, sampleSize, channels ) end ---Copy a wave to a new wave ----- Failure return -1 ----- Success return int +---- Success return Wave ---@param wave any ---@return any wave function RL.WaveCopy( wave ) end ---Crop a wave to defined samples range ----- Failure return false ----- Success return true ---@param wave any ---@param initSample integer ---@param finalSample integer ----@return any success -function RL.WaveCrop( wave, initSample, finalSample ) end +---@return any RL.WaveCrop +function RL.WaveCrop( wave, initSample, finalSample ) end -- Audio - Music management ---Load music stream from file ----- Failure return -1 ----- Success return int +---- Success return Music ---@param fileName string ---@return any music function RL.LoadMusicStream( fileName ) end ---Start music playing ----- Failure return false ----- Success return true ---@param music any ----@return any success -function RL.PlayMusicStream( music ) end +---@return any RL.PlayMusicStream +function RL.PlayMusicStream( music ) end ---Check if music is playing ----- Failure return nil ---- Success return bool ---@param music any ---@return any playing function RL.IsMusicStreamPlaying( music ) end ---Updates buffers for music streaming ----- Failure return false ----- Success return true ---@param music any ----@return any success -function RL.UpdateMusicStream( music ) end +---@return any RL.UpdateMusicStream +function RL.UpdateMusicStream( music ) end ---Stop music playing ----- Failure return false ----- Success return true ---@param music any ----@return any success -function RL.StopMusicStream( music ) end +---@return any RL.StopMusicStream +function RL.StopMusicStream( music ) end ---Pause music playing ----- Failure return false ----- Success return true ---@param music any ----@return any success -function RL.PauseMusicStream( music ) end +---@return any RL.PauseMusicStream +function RL.PauseMusicStream( music ) end ---Resume playing paused music ----- Failure return false ----- Success return true ---@param music any ----@return any success -function RL.ResumeMusicStream( music ) end +---@return any RL.ResumeMusicStream +function RL.ResumeMusicStream( music ) end ----Seek music to a position ( in seconds ) ----- Failure return false ----- Success return true +---Seek music to a position (in seconds) ---@param music any ---@param position number ----@return any success -function RL.SeekMusicStream( music, position ) end +---@return any RL.SeekMusicStream +function RL.SeekMusicStream( music, position ) end ----Set volume for music ( 1.0 is max level ) ----- Failure return false ----- Success return true +---Set volume for music (1.0 is max level) ---@param music any ---@param volume number ----@return any success -function RL.SetMusicVolume( music, volume ) end +---@return any RL.SetMusicVolume +function RL.SetMusicVolume( music, volume ) end ----Set pitch for a music ( 1.0 is base level ) ----- Failure return false ----- Success return true +---Set pitch for a music (1.0 is base level) ---@param music any ---@param pitch number ----@return any success -function RL.SetMusicPitch( music, pitch ) end +---@return any RL.SetMusicPitch +function RL.SetMusicPitch( music, pitch ) end ----Set pan for a music ( 0.5 is center ) ----- Failure return false ----- Success return true +---Set pan for a music (0.5 is center) ---@param music any ---@param pan number ----@return any success -function RL.SetMusicPan( music, pan ) end +---@return any RL.SetMusicPan +function RL.SetMusicPan( music, pan ) end ---Set looping for a music ----- Failure return false ----- Success return true ---@param music any ---@param looping boolean ----@return any success -function RL.SetMusicLooping( music, looping ) end +---@return any RL.SetMusicLooping +function RL.SetMusicLooping( music, looping ) end ---Get looping of a music ----- Failure return nil ---- Success return bool ---@param music any ---@return any looping function RL.GetMusicLooping( music ) end ----Get music time length ( in seconds ) ----- Failure return false +---Get music time length (in seconds) ---- Success return float ---@param music any ---@return any length function RL.GetMusicTimeLength( music ) end ----Get current music time played ( in seconds ) ----- Failure return false +---Get current music time played (in seconds) ---- Success return float ---@param music any ----@return any played +---@return any timePlayed function RL.GetMusicTimePlayed( music ) end -- Math - Utils @@ -5189,8 +5125,7 @@ function RL.GuiCheckIconPixel( iconId, pos ) end -- Lights - Basics ---Create a light and get shader locations ----- Failure return -1 ----- Success return int +---- Success return Light ---@param type integer ---@param position table ---@param target table @@ -5206,75 +5141,60 @@ function RL.CreateLight( type, position, target, color, shader ) end function RL.UpdateLightValues( shader, light ) end ---Set light type ----- Failure return false ----- Success return true ---@param light any ---@param type integer ----@return any success -function RL.SetLightType( light, type ) end +---@return any RL.SetLightType +function RL.SetLightType( light, type ) end ---Set light position ----- Failure return false ----- Success return true ---@param light any ---@param position table ----@return any success -function RL.SetLightPosition( light, position ) end +---@return any RL.SetLightPosition +function RL.SetLightPosition( light, position ) end ---Set light target ----- Failure return false ----- Success return true ---@param light any ---@param target table ----@return any success -function RL.SetLightTarget( light, target ) end +---@return any RL.SetLightTarget +function RL.SetLightTarget( light, target ) end ---Set light color ----- Failure return false ----- Success return true ---@param light any ---@param color table ----@return any success -function RL.SetLightColor( light, color ) end +---@return any RL.SetLightColor +function RL.SetLightColor( light, color ) end ---Set light enabled ----- Failure return false ----- Success return true ---@param light any ---@param enabled boolean ----@return any success -function RL.SetLightEnabled( light, enabled ) end +---@return any RL.SetLightEnabled +function RL.SetLightEnabled( light, enabled ) end ---Get light type ----- Failure return false ---- Success return int ---@param light any ---@return any type function RL.GetLightType( light ) end ---Get light position ----- Failure return false ---- Success return Vector3 ---@param light any ---@return any position function RL.GetLightPosition( light ) end ---Get light target ----- Failure return false ---- Success return Vector3 ---@param light any ---@return any target function RL.GetLightTarget( light ) end ---Get light color ----- Failure return false ---- Success return Color ---@param light any ---@return any color function RL.GetLightColor( light ) end ---Get light enabled ----- Failure return nil ---- Success return boolean ---@param light any ---@return any enabled @@ -14,7 +14,9 @@ DETAILED CHANGES: - ADDED: GetRenderTextureTexture and GetRenderTextureDepthTexture. - REMOVED: UnloadCamera2D and UnloadCamera3D. - REMOVED: UnloadShader. + - REMOVED: UnloadFont. - ADDED: LoadFontEx takes also fontChars. + - REMOVED: UnloadWave and UnloadSound. ------------------------------------------------------------------------ Release: ReiLua version 0.5.0 Using Raylib 4.5 diff --git a/include/audio.h b/include/audio.h index 07f6181..756f16f 100644 --- a/include/audio.h +++ b/include/audio.h @@ -6,8 +6,6 @@ int laudioSetMasterVolume( lua_State *L ); int laudioLoadSound( lua_State *L ); int laudioLoadWave( lua_State *L ); int laudioLoadSoundFromWave( lua_State *L ); -int laudioUnloadSound( lua_State *L ); -int laudioUnloadWave( lua_State *L ); int laudioExportWave( lua_State *L ); int laudioExportWaveAsCode( lua_State *L ); /* Wave/Sound management. */ diff --git a/include/lights.h b/include/lights.h index 1268d86..f6c0f5f 100644 --- a/include/lights.h +++ b/include/lights.h @@ -1,7 +1,5 @@ #pragma once -/* Validators. */ -bool validLight( size_t id ); /* Basics. */ int llightsCreateLight( lua_State *L ); int llightsUpdateLightValues( lua_State *L ); diff --git a/include/lua_core.h b/include/lua_core.h index c90464e..2996b54 100644 --- a/include/lua_core.h +++ b/include/lua_core.h @@ -75,6 +75,10 @@ void uluaPushCamera2D( lua_State *L, Camera2D camera ); void uluaPushCamera3D( lua_State *L, Camera3D camera ); void uluaPushShader( lua_State *L, Shader shader ); void uluaPushFont( lua_State *L, Font font ); +void uluaPushWave( lua_State *L, Wave wave ); +void uluaPushSound( lua_State *L, Sound sound ); +void uluaPushMusic( lua_State *L, Music music ); +void uluaPushLight( lua_State *L, Light light ); int uluaGetTableLen( lua_State *L ); int uluaGetTableLenIndex( lua_State *L, int index ); diff --git a/include/state.h b/include/state.h index bf86d00..37a6d8c 100644 --- a/include/state.h +++ b/include/state.h @@ -15,18 +15,6 @@ typedef struct { Vector2 resolution; int logLevelInvalid; /* Resources. */ - /* Sounds. */ - Wave **waves; - size_t waveCount; - size_t waveAlloc; - /* Sounds. */ - Sound **sounds; - size_t soundCount; - size_t soundAlloc; - /* Music. */ - Music **musics; - size_t musicCount; - size_t musicAlloc; /* Meshes. */ Mesh **meshes; size_t meshCount; @@ -43,10 +31,6 @@ typedef struct { ModelAnimations **animations; size_t animationCount; size_t animationAlloc; - /* Lights. */ - Light **lights; - size_t lightCount; - size_t lightAlloc; /* Raylib GLFW input callback events. */ /* Window events. */ GLFWwindowsizefun raylibWindowSizeCallback; diff --git a/src/audio.c b/src/audio.c index 3ba9cb0..935bf1f 100644 --- a/src/audio.c +++ b/src/audio.c @@ -3,147 +3,21 @@ #include "audio.h" #include "lua_core.h" -static bool validSound( size_t id ) { - if ( id < 0 || state->soundCount < id || state->sounds[ id ] == NULL ) { - TraceLog( state->logLevelInvalid, "%s %d", "Invalid sound", id ); - return false; - } - else { - return true; - } -} - -static bool validWave( size_t id ) { - if ( id < 0 || state->waveCount < id || state->waves[ id ] == NULL ) { - TraceLog( state->logLevelInvalid, "%s %d", "Invalid wave", id ); - return false; - } - else { - return true; - } -} - -static bool validMusic( size_t id ) { - if ( id < 0 || state->musicCount < id || state->musics[ id ] == NULL ) { - TraceLog( state->logLevelInvalid, "%s %d", "Invalid music", id ); - return false; - } - else { - return true; - } -} - -static void checkSoundRealloc( int i ) { - if ( i == state->soundCount ) { - state->soundCount++; - } - - if ( state->soundCount == state->soundAlloc ) { - state->soundAlloc += ALLOC_PAGE_SIZE; - state->sounds = realloc( state->sounds, state->soundAlloc * sizeof( Sound* ) ); - - for ( i = state->soundCount; i < state->soundAlloc; i++ ) { - state->sounds[i] = NULL; - } - } -} - -static void checkWaveRealloc( int i ) { - if ( i == state->waveCount ) { - state->waveCount++; - } - - if ( state->waveCount == state->waveAlloc ) { - state->waveAlloc += ALLOC_PAGE_SIZE; - state->waves = realloc( state->waves, state->waveAlloc * sizeof( Wave* ) ); - - for ( i = state->waveCount; i < state->waveAlloc; i++ ) { - state->waves[i] = NULL; - } - } -} - -static void checkMusicRealloc( int i ) { - if ( i == state->musicCount ) { - state->musicCount++; - } - - if ( state->musicCount == state->musicAlloc ) { - state->musicAlloc += ALLOC_PAGE_SIZE; - state->musics = realloc( state->musics, state->musicAlloc * sizeof( Music* ) ); - - for ( i = state->musicCount; i < state->musicAlloc; i++ ) { - state->musics[i] = NULL; - } - } -} - -static int newSound() { - int i = 0; - - for ( i = 0; i < state->soundCount; i++ ) { - if ( state->sounds[i] == NULL ) { - break; - } - } - state->sounds[i] = malloc( sizeof( Sound ) ); - checkSoundRealloc( i ); - - return i; -} - -static int newWave() { - int i = 0; - - for ( i = 0; i < state->waveCount; i++ ) { - if ( state->waves[i] == NULL ) { - break; - } - } - state->waves[i] = malloc( sizeof( Wave ) ); - checkWaveRealloc( i ); - - return i; -} - -static int newMusic() { - int i = 0; - - for ( i = 0; i < state->musicCount; i++ ) { - if ( state->musics[i] == NULL ) { - break; - } - } - state->musics[i] = malloc( sizeof( Music ) ); - checkMusicRealloc( i ); - - return i; -} - /* ## Audio - Audio device management */ /* -> success = RL.SetMasterVolume( float volume ) +> RL.SetMasterVolume( float volume ) -Set master volume ( listener ) - -- Failure return false -- Success return true +Set master volume (listener) */ int laudioSetMasterVolume( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMasterVolume( float volume )" ); - lua_pushboolean( L, false ); - return 1; - } - float volume = lua_tonumber( L, 1 ); + float volume = luaL_checknumber( L, 1 ); SetMasterVolume( volume ); - lua_pushboolean( L, true ); - return 1; + return 0; } /* @@ -155,26 +29,19 @@ int laudioSetMasterVolume( lua_State *L ) { Load sound from file -- Failure return -1 -- Success return int +- Failure return nil +- Success return Sound */ int laudioLoadSound( lua_State *L ) { - if ( !lua_isstring( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadSound( string fileName )" ); - lua_pushinteger( L, -1 ); - return 1; - } + if ( FileExists( luaL_checkstring( L, 1 ) ) ) { + uluaPushSound( L, LoadSound( lua_tostring( L, 1 ) ) ); - if ( FileExists( lua_tostring( L, 1 ) ) ) { - int i = newSound(); - *state->sounds[i] = LoadSound( lua_tostring( L, 1 ) ); - lua_pushinteger( L, i ); - return 1; - } - else { - lua_pushinteger( L, -1 ); return 1; } + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); + lua_pushnil( L ); + + return 1; } /* @@ -182,26 +49,19 @@ int laudioLoadSound( lua_State *L ) { Load wave data from file -- Failure return -1 -- Success return int +- Failure return nil +- Success return Wave */ int laudioLoadWave( lua_State *L ) { - if ( !lua_isstring( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadWave( string fileName )" ); - lua_pushinteger( L, -1 ); - return 1; - } + if ( FileExists( luaL_checkstring( L, 1 ) ) ) { + uluaPushWave( L, LoadWave( lua_tostring( L, 1 ) ) ); - if ( FileExists( lua_tostring( L, 1 ) ) ) { - int i = newWave(); - *state->waves[i] = LoadWave( lua_tostring( L, 1 ) ); - lua_pushinteger( L, i ); - return 1; - } - else { - lua_pushinteger( L, -1 ); return 1; } + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); + lua_pushnil( L ); + + return 1; } /* @@ -209,78 +69,12 @@ int laudioLoadWave( lua_State *L ) { Load sound from wave data -- Failure return -1 -- Success return int +- Success return Sound */ int laudioLoadSoundFromWave( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadSoundFromWave( Wave wave )" ); - lua_pushinteger( L, -1 ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); + Wave *wave = luaL_checkudata( L, 1, "Wave" ); - if ( !validWave( waveId ) ) { - lua_pushinteger( L, -1 ); - return 1; - } - int i = newSound(); - *state->sounds[i] = LoadSoundFromWave( *state->waves[ waveId ] ); - lua_pushinteger( L, i ); - - return 1; -} - -/* -> success = RL.UnloadSound( Sound sound ) - -Unload sound - -- Failure return false -- Success return true -*/ -int laudioUnloadSound( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadSound( Sound sound )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); - - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - UnloadSound( *state->sounds[ soundId ] ); - state->sounds[ soundId ] = NULL; - lua_pushboolean( L, true ); - - return 1; -} - -/* -> success = RL.UnloadWave( Wave wave ) - -Unload wave data - -- Failure return false -- Success return true -*/ -int laudioUnloadWave( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadWave( Wave wave )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); - - if ( !validWave( waveId ) ) { - lua_pushboolean( L, false ); - return 1; - } - UnloadWave( *state->waves[ waveId ] ); - state->waves[ waveId ] = NULL; - lua_pushboolean( L, true ); + uluaPushSound( L, LoadSoundFromWave( *wave ) ); return 1; } @@ -290,22 +84,12 @@ int laudioUnloadWave( lua_State *L ) { Export wave data to file, returns true on success -- Failure return false -- Success return true +- Success return bool */ int laudioExportWave( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ExportWave( Wave wave, string fileName )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); + Wave *wave = luaL_checkudata( L, 1, "Wave" ); - if ( !validWave( waveId ) ) { - lua_pushboolean( L, false ); - return 1; - } - lua_pushboolean( L, ExportWave( *state->waves[ waveId ], lua_tostring( L, 2 ) ) ); + lua_pushboolean( L, ExportWave( *wave, luaL_checkstring( L, 2 ) ) ); return 1; } @@ -315,22 +99,12 @@ int laudioExportWave( lua_State *L ) { Export wave sample data to code (.h), returns true on success -- Failure return false - Success return true */ int laudioExportWaveAsCode( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ExportWaveAsCode( Wave wave, string fileName )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); + Wave *wave = luaL_checkudata( L, 1, "Wave" ); - if ( !validWave( waveId ) ) { - lua_pushboolean( L, false ); - return 1; - } - lua_pushboolean( L, ExportWaveAsCode( *state->waves[ waveId ], lua_tostring( L, 2 ) ) ); + lua_pushboolean( L, ExportWaveAsCode( *wave, luaL_checkstring( L, 2 ) ) ); return 1; } @@ -340,107 +114,55 @@ int laudioExportWaveAsCode( lua_State *L ) { */ /* -> success = RL.PlaySound( Sound sound ) +> RL.PlaySound( Sound sound ) Play a sound - -- Failure return false -- Success return true */ int laudioPlaySound( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.PlaySound( Sound sound )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - PlaySound( *state->sounds[ soundId ] ); - lua_pushboolean( L, true ); + PlaySound( *sound ); - return 1; + return 0; } /* -> success = RL.StopSound( Sound sound ) +> RL.StopSound( Sound sound ) Stop playing a sound - -- Failure return false -- Success return true */ int laudioStopSound( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.StopSound( Sound sound )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - StopSound( *state->sounds[ soundId ] ); - lua_pushboolean( L, true ); + StopSound( *sound ); - return 1; + return 0; } /* -> success = RL.PauseSound( Sound sound ) +> RL.PauseSound( Sound sound ) Pause a sound - -- Failure return false -- Success return true */ int laudioPauseSound( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.PauseSound( Sound sound )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - PauseSound( *state->sounds[ soundId ] ); - lua_pushboolean( L, true ); + PauseSound( *sound ); - return 1; + return 0; } /* -> success = RL.ResumeSound( Sound sound ) +> RL.ResumeSound( Sound sound ) Resume a paused sound - -- Failure return false -- Success return true */ int laudioResumeSound( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ResumeSound( Sound sound )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - ResumeSound( *state->sounds[ soundId ] ); - lua_pushboolean( L, true ); + ResumeSound( *sound ); - return 1; + return 0; } /* @@ -448,134 +170,72 @@ int laudioResumeSound( lua_State *L ) { Check if a sound is currently playing -- Failure return nil - Success return bool */ int laudioIsSoundPlaying( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.IsSoundPlaying( Sound sound )" ); - lua_pushnil( L ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); - if ( !validSound( soundId ) ) { - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, IsSoundPlaying( *state->sounds[ soundId ] ) ); + lua_pushboolean( L, IsSoundPlaying( *sound ) ); return 1; } /* -> success = RL.SetSoundVolume( Sound sound, float volume ) - -Set volume for a sound ( 1.0 is max level ) +> RL.SetSoundVolume( Sound sound, float volume ) -- Failure return false -- Success return true +Set volume for a sound (1.0 is max level) */ int laudioSetSoundVolume( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetSoundVolume( Sound sound, float volume )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); - float volume = lua_tonumber( L, 2 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); + float volume = luaL_checknumber( L, 2 ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetSoundVolume( *state->sounds[ soundId ], volume ); - lua_pushboolean( L, true ); + SetSoundVolume( *sound, volume ); - return 1; + return 0; } /* -> success = RL.SetSoundPitch( Sound sound, float pitch ) +> RL.SetSoundPitch( Sound sound, float pitch ) -Set pitch for a sound ( 1.0 is base level ) - -- Failure return false -- Success return true +Set pitch for a sound (1.0 is base level) */ int laudioSetSoundPitch( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetSoundPitch( Sound sound, float pitch )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); - float pitch = lua_tonumber( L, 2 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); + float pitch = luaL_checknumber( L, 2 ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetSoundPitch( *state->sounds[ soundId ], pitch ); - lua_pushboolean( L, true ); + SetSoundPitch( *sound, pitch ); - return 1; + return 0; } /* -> success = RL.SetSoundPan( Sound sound, float pan ) - -Set pan for a sound ( 0.5 is center ) +> RL.SetSoundPan( Sound sound, float pan ) -- Failure return false -- Success return true +Set pan for a sound (0.5 is center) */ int laudioSetSoundPan( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetSoundPan( Sound sound, float pitch )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t soundId = lua_tointeger( L, 1 ); - float pan = lua_tonumber( L, 2 ); + Sound *sound = luaL_checkudata( L, 1, "Sound" ); + float pan = luaL_checknumber( L, 2 ); - if ( !validSound( soundId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetSoundPan( *state->sounds[ soundId ], pan ); - lua_pushboolean( L, true ); + SetSoundPan( *sound, pan ); - return 1; + return 0; } /* -> success = RL.WaveFormat( Wave wave, int sampleRate, int sampleSize, int channels ) +> RL.WaveFormat( Wave wave, int sampleRate, int sampleSize, int channels ) Convert wave data to desired format - -- Failure return false -- Success return true */ int laudioWaveFormat( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.WaveFormat( Wave wave, int sampleRate, int sampleSize, int channels )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); - int sampleRate = lua_tointeger( L, 2 ); - int sampleSize = lua_tointeger( L, 3 ); - int channels = lua_tointeger( L, 4 ); + Wave *wave = luaL_checkudata( L, 1, "Wave" ); + int sampleRate = luaL_checkinteger( L, 2 ); + int sampleSize = luaL_checkinteger( L, 3 ); + int channels = luaL_checkinteger( L, 4 ); - if ( !validWave( waveId ) ) { - lua_pushboolean( L, false ); - return 1; - } - WaveFormat( state->waves[ waveId ], sampleRate, sampleSize, channels ); - lua_pushboolean( L, true ); + WaveFormat( wave, sampleRate, sampleSize, channels ); - return 1; + return 0; } /* @@ -583,54 +243,29 @@ int laudioWaveFormat( lua_State *L ) { Copy a wave to a new wave -- Failure return -1 -- Success return int +- Success return Wave */ int laudioWaveCopy( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.WaveCopy( Wave wave )" ); - lua_pushinteger( L, -1 ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); + Wave *wave = luaL_checkudata( L, 1, "Wave" ); - if ( !validWave( waveId ) ) { - lua_pushinteger( L, -1 ); - return 1; - } - int i = newWave(); - *state->waves[i] = WaveCopy( *state->waves[ waveId ] ); - lua_pushinteger( L, i ); + uluaPushWave( L, WaveCopy( *wave ) ); return 1; } /* -> success = RL.WaveCrop( Wave wave, int initSample, int finalSample ) +> RL.WaveCrop( Wave wave, int initSample, int finalSample ) Crop a wave to defined samples range - -- Failure return false -- Success return true */ int laudioWaveCrop( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.WaveCrop( Wave wave, int initSample, int finalSample )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t waveId = lua_tointeger( L, 1 ); - int initSample = lua_tointeger( L, 2 ); - int finalSample = lua_tointeger( L, 3 ); + Wave *wave = luaL_checkudata( L, 1, "Wave" ); + int initSample = luaL_checkinteger( L, 2 ); + int finalSample = luaL_checkinteger( L, 3 ); - if ( !validWave( waveId ) ) { - lua_pushboolean( L, false ); - return 1; - } - WaveCrop( state->waves[ waveId ], initSample, finalSample ); - lua_pushboolean( L, true ); + WaveCrop( wave, initSample, finalSample ); - return 1; + return 0; } /* @@ -642,51 +277,31 @@ int laudioWaveCrop( lua_State *L ) { Load music stream from file -- Failure return -1 -- Success return int +- Success return Music */ int laudioLoadMusicStream( lua_State *L ) { - if ( !lua_isstring( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadMusicStream( string fileName )" ); - lua_pushinteger( L, -1 ); - return 1; - } - if ( !FileExists( lua_tostring( L, 1 ) ) ) { - lua_pushinteger( L, -1 ); + if ( FileExists( luaL_checkstring( L, 1 ) ) ) { + uluaPushMusic( L, LoadMusicStream( lua_tostring( L, 1 ) ) ); + return 1; } - int i = newMusic(); - *state->musics[i] = LoadMusicStream( lua_tostring( L, 1 ) ); - state->musics[i]->looping = true; - lua_pushinteger( L, i ); + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); + lua_pushnil( L ); return 1; } /* -> success = RL.PlayMusicStream( Music music ) +> RL.PlayMusicStream( Music music ) Start music playing - -- Failure return false -- Success return true */ int laudioPlayMusicStream( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.PlayMusicStream( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - PlayMusicStream( *state->musics[ musicId ] ); - lua_pushboolean( L, true ); + PlayMusicStream( *music ); - return 1; + return 0; } /* @@ -694,263 +309,136 @@ int laudioPlayMusicStream( lua_State *L ) { Check if music is playing -- Failure return nil - Success return bool */ int laudioIsMusicStreamPlaying( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.IsMusicStreamPlaying( Music music )" ); - lua_pushnil( L ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, IsMusicStreamPlaying( *state->musics[ musicId ] ) ); + lua_pushboolean( L, IsMusicStreamPlaying( *music ) ); return 1; } /* -> success = RL.UpdateMusicStream( Music music ) +> RL.UpdateMusicStream( Music music ) Updates buffers for music streaming - -- Failure return false -- Success return true */ int laudioUpdateMusicStream( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateMusicStream( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - UpdateMusicStream( *state->musics[ musicId ] ); - lua_pushboolean( L, true ); + UpdateMusicStream( *music ); - return 1; + return 0; } /* -> success = RL.StopMusicStream( Music music ) +> RL.StopMusicStream( Music music ) Stop music playing - -- Failure return false -- Success return true */ int laudioStopMusicStream( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.StopMusicStream( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - StopMusicStream( *state->musics[ musicId ] ); - lua_pushboolean( L, true ); + StopMusicStream( *music ); - return 1; + return 0; } /* -> success = RL.PauseMusicStream( Music music ) +> RL.PauseMusicStream( Music music ) Pause music playing - -- Failure return false -- Success return true */ int laudioPauseMusicStream( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.PauseMusicStream( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - PauseMusicStream( *state->musics[ musicId ] ); - lua_pushboolean( L, true ); + PauseMusicStream( *music ); - return 1; + return 0; } /* -> success = RL.ResumeMusicStream( Music music ) +> RL.ResumeMusicStream( Music music ) Resume playing paused music - -- Failure return false -- Success return true */ int laudioResumeMusicStream( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ResumeMusicStream( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - ResumeMusicStream( *state->musics[ musicId ] ); - lua_pushboolean( L, true ); + ResumeMusicStream( *music ); - return 1; + return 0; } /* -> success = RL.SeekMusicStream( Music music, float position ) - -Seek music to a position ( in seconds ) +> RL.SeekMusicStream( Music music, float position ) -- Failure return false -- Success return true +Seek music to a position (in seconds) */ int laudioSeekMusicStream( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SeekMusicStream( Music music, float position )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); - float position = lua_tonumber( L, 2 ); + Music *music = luaL_checkudata( L, 1, "Music" ); + float position = luaL_checknumber( L, 2 ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SeekMusicStream( *state->musics[ musicId ], position ); - lua_pushboolean( L, true ); + SeekMusicStream( *music, position ); - return 1; + return 0; } /* -> success = RL.SetMusicVolume( Music music, float volume ) +> RL.SetMusicVolume( Music music, float volume ) -Set volume for music ( 1.0 is max level ) - -- Failure return false -- Success return true +Set volume for music (1.0 is max level) */ int laudioSetMusicVolume( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMusicVolume( Music music, float volume )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); - float volume = lua_tonumber( L, 2 ); + Music *music = luaL_checkudata( L, 1, "Music" ); + float volume = luaL_checknumber( L, 2 ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetMusicVolume( *state->musics[ musicId ], volume ); - lua_pushboolean( L, true ); + SetMusicVolume( *music, volume ); - return 1; + return 0; } /* -> success = RL.SetMusicPitch( Music music, float pitch ) - -Set pitch for a music ( 1.0 is base level ) +> RL.SetMusicPitch( Music music, float pitch ) -- Failure return false -- Success return true +Set pitch for a music (1.0 is base level) */ int laudioSetMusicPitch( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMusicPitch( Music music, float pitch )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); - float pitch = lua_tonumber( L, 2 ); + Music *music = luaL_checkudata( L, 1, "Music" ); + float pitch = luaL_checknumber( L, 2 ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetMusicPitch( *state->musics[ musicId ], pitch ); - lua_pushboolean( L, true ); + SetMusicPitch( *music, pitch ); - return 1; + return 0; } /* -> success = RL.SetMusicPan( Music music, float pan ) - -Set pan for a music ( 0.5 is center ) +> RL.SetMusicPan( Music music, float pan ) -- Failure return false -- Success return true +Set pan for a music (0.5 is center) */ int laudioSetMusicPan( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMusicPan( Music music, float pan )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); - float pan = lua_tonumber( L, 2 ); + Music *music = luaL_checkudata( L, 1, "Music" ); + float pan = luaL_checknumber( L, 2 ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - SetMusicPitch( *state->musics[ musicId ], pan ); - lua_pushboolean( L, true ); + SetMusicPitch( *music, pan ); - return 1; + return 0; } /* -> success = RL.SetMusicLooping( Music music, bool looping ) +> RL.SetMusicLooping( Music music, bool looping ) Set looping for a music - -- Failure return false -- Success return true */ int laudioSetMusicLooping( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isboolean( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMusicLooping( Music music, bool looping )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); - bool looping = lua_toboolean( L, 2 ); + Music *music = luaL_checkudata( L, 1, "Music" ); + bool looping = uluaGetBoolean( L, 2 ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->musics[ musicId ]->looping = looping; - lua_pushboolean( L, true ); + music->looping = looping; - return 1; + return 0; } /* @@ -958,22 +446,12 @@ int laudioSetMusicLooping( lua_State *L ) { Get looping of a music -- Failure return nil - Success return bool */ int laudioGetMusicLooping( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMusicLooping( Music music )" ); - lua_pushnil( L ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, state->musics[ musicId ]->looping ); + lua_pushboolean( L, music->looping ); return 1; } @@ -981,49 +459,29 @@ int laudioGetMusicLooping( lua_State *L ) { /* > length = RL.GetMusicTimeLength( Music music ) -Get music time length ( in seconds ) +Get music time length (in seconds) -- Failure return false - Success return float */ int laudioGetMusicTimeLength( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMusicTimeLength( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - lua_pushnumber( L, GetMusicTimeLength( *state->musics[ musicId ] ) ); + lua_pushnumber( L, GetMusicTimeLength( *music ) ); return 1; } /* -> played = RL.GetMusicTimePlayed( Music music ) +> timePlayed = RL.GetMusicTimePlayed( Music music ) -Get current music time played ( in seconds ) +Get current music time played (in seconds) -- Failure return false - Success return float */ int laudioGetMusicTimePlayed( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMusicTimePlayed( Music music )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t musicId = lua_tointeger( L, 1 ); + Music *music = luaL_checkudata( L, 1, "Music" ); - if ( !validMusic( musicId ) ) { - lua_pushboolean( L, false ); - return 1; - } - lua_pushnumber( L, GetMusicTimePlayed( *state->musics[ musicId ] ) ); + lua_pushnumber( L, GetMusicTimePlayed( *music ) ); return 1; } @@ -15,7 +15,7 @@ Copy a block of pixels from one framebuffer object to another. Use -1 RenderTexture for window framebuffer. */ int lglBlitFramebuffer( lua_State *L ) { - // TOCO Currently doesn't support setting window render target because of luaL_checkudata. + // TODO Currently doesn't support setting window render target because of luaL_checkudata. RenderTexture *srcTex = luaL_checkudata( L, 1, "RenderTexture" ); RenderTexture *dstTex = luaL_checkudata( L, 2, "RenderTexture" ); Rectangle srcRect = uluaGetRectangleIndex( L, 3 ); diff --git a/src/lights.c b/src/lights.c index 1a7e0c7..6d78deb 100644 --- a/src/lights.c +++ b/src/lights.c @@ -7,45 +7,6 @@ #define RLIGHTS_IMPLEMENTATION #include "rlights.h" -static void checkLightRealloc( int i ) { - if ( i == state->lightCount ) { - state->lightCount++; - } - - if ( state->lightCount == state->lightAlloc ) { - state->lightAlloc += ALLOC_PAGE_SIZE; - state->lights = realloc( state->lights, state->lightAlloc * sizeof( Light* ) ); - - for ( i = state->lightCount; i < state->lightAlloc; i++ ) { - state->lights[i] = NULL; - } - } -} - -bool validLight( size_t id ) { - if ( id < 0 || state->lightCount < id || state->lights[ id ] == NULL ) { - TraceLog( state->logLevelInvalid, "%s %d", "Invalid light", id ); - return false; - } - else { - return true; - } -} - -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 */ @@ -55,8 +16,7 @@ static int newLight() { Create a light and get shader locations -- Failure return -1 -- Success return int +- Success return Light */ int llightsCreateLight( lua_State *L ) { int type = luaL_checkinteger( L, 1 ); @@ -65,9 +25,7 @@ int llightsCreateLight( lua_State *L ) { Color color = uluaGetColorIndex( L, 4 ); Shader *shader = luaL_checkudata( L, 5, "Shader" ); - int i = newLight(); - *state->lights[i] = CreateLight( type, position, target, color, *shader ); - lua_pushinteger( L, i ); + uluaPushLight( L, CreateLight( type, position, target, color, *shader ) ); return 1; } @@ -79,150 +37,81 @@ Send light properties to shader */ int llightsUpdateLightValues( lua_State *L ) { Shader *shader = luaL_checkudata( L, 1, "Shader" ); - size_t lightId = lua_tointeger( L, 2 ); + Light *light = luaL_checkudata( L, 2, "Light" ); - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - UpdateLightValues( *shader, *state->lights[ lightId ] ); + UpdateLightValues( *shader, *light ); return 0; } /* -> success = RL.SetLightType( Light light, int type ) +> RL.SetLightType( Light light, int type ) Set light type - -- Failure return false -- Success return true */ int llightsSetLightType( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetLightType( Light light, int type )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - int type = lua_tointeger( L, 2 ); - - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->lights[ lightId ]->type = type; - lua_pushboolean( L, true ); + Light *light = luaL_checkudata( L, 1, "Light" ); + int type = luaL_checkinteger( L, 2 ); - return 1; + light->type = type; + + return 0; } /* -> success = RL.SetLightPosition( Light light, Vector3 position ) +> RL.SetLightPosition( Light light, Vector3 position ) Set light position - -- Failure return false -- Success return true */ int llightsSetLightPosition( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetLightPosition( Light light, Vecto3 position )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); + Light *light = luaL_checkudata( L, 1, "Light" ); Vector3 position = uluaGetVector3Index( L, 2 ); - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->lights[ lightId ]->position = position; - lua_pushboolean( L, true ); + light->position = position; - return 1; + return 0; } /* -> success = RL.SetLightTarget( Light light, Vector3 target ) +> RL.SetLightTarget( Light light, Vector3 target ) Set light target - -- Failure return false -- Success return true */ int llightsSetLightTarget( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetLightTarget( Light light, Vecto3 target )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); + Light *light = luaL_checkudata( L, 1, "Light" ); Vector3 target = uluaGetVector3Index( L, 2 ); - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->lights[ lightId ]->target = target; - lua_pushboolean( L, true ); + light->target = target; - return 1; + return 0; } /* -> success = RL.SetLightColor( Light light, Color color ) +> RL.SetLightColor( Light light, Color color ) Set light color - -- Failure return false -- Success return true */ int llightsSetLightColor( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetLightColor( Light light, Color color )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); + Light *light = luaL_checkudata( L, 1, "Light" ); Color color = uluaGetColorIndex( L, 2 ); - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->lights[ lightId ]->color = color; - lua_pushboolean( L, true ); + light->color = color; - return 1; + return 0; } /* -> success = RL.SetLightEnabled( Light light, bool enabled ) +> RL.SetLightEnabled( Light light, bool enabled ) Set light enabled - -- Failure return false -- Success return true */ int llightsSetLightEnabled( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) || !lua_isboolean( L, 2 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetLightEnabled( Light light, bool enabled )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - bool enabled = lua_toboolean( L, 2 ); - - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - state->lights[ lightId ]->enabled = enabled; - lua_pushboolean( L, true ); + Light *light = luaL_checkudata( L, 1, "Light" ); + bool enabled = uluaGetBoolean( L, 2 ); - return 1; + light->enabled = enabled; + + return 0; } /* @@ -230,22 +119,12 @@ int llightsSetLightEnabled( lua_State *L ) { Get light type -- Failure return false - Success return int */ int llightsGetLightType( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetLightType( Light light )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - lua_pushinteger( L, state->lights[ lightId ]->type ); + Light *light = luaL_checkudata( L, 1, "Light" ); + + lua_pushinteger( L, light->type ); return 1; } @@ -255,22 +134,12 @@ int llightsGetLightType( lua_State *L ) { Get light position -- Failure return false - Success return Vector3 */ int llightsGetLightPosition( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetLightPosition( Light light )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - uluaPushVector3( L, state->lights[ lightId ]->position ); + Light *light = luaL_checkudata( L, 1, "Light" ); + + uluaPushVector3( L, light->position ); return 1; } @@ -280,22 +149,12 @@ int llightsGetLightPosition( lua_State *L ) { Get light target -- Failure return false - Success return Vector3 */ int llightsGetLightTarget( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetLightTarget( Light light )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - uluaPushVector3( L, state->lights[ lightId ]->target ); + Light *light = luaL_checkudata( L, 1, "Light" ); + + uluaPushVector3( L, light->target ); return 1; } @@ -305,22 +164,12 @@ int llightsGetLightTarget( lua_State *L ) { Get light color -- Failure return false - Success return Color */ int llightsGetLightColor( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetLightColor( Light light )" ); - lua_pushboolean( L, false ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - - if ( !validLight( lightId ) ) { - lua_pushboolean( L, false ); - return 1; - } - uluaPushColor( L, state->lights[ lightId ]->color ); + Light *light = luaL_checkudata( L, 1, "Light" ); + + uluaPushColor( L, light->color ); return 1; } @@ -330,22 +179,12 @@ int llightsGetLightColor( lua_State *L ) { Get light enabled -- Failure return nil - Success return boolean */ int llightsIsLightEnabled( lua_State *L ) { - if ( !lua_isnumber( L, 1 ) ) { - TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.IsLightEnabled( Light light )" ); - lua_pushnil( L ); - return 1; - } - size_t lightId = lua_tointeger( L, 1 ); - - if ( !validLight( lightId ) ) { - lua_pushnil( L ); - return 1; - } - lua_pushboolean( L, state->lights[ lightId ]->enabled ); + Light *light = luaL_checkudata( L, 1, "Light" ); + + lua_pushboolean( L, light->enabled ); return 1; } diff --git a/src/lua_core.c b/src/lua_core.c index 385ec93..9641fdf 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -140,6 +140,69 @@ static void defineFont() { lua_setfield( L, -2, "__gc" ); } +/* Wave. */ +static int gcWave( lua_State *L ) { + Wave *wave = luaL_checkudata ( L, 1, "Wave" ); + printf( "gcWave\n" ); + + UnloadWave( *wave ); +} + +static void defineWave() { + lua_State *L = state->luaState; + + luaL_newmetatable( L, "Wave" ); + lua_pushvalue( L, -1 ); + lua_setfield( L, -2, "__index" ); + lua_pushcfunction( L, gcWave ); + lua_setfield( L, -2, "__gc" ); +} + +/* Sound. */ +static int gcSound( lua_State *L ) { + Sound *sound = luaL_checkudata ( L, 1, "Sound" ); + printf( "gcSound\n" ); + + UnloadSound( *sound ); +} + +static void defineSound() { + lua_State *L = state->luaState; + + luaL_newmetatable( L, "Sound" ); + lua_pushvalue( L, -1 ); + lua_setfield( L, -2, "__index" ); + lua_pushcfunction( L, gcSound ); + lua_setfield( L, -2, "__gc" ); +} + +/* Music. */ +static int gcMusic( lua_State *L ) { + Music *music = luaL_checkudata ( L, 1, "Music" ); + printf( "gcMusic\n" ); + + UnloadMusicStream( *music ); +} + +static void defineMusic() { + lua_State *L = state->luaState; + + luaL_newmetatable( L, "Music" ); + lua_pushvalue( L, -1 ); + lua_setfield( L, -2, "__index" ); + lua_pushcfunction( L, gcMusic ); + lua_setfield( L, -2, "__gc" ); +} + +/* Music. */ +static void defineLight() { + lua_State *L = state->luaState; + + luaL_newmetatable( L, "Light" ); + lua_pushvalue( L, -1 ); + lua_setfield( L, -2, "__index" ); +} + /* Assing globals. */ static void assignGlobalInt( int value, const char *name ) { @@ -1162,6 +1225,10 @@ bool luaInit( int argn, const char **argc ) { defineCamera3D(); defineShader(); defineFont(); + defineWave(); + defineSound(); + defineMusic(); + defineLight(); /* Define globals. */ defineGlobals(); @@ -1777,8 +1844,6 @@ void luaRegister() { assingGlobalFunction( "LoadSound", laudioLoadSound ); assingGlobalFunction( "LoadWave", laudioLoadWave ); assingGlobalFunction( "LoadSoundFromWave", laudioLoadSoundFromWave ); - assingGlobalFunction( "UnloadSound", laudioUnloadSound ); - assingGlobalFunction( "UnloadWave", laudioUnloadWave ); assingGlobalFunction( "ExportWave", laudioExportWave ); assingGlobalFunction( "ExportWaveAsCode", laudioExportWaveAsCode ); /* Wave/Sound management */ @@ -2899,6 +2964,30 @@ void uluaPushFont( lua_State *L, Font font ) { luaL_setmetatable( L, "Font" ); } +void uluaPushWave( lua_State *L, Wave wave ) { + Wave *waveP = lua_newuserdata( L, sizeof( Wave ) ); + *waveP = wave; + luaL_setmetatable( L, "Wave" ); +} + +void uluaPushSound( lua_State *L, Sound sound ) { + Sound *soundP = lua_newuserdata( L, sizeof( Sound ) ); + *soundP = sound; + luaL_setmetatable( L, "Sound" ); +} + +void uluaPushMusic( lua_State *L, Music music ) { + Music *musicP = lua_newuserdata( L, sizeof( Music ) ); + *musicP = music; + luaL_setmetatable( L, "Music" ); +} + +void uluaPushLight( lua_State *L, Light light ) { + Light *lightP = lua_newuserdata( L, sizeof( Light ) ); + *lightP = light; + luaL_setmetatable( L, "Light" ); +} + int uluaGetTableLen( lua_State *L ) { return uluaGetTableLenIndex( L, lua_gettop( L ) ); } diff --git a/src/state.c b/src/state.c index 010210e..b6de876 100644 --- a/src/state.c +++ b/src/state.c @@ -17,18 +17,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) { state->resolution = (Vector2){ 800, 600 }; state->luaState = NULL; state->logLevelInvalid = LOG_ERROR; - /* Waves. */ - state->waveAlloc = ALLOC_PAGE_SIZE; - state->waveCount = 0; - state->waves = malloc( state->waveAlloc * sizeof( Wave* ) ); - /* Sounds. */ - state->soundAlloc = ALLOC_PAGE_SIZE; - state->soundCount = 0; - state->sounds = malloc( state->soundAlloc * sizeof( Sound* ) ); - /* Musics. */ - state->musicAlloc = ALLOC_PAGE_SIZE; - state->musicCount = 0; - state->musics = malloc( state->musicAlloc * sizeof( Music* ) ); /* Meshes. */ state->meshAlloc = ALLOC_PAGE_SIZE; state->meshCount = 0; @@ -45,18 +33,11 @@ bool stateInit( int argn, const char **argc, const char *exePath ) { state->animationAlloc = ALLOC_PAGE_SIZE; state->animationCount = 0; state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) ); - /* Lights. */ - state->lightAlloc = ALLOC_PAGE_SIZE; - state->lightCount = 0; - state->lights = malloc( state->lightAlloc * sizeof( Light* ) ); for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) { - state->waves[i] = NULL; - state->sounds[i] = NULL; state->meshes[i] = NULL; state->models[i] = NULL; state->animations[i] = NULL; - state->lights[i] = NULL; /* The ones we want to save the first. */ if ( 0 < i ) { @@ -86,24 +67,6 @@ void stateInitInterpret( int argn, const char **argc ) { } void stateFree() { - for ( int i = 0; i < state->waveCount; ++i ) { - if ( state->waves[i] != NULL ) { - UnloadWave( *state->waves[i] ); - free( state->waves[i] ); - } - } - for ( int i = 0; i < state->soundCount; ++i ) { - if ( state->sounds[i] != NULL ) { - UnloadSound( *state->sounds[i] ); - free( state->sounds[i] ); - } - } - for ( int i = 0; i < state->musicCount; ++i ) { - if ( state->musics[i] != NULL ) { - UnloadMusicStream( *state->musics[i] ); - free( state->musics[i] ); - } - } for ( int i = 0; i < state->modelCount; ++i ) { if ( state->models[i] != NULL ) { //TODO Test if UnloadModel causes segfaults on exit. @@ -134,13 +97,6 @@ void stateFree() { } } -#if !defined( PLATFORM_RPI ) || !defined( PLATFORM_DRM ) - for ( int i = 0; i < state->lightCount; ++i ) { - if ( state->lights[i] != NULL ) { - free( state->lights[i] ); - } - } -#endif if ( IsAudioDeviceReady() ) { CloseAudioDevice(); } @@ -151,14 +107,10 @@ void stateFree() { if ( state->hasWindow ) { CloseWindow(); } - free( state->waves ); - free( state->sounds ); - free( state->musics ); free( state->meshes ); free( state->materials ); free( state->models ); free( state->animations ); - free( state->lights ); free( state->exePath ); free( state ); } @@ -33,7 +33,7 @@ int ltextLoadFont( lua_State *L ) { return 1; } - TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) ); + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); lua_pushnil( L ); return 1; @@ -73,7 +73,7 @@ int ltextLoadFontEx( lua_State *L ) { return 1; } - TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) ); + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); lua_pushnil( L ); return 1; @@ -82,7 +82,7 @@ int ltextLoadFontEx( lua_State *L ) { /* > font = RL.LoadFontFromImage( Image image, Color key, int firstChar ) -Load font from Image ( XNA style ) +Load font from Image ( XNA style) - Success return Font */ diff --git a/src/textures.c b/src/textures.c index 2121d12..a66902d 100644 --- a/src/textures.c +++ b/src/textures.c @@ -21,7 +21,7 @@ int ltexturesLoadImage( lua_State *L ) { return 1; } - TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) ); + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); lua_pushnil( L ); return 1; @@ -929,7 +929,7 @@ int ltexturesLoadTexture( lua_State *L ) { return 1; } - TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) ); + TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); lua_pushnil( L ); return 1; |
