Can now have multiple Music objects like other Raylib objects instead of just one.

This commit is contained in:
jussi
2023-04-25 18:19:14 +03:00
parent 8182c486e6
commit a9ce78128d
12 changed files with 442 additions and 107 deletions

76
API.md
View File

@@ -4775,48 +4775,70 @@ Crop a wave to defined samples range
---
> success = RL.LoadMusicStream( string fileName )
> music = RL.LoadMusicStream( string fileName )
Load music stream from file
- Failure return -1
- Success return int
---
> success = RL.PlayMusicStream( Music music )
Start music playing
- Failure return false
- Success return true
---
> RL.PlayMusicStream()
Start music playing
---
> playing = RL.IsMusicStreamPlaying()
> playing = RL.IsMusicStreamPlaying( Music music )
Check if music is playing
- Failure return nil
- Success return bool
---
> RL.StopMusicStream()
> success = RL.UpdateMusicStream( Music music )
Updates buffers for music streaming
- Failure return false
- Success return true
---
> success = RL.StopMusicStream( Music music )
Stop music playing
- Failure return false
- Success return true
---
> RL.PauseMusicStream()
> success = RL.PauseMusicStream( Music music )
Pause music playing
- Failure return false
- Success return true
---
> RL.ResumeMusicStream()
> success = RL.ResumeMusicStream( Music music )
Resume playing paused music
- Failure return false
- Success return true
---
> success = RL.SeekMusicStream( float position )
> success = RL.SeekMusicStream( Music music, float position )
Seek music to a position ( in seconds )
@@ -4825,7 +4847,7 @@ Seek music to a position ( in seconds )
---
> success = RL.SetMusicVolume( float volume )
> success = RL.SetMusicVolume( Music music, float volume )
Set volume for music ( 1.0 is max level )
@@ -4834,7 +4856,7 @@ Set volume for music ( 1.0 is max level )
---
> success = RL.SetMusicPitch( float pitch )
> success = RL.SetMusicPitch( Music music, float pitch )
Set pitch for a music ( 1.0 is base level )
@@ -4843,7 +4865,7 @@ Set pitch for a music ( 1.0 is base level )
---
> success = RL.SetMusicPan( float pan )
> success = RL.SetMusicPan( Music music, float pan )
Set pan for a music ( 0.5 is center )
@@ -4852,18 +4874,38 @@ Set pan for a music ( 0.5 is center )
---
> length = RL.GetMusicTimeLength()
> success = 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 )
- Failure return false
- Success return float
---
> played = RL.GetMusicTimePlayed()
> played = RL.GetMusicTimePlayed( Music music )
Get current music time played ( in seconds )
- Failure return false
- Success return float
---

View File

@@ -30,7 +30,7 @@ if( EMSCRIPTEN ) # Web
else() # Desktop
if( SHARED )
message( Shared )
# find_package( raylib 4.0 REQUIRED ) # Requires at least version 4.0
find_package( raylib 4.5 REQUIRED ) # Requires at least version 4.5
target_link_libraries( ${PROJECT_NAME} raylib )
target_link_libraries( ${PROJECT_NAME} lua )
else()
@@ -42,7 +42,7 @@ else() # Desktop
if( UNIX )
set( CMAKE_C_COMPILER "gcc" )
if( DRM ) # Mainly for Raspberry pi
if( DRM ) # Mainly for Raspberry Pi
# target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm rt bcm_host m dl pthread )
target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm rt m dl pthread )
else()

View File

@@ -10,7 +10,7 @@ Reilua means fair in finnish.
## Status
ReiLua is WIP and some planned raylib functionality is still missing but it already has over 400 functions and should include all functions to make most 2d and 3d games. Current Raylib version 4.2.0.
ReiLua is WIP and some planned raylib functionality is still missing but it already has over 600 functions and should include all functions to make most 2d and 3d games. Current Raylib version 4.5.0.
Included submodules.

View File

