diff options
| author | jussi | 2024-03-01 23:11:54 +0200 |
|---|---|---|
| committer | jussi | 2024-03-01 23:11:54 +0200 |
| commit | ca238975dc63d2dddcd2b17ad627bedc95dd158c (patch) | |
| tree | d1cf76dbc3ec24163d952e12204bb7f854a95501 /src | |
| parent | 625e4e0e4df7d08b58d6ba5741b932e57a70f3dd (diff) | |
| download | reilua-enhanced-ca238975dc63d2dddcd2b17ad627bedc95dd158c.tar.gz reilua-enhanced-ca238975dc63d2dddcd2b17ad627bedc95dd158c.tar.bz2 reilua-enhanced-ca238975dc63d2dddcd2b17ad627bedc95dd158c.zip | |
Automation events.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 229 | ||||
| -rw-r--r-- | src/lua_core.c | 77 |
2 files changed, 298 insertions, 8 deletions
@@ -1030,16 +1030,16 @@ int lcoreSetShaderValue( lua_State* L ) { /* t = values index. */ int t = 3, i = 0; - lua_pushnil( L ); + lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { - if ( lua_isnumber( L, -1 ) ) { + if ( lua_isnumber( L, -1 ) ) { floats[i] = lua_tonumber( L, -1 ); ints[i] = lua_tointeger( L, -1 ); - } - i++; - lua_pop( L, 1 ); - } + } + i++; + lua_pop( L, 1 ); + } lua_pop( L, 1 ); /* Read values end. */ @@ -1950,6 +1950,223 @@ int lcoreDecodeDataBase64( lua_State* L ) { } /* +## Core - Automation events functionality +*/ + +/* +> eventList = RL.LoadAutomationEventList( string|nil fileName ) + +Load automation events list from file, nil for empty list, capacity = MAX_AUTOMATION_EVENTS + +- Success return AutomationEventList +*/ +int lcoreLoadAutomationEventList( lua_State* L ) { + if ( lua_isstring( L, 1 ) ) { + uluaPushAutomationEventList( L, LoadAutomationEventList( lua_tostring( L, 1 ) ) ); + } + else if ( lua_isnil( L, 1 ) ) { + uluaPushAutomationEventList( L, LoadAutomationEventList( NULL ) ); + } + + return 1; +} + +/* +> RL.UnloadAutomationEventList( AutomationEventList list ) + +Unload automation events list from file +*/ +int lcoreUnloadAutomationEventList( lua_State* L ) { + AutomationEventList* list = uluaGetAutomationEventList( L, 1 ); + + UnloadAutomationEventList( list ); + + return 0; +} + +/* +> success = RL.ExportAutomationEventList( string fileName ) + +Export automation events list as text file + +- Failure return false +- Success return true +*/ +int lcoreExportAutomationEventList( lua_State* L ) { + AutomationEventList* list = uluaGetAutomationEventList( L, 1 ); + const char* fileName = luaL_checkstring( L, 2 ); + + lua_pushboolean( L, ExportAutomationEventList( *list, fileName ) ); + + return 1; +} + +/* +> RL.SetAutomationEventList( AutomationEventList list ) + +Set automation event list to record to +*/ +int lcoreSetAutomationEventList( lua_State* L ) { + AutomationEventList* list = uluaGetAutomationEventList( L, 1 ); + + SetAutomationEventList( list ); + + return 0; +} + +/* +> RL.SetAutomationEventBaseFrame( int frame ) + +Set automation event internal base frame to start recording +*/ +int lcoreSetAutomationEventBaseFrame( lua_State* L ) { + int frame = luaL_checkinteger( L, 1 ); + + SetAutomationEventBaseFrame( frame ); + + return 0; +} + +/* +> RL.StartAutomationEventRecording() + +Start recording automation events (AutomationEventList must be set) +*/ +int lcoreStartAutomationEventRecording( lua_State* L ) { + StartAutomationEventRecording(); + + return 0; +} + +/* +> RL.StopAutomationEventRecording() + +Stop recording automation events +*/ +int lcoreStopAutomationEventRecording( lua_State* L ) { + + StopAutomationEventRecording(); + + return 0; +} + +/* +> RL.PlayAutomationEvent( AutomationEvent event ) + +Play a recorded automation event +*/ +int lcorePlayAutomationEvent( lua_State* L ) { + AutomationEvent* event = uluaGetAutomationEvent( L, 1 ); + + PlayAutomationEvent( *event ); + + return 0; +} + +/* +> capacity = RL.GetAutomationEventListCapacity( AutomationEventList list ) + +Get automation event list capacity + +- Success return int +*/ +int lcoreGetAutomationEventListCapacity( lua_State* L ) { + AutomationEventList* list = uluaGetAutomationEventList( L, 1 ); + + lua_pushinteger( L, list->capacity ); + + return 1; +} + +/* +> count = RL.GetAutomationEventListCount( AutomationEventList list ) + +Get automation event list count + +- Success return int +*/ +int lcoreGetAutomationEventListCount( lua_State* L ) { + AutomationEventList* list = uluaGetAutomationEventList( L, 1 ); + + lua_pushinteger( L, list->count ); + + return 1; +} + +/* +> event = RL.GetAutomationEvent( AutomationEventList list, int index ) + +Get automation event from automation event list + +- Failure return nil +- Success return AutomationEvent +*/ +int lcoreGetAutomationEvent( lua_State* L ) { + AutomationEventList* list = uluaGetAutomationEventList( L, 1 ); + int index = luaL_checkinteger( L, 2 ); + + if ( 0 <= index && index < list->count ) { + uluaPushAutomationEvent( L, list->events[ index ] ); + } + else { + TraceLog( LOG_WARNING, "GetAutomationEvent index %d out of bounds", index ); + lua_pushnil( L ); + } + + return 1; +} + +/* +> frame = RL.GetAutomationEventFrame( AutomationEvent event ) + +Get automation event frame + +- Success return int +*/ +int lcoreGetAutomationEventFrame( lua_State* L ) { + AutomationEvent* event = uluaGetAutomationEvent( L, 1 ); + + lua_pushinteger( L, event->frame ); + + return 1; +} + +/* +> type = RL.GetAutomationEventType( AutomationEvent event ) + +Get automation event type + +- Success return int +*/ +int lcoreGetAutomationEventType( lua_State* L ) { + AutomationEvent* event = uluaGetAutomationEvent( L, 1 ); + + lua_pushinteger( L, event->type ); + + return 1; +} + +/* +> params = RL.GetAutomationEventParams( AutomationEvent event ) + +Get automation event params + +- Success return int{} +*/ +int lcoreGetAutomationEventParams( lua_State* L ) { + AutomationEvent* event = uluaGetAutomationEvent( L, 1 ); + + lua_createtable( L, 4, 0 ); + + for ( int i = 0; i < 4; i++ ) { + lua_pushnumber( L, event->params[i] ); + lua_rawseti( L, -2, i + 1 ); + } + + return 1; +} + +/* ## Core - Input-related functions: keyboard */ diff --git a/src/lua_core.c b/src/lua_core.c index d4820bf..0c15c18 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -337,6 +337,34 @@ static void defineRLRenderBatch() { lua_setfield( L, -2, "__gc" ); } + /* AutomationEvent. */ +static void defineAutomationEvent() { + lua_State* L = state->luaState; + + luaL_newmetatable( L, "AutomationEvent" ); + lua_pushvalue( L, -1 ); + lua_setfield( L, -2, "__index" ); +} + + /* AutomationEventList. */ +static int gcAutomationEventList( lua_State* L ) { + if ( state->gcUnload ) { + AutomationEventList* automationEventList = luaL_checkudata( L, 1, "AutomationEventList" ); + UnloadAutomationEventList( automationEventList ); + } + return 0; +} + +static void defineAutomationEventList() { + lua_State* L = state->luaState; + + luaL_newmetatable( L, "AutomationEventList" ); + lua_pushvalue( L, -1 ); + lua_setfield( L, -2, "__index" ); + lua_pushcfunction( L, gcAutomationEventList ); + lua_setfield( L, -2, "__gc" ); +} + /* Assing globals. */ void assignGlobalInt( int value, const char* name ) { @@ -1033,6 +1061,8 @@ bool luaInit( int argn, const char** argc ) { defineModel(); defineModelAnimation(); defineRLRenderBatch(); + defineAutomationEvent(); + defineAutomationEventList(); /* Define globals. */ defineGlobals(); platformDefineGlobals(); @@ -1339,6 +1369,21 @@ void luaRegister() { assingGlobalFunction( "DecompressData", lcoreDecompressData ); assingGlobalFunction( "EncodeDataBase64", lcoreEncodeDataBase64 ); assingGlobalFunction( "DecodeDataBase64", lcoreDecodeDataBase64 ); + /* Automation events functionality. */ + assingGlobalFunction( "LoadAutomationEventList", lcoreLoadAutomationEventList ); + assingGlobalFunction( "UnloadAutomationEventList", lcoreUnloadAutomationEventList ); + assingGlobalFunction( "ExportAutomationEventList", lcoreExportAutomationEventList ); + assingGlobalFunction( "SetAutomationEventList", lcoreSetAutomationEventList ); + assingGlobalFunction( "SetAutomationEventBaseFrame", lcoreSetAutomationEventBaseFrame ); + assingGlobalFunction( "StartAutomationEventRecording", lcoreStartAutomationEventRecording ); + assingGlobalFunction( "StopAutomationEventRecording", lcoreStopAutomationEventRecording ); + assingGlobalFunction( "PlayAutomationEvent", lcorePlayAutomationEvent ); + assingGlobalFunction( "GetAutomationEventListCapacity", lcoreGetAutomationEventListCapacity ); + assingGlobalFunction( "GetAutomationEventListCount", lcoreGetAutomationEventListCount ); + assingGlobalFunction( "GetAutomationEvent", lcoreGetAutomationEvent ); + assingGlobalFunction( "GetAutomationEventFrame", lcoreGetAutomationEventFrame ); + assingGlobalFunction( "GetAutomationEventType", lcoreGetAutomationEventType ); + assingGlobalFunction( "GetAutomationEventParams", lcoreGetAutomationEventParams ); /* Input-related functions: keyboard. */ assingGlobalFunction( "IsKeyPressed", lcoreIsKeyPressed ); assingGlobalFunction( "IsKeyPressedRepeat", lcoreIsKeyPressedRepeat ); @@ -2619,7 +2664,7 @@ Ray uluaGetRay( lua_State* L, int index ) { Ray ray = { .position = { 0.0, 0.0, 0.0 }, .direction = { 0.0, 0.0, 0.0 } }; int t = index, i = 0; - lua_pushnil( L ); + lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { if ( lua_istable( L, -1 ) ) { @@ -2646,7 +2691,7 @@ Ray uluaGetRay( lua_State* L, int index ) { i++; lua_pop( L, 1 ); } - } + } return ray; } @@ -2915,6 +2960,20 @@ rlRenderBatch* uluaGetRLRenderBatch( lua_State* L, int index ) { return luaL_checkudata( L, index, "rlRenderBatch" ); } +AutomationEvent* uluaGetAutomationEvent( lua_State* L, int index ) { + if ( lua_islightuserdata( L, index ) ) { + return (AutomationEvent*)lua_touserdata( L, index ); + } + return luaL_checkudata( L, index, "AutomationEvent" ); +} + +AutomationEventList* uluaGetAutomationEventList( lua_State* L, int index ) { + if ( lua_islightuserdata( L, index ) ) { + return (AutomationEventList*)lua_touserdata( L, index ); + } + return luaL_checkudata( L, index, "AutomationEventList" ); +} + /* Push types. */ void uluaPushColor( lua_State* L, Color color ) { @@ -3216,6 +3275,20 @@ void uluaPushRLRenderBatch( lua_State* L, rlRenderBatch renderBatch ) { luaL_setmetatable( L, "rlRenderBatch" ); } +void uluaPushAutomationEvent( lua_State* L, AutomationEvent event ) { + AutomationEvent* eventP = lua_newuserdata( L, sizeof( AutomationEvent ) ); + *eventP = event; + luaL_setmetatable( L, "AutomationEvent" ); +} + +void uluaPushAutomationEventList( lua_State* L, AutomationEventList eventList ) { + AutomationEventList* eventListP = lua_newuserdata( L, sizeof( AutomationEventList ) ); + *eventListP = eventList; + luaL_setmetatable( L, "AutomationEventList" ); +} + +/* Utils. */ + int uluaGetTableLen( lua_State* L, int index ) { luaL_checktype( L, index, LUA_TTABLE ); int t = index, i = 0; |
