Rename mpong to breakout

This commit is contained in:
Thomas Farstrike
2026-03-11 11:57:42 +01:00
parent 3651062c15
commit 983d54f271
6 changed files with 26 additions and 41 deletions
@@ -1,10 +1,10 @@
MPY_DIR = ../../lvgl_micropython/lib/micropython/
# Name of module
MOD = mpong
MOD = breakout
# Source files (.c or .py)
SRC = mpong.c
SRC = breakout.c
# Link runtime libraries (needed for memset on xtensawin)
LINK_RUNTIME = 1
@@ -32,24 +32,6 @@ uint32_t g_fps_frames;
#define BRICK_COLS 8
uint8_t g_bricks[BRICK_ROWS][BRICK_COLS];
// readfile(filename): return first 10 bytes of a file as bytes
static mp_obj_t readfile(mp_obj_t filename_obj) {
mp_obj_t open_fun = mp_load_global(MP_QSTR_open);
mp_obj_t open_args[2] = { filename_obj, mp_obj_new_str("rb", 2) };
mp_obj_t file_obj = mp_call_function_n_kw(open_fun, 2, 0, open_args);
mp_obj_t read_fun = mp_load_attr(file_obj, MP_QSTR_read);
mp_obj_t read_args[1] = { mp_obj_new_int(10) };
mp_obj_t data_obj = mp_call_function_n_kw(read_fun, 1, 0, read_args);
mp_obj_t close_fun = mp_load_attr(file_obj, MP_QSTR_close);
mp_obj_t close_args[1];
mp_call_function_n_kw(close_fun, 0, 0, close_args);
return data_obj;
}
static MP_DEFINE_CONST_FUN_OBJ_1(readfile_obj, readfile);
static uint32_t ticks_ms(void) {
mp_obj_t time_mod = mp_import_name(MP_QSTR_time, mp_const_none, MP_OBJ_NEW_SMALL_INT(0));
mp_obj_t ticks_fun = mp_load_attr(time_mod, MP_QSTR_ticks_ms);
@@ -157,7 +139,7 @@ static mp_obj_t render(void) {
const uint32_t elapsed_ms = now_ms - g_fps_last_ms;
if (elapsed_ms >= 1000) {
const uint32_t fps = (g_fps_frames * 1000) / elapsed_ms;
mp_printf(&mp_plat_print, "mpong fps: %lu\n", (unsigned long)fps);
mp_printf(&mp_plat_print, "breakout.c fps: %lu\n", (unsigned long)fps);
g_fps_last_ms = now_ms;
g_fps_frames = 0;
}
@@ -277,7 +259,6 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
mp_store_global(MP_QSTR_init, MP_OBJ_FROM_PTR(&init_obj));
mp_store_global(MP_QSTR_render, MP_OBJ_FROM_PTR(&render_obj));
mp_store_global(MP_QSTR_move_paddle, MP_OBJ_FROM_PTR(&move_paddle_obj));
mp_store_global(MP_QSTR_readfile, MP_OBJ_FROM_PTR(&readfile_obj));
// This must be last, it restores the globals dict
MP_DYNRUNTIME_INIT_EXIT
@@ -10,4 +10,4 @@ rm *.mpy
PATH=~/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20241119/xtensa-esp-elf/bin/:$PATH make </dev/null
mv mpong*.mpy "$mydir"/../../internal_filesystem/apps/com.micropythonos.mpong/assets/
mv breakout*.mpy "$mydir"/../../internal_filesystem/apps/com.micropythonos.breakout/assets/
@@ -1,11 +1,11 @@
{
"name": "Breakout",
"publisher": "MicroPythonOS",
"short_description": "PingPong game",
"long_description": "Demonstrates native machinecode in .mpy files on both AMD64 and ESP32",
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.mpong/icons/com.micropythonos.mpong_0.1.0_64x64.png",
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.mpong/mpks/com.micropythonos.mpong_0.1.0.mpk",
"fullname": "com.micropythonos.mpong",
"short_description": "Classic Breakout game",
"long_description": "Classic Breakout game to demonstrate native machinecode (from C) in .mpy files on both AMD64 and ESP32",
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.breakout/icons/com.micropythonos.breakout_0.1.0_64x64.png",
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.breakout/mpks/com.micropythonos.breakout_0.1.0.mpk",
"fullname": "com.micropythonos.breakout",
"version": "0.1.0",
"category": "games",
"activities": [
@@ -1,3 +1,4 @@
# On the 320x170 T-Display-S3:
# This gets just 7.5 FPS on actual ESP32S3 hardware
# Probably because the double buffer copies.
# With a direct buffer, it's still only 10 FPS. (and flickering buttons on black screen)
@@ -6,7 +7,10 @@
# adding a wait for the render of 10ms gives a non-flicker 17.5 FPS
# not waiting for the render but adding a callback brings the FPS to 25.5 !
# on the emulator, it gets around 8 FPS (LVGL) and 3.5 FPS (mpong)
# on the emulator, it gets around 8 FPS (LVGL) and 3.5 FPS (breakout.c)
# at 33ms, it's 4.5 and 2.5 FPS (mpong)
# On the 320x230 (instead of 240 because memory limitation) it gets 17 FPS (LVGL) or 12 FPS (breakout.c)
import lvgl as lv
@@ -17,9 +21,9 @@ from mpos import Activity, DisplayMetrics, InputManager
import sys
if sys.platform == "esp32":
import mpong_xtensawin as mpong
import breakout_xtensawin as breakout
else:
import mpong_x64 as mpong
import breakout_x64 as breakout
class Breakout(Activity):
@@ -101,7 +105,7 @@ class Breakout(Activity):
#mpos.ui.main_display.delete_refr_timer() # how to enable after? also it doesnt help
#lv.timer_create(self.startit, 1000, None).set_repeat_count(1)
# 10ms is fine on real hardware
# 10ms is fine on real hardware but needs > 1000ms on emulator
lv.timer_create(self.startit, 5000, None).set_repeat_count(1) # this needs to be delayed, otherwise the whole thing hangs
#lv.async_call(self.startit, None)
@@ -113,9 +117,9 @@ class Breakout(Activity):
def startit(self, arg1=None):
print("starting it!")
mpong.init(mpos.ui.main_display._frame_buffer1, self.hor_res, self.ver_res) # stays black
breakout.init(mpos.ui.main_display._frame_buffer1, self.hor_res, min(self.ver_res, 230))
mpos.ui.main_display._data_bus.register_callback(self.flush_ready_cb)
self.refresh_timer = lv.timer_create(self.run_mpong, 20, None) # max 1000ms/50fps = 20ms/frame
self.refresh_timer = lv.timer_create(self.drawframe, 20, None) # max 1000ms/50fps = 20ms/frame
#self.refresh_timer = lv.timer_create(self.run_mpong, 33, None).set_repeat_count(1) # max 1000ms/60fps = 16ms/frame
#lv.async_call(self.run_mpong, None)
@@ -128,18 +132,18 @@ class Breakout(Activity):
self.render_next = True
def move_left(self):
mpong.move_paddle(-self.paddle_move_step)
breakout.move_paddle(-self.paddle_move_step)
def move_right(self):
mpong.move_paddle(self.paddle_move_step)
breakout.move_paddle(self.paddle_move_step)
def move_left_unfocus(self):
self.unfocus()
mpong.move_paddle(-self.paddle_move_step)
breakout.move_paddle(-self.paddle_move_step)
def move_right_unfocus(self):
self.unfocus()
mpong.move_paddle(self.paddle_move_step)
breakout.move_paddle(self.paddle_move_step)
# This only works with the PREV/pageup and NEXT/pagedown buttons,
# because the focus_direction handling of the arrow keys uses a trick to move focus (focus_next)
@@ -186,11 +190,11 @@ class Breakout(Activity):
True,
)
def run_mpong(self, arg1=None, arg2=None):
def drawframe(self, arg1=None, arg2=None):
if self.render_next == False:
return
self.render_next = False
mpong.render()
breakout.render()
#self.play_button.set_style_opa(lv.OPA.TRANSP, lv.PART.MAIN) # works to force refresh on desktop but not esp32
#self.screen.invalidate()
#lv.refr_now(None)
@@ -231,7 +235,7 @@ class Breakout(Activity):
if self.touch_last_x is not None:
delta = x - self.touch_last_x
if delta:
mpong.move_paddle(delta)
breakout.move_paddle(delta)
self.touch_last_x = x
return