重构平台条件编译,剥离 LightGame 调试内容到 Debug 配置
- 把 USE_FRAMEBUFFER 替换为 TARGET_IMX / TARGET_PC 双正向互斥宏,由 CMake 选项 TARGET_IMX 推导,代码层只用 #ifdef 正向判断 - 新增 IMX6U_DEBUG 宏,通过 $<$<CONFIG:Debug>:...> 只在 Debug 构建中注入 - LightGame 关卡编辑器(LevelEditor + ImGui)改为仅 PC + Debug 编入,Release 不参与编译 - LightGame draw_debug、debug_mode_、--debug 命令行、[INFO] 启动日志全部用 IMX6U_DEBUG 门控,Release 二进制中完全消失 - [WARN] 硬件初始化失败提示保留在 Release,作为现场诊断信息 - README、APP_AND_CORE_ARCHITECTURE、Game README 同步新宏命名,并新增「构建类型与调试开关」小节
This commit is contained in:
@@ -15,9 +15,10 @@
|
||||
#include "font_atlas.h"
|
||||
#include "test_sprite.h"
|
||||
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
#include "FBDisplay.h"
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
#include "SDLDisplay.h"
|
||||
#endif
|
||||
|
||||
@@ -47,9 +48,10 @@ namespace
|
||||
|
||||
static Platform::IDisplay* CreateDisplay()
|
||||
{
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
return new Platform::FBDisplay();
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
return new Platform::SDLDisplay();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ set(TOM_ATLAS_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/generated/tom_atlas.h")
|
||||
set_source_files_properties(${TOM_ATLAS_HEADER} PROPERTIES GENERATED TRUE)
|
||||
|
||||
set(TOM_GAME_ENABLE_TFLITE_C_API_DEFAULT OFF)
|
||||
if(CMAKE_CROSSCOMPILING AND USE_FRAMEBUFFER)
|
||||
if(CMAKE_CROSSCOMPILING AND TARGET_IMX)
|
||||
set(TOM_GAME_ENABLE_TFLITE_C_API_DEFAULT ON)
|
||||
endif()
|
||||
|
||||
@@ -109,7 +109,7 @@ if(CMAKE_CROSSCOMPILING AND NOT EXISTS "${TOM_ATLAS_HEADER}")
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT USE_FRAMEBUFFER)
|
||||
if(NOT TARGET_IMX)
|
||||
set(TOM_ATLAS_TOOL_SOURCES
|
||||
tools/asset_pipeline/SpriteAssetTool.cpp
|
||||
)
|
||||
|
||||
@@ -20,9 +20,10 @@
|
||||
#include "recognition/TinyKwsRecognizer.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
#include "FBDisplay.h"
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
#include "SDLDisplay.h"
|
||||
#endif
|
||||
|
||||
@@ -49,9 +50,10 @@ namespace
|
||||
|
||||
static Platform::IDisplay* CreateDisplay()
|
||||
{
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
return new Platform::FBDisplay();
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
return new Platform::SDLDisplay();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
- Windows C++ 构建默认不启用 TFLite C API,避免在 Windows 上编译/链接
|
||||
TensorFlow C++。
|
||||
- ARM framebuffer 交叉编译时默认启用 TFLite C API:
|
||||
`CMAKE_CROSSCOMPILING && USE_FRAMEBUFFER` 时
|
||||
`CMAKE_CROSSCOMPILING && TARGET_IMX` 时
|
||||
`TOM_GAME_ENABLE_TFLITE_C_API=ON`。
|
||||
- 仓库里的 `runtime/lib/tensorflow/lite/c/libtensorflowlite_c.so` 是 ELF32 ARM
|
||||
hard-float 动态库,方向上匹配 IMX6ULL 常见的 `arm-linux-gnueabihf`
|
||||
@@ -98,7 +98,7 @@ python src\Apps\Game\tools\kws_python_test.py --wav tmp\kws_test.wav
|
||||
```bash
|
||||
cmake -B build-arm-fb \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm-linux-gnueabihf.cmake \
|
||||
-DUSE_FRAMEBUFFER=ON \
|
||||
-DTARGET_IMX=ON \
|
||||
-DTOM_GAME_ENABLE_TFLITE_C_API=ON \
|
||||
-DTOM_GAME_TFLITE_INCLUDE_DIR=/path/to/tensorflow-source-root \
|
||||
-DTOM_GAME_TFLITE_LIBRARY=$PWD/src/Apps/Game/runtime/lib/tensorflow/lite/c/libtensorflowlite_c.so \
|
||||
@@ -112,7 +112,7 @@ cmake --build build-arm-fb --target IMX6U-Game
|
||||
```bash
|
||||
cmake -B build-arm-fb-no-kws \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm-linux-gnueabihf.cmake \
|
||||
-DUSE_FRAMEBUFFER=ON \
|
||||
-DTARGET_IMX=ON \
|
||||
-DTOM_GAME_ENABLE_TFLITE_C_API=OFF \
|
||||
.
|
||||
|
||||
|
||||
@@ -12,13 +12,18 @@ set(LIGHTGAME_SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
if(NOT USE_FRAMEBUFFER)
|
||||
list(APPEND LIGHTGAME_SOURCES src/editor/LevelEditor.cpp)
|
||||
endif()
|
||||
|
||||
add_executable(IMX6U-LightGame ${LIGHTGAME_SOURCES})
|
||||
target_include_directories(IMX6U-LightGame PRIVATE src/engine src/systems src/levels generated)
|
||||
if(NOT USE_FRAMEBUFFER)
|
||||
target_include_directories(IMX6U-LightGame PRIVATE src/editor)
|
||||
endif()
|
||||
|
||||
# 关卡编辑器仅在 PC + Debug 构建中编入:
|
||||
# - TARGET_IMX=OFF (即 TARGET_PC) 才有 SDL/ImGui 这套依赖
|
||||
# - $<CONFIG:Debug> 让单/多配置生成器都能正确选择
|
||||
set(LIGHTGAME_EDITOR_GUARD "$<AND:$<NOT:$<BOOL:${TARGET_IMX}>>,$<CONFIG:Debug>>")
|
||||
target_sources(IMX6U-LightGame PRIVATE
|
||||
"$<${LIGHTGAME_EDITOR_GUARD}:${CMAKE_CURRENT_SOURCE_DIR}/src/editor/LevelEditor.cpp>"
|
||||
)
|
||||
target_include_directories(IMX6U-LightGame PRIVATE
|
||||
"$<${LIGHTGAME_EDITOR_GUARD}:${CMAKE_CURRENT_SOURCE_DIR}/src/editor>"
|
||||
)
|
||||
|
||||
imx6u_configure_app_target(IMX6U-LightGame)
|
||||
|
||||
@@ -90,6 +90,7 @@ namespace LightGame
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef IMX6U_DEBUG
|
||||
void LevelRenderer::draw_debug(Core::DrawContext& ctx, const Level& level,
|
||||
const Camera2D& camera, const RenderData::BitmapFont& font)
|
||||
{
|
||||
@@ -119,4 +120,5 @@ namespace LightGame
|
||||
ctx.draw_line(Math::Vector2Int(sx, sy + h), Math::Vector2Int(sx, sy), color);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ namespace LightGame
|
||||
const LightEffectSystem& light_system, uint16_t light_level,
|
||||
bool draw_background = true);
|
||||
|
||||
#ifdef IMX6U_DEBUG
|
||||
void draw_debug(Core::DrawContext& ctx, const Level& level, const Camera2D& camera,
|
||||
const RenderData::BitmapFont& font);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,7 +43,9 @@ namespace LightGame
|
||||
light_step_(256),
|
||||
smoothed_light_q8_(2048 << 8),
|
||||
has_manual_override_(false),
|
||||
#ifdef IMX6U_DEBUG
|
||||
debug_mode_(false),
|
||||
#endif
|
||||
death_processed_(false)
|
||||
{
|
||||
camera_.configure(screen_width, screen_height - LevelRenderer::kTopBlackBorder);
|
||||
@@ -136,14 +138,17 @@ namespace LightGame
|
||||
const uint16_t light = manual_light_level_;
|
||||
renderer_.draw(ctx, level_, camera_, light_system_, light);
|
||||
|
||||
#ifdef IMX6U_DEBUG
|
||||
if (debug_mode_)
|
||||
{
|
||||
renderer_.draw_debug(ctx, level_, camera_, font);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
state_manager_.draw(ctx, font, screen_width_, screen_height_);
|
||||
|
||||
#ifdef IMX6U_DEBUG
|
||||
if (debug_mode_ && state_manager_.get_state() == GameState::Playing)
|
||||
{
|
||||
const uint16_t light = manual_light_level_;
|
||||
@@ -152,6 +157,7 @@ namespace LightGame
|
||||
ctx.draw_text(font, screen_width_ - 64, screen_height_ - 16,
|
||||
RenderData::Color(128, 128, 128, 255), buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool LightGameApp::is_action_pressed()
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace LightGame
|
||||
Platform::IKeyboardState* keyboard_input_;
|
||||
Platform::IPointerInput* pointer_input_;
|
||||
Platform::IPhotoSensor* photo_sensor_;
|
||||
// TODO: consolidate input interfaces into IInputState when a 4th modality arrives
|
||||
|
||||
Level level_;
|
||||
Camera2D camera_;
|
||||
@@ -65,7 +64,9 @@ namespace LightGame
|
||||
int32_t smoothed_light_q8_;
|
||||
|
||||
bool has_manual_override_;
|
||||
#ifdef IMX6U_DEBUG
|
||||
bool debug_mode_;
|
||||
#endif
|
||||
bool death_processed_;
|
||||
|
||||
public:
|
||||
@@ -81,7 +82,9 @@ namespace LightGame
|
||||
void draw(Core::DrawContext& ctx, const RenderData::BitmapFont& font);
|
||||
|
||||
GameState get_state() const { return state_manager_.get_state(); }
|
||||
#ifdef IMX6U_DEBUG
|
||||
void set_debug_mode(bool enabled) { debug_mode_ = enabled; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
void load_room(int32_t room_index);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#ifdef IMX6U_DEBUG
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#include "DefaultHardware.h"
|
||||
#include "Display.h"
|
||||
@@ -15,10 +17,13 @@
|
||||
#include "font_atlas.h"
|
||||
#include "LevelTotalData.h"
|
||||
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
#include "FBDisplay.h"
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
#include "SDLDisplay.h"
|
||||
#endif
|
||||
#ifdef IMX6U_DEBUG
|
||||
#include "LevelEditor.h"
|
||||
#include "imgui.h"
|
||||
#include "backends/imgui_impl_sdl2.h"
|
||||
@@ -32,9 +37,10 @@ namespace
|
||||
|
||||
static Platform::IDisplay* CreateDisplay()
|
||||
{
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
return new Platform::FBDisplay();
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
return new Platform::SDLDisplay();
|
||||
#endif
|
||||
}
|
||||
@@ -97,10 +103,12 @@ int main(int argc, char* argv[])
|
||||
&pointerInput,
|
||||
&photoSensor);
|
||||
|
||||
#ifndef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_PC
|
||||
Platform::SDLDisplay* sdl_display = static_cast<Platform::SDLDisplay*>(display);
|
||||
#endif
|
||||
#ifdef IMX6U_DEBUG
|
||||
LightGame::LevelEditor editor(ScreenWidth, ScreenHeight);
|
||||
|
||||
Platform::SDLDisplay* sdl_display = static_cast<Platform::SDLDisplay*>(display);
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGui::StyleColorsDark();
|
||||
@@ -108,6 +116,7 @@ int main(int argc, char* argv[])
|
||||
ImGui_ImplSDLRenderer2_Init(sdl_display->get_renderer());
|
||||
#endif
|
||||
|
||||
#ifdef IMX6U_DEBUG
|
||||
bool debug_mode = false;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
@@ -119,6 +128,10 @@ int main(int argc, char* argv[])
|
||||
app.set_debug_mode(debug_mode);
|
||||
|
||||
std::cout << "[INFO] LightGame started. Target FPS: " << timer.target_fps() << std::endl;
|
||||
#else
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
#endif
|
||||
|
||||
bool is_running = true;
|
||||
while (is_running)
|
||||
@@ -127,13 +140,16 @@ int main(int argc, char* argv[])
|
||||
|
||||
bool should_quit = false;
|
||||
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
display->poll_events(should_quit);
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
#ifdef IMX6U_DEBUG
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
#endif
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
should_quit = true;
|
||||
@@ -142,10 +158,12 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
should_quit = true;
|
||||
}
|
||||
#ifdef IMX6U_DEBUG
|
||||
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F1)
|
||||
{
|
||||
editor.set_active(!editor.is_active());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
if (should_quit)
|
||||
@@ -156,7 +174,7 @@ int main(int argc, char* argv[])
|
||||
buttonInput.update();
|
||||
pointerInput.update();
|
||||
|
||||
#ifndef USE_FRAMEBUFFER
|
||||
#ifdef IMX6U_DEBUG
|
||||
if (editor.is_active())
|
||||
{
|
||||
if (editor.get_pending_load() >= 0)
|
||||
@@ -169,23 +187,22 @@ int main(int argc, char* argv[])
|
||||
editor.draw(ctx, font);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
app.update(timer.fixed_delta_ms());
|
||||
app.draw(ctx, font);
|
||||
}
|
||||
#else
|
||||
app.update(timer.fixed_delta_ms());
|
||||
app.draw(ctx, font);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
ctx.present(display);
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
const Core::FrameBuffer* fb = ctx.get_frame_buffer();
|
||||
SDL_UpdateTexture(sdl_display->get_texture(), nullptr, fb->get_buffer(), ScreenWidth * 2);
|
||||
SDL_RenderClear(sdl_display->get_renderer());
|
||||
SDL_RenderCopy(sdl_display->get_renderer(), sdl_display->get_texture(), nullptr, nullptr);
|
||||
|
||||
#ifdef IMX6U_DEBUG
|
||||
ImGui_ImplSDLRenderer2_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
@@ -195,6 +212,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
ImGui::Render();
|
||||
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), sdl_display->get_renderer());
|
||||
#endif
|
||||
SDL_RenderPresent(sdl_display->get_renderer());
|
||||
#endif
|
||||
SleepRemainingFrameTime(timer, time_source);
|
||||
@@ -204,7 +222,7 @@ int main(int argc, char* argv[])
|
||||
pointerInput.shutdown();
|
||||
buttonInput.shutdown();
|
||||
|
||||
#ifndef USE_FRAMEBUFFER
|
||||
#ifdef IMX6U_DEBUG
|
||||
ImGui_ImplSDLRenderer2_Shutdown();
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
#include "AlsaAudioInput.h"
|
||||
#include "AlsaAudioOutput.h"
|
||||
#include "EvdevButtonInput.h"
|
||||
#include "EvdevKeyboardState.h"
|
||||
#include "EvdevTouchInput.h"
|
||||
#include "Ap3216cPhotoSensor.h"
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
#include "SdlAudioInput.h"
|
||||
#include "SdlAudioOutput.h"
|
||||
#include "SdlKeyboardButtonInput.h"
|
||||
@@ -18,14 +19,15 @@
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
#ifdef USE_FRAMEBUFFER
|
||||
#ifdef TARGET_IMX
|
||||
typedef AlsaAudioInput DefaultAudioInput;
|
||||
typedef AlsaAudioOutput DefaultAudioOutput;
|
||||
typedef EvdevButtonInput DefaultButtonInput;
|
||||
typedef EvdevKeyboardState DefaultKeyboardState;
|
||||
typedef EvdevTouchInput DefaultPointerInput;
|
||||
typedef Ap3216cPhotoSensor DefaultPhotoSensor;
|
||||
#else
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
typedef SdlAudioInput DefaultAudioInput;
|
||||
typedef SdlAudioOutput DefaultAudioOutput;
|
||||
typedef SdlKeyboardButtonInput DefaultButtonInput;
|
||||
|
||||
Reference in New Issue
Block a user