@@ -3756,70 +3756,114 @@ function RL.WaveCrop( wave, initSample, finalSample ) end
-- Audio - Music management
---Load music stream from file
---- Failure return false
---- Success return true
---- Failure return -1
---- Success return int
---@param fileName string
---@return any success
---@return any music
function RL.LoadMusicStream( fileName ) end
---Start music playing
---@return any RL.PlayMusicStream
function RL.PlayMusicStream() end
---- Failure return false
---- Success return true
---@param music any
---@return any success
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() end
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
---Stop music playing
---@return any RL.StopMusicStream
function RL.StopMusicStream() end
---- Failure return false
---- Success return true
---@param music any
---@return any success
function RL.StopMusicStream( music ) end
---Pause music playing
---@return any RL.PauseMusicStream
function RL.PauseMusicStream() end
---- Failure return false
---- Success return true
---@param music any
---@return any success
function RL.PauseMusicStream( music ) end
---Resume playing paused music
---@return any RL.ResumeMusicStream
function RL.ResumeMusicStream() end
---- Failure return false
---- Success return true
---@param music any
---@return any success
function RL.ResumeMusicStream( music ) end
---Seek music to a position ( in seconds )
---- Failure return false
---- Success return true
---@param music any
---@param position number
---@return any success
function RL.SeekMusicStream( position ) end
function RL.SeekMusicStream( music, position ) end
---Set volume for music ( 1.0 is max level )
---- Failure return false
---- Success return true
---@param music any
---@param volume number
---@return any success
function RL.SetMusicVolume( volume ) end
function RL.SetMusicVolume( music, volume ) end
---Set pitch for a music ( 1.0 is base level )
---- Failure return false
---- Success return true
---@param music any
---@param pitch number
---@return any success
function RL.SetMusicPitch( pitch ) end
function RL.SetMusicPitch( music, pitch ) end
---Set pan for a music ( 0.5 is center )
---- Failure return false
---- Success return true
---@param music any
---@param pan number
---@return any success
function RL.SetMusicPan( pan ) end
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
---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
---- Success return float
---@param music any
---@return any length
function RL.GetMusicTimeLength() end
function RL.GetMusicTimeLength( music ) end
---Get current music time played ( in seconds )
---- Failure return false
---- Success return float
---@param music any
---@return any played
function RL.GetMusicTimePlayed() end
function RL.GetMusicTimePlayed( music ) end
-- Math - Utils

View File

