refactor: more maintainability
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[](https://github.com/klemek/forge-steel/releases) [](https://github.com/klemek/forge-steel/releases) [](https://github.com/klemek/forge-steel/commits/master/) [](https://github.com/klemek/forge-steel/actions/workflows/ci.yml) [](https://sonarcloud.io/summary/new_code?id=klemek_forge-steel) 
|
||||
[](https://github.com/klemek/forge-steel/releases) [](https://github.com/klemek/forge-steel/releases) [](https://github.com/klemek/forge-steel/commits/master/) [](https://github.com/klemek/forge-steel/actions/workflows/ci.yml) [](https://sonarcloud.io/summary/new_code?id=klemek_forge-steel) 
|
||||
|
||||
<!-- omit from toc -->
|
||||
# F.O.R.G.E. (Steel)
|
||||
|
||||
+57
-41
@@ -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(¶ms->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
@@ -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];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user