Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_callbacks.h73
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/intern/blender.c4
-rw-r--r--source/blender/blenkernel/intern/callbacks.c67
-rw-r--r--source/blender/blenkernel/intern/scene.c10
5 files changed, 149 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_callbacks.h b/source/blender/blenkernel/BKE_callbacks.h
new file mode 100644
index 00000000000..380ce30668d
--- /dev/null
+++ b/source/blender/blenkernel/BKE_callbacks.h
@@ -0,0 +1,73 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#ifndef __BKE_CALLBACKS_H__
+#define __BKE_CALLBACKS_H__
+
+struct ID;
+struct Main;
+
+/**
+ * Common suffix uses:
+ * - ``_PRE/_POST``:
+ * For handling discrete non-interactive events.
+ * - ``_INIT/_COMPLETE/_CANCEL``:
+ * For handling jobs (which may in turn cause other handlers to be called).
+ */
+typedef enum {
+ BKE_CB_EVT_FRAME_CHANGE_PRE,
+ BKE_CB_EVT_FRAME_CHANGE_POST,
+ BKE_CB_EVT_RENDER_PRE,
+ BKE_CB_EVT_RENDER_POST,
+ BKE_CB_EVT_RENDER_WRITE,
+ BKE_CB_EVT_RENDER_STATS,
+ BKE_CB_EVT_RENDER_INIT,
+ BKE_CB_EVT_RENDER_COMPLETE,
+ BKE_CB_EVT_RENDER_CANCEL,
+ BKE_CB_EVT_LOAD_PRE,
+ BKE_CB_EVT_LOAD_POST,
+ BKE_CB_EVT_SAVE_PRE,
+ BKE_CB_EVT_SAVE_POST,
+ BKE_CB_EVT_UNDO_PRE,
+ BKE_CB_EVT_UNDO_POST,
+ BKE_CB_EVT_REDO_PRE,
+ BKE_CB_EVT_REDO_POST,
+ BKE_CB_EVT_DEPSGRAPH_UPDATE_PRE,
+ BKE_CB_EVT_DEPSGRAPH_UPDATE_POST,
+ BKE_CB_EVT_VERSION_UPDATE,
+ BKE_CB_EVT_LOAD_FACTORY_USERDEF_POST,
+ BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST,
+ BKE_CB_EVT_TOT,
+} eCbEvent;
+
+typedef struct bCallbackFuncStore {
+ struct bCallbackFuncStore *next, *prev;
+ void (*func)(struct Main *, struct ID *, void *arg);
+ void *arg;
+ short alloc;
+} bCallbackFuncStore;
+
+void BKE_callback_exec(struct Main *bmain, struct ID *self, eCbEvent evt);
+void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt);
+
+void BKE_callback_global_init(void);
+void BKE_callback_global_finalize(void);
+
+#endif /* __BKE_CALLBACKS_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 669abff6599..a1c47ba6d06 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -83,6 +83,7 @@ set(SRC
intern/brush.c
intern/bvhutils.c
intern/cachefile.c
+ intern/callbacks.c
intern/camera.c
intern/cdderivedmesh.c
intern/cloth.c
@@ -243,6 +244,7 @@ set(SRC
BKE_brush.h
BKE_bvhutils.h
BKE_cachefile.h
+ BKE_callbacks.h
BKE_camera.h
BKE_ccg.h
BKE_cdderivedmesh.h
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 805c098d238..ac432bf0b64 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -32,7 +32,6 @@
#include "BLI_string.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
-#include "BLI_callbacks.h"
#include "IMB_imbuf.h"
#include "IMB_moviecache.h"
@@ -44,6 +43,7 @@
#include "BKE_blendfile.h"
#include "BKE_brush.h"
#include "BKE_cachefile.h"
+#include "BKE_callbacks.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
@@ -95,7 +95,7 @@ void BKE_blender_free(void)
BKE_brush_system_exit();
RE_texture_rng_exit();
- BLI_callback_global_finalize();
+ BKE_callback_global_finalize();
IMB_moviecache_destruct();
diff --git a/source/blender/blenkernel/intern/callbacks.c b/source/blender/blenkernel/intern/callbacks.c
new file mode 100644
index 00000000000..cbecba2efe1
--- /dev/null
+++ b/source/blender/blenkernel/intern/callbacks.c
@@ -0,0 +1,67 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+
+#include "BKE_callbacks.h"
+
+#include "MEM_guardedalloc.h"
+
+static ListBase callback_slots[BKE_CB_EVT_TOT] = {{NULL}};
+
+void BKE_callback_exec(struct Main *bmain, struct ID *self, eCbEvent evt)
+{
+ ListBase *lb = &callback_slots[evt];
+ bCallbackFuncStore *funcstore;
+
+ for (funcstore = lb->first; funcstore; funcstore = funcstore->next) {
+ funcstore->func(bmain, self, funcstore->arg);
+ }
+}
+
+void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
+{
+ ListBase *lb = &callback_slots[evt];
+ BLI_addtail(lb, funcstore);
+}
+
+void BKE_callback_global_init(void)
+{
+ /* do nothing */
+}
+
+/* call on application exit */
+void BKE_callback_global_finalize(void)
+{
+ eCbEvent evt;
+ for (evt = 0; evt < BKE_CB_EVT_TOT; evt++) {
+ ListBase *lb = &callback_slots[evt];
+ bCallbackFuncStore *funcstore;
+ bCallbackFuncStore *funcstore_next;
+ for (funcstore = lb->first; funcstore; funcstore = funcstore_next) {
+ funcstore_next = funcstore->next;
+ BLI_remlink(lb, funcstore);
+ if (funcstore->alloc) {
+ MEM_freeN(funcstore);
+ }
+ }
+ }
+}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index b0e0f9f1efc..c55aa1b835c 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -48,7 +48,7 @@
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
-#include "BLI_callbacks.h"
+#include "BKE_callbacks.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_threads.h"
@@ -1554,7 +1554,7 @@ static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool on
bool run_callbacks = DEG_id_type_any_updated(depsgraph);
if (run_callbacks) {
- BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_DEPSGRAPH_UPDATE_PRE);
+ BKE_callback_exec(bmain, &scene->id, BKE_CB_EVT_DEPSGRAPH_UPDATE_PRE);
}
for (int pass = 0; pass < 2; pass++) {
@@ -1572,7 +1572,7 @@ static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool on
BKE_scene_update_sound(depsgraph, bmain);
/* Notify python about depsgraph update. */
if (run_callbacks) {
- BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_DEPSGRAPH_UPDATE_POST);
+ BKE_callback_exec(bmain, &scene->id, BKE_CB_EVT_DEPSGRAPH_UPDATE_POST);
}
/* Inform editors about possible changes. */
DEG_ids_check_recalc(bmain, depsgraph, scene, view_layer, false);
@@ -1607,7 +1607,7 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain)
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
/* Keep this first. */
- BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_PRE);
+ BKE_callback_exec(bmain, &scene->id, BKE_CB_EVT_FRAME_CHANGE_PRE);
for (int pass = 0; pass < 2; pass++) {
/* Update animated image textures for particles, modifiers, gpu, etc,
@@ -1629,7 +1629,7 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain)
/* Notify editors and python about recalc. */
if (pass == 0) {
- BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST);
+ BKE_callback_exec(bmain, &scene->id, BKE_CB_EVT_FRAME_CHANGE_POST);
}
/* Inform editors about possible changes. */