@@ -10,6 +10,7 @@ KEY CHANGES:
Also using positive stack indexing.
- ADDED: Camera3D Lua lib.
- ADDED: Raygui wrapper lib.
- CHANGED: Can now have multiple Music objects like other Raylib objects instead of just one.
Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables.
@@ -53,6 +54,9 @@ Detailed changes:
- ADDED: glBlitFramebuffer
- ADDED: GuiGetFont
- FIXED: GuiScrollPanel
- ADDED: UpdateMusicStream
- ADDED: SetMusicLooping
- ADDED: GetMusicLooping
------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -1,5 +1,4 @@
Current {
* Check raylib changes from https://github.com/raysan5/raylib/blob/master/CHANGELOG
}
Backlog {

View File

@@ -26,6 +26,7 @@ int laudioWaveCrop( lua_State *L );
int laudioLoadMusicStream( lua_State *L );
int laudioPlayMusicStream( lua_State *L );
int laudioIsMusicStreamPlaying( lua_State *L );
int laudioUpdateMusicStream( lua_State *L );
int laudioStopMusicStream( lua_State *L );
int laudioPauseMusicStream( lua_State *L );
int laudioResumeMusicStream( lua_State *L );
@@ -33,5 +34,7 @@ int laudioSeekMusicStream( lua_State *L );
int laudioSetMusicVolume( lua_State *L );
int laudioSetMusicPitch( lua_State *L );
int laudioSetMusicPan( lua_State *L );
int laudioSetMusicLooping( lua_State *L );
int laudioGetMusicLooping( lua_State *L );
int laudioGetMusicTimeLength( lua_State *L );
int laudioGetMusicTimePlayed( lua_State *L );

View File

@@ -41,7 +41,9 @@ typedef struct {
size_t soundCount;
size_t soundAlloc;
/* Music. */
Music music;
Music **musics;
size_t musicCount;
size_t musicAlloc;
/* Camera2D's. */
Camera2D **camera2Ds;
size_t camera2DCount;

View File

@@ -23,6 +23,16 @@ static bool validWave( size_t id ) {
}
}
static bool validMusic( size_t id ) {
if ( id < 0 || state->musicCount < id || state->musics[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid music", id );
return false;
}
else {
return true;
}
}
static void checkSoundRealloc( int i ) {
if ( i == state->soundCount ) {
state->soundCount++;
@@ -53,6 +63,21 @@ static void checkWaveRealloc( int i ) {
}
}
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;
@@ -81,6 +106,20 @@ static int newWave() {
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
*/
@@ -599,91 +638,188 @@ int laudioWaveCrop( lua_State *L ) {
*/
/*
> success = RL.LoadMusicStream( string fileName )
> music = RL.LoadMusicStream( string fileName )
Load music stream from file
- Failure return false
- Success return true
- Failure return -1
- Success return int
*/
int laudioLoadMusicStream( lua_State *L ) {
if ( !lua_isstring( L, 1 ) ) {
TraceLog( LOG_WARNING, "%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 );
return 1;
}
int i = newMusic();
*state->musics[i] = LoadMusicStream( lua_tostring( L, 1 ) );
state->musics[i]->looping = true;
lua_pushinteger( L, i );
return 1;
}
/*
> success = RL.PlayMusicStream( Music music )
Start music playing
- Failure return false
- Success return true
*/
int laudioPlayMusicStream( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.PlayMusicStream( Music music )" );
lua_pushboolean( L, false );
return 1;
}
if ( FileExists( lua_tostring( L, 1 ) ) ) {
state->music = LoadMusicStream( lua_tostring( L, 1 ) );
state->music.looping = false;
size_t musicId = lua_tointeger( L, 1 );
lua_pushboolean( L, true );
}
else {
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
PlayMusicStream( *state->musics[ musicId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> RL.PlayMusicStream()
Start music playing
*/
int laudioPlayMusicStream( lua_State *L ) {
PlayMusicStream( state->music );
return 0;
}
/*
> playing = RL.IsMusicStreamPlaying()
> playing = RL.IsMusicStreamPlaying( Music music )
Check if music is playing
- Failure return nil
- Success return bool
*/
int laudioIsMusicStreamPlaying( lua_State *L ) {
lua_pushboolean( L, IsMusicStreamPlaying( state->music ) );
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.IsMusicStreamPlaying( Music music )" );
lua_pushnil( L );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
if ( !validMusic( musicId ) ) {
lua_pushnil( L );
return 1;
}
lua_pushboolean( L, IsMusicStreamPlaying( *state->musics[ musicId ] ) );
return 1;
}
/*
> RL.StopMusicStream()
> success = 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( LOG_WARNING, "%s", "Bad call of function. RL.UpdateMusicStream( Music music )" );
lua_pushboolean( L, false );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
UpdateMusicStream( *state->musics[ musicId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.StopMusicStream( Music music )
Stop music playing
- Failure return false
- Success return true
*/
int laudioStopMusicStream( lua_State *L ) {
StopMusicStream( state->music );
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.StopMusicStream( Music music )" );
lua_pushboolean( L, false );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
return 0;
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
StopMusicStream( *state->musics[ musicId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> RL.PauseMusicStream()
> success = RL.PauseMusicStream( Music music )
Pause music playing
- Failure return false
- Success return true
*/
int laudioPauseMusicStream( lua_State *L ) {
PauseMusicStream( state->music );
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.PauseMusicStream( Music music )" );
lua_pushboolean( L, false );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
return 0;
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
PauseMusicStream( *state->musics[ musicId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> RL.ResumeMusicStream()
> success = RL.ResumeMusicStream( Music music )
Resume playing paused music
- Failure return false
- Success return true
*/
int laudioResumeMusicStream( lua_State *L ) {
ResumeMusicStream( state->music );
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.ResumeMusicStream( Music music )" );
lua_pushboolean( L, false );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
return 0;
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
ResumeMusicStream( *state->musics[ musicId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.SeekMusicStream( float position )
> success = RL.SeekMusicStream( Music music, float position )
Seek music to a position ( in seconds )
@@ -691,21 +827,26 @@ Seek music to a position ( in seconds )
- Success return true
*/
int laudioSeekMusicStream( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SeekMusicStream( float position )" );
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SeekMusicStream( Music music, float position )" );
lua_pushboolean( L, false );
return 1;
}
float position = lua_tonumber( L, 1 );
size_t musicId = lua_tointeger( L, 1 );
float position = lua_tonumber( L, 2 );
SeekMusicStream( state->music, position );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
SeekMusicStream( *state->musics[ musicId ], position );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.SetMusicVolume( float volume )
> success = RL.SetMusicVolume( Music music, float volume )
Set volume for music ( 1.0 is max level )
@@ -713,21 +854,26 @@ Set volume for music ( 1.0 is max level )
- Success return true
*/
int laudioSetMusicVolume( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMusicVolume( float volume )" );
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMusicVolume( Music music, float volume )" );
lua_pushboolean( L, false );
return 1;
}
float volume = lua_tonumber( L, 1 );
size_t musicId = lua_tointeger( L, 1 );
float volume = lua_tonumber( L, 2 );
SetMusicVolume( state->music, volume );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
SetMusicVolume( *state->musics[ musicId ], volume );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.SetMusicPitch( float pitch )
> success = RL.SetMusicPitch( Music music, float pitch )
Set pitch for a music ( 1.0 is base level )
@@ -735,21 +881,26 @@ Set pitch for a music ( 1.0 is base level )
- Success return true
*/
int laudioSetMusicPitch( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMusicPitch( float pitch )" );
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMusicPitch( Music music, float pitch )" );
lua_pushboolean( L, false );
return 1;
}
float pitch = lua_tonumber( L, 1 );
size_t musicId = lua_tointeger( L, 1 );
float pitch = lua_tonumber( L, 2 );
SetMusicPitch( state->music, pitch );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
SetMusicPitch( *state->musics[ musicId ], pitch );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL.SetMusicPan( float pan )
> success = RL.SetMusicPan( Music music, float pan )
Set pan for a music ( 0.5 is center )
@@ -757,41 +908,122 @@ Set pan for a music ( 0.5 is center )
- Success return true
*/
int laudioSetMusicPan( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMusicPan( float pan )" );
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.SetMusicPan( Music music, float pan )" );
lua_pushboolean( L, false );
return 1;
}
float pan = lua_tonumber( L, 1 );
size_t musicId = lua_tointeger( L, 1 );
float pan = lua_tonumber( L, 2 );
SetMusicPitch( state->music, pan );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
SetMusicPitch( *state->musics[ musicId ], pan );
lua_pushboolean( L, true );
return 1;
}
/*
> length = RL.GetMusicTimeLength()
> success = RL.SetMusicLooping( Music music, bool looping )
Get music time length ( in seconds )
Set looping for a music
- Success return float
- Failure return false
- Success return true
*/
int laudioGetMusicTimeLength( lua_State *L ) {
lua_pushnumber( L, GetMusicTimeLength( state->music ) );
int laudioSetMusicLooping( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isboolean( L, 2 ) ) {
TraceLog( LOG_WARNING, "%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 );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
state->musics[ musicId ]->looping = looping;
lua_pushboolean( L, true );
return 1;
}
/*
> played = RL.GetMusicTimePlayed()
> looping = RL.GetMusicLooping( Music music )
Get current music time played ( in seconds )
Get looping of a music
- Success return float
- Failure return nil
- Success return bool
*/
int laudioGetMusicTimePlayed( lua_State *L ) {
lua_pushnumber( L, GetMusicTimePlayed( state->music ) );
int laudioGetMusicLooping( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMusicLooping( Music music )" );
lua_pushnil( L );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
if ( !validMusic( musicId ) ) {
lua_pushnil( L );
return 1;
}
lua_pushboolean( L, state->musics[ musicId ]->looping );
return 1;
}
/*
> length = RL.GetMusicTimeLength( Music music )
Get music time length ( in seconds )
- Failure return false
- Success return float
*/
int laudioGetMusicTimeLength( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMusicTimeLength( Music music )" );
lua_pushboolean( L, false );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
lua_pushnumber( L, GetMusicTimeLength( *state->musics[ musicId ] ) );
return 1;
}
/*
> played = RL.GetMusicTimePlayed( Music music )
Get current music time played ( in seconds )
- Failure return false
- Success return float
*/
int laudioGetMusicTimePlayed( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.GetMusicTimePlayed( Music music )" );
lua_pushboolean( L, false );
return 1;
}
size_t musicId = lua_tointeger( L, 1 );
if ( !validMusic( musicId ) ) {
lua_pushboolean( L, false );
return 1;
}
lua_pushnumber( L, GetMusicTimePlayed( *state->musics[ musicId ] ) );
return 1;
}

View File

@@ -1153,12 +1153,15 @@ void luaRegister() {
assingGlobalFunction( "LoadMusicStream", laudioLoadMusicStream );
assingGlobalFunction( "PlayMusicStream", laudioPlayMusicStream );
assingGlobalFunction( "IsMusicStreamPlaying", laudioIsMusicStreamPlaying );
assingGlobalFunction( "UpdateMusicStream", laudioUpdateMusicStream );
assingGlobalFunction( "StopMusicStream", laudioStopMusicStream );
assingGlobalFunction( "PauseMusicStream", laudioPauseMusicStream );
assingGlobalFunction( "ResumeMusicStream", laudioResumeMusicStream );
assingGlobalFunction( "SetMusicVolume", laudioSetMusicVolume );
assingGlobalFunction( "SetMusicPitch", laudioSetMusicPitch );
assingGlobalFunction( "SetMusicPan", laudioSetMusicPan );
assingGlobalFunction( "SetMusicLooping", laudioSetMusicLooping );
assingGlobalFunction( "GetMusicLooping", laudioGetMusicLooping );
assingGlobalFunction( "GetMusicTimeLength", laudioGetMusicTimeLength );
assingGlobalFunction( "GetMusicTimePlayed", laudioGetMusicTimePlayed );

View File

@@ -65,15 +65,11 @@ int main( int argn, const char **argc ) {
if ( WindowShouldClose() ) {
state->run = false;
}
if ( IsAudioDeviceReady() ) {
UpdateMusicStream( state->music );
}
luaCallProcess();
luaCallDraw();
}
luaCallExit();
}
stateFree();
return 1;

View File

@@ -42,6 +42,10 @@ bool stateInit( const char *exePath ) {
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* ) );
/* Camera2D's. */
state->camera2DAlloc = ALLOC_PAGE_SIZE;
state->camera2DCount = 0;
@@ -157,6 +161,12 @@ void stateFree() {
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->camera2DCount; ++i ) {
if ( state->camera2Ds[i] != NULL ) {
free( state->camera2Ds[i] );
@@ -213,7 +223,6 @@ void stateFree() {
if ( IsAudioDeviceReady() ) {
CloseAudioDevice();
UnloadMusicStream( state->music );
}
if ( state->hasWindow ) {
CloseWindow();
@@ -227,6 +236,7 @@ void stateFree() {
free( state->fonts );
free( state->waves );
free( state->sounds );
free( state->musics );
free( state->camera2Ds );
free( state->camera3Ds );
free( state->meshes );