diff --git a/Apps/LuaGame/main/Source/main.c b/Apps/LuaGame/main/Source/main.c index 3b9f22a..90e784c 100644 --- a/Apps/LuaGame/main/Source/main.c +++ b/Apps/LuaGame/main/Source/main.c @@ -247,7 +247,9 @@ static int l_renderer_clear(lua_State* L){ bool white = false; if(lua_gettop(L)>=1) white = lua_toboolean(L,1); uint16_t col = white ? 0xFFFF : 0x0000; - fill_rect(ctx,0,0,GAME_W,GAME_H,col,true); + int w = ctx->game_w ? ctx->game_w : GAME_W_DEFAULT; + int h = ctx->game_h ? ctx->game_h : GAME_H_DEFAULT; + fill_rect(ctx,0,0,w,h,col,true); clear_labels(ctx); return 0; } @@ -604,7 +606,7 @@ static void lua_init_task(void* arg){ lua_pop(ctx->L,1); } } else lua_pop(ctx->L,1); - if(tt_lvgl_lock(portMAX_DELAY)){ + if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){ invalidate_canvas(ctx); tt_lvgl_unlock(); } @@ -690,23 +692,25 @@ static void lua_init_task(void* arg){ if(lua_isfunction(L,-1)){ if(lua_pcall(L,0,0,0)!=LUA_OK){const char* e=lua_tostring(L,-1); printf("[LUA ERR draw] %s\n",e); lua_pop(L,1); ctx->lua_ok=false;} }else lua_pop(L,1); - if(tt_lvgl_lock(portMAX_DELAY)){ - invalidate_canvas(ctx); - ctx->fps_frames++; - uint64_t elapsed = now - ctx->fps_last_us; - if(elapsed >= 1000000){ - ctx->fps = (float)ctx->fps_frames * 1000000.0f / (float)elapsed; - printf("[LuaGame] FPS %.1f (on-demand)\n", ctx->fps); - if(ctx->fps_label){ - char buf[32]; - snprintf(buf,sizeof(buf),"FPS %.0f",ctx->fps); - lv_label_set_text(ctx->fps_label, buf); - } - ctx->fps_frames=0; - ctx->fps_last_us=now; + if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){ + invalidate_canvas(ctx); + ctx->fps_frames++; + uint64_t elapsed = now - ctx->fps_last_us; + if(elapsed >= 1000000){ + ctx->fps = (float)ctx->fps_frames * 1000000.0f / (float)elapsed; + printf("[LuaGame] FPS %.1f (on-demand)\n", ctx->fps); + if(ctx->fps_label){ + char buf[32]; + snprintf(buf,sizeof(buf),"FPS %.0f",ctx->fps); + lv_label_set_text(ctx->fps_label, buf); } - tt_lvgl_unlock(); + ctx->fps_frames=0; + ctx->fps_last_us=now; } + tt_lvgl_unlock(); + } else { + printf("[LuaGame] lvgl lock timeout\n"); + } } } // For on-demand games, sleep longer to save CPU @@ -739,7 +743,7 @@ static void game_loop_task(void* arg){ if(lua_pcall(L,0,0,0)!=LUA_OK){const char* e=lua_tostring(L,-1); printf("[LUA ERR draw] %s\n",e); lua_pop(L,1); ctx->lua_ok=false;} }else lua_pop(L,1); // Invalidate canvas with LVGL lock - if(tt_lvgl_lock(portMAX_DELAY)){ + if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){ invalidate_canvas(ctx); // fps tracking inside lock for label update ctx->fps_frames++; @@ -872,9 +876,10 @@ static void app_on_show(AppHandle app,void* data,lv_obj_t* parent){ lv_obj_add_event_cb(cont,touch_event_cb,LV_EVENT_RELEASED,ctx); lv_obj_add_event_cb(cont,touch_event_cb,LV_EVENT_PRESS_LOST,ctx); printf("[LuaGame] spawning init task\n"); - xTaskCreate(lua_init_task,"lua_init",16384,ctx,5,&ctx->lua_task); - fill_rect(ctx,0,0,GAME_W,GAME_H,hex_to_rgb565(0x1e1e2e),true); - if(tt_lvgl_lock(portMAX_DELAY)){ + BaseType_t ret = xTaskCreate(lua_init_task,"lua_init",8192,ctx,5,&ctx->lua_task); + printf("[LuaGame] init task create ret=%d\n", ret); + fill_rect(ctx,0,0,ctx->fb_w,ctx->fb_h,hex_to_rgb565(0x1e1e2e),true); + if(tt_lvgl_lock(pdMS_TO_TICKS(1000))){ invalidate_canvas(ctx); tt_lvgl_unlock(); }