Add Lua scripting support to desktop emulator
- Created emulator-specific lua_game_emulator.cpp using filesystem instead of FatFS - Created lua_game_loader_emulator.cpp to scan games/lua_examples directory - Updated CMakeLists.txt to include Lua 5.4 engine and bindings - Updated to SFML 3.0 API compatibility (event handling, sprite initialization) - Updated Game class to use public members for Lua bindings - Updated GameLauncher to use std::function for lambda captures - Added continuous 60 FPS rendering for smooth display - Emulator now loads and runs all three example Lua games
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
#include <vector>
|
||||
|
||||
// Add missing method implementations for emulator linkage
|
||||
bool LowLevelDisplaySFML::pollEvent(sf::Event& event) {
|
||||
return window.pollEvent(event);
|
||||
std::optional<sf::Event> LowLevelDisplaySFML::pollEvent() {
|
||||
return window.pollEvent();
|
||||
}
|
||||
|
||||
void LowLevelDisplaySFML::close() {
|
||||
@@ -14,18 +14,22 @@ void LowLevelDisplaySFML::close() {
|
||||
}
|
||||
|
||||
LowLevelDisplaySFML::LowLevelDisplaySFML(int w, int h)
|
||||
: width(w), height(h), window(sf::VideoMode(w, h), "basic1 Emulator"), framebuffer((w * h + 7) / 8, 0) {}
|
||||
: width(w), height(h),
|
||||
window(sf::VideoMode({(unsigned)w, (unsigned)h}), "basic1 Emulator"),
|
||||
framebuffer((w * h + 7) / 8, 0) {}
|
||||
|
||||
bool LowLevelDisplaySFML::init() {
|
||||
texture.create(width, height);
|
||||
sprite.setTexture(texture);
|
||||
if (!texture.resize({(unsigned)width, (unsigned)height})) {
|
||||
return false;
|
||||
}
|
||||
sprite.emplace(texture);
|
||||
return window.isOpen();
|
||||
}
|
||||
|
||||
void LowLevelDisplaySFML::draw_buffer(const uint8_t* bit_buffer) {
|
||||
// Convert 1-bit buffer to 8-bit grayscale (or RGBA) for SFML
|
||||
// Each bit in bit_buffer represents a pixel (0=black, 1=white)
|
||||
std::vector<sf::Uint8> pixels(width * height * 4, 0);
|
||||
std::vector<std::uint8_t> pixels(width * height * 4, 0);
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
int bit_index = y * width + x;
|
||||
@@ -33,7 +37,7 @@ void LowLevelDisplaySFML::draw_buffer(const uint8_t* bit_buffer) {
|
||||
int bit_offset = 7 - (bit_index % 8);
|
||||
bool on = (bit_buffer[byte_index] >> bit_offset) & 0x1;
|
||||
int idx = (y * width + x) * 4;
|
||||
sf::Uint8 color = on ? 255 : 0;
|
||||
std::uint8_t color = on ? 255 : 0;
|
||||
pixels[idx + 0] = color; // R
|
||||
pixels[idx + 1] = color; // G
|
||||
pixels[idx + 2] = color; // B
|
||||
@@ -44,14 +48,10 @@ void LowLevelDisplaySFML::draw_buffer(const uint8_t* bit_buffer) {
|
||||
}
|
||||
|
||||
void LowLevelDisplaySFML::refresh() {
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
// TODO: Handle mouse/keyboard input here
|
||||
}
|
||||
window.clear(sf::Color::Black);
|
||||
window.draw(sprite);
|
||||
if (sprite) {
|
||||
window.draw(*sprite);
|
||||
}
|
||||
window.display();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user