Add frame tick system for continuous animation

- Added INPUT_FRAME_TICK event type to input_event.h
- Added wants_frame_updates() virtual method to Game base class
- Implemented frame tick logic in main loop (basic1.cpp and emulator/main.cpp)
- Added Lua bindings: game.set_frame_updates(bool) and INPUT.FRAME_TICK
- Updated LuaGame to support frame updates via registry flag
- Updated ball.lua to use continuous frame updates for smooth animation
- Both hardware and emulator now support continuous animation for physics/games
This commit is contained in:
Adolfo Reyna
2026-02-07 13:20:10 -05:00
parent 8d176925f8
commit 2a472fc29f
10 changed files with 86 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ public:
virtual bool update(const InputEvent& event) = 0;
virtual void draw() = 0;
virtual bool wants_to_exit() const { return false; }
virtual bool wants_frame_updates() const { return false; }
// Public members for Lua bindings access
uint16_t width;

View File

@@ -171,7 +171,17 @@ bool LuaGame::wants_to_exit() const {
return exit;
}
bool LuaGame::wants_frame_updates() const {
if (!L) return false;
// Check registry for frame updates flag
lua_pushstring(L, "__wants_frame_updates");
lua_gettable(L, LUA_REGISTRYINDEX);
bool wants_updates = lua_toboolean(L, -1);
lua_pop(L, 1);
return wants_updates;
}
bool LuaGame::call_lua_function(const char* func_name, int nargs, int nresults) {
int result = lua_pcall(L, nargs, nresults, 0);
if (result != LUA_OK) {

View File

@@ -107,6 +107,17 @@ int main() {
needs_redraw = true;
}
}
} else if (launcher.is_game_selected()) {
// No user input, but check if game wants frame tick updates
current_game = launcher.get_selected_game();
if (current_game->wants_frame_updates()) {
InputEvent frame_event = {INPUT_FRAME_TICK, 0, 0, 0, 0, 0, true};
needs_redraw = current_game->update(frame_event) || needs_redraw;
if (current_game->wants_to_exit()) {
launcher.reset();
needs_redraw = true;
}
}
}
// Always redraw every frame for emulator