Fix frame update logic and emulator support
- Fix basic1.cpp loop to handle set_frame_updates(true) correctly with sleep - Update emulator loop for concurrent input and frame updates - Update emulator for SFML 3.0 compatibility - Add INPUT.FRAME_TICK constant to Lua bindings - Enable frame updates in snake.lua example
This commit is contained in:
@@ -62,13 +62,13 @@ int main() {
|
||||
InputEvent event = {INPUT_NONE, 0, 0, 0, 0, 0, false};
|
||||
|
||||
while (const auto sfEvent = display.pollEvent()) {
|
||||
if (const auto* closed = sfEvent->getIf<sf::Event::Closed>()) {
|
||||
if (sfEvent->is<sf::Event::Closed>()) {
|
||||
display.close();
|
||||
running = false;
|
||||
} else if (const auto* mousePressed = sfEvent->getIf<sf::Event::MouseButtonPressed>()) {
|
||||
} else if (const auto* mouse = sfEvent->getIf<sf::Event::MouseButtonPressed>()) {
|
||||
event.type = INPUT_TOUCH_DOWN;
|
||||
event.x = mousePressed->position.x;
|
||||
event.y = mousePressed->position.y;
|
||||
event.x = mouse->position.x;
|
||||
event.y = mouse->position.y;
|
||||
event.valid = true;
|
||||
|
||||
// Check for virtual buttons
|
||||
@@ -76,14 +76,14 @@ int main() {
|
||||
if (input_manager.check_virtual_buttons(event.x, event.y, virtual_type)) {
|
||||
event.type = virtual_type;
|
||||
}
|
||||
} else if (const auto* keyPressed = sfEvent->getIf<sf::Event::KeyPressed>()) {
|
||||
if (keyPressed->code == sf::Keyboard::Key::Space) {
|
||||
} else if (const auto* key = sfEvent->getIf<sf::Event::KeyPressed>()) {
|
||||
if (key->code == sf::Keyboard::Key::Space) {
|
||||
event.type = INPUT_BUTTON_0;
|
||||
event.valid = true;
|
||||
} else if (keyPressed->code == sf::Keyboard::Key::Enter) {
|
||||
} else if (key->code == sf::Keyboard::Key::Enter) {
|
||||
event.type = INPUT_BUTTON_1;
|
||||
event.valid = true;
|
||||
} else if (keyPressed->code == sf::Keyboard::Key::Escape) {
|
||||
} else if (key->code == sf::Keyboard::Key::Escape) {
|
||||
// Simulate long-press exit
|
||||
if (launcher.is_game_selected()) {
|
||||
launcher.reset();
|
||||
@@ -107,8 +107,10 @@ int main() {
|
||||
needs_redraw = true;
|
||||
}
|
||||
}
|
||||
} else if (launcher.is_game_selected()) {
|
||||
// No user input, but check if game wants frame tick updates
|
||||
}
|
||||
|
||||
// Check if game wants frame tick updates (independent of user input)
|
||||
if (launcher.is_game_selected()) {
|
||||
current_game = launcher.get_selected_game();
|
||||
if (current_game->wants_frame_updates()) {
|
||||
InputEvent frame_event = {INPUT_FRAME_TICK, 0, 0, 0, 0, 0, true};
|
||||
|
||||
Reference in New Issue
Block a user