Round and pubsub lib.
This commit is contained in:
22
API.md
22
API.md
@@ -273,6 +273,18 @@ ModelAnimation
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
> AutomationEvent = Userdata
|
||||||
|
|
||||||
|
Automation event
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> AutomationEventList = Userdata
|
||||||
|
|
||||||
|
Automation event list
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
> Buffer = Buffer userdata
|
> Buffer = Buffer userdata
|
||||||
|
|
||||||
Data buffer for C primitive types. Type should be one of the Buffer types.
|
Data buffer for C primitive types. Type should be one of the Buffer types.
|
||||||
@@ -4591,7 +4603,7 @@ Get automation event list count
|
|||||||
|
|
||||||
> event = RL.GetAutomationEvent( AutomationEventList list, int index )
|
> event = RL.GetAutomationEvent( AutomationEventList list, int index )
|
||||||
|
|
||||||
Get automation event from automation event list
|
Get automation event from automation event list. Return as lightuserdata
|
||||||
|
|
||||||
- Failure return nil
|
- Failure return nil
|
||||||
- Success return AutomationEvent
|
- Success return AutomationEvent
|
||||||
@@ -8077,6 +8089,14 @@ Get current music time played (in seconds)
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
> result = RL.Round( float value )
|
||||||
|
|
||||||
|
Round float value
|
||||||
|
|
||||||
|
- Success return float
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
> result = RL.Clamp( float value, float min, float max )
|
> result = RL.Clamp( float value, float min, float max )
|
||||||
|
|
||||||
Clamp float value
|
Clamp float value
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ end
|
|||||||
function RL.update( delta )
|
function RL.update( delta )
|
||||||
if RL.IsKeyPressed( RL.KEY_ENTER ) then
|
if RL.IsKeyPressed( RL.KEY_ENTER ) then
|
||||||
local winSize = RL.GetScreenSize()
|
local winSize = RL.GetScreenSize()
|
||||||
|
local measuredSize = RL.MeasureTextEx( RL.GetFontDefault(), text, textSize, 2 )
|
||||||
|
|
||||||
textSize = RL.MeasureText( text, textSize )
|
|
||||||
textColor = RL.BLUE
|
textColor = RL.BLUE
|
||||||
textPos = { winSize[1] / 2 - textSize[1] / 2, winSize[2] / 2 - textSize[2] / 2 }
|
textPos = { winSize[1] / 2 - measuredSize[1] / 2, winSize[2] / 2 - measuredSize[2] / 2 }
|
||||||
end
|
end
|
||||||
|
|
||||||
if RL.IsKeyPressed( RL.KEY_SPACE ) then
|
if RL.IsKeyPressed( RL.KEY_SPACE ) then
|
||||||
@@ -87,7 +87,7 @@ ReiLua_API.lua can be put into project folder to provide annotations when using
|
|||||||
Some objects allocate memory that needs to be freed when object is no longer needed. By default objects like Textures are unloaded by the Lua garbage collector. It is generatty however recommended to handle this manually in more complex projects. You can change the behavior with:
|
Some objects allocate memory that needs to be freed when object is no longer needed. By default objects like Textures are unloaded by the Lua garbage collector. It is generatty however recommended to handle this manually in more complex projects. You can change the behavior with:
|
||||||
|
|
||||||
```
|
```
|
||||||
SetGCUnload()
|
RL.SetGCUnload()
|
||||||
```
|
```
|
||||||
|
|
||||||
## Interpreter Mode
|
## Interpreter Mode
|
||||||
|
|||||||
@@ -2033,7 +2033,7 @@ function RL.GetAutomationEventListCapacity( list ) end
|
|||||||
---@return any count
|
---@return any count
|
||||||
function RL.GetAutomationEventListCount( list ) end
|
function RL.GetAutomationEventListCount( list ) end
|
||||||
|
|
||||||
---Get automation event from automation event list
|
---Get automation event from automation event list. Return as lightuserdata
|
||||||
---- Failure return nil
|
---- Failure return nil
|
||||||
---- Success return AutomationEvent
|
---- Success return AutomationEvent
|
||||||
---@param list any
|
---@param list any
|
||||||
@@ -5299,6 +5299,12 @@ function RL.GetMusicTimePlayed( music ) end
|
|||||||
|
|
||||||
-- Math - Utils
|
-- Math - Utils
|
||||||
|
|
||||||
|
---Round float value
|
||||||
|
---- Success return float
|
||||||
|
---@param value number
|
||||||
|
---@return any result
|
||||||
|
function RL.Round( value ) end
|
||||||
|
|
||||||
---Clamp float value
|
---Clamp float value
|
||||||
---- Success return float
|
---- Success return float
|
||||||
---@param value number
|
---@param value number
|
||||||
|
|||||||
12
changelog
12
changelog
@@ -2,13 +2,8 @@
|
|||||||
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
|
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
KEY CHANGES:
|
KEY CHANGES:
|
||||||
- CHANGE: GetBufferData takes also position and length arguments.
|
|
||||||
- ADDED: LoadImageFromData.
|
|
||||||
- CHANGE: Process renamed to update to be more inline with naming of raylib and common convention.
|
- CHANGE: Process renamed to update to be more inline with naming of raylib and common convention.
|
||||||
- ADDED: Raygui lib tooltip.
|
|
||||||
- ADDED: apiScanner.lua for searching unimplemented functions from raylib.
|
- ADDED: apiScanner.lua for searching unimplemented functions from raylib.
|
||||||
- ADDED & CHANGE: ImageText. ImageTextEx is now equivalent to raylib function and old ImageText.
|
|
||||||
- ADDED & CHANGE: MeasureText. MeasureTextEx is now equivalent to raylib function and old MeasureText.
|
|
||||||
- ADDED Automation events.
|
- ADDED Automation events.
|
||||||
|
|
||||||
DETAILED CHANGES:
|
DETAILED CHANGES:
|
||||||
@@ -32,6 +27,13 @@ DETAILED CHANGES:
|
|||||||
- ADDED: Custom frame control functions.
|
- ADDED: Custom frame control functions.
|
||||||
- REMOVED: GetPixelColor. Deviates too much from raylib function.
|
- REMOVED: GetPixelColor. Deviates too much from raylib function.
|
||||||
- ADDED: EnableEventWaiting and DisableEventWaiting.
|
- ADDED: EnableEventWaiting and DisableEventWaiting.
|
||||||
|
- CHANGE: GetBufferData takes also position and length arguments.
|
||||||
|
- ADDED & CHANGE: ImageText. ImageTextEx is now equivalent to raylib function and old ImageText.
|
||||||
|
- ADDED & CHANGE: MeasureText. MeasureTextEx is now equivalent to raylib function and old MeasureText.
|
||||||
|
- ADDED: LoadImageFromData.
|
||||||
|
- ADDED: Raygui lib tooltip.
|
||||||
|
- ADDED: Round.
|
||||||
|
- ADDED: PubSub lib.
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0
|
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0
|
||||||
|
|||||||
4
devnotes
4
devnotes
@@ -3,8 +3,8 @@ Current {
|
|||||||
|
|
||||||
Backlog {
|
Backlog {
|
||||||
* Raygui lib
|
* Raygui lib
|
||||||
* Check if could remove flickering from changing draw order by making queue for order changing and only
|
* Check if could remove flickering from changing draw order by making queue for order
|
||||||
change them after everything is drawn.
|
changing and only change them after everything is drawn.
|
||||||
* Platform desktop SDL
|
* Platform desktop SDL
|
||||||
* Text input not working on gui. Could this be Raylib issue?
|
* Text input not working on gui. Could this be Raylib issue?
|
||||||
* Haptic functions.
|
* Haptic functions.
|
||||||
|
|||||||
@@ -246,6 +246,10 @@ apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PAT
|
|||||||
NPatchInfo, n-patch layout info\n\n---\n" )
|
NPatchInfo, n-patch layout info\n\n---\n" )
|
||||||
apiFile:write( "\n> ModelAnimations = Userdata\n\
|
apiFile:write( "\n> ModelAnimations = Userdata\n\
|
||||||
ModelAnimation\n\n---\n" )
|
ModelAnimation\n\n---\n" )
|
||||||
|
apiFile:write( "\n> AutomationEvent = Userdata\n\
|
||||||
|
Automation event\n\n---\n" )
|
||||||
|
apiFile:write( "\n> AutomationEventList = Userdata\n\
|
||||||
|
Automation event list\n\n---\n" )
|
||||||
apiFile:write( "\n> Buffer = Buffer userdata\n\
|
apiFile:write( "\n> Buffer = Buffer userdata\n\
|
||||||
Data buffer for C primitive types. Type should be one of the Buffer types.\n\n---\n" )
|
Data buffer for C primitive types. Type should be one of the Buffer types.\n\n---\n" )
|
||||||
|
|
||||||
@@ -368,7 +372,6 @@ for _, src in ipairs( sourceFiles ) do
|
|||||||
local splits = split( src, "/" )
|
local splits = split( src, "/" )
|
||||||
|
|
||||||
apiFile = io.open( "../"..splits[ #splits ]..".md", "a" )
|
apiFile = io.open( "../"..splits[ #splits ]..".md", "a" )
|
||||||
-- apiFile = io.open( "../"..src..".md", "w" )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ function RL.init()
|
|||||||
camera:setTarget( { 0, 0, 0 } )
|
camera:setTarget( { 0, 0, 0 } )
|
||||||
camera:setUp( { 0, 1, 0 } )
|
camera:setUp( { 0, 1, 0 } )
|
||||||
camera.mode = camera.MODES.ORBITAL
|
camera.mode = camera.MODES.ORBITAL
|
||||||
-- camera.mode = camera.MODES.FREE
|
|
||||||
-- camera.mode = camera.MODES.FIRST_PERSON
|
|
||||||
|
|
||||||
heigthImage = RL.LoadImage( RL.GetBasePath().."../resources/images/heightmap.png" )
|
heigthImage = RL.LoadImage( RL.GetBasePath().."../resources/images/heightmap.png" )
|
||||||
|
|
||||||
@@ -78,7 +76,7 @@ function RL.init()
|
|||||||
material = RL.LoadMaterialDefault()
|
material = RL.LoadMaterialDefault()
|
||||||
RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture )
|
RL.SetMaterialTexture( material, RL.MATERIAL_MAP_ALBEDO, groundTexture )
|
||||||
|
|
||||||
matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
|
matrix = RL.MatrixTranslate( { -4, 0, -4 } )
|
||||||
end
|
end
|
||||||
|
|
||||||
function RL.update( delta )
|
function RL.update( delta )
|
||||||
|
|||||||
@@ -31,15 +31,12 @@ function RL.init()
|
|||||||
camera:setTarget( { 0, 0, 0 } )
|
camera:setTarget( { 0, 0, 0 } )
|
||||||
camera:setUp( { 0, 1, 0 } )
|
camera:setUp( { 0, 1, 0 } )
|
||||||
camera.mode = camera.MODES.ORBITAL
|
camera.mode = camera.MODES.ORBITAL
|
||||||
-- camera.mode = camera.MODES.FREE
|
|
||||||
-- camera.mode = camera.MODES.FIRST_PERSON
|
|
||||||
|
|
||||||
local ts = PLANE_SIZE
|
|
||||||
local meshData = {
|
local meshData = {
|
||||||
vertices = { { 0, 0, 0 }, { 0, 0, PLANE_SIZE }, { PLANE_SIZE, 0, PLANE_SIZE },
|
vertices = { { 0, 0, 0 }, { 0, 0, PLANE_SIZE }, { PLANE_SIZE, 0, PLANE_SIZE },
|
||||||
{ 0, 0, 0 }, { PLANE_SIZE, 0, PLANE_SIZE }, { PLANE_SIZE, 0, 0 } },
|
{ 0, 0, 0 }, { PLANE_SIZE, 0, PLANE_SIZE }, { PLANE_SIZE, 0, 0 } },
|
||||||
texcoords = { { 0, 0 }, { 0, ts }, { ts, ts },
|
texcoords = { { 0, 0 }, { 0, PLANE_SIZE }, { PLANE_SIZE, PLANE_SIZE },
|
||||||
{ 0, 0 }, { ts, ts }, { ts, 0 } },
|
{ 0, 0 }, { PLANE_SIZE, PLANE_SIZE }, { PLANE_SIZE, 0 } },
|
||||||
texcoords2 = { { 0, 0 }, { 0, 1 }, { 1, 1 },
|
texcoords2 = { { 0, 0 }, { 0, 1 }, { 1, 1 },
|
||||||
{ 0, 0 }, { 1, 1 }, { 1, 0 } },
|
{ 0, 0 }, { 1, 1 }, { 1, 0 } },
|
||||||
colors = { RL.WHITE, RL.WHITE, RL.WHITE,
|
colors = { RL.WHITE, RL.WHITE, RL.WHITE,
|
||||||
@@ -80,7 +77,7 @@ function RL.init()
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
material = RL.CreateMaterial( materialData )
|
material = RL.CreateMaterial( materialData )
|
||||||
matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
|
matrix = RL.MatrixTranslate( { -PLANE_SIZE / 2, 0, -PLANE_SIZE / 2 } )
|
||||||
end
|
end
|
||||||
|
|
||||||
function RL.update( delta )
|
function RL.update( delta )
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ local function addPropertyList()
|
|||||||
nil,
|
nil,
|
||||||
{
|
{
|
||||||
properties = {
|
properties = {
|
||||||
{ RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
|
-- { RL.SCROLLBAR, RL.ARROWS_VISIBLE, RL.ARROWS_VISIBLE },
|
||||||
|
{ RL.LISTVIEW, RL.BORDER_COLOR_FOCUSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },
|
||||||
|
{ RL.LISTVIEW, RL.BORDER_COLOR_PRESSED, RL.GuiGetStyle( RL.LISTVIEW, RL.BORDER_COLOR_NORMAL ) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -144,4 +144,13 @@ function Color:alphaBlend( dst, src, tint )
|
|||||||
return Color:new( RL.ColorAlphaBlend( dst, src, tint ) )
|
return Color:new( RL.ColorAlphaBlend( dst, src, tint ) )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Color:lerp( color, amount )
|
||||||
|
return Color:new(
|
||||||
|
RL.Lerp( self.r, color.r, amount ),
|
||||||
|
RL.Lerp( self.g, color.g, amount ),
|
||||||
|
RL.Lerp( self.b, color.b, amount ),
|
||||||
|
RL.Lerp( self.a, color.a, amount )
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
return Color
|
return Color
|
||||||
|
|||||||
34
examples/resources/lib/pubsub.lua
Normal file
34
examples/resources/lib/pubsub.lua
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
local PubSub = {}
|
||||||
|
PubSub.__index = PubSub
|
||||||
|
|
||||||
|
function PubSub:new()
|
||||||
|
local object = setmetatable( {}, self )
|
||||||
|
|
||||||
|
object.signals = {}
|
||||||
|
|
||||||
|
return object
|
||||||
|
end
|
||||||
|
|
||||||
|
function PubSub:add( name )
|
||||||
|
self.signals[ name ] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function PubSub:subscribe( name, func )
|
||||||
|
table.insert( self.signals[ name ], func )
|
||||||
|
end
|
||||||
|
|
||||||
|
function PubSub:unSubscribe( name, uFunc )
|
||||||
|
for i, func in ipairs( self.signals[ name ] ) do
|
||||||
|
if func == uFunc then
|
||||||
|
table.remove( self.signals[ name ], i )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function PubSub:publish( name, ... )
|
||||||
|
for _, func in ipairs( self.signals[ name ] ) do
|
||||||
|
func( ... )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return PubSub
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
-- Define useful global functions.
|
-- Define useful global functions.
|
||||||
|
|
||||||
|
-- For luaJit compatibility.
|
||||||
|
if table.unpack == nil then
|
||||||
|
table.unpack = unpack
|
||||||
|
end
|
||||||
|
|
||||||
local utillib = {}
|
local utillib = {}
|
||||||
|
|
||||||
function utillib.tableClone( org )
|
function utillib.tableClone( org )
|
||||||
|
|||||||
@@ -248,4 +248,6 @@ function RL.draw()
|
|||||||
0.0,
|
0.0,
|
||||||
RL.WHITE
|
RL.WHITE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
RL.DrawFPS( { 20, 20 } )
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ end
|
|||||||
function RL.update( delta )
|
function RL.update( delta )
|
||||||
if RL.IsKeyPressed( RL.KEY_ENTER ) then
|
if RL.IsKeyPressed( RL.KEY_ENTER ) then
|
||||||
local winSize = RL.GetScreenSize()
|
local winSize = RL.GetScreenSize()
|
||||||
|
local measuredSize = RL.MeasureTextEx( RL.GetFontDefault(), text, textSize, 2 )
|
||||||
|
|
||||||
textSize = RL.MeasureText( text, textSize )
|
|
||||||
textColor = RL.BLUE
|
textColor = RL.BLUE
|
||||||
textPos = { winSize[1] / 2 - textSize[1] / 2, winSize[2] / 2 - textSize[2] / 2 }
|
textPos = { winSize[1] / 2 - measuredSize[1] / 2, winSize[2] / 2 - measuredSize[2] / 2 }
|
||||||
end
|
end
|
||||||
|
|
||||||
if RL.IsKeyPressed( RL.KEY_SPACE ) then
|
if RL.IsKeyPressed( RL.KEY_SPACE ) then
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ int imin( int a, int b );
|
|||||||
int imax( int a, int b );
|
int imax( int a, int b );
|
||||||
|
|
||||||
/* Utils. */
|
/* Utils. */
|
||||||
|
int lmathRound( lua_State* L );
|
||||||
int lmathClamp( lua_State* L );
|
int lmathClamp( lua_State* L );
|
||||||
int lmathLerp( lua_State* L );
|
int lmathLerp( lua_State* L );
|
||||||
int lmathNormalize( lua_State* L );
|
int lmathNormalize( lua_State* L );
|
||||||
|
|||||||
@@ -2096,7 +2096,7 @@ int lcoreGetAutomationEventListCount( lua_State* L ) {
|
|||||||
/*
|
/*
|
||||||
> event = RL.GetAutomationEvent( AutomationEventList list, int index )
|
> event = RL.GetAutomationEvent( AutomationEventList list, int index )
|
||||||
|
|
||||||
Get automation event from automation event list
|
Get automation event from automation event list. Return as lightuserdata
|
||||||
|
|
||||||
- Failure return nil
|
- Failure return nil
|
||||||
- Success return AutomationEvent
|
- Success return AutomationEvent
|
||||||
@@ -2106,7 +2106,7 @@ int lcoreGetAutomationEvent( lua_State* L ) {
|
|||||||
int index = luaL_checkinteger( L, 2 );
|
int index = luaL_checkinteger( L, 2 );
|
||||||
|
|
||||||
if ( 0 <= index && index < list->count ) {
|
if ( 0 <= index && index < list->count ) {
|
||||||
uluaPushAutomationEvent( L, list->events[ index ] );
|
lua_pushlightuserdata( L, &list->events[ index ] );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TraceLog( LOG_WARNING, "GetAutomationEvent index %d out of bounds", index );
|
TraceLog( LOG_WARNING, "GetAutomationEvent index %d out of bounds", index );
|
||||||
|
|||||||
@@ -1893,6 +1893,7 @@ void luaRegister() {
|
|||||||
|
|
||||||
/* Math. */
|
/* Math. */
|
||||||
/* Utils. */
|
/* Utils. */
|
||||||
|
assingGlobalFunction( "Round", lmathRound );
|
||||||
assingGlobalFunction( "Clamp", lmathClamp );
|
assingGlobalFunction( "Clamp", lmathClamp );
|
||||||
assingGlobalFunction( "Lerp", lmathLerp );
|
assingGlobalFunction( "Lerp", lmathLerp );
|
||||||
assingGlobalFunction( "Normalize", lmathNormalize );
|
assingGlobalFunction( "Normalize", lmathNormalize );
|
||||||
|
|||||||
15
src/rmath.c
15
src/rmath.c
@@ -15,6 +15,21 @@ inline int imax( int a, int b ) {
|
|||||||
## Math - Utils
|
## Math - Utils
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
> result = RL.Round( float value )
|
||||||
|
|
||||||
|
Round float value
|
||||||
|
|
||||||
|
- Success return float
|
||||||
|
*/
|
||||||
|
int lmathRound( lua_State* L ) {
|
||||||
|
float value = luaL_checknumber( L, 1 );
|
||||||
|
|
||||||
|
lua_pushnumber( L, round( value ) );
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> result = RL.Clamp( float value, float min, float max )
|
> result = RL.Clamp( float value, float min, float max )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user