/
antim
/
LuaPlayer-by-YuliaTeam
Обзор
Документация
Войти
/
antim
/
LuaPlayer-by-YuliaTeam
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lua/asyncCycle.c
131 строка
7 KB
antim0118
Заменил заголовки файлов
25 фев 2026, 22:25
25 фев 2026, 22:25
842b6c8
Код
Авторство
О чём код?
/*-----------------------------------------------------------------------------------------------------------------------# #------------- This file is part of: ------------------------------------------------------------------------------------# #---█████----------------------------███████████--████------------------------------------------█████-█████-███████████--# #--░░███----------------------------░░███░░░░░███░░███-----------------------------------------░░███-░░███-░█░░░███░░░█--# #---░███--------█████-████--██████---░███----░███-░███---██████---█████-████--██████--████████--░░███-███--░---░███--░---# #---░███-------░░███-░███--░░░░░███--░██████████--░███--░░░░░███-░░███-░███--███░░███░░███░░███--░░█████-------░███------# #---░███--------░███-░███---███████--░███░░░░░░---░███---███████--░███-░███-░███████--░███-░░░----░░███--------░███------# #---░███------█-░███-░███--███░░███--░███---------░███--███░░███--░███-░███-░███░░░---░███---------░███--------░███------# #---███████████-░░████████░░████████-█████--------█████░░████████-░░███████-░░██████--█████--------█████-------█████-----# #--░░░░░░░░░░░---░░░░░░░░--░░░░░░░░-░░░░░--------░░░░░--░░░░░░░░---░░░░░███--░░░░░░--░░░░░--------░░░░░-------░░░░░------# #------------------------------------------------------------------███-░███----------------------------------------------# #-----------------------------------------------------------------░░██████-----------------------------------------------# #------------------------------------------------------------------░░░░░░------------------------------------------------# #------------------------------------------------------------------------------------ Made by Kodilo --------------------# #- Special Thanks to: ---------------------------------------------------------------------------------------------------# #------------------------------------------------------------------------------------------------------------------------# #- BenHur for intraFont -------------------------------------------------------------------------------------------------# #- Geecko for gLib2D ----------------------------------------------------------------------------------------------------# #- Arshia001 for PSPAALIB -----------------------------------------------------------------------------------------------# #- jonny & Raphael for PMP Mod ------------------------------------------------------------------------------------------# #- InsertWittyName & MK2k for PGE source code ---------------------------------------------------------------------------# #- Rinnegatamante & Nanni for example of awesome Lua Player -------------------------------------------------------------# #-----------------------------------------------------------------------------------------------------------------------*/ #include "asyncCycle.h" #include "timer.h" #define MAX_ARRAY_SIZE 100 typedef struct { int i; int max; float step; float ms; LUA_timer *timer; const char *func; const char *funcName; } AsyncOperation; AsyncOperation asyncArray[MAX_ARRAY_SIZE]; int numOfAsyncOperations = 0; int upd(AsyncOperation *async, const char *luaFuncCode, lua_State *L) { if (TIMER_TIME(async->timer) > async->ms) { async->i += async->step; TIMER_RESET(async->timer); } if ((async->step > 0 && async->i > async->max) || (async->step < 0 && async->i < async->max)) { async->i = async->max; } if ((luaL_loadstring(L, luaFuncCode) && lua_pcall(L, 0, 0, 0)) != 0) return luaL_error(L, "asyncCycle error 1"); lua_getglobal(L, async->funcName); // Передача значения async->i в Lua функцию lua_pushnumber(L, async->i); // Вызов Lua функции if (lua_pcall(L, 1, 0, 0) != 0) { return luaL_error(L, "asyncCycle error 2"); } return 0; } void update(lua_State *L) { int i, j; for (i = 0; i < numOfAsyncOperations; i++) { if (asyncArray[i].i == asyncArray[i].max) { // Удаление операции и сдвиг массива TIMER_REMOVE(&asyncArray[i].timer); for (j = i; j < numOfAsyncOperations - 1; j++) { asyncArray[j] = asyncArray[j + 1]; } numOfAsyncOperations--; i--; } else { upd(&asyncArray[i], asyncArray[i].func, L); } } } void newAsyncOperation(int from, int to, float step, float ms, const char *func, const char *funcName) { if (numOfAsyncOperations < MAX_ARRAY_SIZE) { AsyncOperation newAsync = { from, to, step, ms, TIMER_CREATE(), func, funcName }; asyncArray[numOfAsyncOperations] = newAsync; numOfAsyncOperations++; } } static int asyncCycle_UPDATE(lua_State *L) { if (lua_gettop(L) != 0) return luaL_error(L, "asyncCycle.update() takes 0 arguments"); update(L); return 0; } static int asyncCycle_NEW(lua_State *L) { if (lua_gettop(L) != 6) return luaL_error(L, "asyncCycle.new(from, to, step, ms, func, funcName) takes 5 arguments"); int from = luaL_checknumber(L, 1); int to = luaL_checknumber(L, 2); float step = luaL_checknumber(L, 3); float ms = luaL_checknumber(L, 4); const char *func = luaL_checkstring(L, 5); const char *funcName = luaL_checkstring(L, 6); newAsyncOperation(from, to, step, ms, func, funcName); return 0; } static const luaL_Reg async_methods[] = { {"update", asyncCycle_UPDATE}, {"new", asyncCycle_NEW}, {0, 0} }; int ASYNC_init(lua_State *L) { luaL_register(L, "asyncCycle", async_methods); return 0; }