From 77ba40f97e6176e5bdeccf632ea17cb3121a0333 Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 18 Sep 2025 15:30:12 +0300 Subject: Fixed fast_tilemap and texture_atlas_repeat examples. --- changelog | 2 ++ examples/fast_tilemap/main.lua | 2 +- examples/texture_atlas_repeat/main.lua | 4 +-- include/main.h | 7 ++++ src/core.c | 9 +++-- src/lua_core.c | 65 ++++++++++++++++++++++------------ 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/changelog b/changelog index bc31ce6..e7f8b3d 100644 --- a/changelog +++ b/changelog @@ -60,6 +60,8 @@ DETAILED CHANGES: - ADDED: GetSoundStream and GetMusicStream. - ADDED: Audio stream effects example. - CHANGE: Bit fastes uluaGet* functions for vectors, color, rectangle and quaternion. + - FIXED: fast_tilemap and texture_atlas_repeat examples were giving truncated vectors + which isn't allowed anymore. ------------------------------------------------------------------------ Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0 diff --git a/examples/fast_tilemap/main.lua b/examples/fast_tilemap/main.lua index da7fdbf..4ba209c 100644 --- a/examples/fast_tilemap/main.lua +++ b/examples/fast_tilemap/main.lua @@ -39,7 +39,7 @@ local function setTile( meshData, pos, texcoord ) local texelSize = Vector2:new( 1 / tilemap.texSize.x, 1 / tilemap.texSize.y ) for i, v in ipairs( QUAD.VERTICES ) do - table.insert( meshData.vertices, ( pos + v ):scale( tilemap.tileSize ) ) + table.insert( meshData.vertices, ( Vector3:temp( pos.x + v.x, pos.y + v.y, 0 ) ):scale( tilemap.tileSize ) ) table.insert( meshData.texcoords, ( QUAD.TEXCOORDS[i] + texcoord ) * texelSize:scale( tilemap.tileSize ) ) table.insert( meshData.colors, RL.WHITE ) end diff --git a/examples/texture_atlas_repeat/main.lua b/examples/texture_atlas_repeat/main.lua index 6056e71..b0b9499 100644 --- a/examples/texture_atlas_repeat/main.lua +++ b/examples/texture_atlas_repeat/main.lua @@ -28,8 +28,8 @@ function RL.draw() RL.ClearBackground( RL.RAYWHITE ) RL.BeginShaderMode( shader ) - RL.DrawTexturePro( atlas, { 0, 0, 32, 32 }, { 0, 0, 64, 64 }, { 0.0 }, 0.0, RL.WHITE ) - RL.DrawTexturePro( atlas, { 32, 0, 32, 32 }, { 0, 64, 128, 64 }, { 0.0 }, 0.0, RL.WHITE ) + RL.DrawTexturePro( atlas, { 0, 0, 32, 32 }, { 0, 0, 64, 64 }, { 0.0, 0.0 }, 0.0, RL.WHITE ) + RL.DrawTexturePro( atlas, { 32, 0, 32, 32 }, { 0, 64, 128, 64 }, { 0.0, 0.0 }, 0.0, RL.WHITE ) RL.DrawTriangle( { 32, 200 }, { 128, 400 }, { 320, 240 }, RL.WHITE ) RL.EndShaderMode() end diff --git a/include/main.h b/include/main.h index 7aadb6b..110e5d4 100644 --- a/include/main.h +++ b/include/main.h @@ -13,6 +13,13 @@ #include #include "external/glad.h" + +// #ifndef STB_RECT_PACK_IMPLEMENTATION +// #if !defined(SUPPORT_FILEFORMAT_TTF) && !defined(SUPPORT_FILEFORMAT_BDF) +// #ifndef STB_INCLUDE_STB_RECT_PACK_H +// #define STB_RECT_PACK_IMPLEMENTATION +// #endif + #include "external/stb_rect_pack.h" #ifdef PLATFORM_DESKTOP diff --git a/src/core.c b/src/core.c index cd9c9c0..338778e 100644 --- a/src/core.c +++ b/src/core.c @@ -2142,6 +2142,7 @@ Decompress data (DEFLATE algorithm). */ int lcoreDecompressData( lua_State* L ) { Buffer* inBuffer = uluaGetBuffer( L, 1 ); + Buffer outBuffer = { .size = 0, .type = inBuffer->type @@ -2166,10 +2167,10 @@ Encode data to Base64 string */ int lcoreEncodeDataBase64( lua_State* L ) { int dataSize = 0; - const char* string = luaL_checklstring( L, 1, (size_t*)&dataSize ); + const unsigned char* data = luaL_checklstring( L, 1, (size_t*)&dataSize ); int outputSize = 0; - char* compData = EncodeDataBase64( string, dataSize, &outputSize ); + char* compData = EncodeDataBase64( data, dataSize, &outputSize ); lua_pushstring( L, compData ); lua_pushinteger( L, outputSize ); @@ -2187,8 +2188,10 @@ Decode Base64 string data - Success return string, int */ int lcoreDecodeDataBase64( lua_State* L ) { + const unsigned char* data = luaL_checkstring( L, 1 ); + int outputSize = 0; - unsigned char* decodedData = DecodeDataBase64( luaL_checkstring( L, 1 ), &outputSize ); + unsigned char* decodedData = DecodeDataBase64( data, &outputSize ); lua_pushstring( L, decodedData ); lua_pushinteger( L, outputSize ); diff --git a/src/lua_core.c b/src/lua_core.c index ace25f6..61a522c 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -3339,11 +3339,12 @@ Transform uluaGetTransform( lua_State* L, int index ) { } Buffer* uluaGetBuffer( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Buffer*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "buffer", lua_tostring( L, -2 ) ) ) { @@ -3369,11 +3370,12 @@ Buffer* uluaGetBuffer( lua_State* L, int index ) { } Image* uluaGetImage( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Image*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "image", lua_tostring( L, -2 ) ) ) { @@ -3399,11 +3401,12 @@ Image* uluaGetImage( lua_State* L, int index ) { } Texture* uluaGetTexture( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Texture*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "texture", lua_tostring( L, -2 ) ) ) { @@ -3429,11 +3432,12 @@ Texture* uluaGetTexture( lua_State* L, int index ) { } RenderTexture* uluaGetRenderTexture( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (RenderTexture*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "renderTexture", lua_tostring( L, -2 ) ) ) { @@ -3459,11 +3463,12 @@ RenderTexture* uluaGetRenderTexture( lua_State* L, int index ) { } Shader* uluaGetShader( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Shader*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "shader", lua_tostring( L, -2 ) ) ) { @@ -3489,11 +3494,12 @@ Shader* uluaGetShader( lua_State* L, int index ) { } Mesh* uluaGetMesh( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Mesh*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "mesh", lua_tostring( L, -2 ) ) ) { @@ -3519,11 +3525,12 @@ Mesh* uluaGetMesh( lua_State* L, int index ) { } Camera2D* uluaGetCamera2D( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Camera2D*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "camera2D", lua_tostring( L, -2 ) ) ) { @@ -3549,11 +3556,12 @@ Camera2D* uluaGetCamera2D( lua_State* L, int index ) { } Camera3D* uluaGetCamera3D( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Camera3D*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "camera3D", lua_tostring( L, -2 ) ) ) { @@ -3579,11 +3587,12 @@ Camera3D* uluaGetCamera3D( lua_State* L, int index ) { } Font* uluaGetFont( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Font*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "font", lua_tostring( L, -2 ) ) ) { @@ -3609,11 +3618,12 @@ Font* uluaGetFont( lua_State* L, int index ) { } GlyphInfo* uluaGetGlyphInfo( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (GlyphInfo*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "glyphInfo", lua_tostring( L, -2 ) ) ) { @@ -3639,11 +3649,12 @@ GlyphInfo* uluaGetGlyphInfo( lua_State* L, int index ) { } Wave* uluaGetWave( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Wave*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "wave", lua_tostring( L, -2 ) ) ) { @@ -3669,11 +3680,12 @@ Wave* uluaGetWave( lua_State* L, int index ) { } Sound* uluaGetSound( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Sound*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "sound", lua_tostring( L, -2 ) ) ) { @@ -3699,17 +3711,18 @@ Sound* uluaGetSound( lua_State* L, int index ) { return (Sound*)lua_touserdata( L, index ); } else { - luaL_checkudata( L, index, "Sound" ); + return luaL_checkudata( L, index, "Sound" ); } } } Music* uluaGetMusic( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Music*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "music", lua_tostring( L, -2 ) ) ) { @@ -3735,11 +3748,12 @@ Music* uluaGetMusic( lua_State* L, int index ) { } AudioStream* uluaGetAudioStream( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (AudioStream*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "audioStream", lua_tostring( L, -2 ) ) ) { @@ -3765,11 +3779,12 @@ AudioStream* uluaGetAudioStream( lua_State* L, int index ) { } Light* uluaGetLight( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Light*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "light", lua_tostring( L, -2 ) ) ) { @@ -3795,11 +3810,12 @@ Light* uluaGetLight( lua_State* L, int index ) { } Material* uluaGetMaterial( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Material*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "material", lua_tostring( L, -2 ) ) ) { @@ -3825,11 +3841,12 @@ Material* uluaGetMaterial( lua_State* L, int index ) { } Model* uluaGetModel( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (Model*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "model", lua_tostring( L, -2 ) ) ) { @@ -3855,11 +3872,12 @@ Model* uluaGetModel( lua_State* L, int index ) { } ModelAnimation* uluaGetModelAnimation( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (ModelAnimation*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "modelAnimation", lua_tostring( L, -2 ) ) ) { @@ -3885,11 +3903,12 @@ ModelAnimation* uluaGetModelAnimation( lua_State* L, int index ) { } rlRenderBatch* uluaGetRLRenderBatch( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (rlRenderBatch*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "rlRenderBatch", lua_tostring( L, -2 ) ) ) { @@ -3915,11 +3934,12 @@ rlRenderBatch* uluaGetRLRenderBatch( lua_State* L, int index ) { } AutomationEvent* uluaGetAutomationEvent( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (AutomationEvent*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "automationEvent", lua_tostring( L, -2 ) ) ) { @@ -3945,11 +3965,12 @@ AutomationEvent* uluaGetAutomationEvent( lua_State* L, int index ) { } AutomationEventList* uluaGetAutomationEventList( lua_State* L, int index ) { + int t = index, i = 0; + switch ( lua_type( L, index ) ) { case LUA_TLIGHTUSERDATA: return (AutomationEventList*)lua_touserdata( L, index ); case LUA_TTABLE: - int t = index, i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( TextIsEqual( "automationEventList", lua_tostring( L, -2 ) ) ) { -- cgit v1.2.3