refactor: more maintainability

This commit is contained in:
2025-11-23 15:55:43 +01:00
parent 1f5f502905
commit 06544ee23e
3 changed files with 60 additions and 43 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[![GitHub Release](https://img.shields.io/github/v/release/klemek/forge-steel?style=flat-square)](https://github.com/klemek/forge-steel/releases) [![GitHub Release Date](https://img.shields.io/github/release-date/klemek/forge-steel?style=flat-square)](https://github.com/klemek/forge-steel/releases) [![GitHub last commit](https://img.shields.io/github/last-commit/klemek/forge?style=flat-square)](https://github.com/klemek/forge-steel/commits/master/) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/klemek/forge-steel/ci.yml?style=flat-square)](https://github.com/klemek/forge-steel/actions/workflows/ci.yml) [![Sonar Quality Gate](https://img.shields.io/sonar/quality_gate/klemek_forge-steel?server=https%3A%2F%2Fsonarcloud.io&style=flat-square)](https://sonarcloud.io/summary/new_code?id=klemek_forge-steel) ![LOC](https://img.shields.io/badge/LOC-~3500-blue?style=flat-square)
[![GitHub Release](https://img.shields.io/github/v/release/klemek/forge-steel?style=flat-square)](https://github.com/klemek/forge-steel/releases) [![GitHub Release Date](https://img.shields.io/github/release-date/klemek/forge-steel?style=flat-square)](https://github.com/klemek/forge-steel/releases) [![GitHub last commit](https://img.shields.io/github/last-commit/klemek/forge?style=flat-square)](https://github.com/klemek/forge-steel/commits/master/) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/klemek/forge-steel/ci.yml?style=flat-square)](https://github.com/klemek/forge-steel/actions/workflows/ci.yml) [![Sonar Quality Gate](https://img.shields.io/sonar/quality_gate/klemek_forge-steel?server=https%3A%2F%2Fsonarcloud.io&style=flat-square)](https://sonarcloud.io/summary/new_code?id=klemek_forge-steel) ![LOC](https://img.shields.io/badge/LOC-3.8k-blue?style=flat-square)
<!-- omit from toc -->
# F.O.R.G.E. (Steel)
+57 -41
View File
@@ -58,6 +58,10 @@ static void compute_fps(bool trace_fps) {
}
static void init_context(const Parameters *params) {
context = shared_init_context("/" PACKAGE "_context");
context->stop = false;
state_init(context, &project.state_config, params->demo, params->auto_random,
params->auto_random_cycle, params->base_tempo, params->load_state);
@@ -134,44 +138,11 @@ static void midi_callback(unsigned char code, unsigned char value) {
trace_midi);
}
static void loop(bool hr, bool trace_fps) {
if (hr) {
project_reload(&project, reload_shader);
}
compute_fps(trace_fps);
context->time = window_get_time();
context->tempo_total = (float)tempo_total(&context->tempo);
if (window_output != NULL) {
window_use(window_output, context);
shaders_compute(&program, context, false, false);
window_refresh(window_output);
}
if (window_monitor != NULL) {
window_use(window_monitor, context);
shaders_compute(&program, context, true, window_output != NULL);
window_refresh(window_monitor);
}
window_events();
}
void forge_run(const Parameters *params) {
context = shared_init_context("/" PACKAGE "_context");
context->stop = false;
static bool init(const Parameters *params) {
project_init(&project, params->project_path, params->config_file);
if (project.error) {
return;
return false;
}
init_context(params);
@@ -180,7 +151,7 @@ void forge_run(const Parameters *params) {
init_inputs(&params->video_in, params->video_size);
if (!start_video_captures(params->video_in.length, params->trace_fps)) {
return;
return false;
}
#endif /* VIDEO_IN */
@@ -192,12 +163,12 @@ void forge_run(const Parameters *params) {
trace_midi = params->trace_midi;
if (!midi_background_listen(&midi, context, midi_callback)) {
return;
return false;
}
}
if (!state_background_write(context, &project.state_config, &midi)) {
return;
return false;
}
window_startup(error_callback);
@@ -241,11 +212,44 @@ void forge_run(const Parameters *params) {
log_info("Initialized");
while ((window_output == NULL || !window_should_close(window_output)) &&
(window_monitor == NULL || !window_should_close(window_monitor))) {
loop(params->hot_reload, params->trace_fps);
return true;
}
static bool should_close() {
return (window_output != NULL && window_should_close(window_output)) ||
(window_monitor != NULL && window_should_close(window_monitor));
}
static void loop(bool hr, bool trace_fps) {
if (hr) {
project_reload(&project, reload_shader);
}
compute_fps(trace_fps);
context->time = window_get_time();
context->tempo_total = (float)tempo_total(&context->tempo);
if (window_output != NULL) {
window_use(window_output, context);
shaders_compute(&program, context, false, false);
window_refresh(window_output);
}
if (window_monitor != NULL) {
window_use(window_monitor, context);
shaders_compute(&program, context, true, window_output != NULL);
window_refresh(window_monitor);
}
window_events();
}
static void shutdown(const Parameters *params) {
context->stop = true;
if (params->save_state) {
@@ -276,3 +280,15 @@ void forge_run(const Parameters *params) {
window_terminate();
}
void forge_run(const Parameters *params) {
if (!init(params)) {
return;
}
while (!should_close()) {
loop(params->hot_reload, params->trace_fps);
}
shutdown(params);
}
+2 -1
View File
@@ -116,7 +116,8 @@ static void randomize(SharedContext *context, const StateConfig *state_config) {
}
static void load_from_file(SharedContext *context,
const StateConfig *state_config, char *state_file) {
const StateConfig *state_config,
const char *state_file) {
ConfigFile saved_state;
char key[STR_LEN];