Timer: Use explicit re-initialization on file load

Before this the timer API was relying on using a callback API to do
initialization when new file is loaded. This isn't how rest of Blender
works and it gets in a way because callbacks API is to be move to the
BKE level.

Use explicit call to timer API from where the file is loaded.
This commit is contained in:
Sergey Sharybin
2019-09-05 15:46:55 +02:00
parent 423435bd2e
commit 103d29e2b2
3 changed files with 10 additions and 23 deletions

View File

@@ -50,4 +50,8 @@ void BLI_timer_execute(void);
void BLI_timer_free(void); void BLI_timer_free(void);
/* This function is to be called next to BLI_CB_EVT_LOAD_PRE, to make sure the module
* is properly configured for the new file. */
void BLI_timer_on_file_load(void);
#endif /* __BLI_TIMER_H__ */ #endif /* __BLI_TIMER_H__ */

View File

@@ -23,7 +23,6 @@
#include "BLI_timer.h" #include "BLI_timer.h"
#include "BLI_listbase.h" #include "BLI_listbase.h"
#include "BLI_callbacks.h"
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "PIL_time.h" #include "PIL_time.h"
@@ -48,8 +47,6 @@ typedef struct TimerContainer {
static TimerContainer GlobalTimer = {{0}}; static TimerContainer GlobalTimer = {{0}};
static void ensure_callback_is_registered(void);
void BLI_timer_register(uintptr_t uuid, void BLI_timer_register(uintptr_t uuid,
BLI_timer_func func, BLI_timer_func func,
void *user_data, void *user_data,
@@ -57,8 +54,6 @@ void BLI_timer_register(uintptr_t uuid,
double first_interval, double first_interval,
bool persistent) bool persistent)
{ {
ensure_callback_is_registered();
TimedFunction *timed_func = MEM_callocN(sizeof(TimedFunction), __func__); TimedFunction *timed_func = MEM_callocN(sizeof(TimedFunction), __func__);
timed_func->func = func; timed_func->func = func;
timed_func->user_data_free = user_data_free; timed_func->user_data_free = user_data_free;
@@ -156,11 +151,7 @@ void BLI_timer_free()
remove_tagged_functions(); remove_tagged_functions();
} }
struct ID; static void remove_non_persistent_functions(void)
struct Main;
static void remove_non_persistent_functions(struct Main *UNUSED(_1),
struct ID *UNUSED(_2),
void *UNUSED(_3))
{ {
LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) { LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
if (!timed_func->persistent) { if (!timed_func->persistent) {
@@ -169,18 +160,7 @@ static void remove_non_persistent_functions(struct Main *UNUSED(_1),
} }
} }
static bCallbackFuncStore load_pre_callback = { void BLI_timer_on_file_load(void)
NULL,
NULL, /* next, prev */
remove_non_persistent_functions, /* func */
NULL, /* arg */
0, /* alloc */
};
static void ensure_callback_is_registered()
{ {
if (!GlobalTimer.file_load_cb_registered) { remove_non_persistent_functions();
BLI_callback_add(&load_pre_callback, BLI_CB_EVT_LOAD_PRE);
GlobalTimer.file_load_cb_registered = true;
}
} }

View File

@@ -52,6 +52,7 @@
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_linklist.h" #include "BLI_linklist.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BLI_timer.h"
#include "BLI_threads.h" #include "BLI_threads.h"
#include "BLI_callbacks.h" #include "BLI_callbacks.h"
#include "BLI_system.h" #include "BLI_system.h"
@@ -609,6 +610,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
WM_cursor_wait(1); WM_cursor_wait(1);
BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE); BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE);
BLI_timer_on_file_load();
UI_view2d_zoom_cache_reset(); UI_view2d_zoom_cache_reset();
@@ -806,6 +808,7 @@ void wm_homefile_read(bContext *C,
if (use_data) { if (use_data) {
BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE); BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE);
BLI_timer_on_file_load();
G.relbase_valid = 0; G.relbase_valid = 0;