添加LightGame报告,规范接口命名

This commit is contained in:
2026-07-04 19:07:53 +08:00
parent 10872fde82
commit 36cbaf18c4
24 changed files with 619 additions and 163 deletions
+12 -12
View File
@@ -7,7 +7,7 @@
#include <thread>
#include "DefaultHardware.h"
#include "Display.h"
#include "IDisplay.h"
#include "DrawContext.h"
#include "TimeSource.h"
#include "Timer.h"
@@ -48,7 +48,7 @@ namespace
}
};
static Platform::IDisplay* CreateDisplay()
static Platform::IDisplay *CreateDisplay()
{
#ifdef TARGET_IMX
return new Platform::FBDisplay();
@@ -58,23 +58,23 @@ namespace
#endif
}
static void PrintUsage(const char* program_name)
static void PrintUsage(const char *program_name)
{
std::cout
<< "Usage: " << program_name << " [--fps 30|45|60] [--kws-model path] [--kws-threshold 0.75]\n"
<< " " << program_name << " [--fps=30|45|60] [--kws-model=path] [--kws-threshold=0.75]\n";
}
static ProgramOptions ParseProgramOptions(int argc, char* argv[])
static ProgramOptions ParseProgramOptions(int argc, char *argv[])
{
ProgramOptions options;
for (int i = 1; i < argc; ++i)
{
const char* arg = argv[i];
const char* fps_value = nullptr;
const char* kws_model_value = nullptr;
const char* kws_threshold_value = nullptr;
const char *arg = argv[i];
const char *fps_value = nullptr;
const char *kws_model_value = nullptr;
const char *kws_threshold_value = nullptr;
if (std::strcmp(arg, "--help") == 0 || std::strcmp(arg, "-h") == 0)
{
@@ -148,7 +148,7 @@ namespace
if (kws_threshold_value != nullptr)
{
char* threshold_end = nullptr;
char *threshold_end = nullptr;
const float parsed_threshold = std::strtof(kws_threshold_value, &threshold_end);
if (threshold_end != kws_threshold_value && *threshold_end == '\0' && parsed_threshold >= 0.0f)
{
@@ -165,7 +165,7 @@ namespace
return options;
}
static void SleepRemainingFrameTime(const Core::Timer& timer, const Platform::ITimeSource& time_source)
static void SleepRemainingFrameTime(const Core::Timer &timer, const Platform::ITimeSource &time_source)
{
const uint32_t sleep_ms = timer.remaining_frame_ms(time_source.get_time_ms());
if (sleep_ms > 0u)
@@ -175,7 +175,7 @@ namespace
}
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
const ProgramOptions options = ParseProgramOptions(argc, argv);
if (options.show_help)
@@ -184,7 +184,7 @@ int main(int argc, char* argv[])
return 0;
}
Platform::IDisplay* display = CreateDisplay();
Platform::IDisplay *display = CreateDisplay();
if (!display->init(ScreenWidth, ScreenHeight))
{
delete display;
+23 -25
View File
@@ -1,8 +1,8 @@
#include "TomGameApp.h"
#include "../audio/VoiceEffect.h"
#include "AudioInput.h"
#include "AudioOutput.h"
#include "ButtonInput.h"
#include "IAudioInput.h"
#include "IAudioOutput.h"
#include "IButtonInput.h"
#include "Color.h"
#include "DrawContext.h"
#include "PointerInput.h"
@@ -20,32 +20,30 @@ namespace
const int32_t TomBottomPadding = 72;
const int32_t ButtonBottomPadding = 16;
const RenderData::Sprite* const SpeakingFrames[] = {
const RenderData::Sprite *const SpeakingFrames[] = {
&TomAtlas::tom_say1,
&TomAtlas::tom_say2,
&TomAtlas::tom_say3,
&TomAtlas::tom_say4,
&TomAtlas::tom_say3,
&TomAtlas::tom_say2
};
&TomAtlas::tom_say2};
const RenderData::Sprite* const JumpingFrames[] = {
const RenderData::Sprite *const JumpingFrames[] = {
&TomAtlas::tom_jump1,
&TomAtlas::tom_jump2,
&TomAtlas::tom_jump3,
&TomAtlas::tom_jump4,
&TomAtlas::tom_jump5,
&TomAtlas::tom_jump6
};
&TomAtlas::tom_jump6};
static const RenderData::Sprite& SelectSpeakingFrame(uint32_t animationMs)
static const RenderData::Sprite &SelectSpeakingFrame(uint32_t animationMs)
{
const size_t frameCount = sizeof(SpeakingFrames) / sizeof(SpeakingFrames[0]);
const size_t frameIndex = (animationMs / SpeakingFrameMs) % frameCount;
return *SpeakingFrames[frameIndex];
}
static const RenderData::Sprite& SelectJumpingFrame(uint32_t animationMs)
static const RenderData::Sprite &SelectJumpingFrame(uint32_t animationMs)
{
const size_t frameCount = sizeof(JumpingFrames) / sizeof(JumpingFrames[0]);
size_t frameIndex = animationMs / JumpingFrameMs;
@@ -68,11 +66,11 @@ namespace Game
TomGameApp::TomGameApp(
int32_t screenWidth,
int32_t screenHeight,
Platform::IAudioInput* audioInput,
Platform::IAudioOutput* audioOutput,
Platform::IButtonInput* buttonInput,
Platform::IPointerInput* pointerInput,
IKeywordRecognizer* keywordRecognizer)
Platform::IAudioInput *audioInput,
Platform::IAudioOutput *audioOutput,
Platform::IButtonInput *buttonInput,
Platform::IPointerInput *pointerInput,
IKeywordRecognizer *keywordRecognizer)
: audioInput(audioInput),
audioOutput(audioOutput),
buttonInput(buttonInput),
@@ -154,12 +152,12 @@ namespace Game
}
}
void TomGameApp::draw(Core::DrawContext& ctx)
void TomGameApp::draw(Core::DrawContext &ctx)
{
ctx.clear_color(RenderData::Color(18, 18, 24, 255));
ctx.draw_sprite(0, 0, TomAtlas::background);
const RenderData::Sprite* tom = &TomAtlas::tom_stand;
const RenderData::Sprite *tom = &TomAtlas::tom_stand;
if (state == TomGameState::Recording)
{
tom = &TomAtlas::tom_listhen;
@@ -184,7 +182,7 @@ namespace Game
ctx.draw_sprite(buttonX, buttonY, TomAtlas::ui_record);
}
void TomGameApp::update_input(bool& recordTrigger)
void TomGameApp::update_input(bool &recordTrigger)
{
recordTrigger = false;
@@ -290,7 +288,7 @@ namespace Game
start_speaking(samples);
}
bool TomGameApp::try_handle_keyword(const std::vector<int16_t>& samples)
bool TomGameApp::try_handle_keyword(const std::vector<int16_t> &samples)
{
if (keywordRecognizer == nullptr || !keywordRecognizerReady || samples.empty())
{
@@ -316,7 +314,7 @@ namespace Game
return handle_keyword_result(result);
}
bool TomGameApp::handle_keyword_result(const KeywordRecognitionResult& result)
bool TomGameApp::handle_keyword_result(const KeywordRecognitionResult &result)
{
switch (result.command)
{
@@ -369,7 +367,7 @@ namespace Game
state = TomGameState::Jumping;
}
void TomGameApp::start_speaking(const std::vector<int16_t>& samples)
void TomGameApp::start_speaking(const std::vector<int16_t> &samples)
{
if (samples.empty() || audioOutput == nullptr)
{
@@ -460,8 +458,8 @@ namespace Game
bool TomGameApp::is_record_button_hit(int32_t x, int32_t y) const
{
return x >= buttonX &&
x < buttonX + TomAtlas::ui_record.width &&
y >= buttonY &&
y < buttonY + TomAtlas::ui_record.height;
x < buttonX + TomAtlas::ui_record.width &&
y >= buttonY &&
y < buttonY + TomAtlas::ui_record.height;
}
}
+4 -4
View File
@@ -2,7 +2,7 @@
#include <cstddef>
#include <cstdint>
#include <vector>
#include "AudioOutput.h"
#include "IAudioOutput.h"
namespace Game
{
@@ -21,14 +21,14 @@ namespace Game
public:
VoicePlayer();
void set_voice(const std::vector<int16_t>& samples, uint32_t sampleRate = 16000, uint32_t channels = 1);
void set_voice(const std::vector<int16_t> &samples, uint32_t sampleRate = 16000, uint32_t channels = 1);
void play();
void stop();
void reset();
void clear();
int update(Platform::IAudioOutput& audioOutput, int maxSamplesPerUpdate = 1024);
int update(Platform::IAudioOutput &audioOutput, int maxSamplesPerUpdate = 1024);
const std::vector<int16_t>& get_samples() const { return samples; }
const std::vector<int16_t> &get_samples() const { return samples; }
size_t get_sample_count() const { return samples.size(); }
size_t get_play_position() const { return playPosition; }
size_t get_remaining_samples() const;
+4 -4
View File
@@ -2,7 +2,7 @@
#include <cstddef>
#include <cstdint>
#include <vector>
#include "AudioInput.h"
#include "IAudioInput.h"
namespace Game
{
@@ -25,7 +25,7 @@ namespace Game
size_t get_max_sample_count() const;
size_t get_silence_sample_limit() const;
size_t get_min_sample_count() const;
float calculate_volume(const int16_t* buffer, int sampleCount) const;
float calculate_volume(const int16_t *buffer, int sampleCount) const;
public:
VoiceRecorder();
@@ -41,9 +41,9 @@ namespace Game
void start();
void stop();
void clear();
int update(Platform::IAudioInput& audioInput, int sampleCount = 512);
int update(Platform::IAudioInput &audioInput, int sampleCount = 512);
const std::vector<int16_t>& get_samples() const { return samples; }
const std::vector<int16_t> &get_samples() const { return samples; }
size_t get_sample_count() const { return samples.size(); }
uint32_t get_sample_rate() const { return sampleRate; }
uint32_t get_channels() const { return channels; }