mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 02:05:55 +02:00
Adding event callback handling. Crash with animations exists (must stop animation too)
This commit is contained in:
@@ -98,9 +98,11 @@ set(RETROFE_HEADERS
|
||||
"${RETROFE_DIR}/Source/Graphics/Component/ComponentFactory.h"
|
||||
"${RETROFE_DIR}/Source/Lua/Lua.h"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaDisplay.h"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaEvent.h"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaImage.h"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaLog.h"
|
||||
"${RETROFE_DIR}/Source/RetroFE.h"
|
||||
"${RETROFE_DIR}/Source/StateMachine.h"
|
||||
"${RETROFE_DIR}/Source/SDL.h"
|
||||
"${RETROFE_DIR}/Source/Version.h"
|
||||
)
|
||||
@@ -115,9 +117,11 @@ set(RETROFE_SOURCES
|
||||
"${RETROFE_DIR}/Source/Lua/Lua.cpp"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaDisplay.cpp"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaImage.cpp"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaEvent.cpp"
|
||||
"${RETROFE_DIR}/Source/Lua/LuaLog.cpp"
|
||||
"${RETROFE_DIR}/Source/Main.cpp"
|
||||
"${RETROFE_DIR}/Source/RetroFE.cpp"
|
||||
"${RETROFE_DIR}/Source/StateMachine.cpp"
|
||||
"${RETROFE_DIR}/Source/SDL.cpp"
|
||||
"${RETROFE_DIR}/Source/Version.cpp"
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "LuaEvents.h"
|
||||
#include "LuaEvent.h"
|
||||
|
||||
void LuaEvents::registerOnInit(std::string functionName)
|
||||
void LuaEvent::registerOnInit(std::string functionName)
|
||||
{
|
||||
onInit_.push_back(functionName);
|
||||
}
|
||||
|
||||
void LuaEvents::triggerOnInit(lua_State *l)
|
||||
void LuaEvent::triggerOnInit(lua_State *l)
|
||||
{
|
||||
for(unsigned int i = 0; i < onInit_.size(); ++i) {
|
||||
lua_getglobal(l, onInit_[i].c_str());
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include "Lua.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class LuaEvents {
|
||||
public:
|
||||
void registerOnInit(std::string functionName);
|
||||
void triggerOnInit(lua_State *l);
|
||||
private:
|
||||
std::vector<std::string> onInit_;
|
||||
};
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "RetroFE.h"
|
||||
#include "StateMachine.h"
|
||||
#include "Utility/Log.h"
|
||||
#include "Utility/Utils.h"
|
||||
#include "SDL.h"
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "Lua/LuaDisplay.h"
|
||||
#include "Lua/LuaImage.h"
|
||||
#include "Lua/LuaLog.h"
|
||||
#include "Lua/LuaEvent.h"
|
||||
#include <vector>
|
||||
|
||||
#ifdef __linux
|
||||
@@ -73,9 +75,7 @@ const luaL_Reg RetroFE::luaImageFuncs[] = {
|
||||
{"setAlpha", LuaImage::setAlpha},
|
||||
{"addAnimation", LuaImage::addAnimation},
|
||||
{"animate", LuaImage::animate},
|
||||
#if 0
|
||||
{"delete", lua_imageDelete},
|
||||
#endif
|
||||
{"destroy", LuaImage::destroy},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -121,6 +121,9 @@ void RetroFE::reloadLuaScripts()
|
||||
std::string path = config_.absolutePath + "/layouts/LUATest/Page.lua";
|
||||
luaL_loadfile(lua_.state, path.c_str());
|
||||
lua_pcall(lua_.state, 0, LUA_MULTRET, 0);
|
||||
|
||||
luaEvent_.registerCallback("onInitEnter", "onInitEnter", "onInitEnterComplete");
|
||||
luaEvent_.registerCallback("onInitExit", "onInitExit", "onInitExitComplete");
|
||||
}
|
||||
|
||||
RetroFE::RetroFE(Configuration &c)
|
||||
@@ -139,6 +142,7 @@ void RetroFE::run()
|
||||
if(!SDL::initialize(config_)) return;
|
||||
|
||||
initializeLua();
|
||||
StateMachine state(lua_.state, &luaEvent_);
|
||||
|
||||
reloadLuaScripts();
|
||||
// events.triggerOnInit(lua_.state);
|
||||
@@ -148,6 +152,7 @@ void RetroFE::run()
|
||||
double deltaTime = 0;
|
||||
while(!quit) {
|
||||
|
||||
|
||||
lastTime = currentTime;
|
||||
currentTime = static_cast<float>(SDL_GetTicks()) / 1000;
|
||||
|
||||
@@ -163,6 +168,8 @@ void RetroFE::run()
|
||||
|
||||
deltaTime = currentTime - lastTime;
|
||||
|
||||
state.update((float)deltaTime);
|
||||
|
||||
SDL_LockMutex(SDL::getMutex());
|
||||
SDL_SetRenderDrawColor(SDL::getRenderer(), 0x0, 0x0, 0x00, 0xFF);
|
||||
SDL_RenderClear(SDL::getRenderer());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Lua/Lua.h"
|
||||
#include "Lua/LuaEvent.h"
|
||||
#include "Database/Configuration.h"
|
||||
#include "Graphics/Component/ComponentFactory.h"
|
||||
#include <SDL2/SDL.h>
|
||||
@@ -33,6 +34,7 @@ private:
|
||||
ComponentFactory factory_;
|
||||
Configuration &config_;
|
||||
Lua lua_;
|
||||
LuaEvent luaEvent_;
|
||||
static const luaL_Reg luaDisplayFuncs[];
|
||||
static const luaL_Reg luaLogFuncs[];
|
||||
static const luaL_Reg luaImageFuncs[];
|
||||
|
||||
Reference in New Issue
Block a user