base: callback cleanup
This commit is contained in:
@@ -827,11 +827,9 @@ static void cmd(struct android_app *app, int32_t cmd) {
|
||||
updateAppForegroundStatus(displayIsInitialized, true);
|
||||
break;
|
||||
case APP_CMD_RESUME:
|
||||
iron_internal_resume_callback();
|
||||
paused = false;
|
||||
break;
|
||||
case APP_CMD_PAUSE:
|
||||
iron_internal_pause_callback();
|
||||
paused = true;
|
||||
break;
|
||||
case APP_CMD_STOP:
|
||||
|
||||
@@ -577,11 +577,9 @@ void importFile(NSURL *url) {
|
||||
}
|
||||
|
||||
- (void)sceneDidBecomeActive:(UIScene *)scene {
|
||||
iron_internal_resume_callback();
|
||||
}
|
||||
|
||||
- (void)sceneWillResignActive:(UIScene *)scene {
|
||||
iron_internal_pause_callback();
|
||||
}
|
||||
|
||||
- (void)sceneWillEnterForeground:(UIScene *)scene {
|
||||
|
||||
@@ -780,11 +780,9 @@ void iron_internal_call_resize_callback(int width, int height) {
|
||||
}
|
||||
|
||||
- (void)windowDidResignMain:(NSNotification *)notification {
|
||||
iron_internal_pause_callback();
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeMain:(NSNotification *)notification {
|
||||
iron_internal_resume_callback();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+1
-7
@@ -591,16 +591,11 @@ void _iron_set_drop_files_callback(void (*callback)(char *)) {
|
||||
iron_set_drop_files_callback(_drop_files, NULL);
|
||||
}
|
||||
|
||||
void iron_set_application_state_callback(void (*on_foreground)(void), void (*on_resume)(void), void (*on_pause)(void), void (*on_background)(void),
|
||||
void (*on_shutdown)(void)) {
|
||||
void iron_set_application_state_callback(void (*on_foreground)(void), void (*on_background)(void), void (*on_shutdown)(void)) {
|
||||
iron_set_foreground_callback(on_foreground != NULL ? _foreground : NULL, NULL);
|
||||
iron_set_resume_callback(on_resume != NULL ? _resume : NULL, NULL);
|
||||
iron_set_pause_callback(on_pause != NULL ? _pause : NULL, NULL);
|
||||
iron_set_background_callback(on_background != NULL ? _background : NULL, NULL);
|
||||
iron_set_shutdown_callback(on_shutdown != NULL ? _shutdown : NULL, NULL);
|
||||
iron_foreground = on_foreground;
|
||||
iron_resume = on_resume;
|
||||
iron_pause = on_pause;
|
||||
iron_background = on_background;
|
||||
iron_shutdown = on_shutdown;
|
||||
}
|
||||
@@ -715,7 +710,6 @@ void *gpu_create_vertex_buffer(i32 count, gpu_vertex_structure_t *structure) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
gpu_shader_t *gpu_create_shader(buffer_t *data, i32 shader_type) {
|
||||
gpu_shader_t *shader = (gpu_shader_t *)malloc(sizeof(gpu_shader_t));
|
||||
gpu_shader_init(shader, data->buffer, data->length, (gpu_shader_type_t)shader_type);
|
||||
|
||||
+8
-65
@@ -13,8 +13,7 @@
|
||||
void _iron_init(iron_window_options_t *ops);
|
||||
void _iron_set_update_callback(void (*callback)(void));
|
||||
void _iron_set_drop_files_callback(void (*callback)(char *));
|
||||
void iron_set_application_state_callback(void (*on_foreground)(void), void (*on_resume)(void), void (*on_pause)(void), void (*on_background)(void),
|
||||
void (*on_shutdown)(void));
|
||||
void iron_set_application_state_callback(void (*on_foreground)(void), void (*on_background)(void), void (*on_shutdown)(void));
|
||||
void iron_set_keyboard_down_callback(void (*callback)(int));
|
||||
void iron_set_keyboard_up_callback(void (*callback)(int));
|
||||
void iron_set_mouse_down_callback(void (*callback)(int, int, int));
|
||||
@@ -46,8 +45,6 @@ f32 _sys_start_time = 0.0f;
|
||||
char _sys_window_title[1024];
|
||||
|
||||
any_array_t *_sys_foreground_listeners = NULL;
|
||||
any_array_t *_sys_resume_listeners = NULL;
|
||||
any_array_t *_sys_pause_listeners = NULL;
|
||||
any_array_t *_sys_background_listeners = NULL;
|
||||
any_array_t *_sys_shutdown_listeners = NULL;
|
||||
any_array_t *_sys_drop_files_listeners = NULL;
|
||||
@@ -55,7 +52,6 @@ any_array_t *_sys_drop_files_listeners = NULL;
|
||||
any_array_t *_sys_on_next_frames = NULL;
|
||||
any_array_t *_sys_on_end_frames = NULL;
|
||||
any_array_t *_sys_on_updates = NULL;
|
||||
any_array_t *_sys_on_renders = NULL;
|
||||
i32 _sys_lastw = -1;
|
||||
i32 _sys_lasth = -1;
|
||||
|
||||
@@ -85,10 +81,6 @@ static callback_t *_callback_create(void (*f)(void *data), void *data) {
|
||||
void sys_start(iron_window_options_t *ops) {
|
||||
_sys_foreground_listeners = any_array_create(0);
|
||||
gc_root(_sys_foreground_listeners);
|
||||
_sys_resume_listeners = any_array_create(0);
|
||||
gc_root(_sys_resume_listeners);
|
||||
_sys_pause_listeners = any_array_create(0);
|
||||
gc_root(_sys_pause_listeners);
|
||||
_sys_background_listeners = any_array_create(0);
|
||||
gc_root(_sys_background_listeners);
|
||||
_sys_shutdown_listeners = any_array_create(0);
|
||||
@@ -101,8 +93,6 @@ void sys_start(iron_window_options_t *ops) {
|
||||
gc_root(_sys_on_end_frames);
|
||||
_sys_on_updates = any_array_create(0);
|
||||
gc_root(_sys_on_updates);
|
||||
_sys_on_renders = any_array_create(0);
|
||||
gc_root(_sys_on_renders);
|
||||
_sys_shaders = any_map_create();
|
||||
gc_root(_sys_shaders);
|
||||
|
||||
@@ -152,7 +142,7 @@ void sys_start(iron_window_options_t *ops) {
|
||||
|
||||
_iron_set_update_callback(sys_render);
|
||||
_iron_set_drop_files_callback(sys_drop_files_callback);
|
||||
iron_set_application_state_callback(sys_foreground_callback, sys_resume_callback, sys_pause_callback, sys_background_callback, sys_shutdown_callback);
|
||||
iron_set_application_state_callback(sys_foreground_callback, sys_background_callback, sys_shutdown_callback);
|
||||
iron_set_keyboard_down_callback(sys_keyboard_down_callback);
|
||||
iron_set_keyboard_up_callback(sys_keyboard_up_callback);
|
||||
iron_set_mouse_down_callback(sys_mouse_down_callback);
|
||||
@@ -172,17 +162,10 @@ void sys_start(iron_window_options_t *ops) {
|
||||
input_register();
|
||||
}
|
||||
|
||||
void sys_notify_on_app_state(void (*on_foreground)(void), void (*on_resume)(void), void (*on_pause)(void), void (*on_background)(void),
|
||||
void (*on_shutdown)(void)) {
|
||||
void sys_notify_on_app_state(void (*on_foreground)(void), void (*on_background)(void), void (*on_shutdown)(void)) {
|
||||
if (on_foreground != NULL) {
|
||||
any_array_push(_sys_foreground_listeners, _sys_callback_create(on_foreground));
|
||||
}
|
||||
if (on_resume != NULL) {
|
||||
any_array_push(_sys_resume_listeners, _sys_callback_create(on_resume));
|
||||
}
|
||||
if (on_pause != NULL) {
|
||||
any_array_push(_sys_pause_listeners, _sys_callback_create(on_pause));
|
||||
}
|
||||
if (on_background != NULL) {
|
||||
any_array_push(_sys_background_listeners, _sys_callback_create(on_background));
|
||||
}
|
||||
@@ -205,20 +188,6 @@ void sys_foreground(void) {
|
||||
input_on_foreground();
|
||||
}
|
||||
|
||||
void sys_resume(void) {
|
||||
for (i32 i = 0; i < (i32)_sys_resume_listeners->length; ++i) {
|
||||
sys_callback_t *cb = _sys_resume_listeners->buffer[i];
|
||||
cb->f();
|
||||
}
|
||||
}
|
||||
|
||||
void sys_pause(void) {
|
||||
for (i32 i = 0; i < (i32)_sys_pause_listeners->length; ++i) {
|
||||
sys_callback_t *cb = _sys_pause_listeners->buffer[i];
|
||||
cb->f();
|
||||
}
|
||||
}
|
||||
|
||||
void sys_background(void) {
|
||||
for (i32 i = 0; i < (i32)_sys_background_listeners->length; ++i) {
|
||||
sys_callback_t *cb = _sys_background_listeners->buffer[i];
|
||||
@@ -252,14 +221,6 @@ void sys_foreground_callback(void) {
|
||||
sys_foreground();
|
||||
}
|
||||
|
||||
void sys_resume_callback(void) {
|
||||
sys_resume();
|
||||
}
|
||||
|
||||
void sys_pause_callback(void) {
|
||||
sys_pause();
|
||||
}
|
||||
|
||||
void sys_background_callback(void) {
|
||||
sys_background();
|
||||
}
|
||||
@@ -441,24 +402,14 @@ static void _sys_run_callbacks(any_array_t *cbs, i32 len) {
|
||||
}
|
||||
|
||||
void sys_render(void) {
|
||||
if (_sys_on_next_frames->length > 0) {
|
||||
i32 len = _sys_on_next_frames->length;
|
||||
_sys_run_callbacks(_sys_on_next_frames, len);
|
||||
array_splice(_sys_on_next_frames, 0, len);
|
||||
}
|
||||
_sys_run_callbacks(_sys_on_next_frames, _sys_on_next_frames->length);
|
||||
array_splice(_sys_on_next_frames, 0, _sys_on_next_frames->length);
|
||||
|
||||
scene_render_frame();
|
||||
_sys_run_callbacks(_sys_on_updates, _sys_on_updates->length);
|
||||
|
||||
if (iron_window_width() > 0 && iron_window_height() > 0) {
|
||||
scene_render_frame();
|
||||
_sys_run_callbacks(_sys_on_renders, _sys_on_renders->length);
|
||||
}
|
||||
|
||||
if (_sys_on_end_frames->length > 0) {
|
||||
i32 len = _sys_on_end_frames->length;
|
||||
_sys_run_callbacks(_sys_on_end_frames, len);
|
||||
array_splice(_sys_on_end_frames, 0, len);
|
||||
}
|
||||
_sys_run_callbacks(_sys_on_end_frames, _sys_on_end_frames->length);
|
||||
array_splice(_sys_on_end_frames, 0, _sys_on_end_frames->length);
|
||||
|
||||
input_end_frame();
|
||||
|
||||
@@ -484,10 +435,6 @@ void sys_notify_on_update(void (*f)(void *data), void *data) {
|
||||
any_array_push(_sys_on_updates, _callback_create(f, data));
|
||||
}
|
||||
|
||||
void sys_notify_on_render(void (*f)(void *data), void *data) {
|
||||
any_array_push(_sys_on_renders, _callback_create(f, data));
|
||||
}
|
||||
|
||||
void sys_notify_on_next_frame(void (*f)(void *data), void *data) {
|
||||
any_array_push(_sys_on_next_frames, _callback_create(f, data));
|
||||
}
|
||||
@@ -510,10 +457,6 @@ void sys_remove_update(void (*f)(void *data)) {
|
||||
_sys_remove_callback(_sys_on_updates, f);
|
||||
}
|
||||
|
||||
void sys_remove_render(void (*f)(void *data)) {
|
||||
_sys_remove_callback(_sys_on_renders, f);
|
||||
}
|
||||
|
||||
void sys_remove_end_frame(void (*f)(void *data)) {
|
||||
_sys_remove_callback(_sys_on_end_frames, f);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ extern f32 _sys_start_time;
|
||||
extern any_array_t *_sys_on_next_frames;
|
||||
extern any_array_t *_sys_on_end_frames;
|
||||
extern any_array_t *_sys_on_updates;
|
||||
extern any_array_t *_sys_on_renders;
|
||||
extern i32 _sys_lastw;
|
||||
extern i32 _sys_lasth;
|
||||
|
||||
@@ -37,8 +36,6 @@ typedef struct callback {
|
||||
} callback_t;
|
||||
|
||||
extern any_array_t *_sys_foreground_listeners;
|
||||
extern any_array_t *_sys_resume_listeners;
|
||||
extern any_array_t *_sys_pause_listeners;
|
||||
extern any_array_t *_sys_background_listeners;
|
||||
extern any_array_t *_sys_shutdown_listeners;
|
||||
extern any_array_t *_sys_drop_files_listeners;
|
||||
@@ -62,15 +59,12 @@ char *sys_shader_ext(void);
|
||||
|
||||
gpu_shader_t *sys_get_shader(char *name);
|
||||
|
||||
void sys_notify_on_app_state(void (*on_foreground)(void), void (*on_resume)(void), void (*on_pause)(void), void (*on_background)(void),
|
||||
void (*on_shutdown)(void));
|
||||
void sys_notify_on_app_state(void (*on_foreground)(void), void (*on_background)(void), void (*on_shutdown)(void));
|
||||
void sys_notify_on_drop_files(void (*drop_files_listener)(char *s));
|
||||
void sys_notify_on_update(void (*f)(void *data), void *data);
|
||||
void sys_notify_on_render(void (*f)(void *data), void *data);
|
||||
void sys_notify_on_next_frame(void (*f)(void *data), void *data);
|
||||
void sys_notify_on_end_frame(void (*f)(void *data), void *data);
|
||||
void sys_remove_update(void (*f)(void *data));
|
||||
void sys_remove_render(void (*f)(void *data));
|
||||
void sys_remove_end_frame(void (*f)(void *data));
|
||||
|
||||
void sys_render(void);
|
||||
@@ -82,8 +76,6 @@ void sys_shutdown(void);
|
||||
void sys_drop_files(char *file_path);
|
||||
|
||||
void sys_foreground_callback(void);
|
||||
void sys_resume_callback(void);
|
||||
void sys_pause_callback(void);
|
||||
void sys_background_callback(void);
|
||||
void sys_shutdown_callback(void);
|
||||
void sys_drop_files_callback(char *file_path);
|
||||
|
||||
@@ -86,10 +86,6 @@ static void (*foreground_callback)(void *) = NULL;
|
||||
static void *foreground_callback_data = NULL;
|
||||
static void (*background_callback)(void *) = NULL;
|
||||
static void *background_callback_data = NULL;
|
||||
static void (*pause_callback)(void *) = NULL;
|
||||
static void *pause_callback_data = NULL;
|
||||
static void (*resume_callback)(void *) = NULL;
|
||||
static void *resume_callback_data = NULL;
|
||||
static void (*shutdown_callback)(void *) = NULL;
|
||||
static void *shutdown_callback_data = NULL;
|
||||
static void (*drop_files_callback)(char *, void *) = NULL;
|
||||
@@ -114,16 +110,6 @@ void iron_set_foreground_callback(void (*callback)(void *), void *data) {
|
||||
foreground_callback_data = data;
|
||||
}
|
||||
|
||||
void iron_set_resume_callback(void (*callback)(void *), void *data) {
|
||||
resume_callback = callback;
|
||||
resume_callback_data = data;
|
||||
}
|
||||
|
||||
void iron_set_pause_callback(void (*callback)(void *), void *data) {
|
||||
pause_callback = callback;
|
||||
pause_callback_data = data;
|
||||
}
|
||||
|
||||
void iron_set_background_callback(void (*callback)(void *), void *data) {
|
||||
background_callback = callback;
|
||||
background_callback_data = data;
|
||||
@@ -166,18 +152,6 @@ void iron_internal_foreground_callback(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void iron_internal_resume_callback(void) {
|
||||
if (resume_callback != NULL) {
|
||||
resume_callback(resume_callback_data);
|
||||
}
|
||||
}
|
||||
|
||||
void iron_internal_pause_callback(void) {
|
||||
if (pause_callback != NULL) {
|
||||
pause_callback(pause_callback_data);
|
||||
}
|
||||
}
|
||||
|
||||
void iron_internal_background_callback(void) {
|
||||
if (background_callback != NULL) {
|
||||
background_callback(background_callback_data);
|
||||
|
||||
@@ -122,8 +122,6 @@ bool iron_internal_handle_messages(void);
|
||||
void iron_internal_shutdown(void);
|
||||
void iron_internal_update_callback(void);
|
||||
void iron_internal_foreground_callback(void);
|
||||
void iron_internal_resume_callback(void);
|
||||
void iron_internal_pause_callback(void);
|
||||
void iron_internal_background_callback(void);
|
||||
void iron_internal_shutdown_callback(void);
|
||||
void iron_internal_drop_files_callback(char *);
|
||||
|
||||
@@ -1749,11 +1749,9 @@ void minic_register_builtins() {
|
||||
R(sys_notify_on_app_state, "v(p,p,p,p,p)");
|
||||
R(sys_notify_on_drop_files, "v(p)");
|
||||
R(sys_notify_on_update, "v(p,p)");
|
||||
R(sys_notify_on_render, "v(p,p)");
|
||||
R(sys_notify_on_next_frame, "v(p,p)");
|
||||
R(sys_notify_on_end_frame, "v(p,p)");
|
||||
R(sys_remove_update, "v(p)");
|
||||
R(sys_remove_render, "v(p)");
|
||||
R(sys_remove_end_frame, "v(p)");
|
||||
R(data_path, "p()");
|
||||
R(video_unload, "v(p)");
|
||||
|
||||
@@ -174,7 +174,7 @@ void _main() {
|
||||
gc_root(ui_on_border_hover);
|
||||
ui_text_area_line_numbers = true;
|
||||
ui_text_area_scroll_past_end = true;
|
||||
sys_notify_on_render(render, NULL);
|
||||
sys_notify_on_update(render, NULL);
|
||||
_iron_set_drop_files_callback(drop_files);
|
||||
iron_set_application_state_callback(NULL, NULL, NULL, NULL, on_shutdown);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user