Add logicbricks to ID looper.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 8 Oct 2015 13:04:09 +0000 (15:04 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 8 Oct 2015 13:05:37 +0000 (15:05 +0200)
source/blender/blenkernel/BKE_sca.h
source/blender/blenkernel/intern/library_query.c
source/blender/blenkernel/intern/sca.c

index ebdd159b40c3f60a910824460d5892d2bce74d38..fa448aa97b8be2a5499aeb365304ea693d7cd3e0 100644 (file)
@@ -73,6 +73,16 @@ void sca_move_sensor(struct bSensor *sens_to_move, struct Object *ob, int move_u
 void sca_move_controller(struct bController *cont_to_move, struct Object *ob, int move_up);
 void sca_move_actuator(struct bActuator *act_to_move, struct Object *ob, int move_up);
 
+/* Callback format for performing operations on ID-pointers for sensors/controllers/actuators. */
+typedef void (*SCASensorIDFunc)(struct bSensor *sensor, struct ID **idpoin, void *userdata, int cd_flag);
+typedef void (*SCAControllerIDFunc)(struct bController *controller, struct ID **idpoin, void *userdata, int cd_flag);
+typedef void (*SCAActuatorIDFunc)(struct bActuator *actuator, struct ID **idpoin, void *userdata, int cd_flag);
+
+void BKE_sca_sensors_id_loop(struct ListBase *senslist, SCASensorIDFunc func, void *userdata);
+void BKE_sca_controllers_id_loop(struct ListBase *contlist, SCAControllerIDFunc func, void *userdata);
+void BKE_sca_actuators_id_loop(struct ListBase *atclist, SCAActuatorIDFunc func, void *userdata);
+
+
 const char *sca_state_name_get(Object *ob, short bit);
 
 #endif
index a1b84324496fea59f6a64f74746ca80c9fb8f38d..a800b3d8834ee2a9786c66d5aa5e4fc86d4af3b5 100644 (file)
 #include <stdlib.h>
 
 
+#include "DNA_actuator_types.h"
 #include "DNA_anim_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_constraint_types.h"
+#include "DNA_controller_types.h"
 #include "DNA_group_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_key_types.h"
@@ -49,6 +51,7 @@
 #include "DNA_object_force.h"
 #include "DNA_rigidbody_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_sensor_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_speaker_types.h"
@@ -67,6 +70,7 @@
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
 #include "BKE_rigidbody.h"
+#include "BKE_sca.h"
 #include "BKE_sequencer.h"
 #include "BKE_tracking.h"
 
@@ -132,6 +136,27 @@ static void library_foreach_particlesystemsObjectLooper(
        FOREACH_CALLBACK_INVOKE_ID_PP(data->self_id, id_pointer, data->flag, data->callback, data->user_data, cd_flag);
 }
 
+static void library_foreach_sensorsObjectLooper(
+        bSensor *UNUSED(sensor), ID **id_pointer, void *user_data, int cd_flag)
+{
+       LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
+       FOREACH_CALLBACK_INVOKE_ID_PP(data->self_id, id_pointer, data->flag, data->callback, data->user_data, cd_flag);
+}
+
+static void library_foreach_controllersObjectLooper(
+        bController *UNUSED(controller), ID **id_pointer, void *user_data, int cd_flag)
+{
+       LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
+       FOREACH_CALLBACK_INVOKE_ID_PP(data->self_id, id_pointer, data->flag, data->callback, data->user_data, cd_flag);
+}
+
+static void library_foreach_actuatorsObjectLooper(
+        bActuator *UNUSED(actuator), ID **id_pointer, void *user_data, int cd_flag)
+{
+       LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
+       FOREACH_CALLBACK_INVOKE_ID_PP(data->self_id, id_pointer, data->flag, data->callback, data->user_data, cd_flag);
+}
+
 static void library_foreach_animationData(LibraryForeachIDData *data, AnimData *adt)
 {
        FCurve *fcu;
@@ -350,6 +375,10 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
                        for (psys = object->particlesystem.first; psys; psys = psys->next) {
                                BKE_particlesystem_id_loop(psys, library_foreach_particlesystemsObjectLooper, &data);
                        }
+
+                       BKE_sca_sensors_id_loop(&object->sensors, library_foreach_sensorsObjectLooper, &data);
+                       BKE_sca_controllers_id_loop(&object->controllers, library_foreach_controllersObjectLooper, &data);
+                       BKE_sca_actuators_id_loop(&object->actuators, library_foreach_actuatorsObjectLooper, &data);
                        break;
                }
 
index c902659c03908bd6f2718e51fc8efa8fd0ab2fb6..88a2822863919ed0906bff59127ae248f5b6ffaf 100644 (file)
@@ -48,6 +48,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_library.h"
+#include "BKE_library_query.h"
 #include "BKE_sca.h"
 
 /* ******************* SENSORS ************************ */
@@ -903,6 +904,179 @@ void unlink_logicbricks(void **poin, void ***ppoin, short *tot)
        }
 }
 
+void BKE_sca_sensors_id_loop(ListBase *senslist, SCASensorIDFunc func, void *userdata)
+{
+       bSensor *sensor;
+
+       for (sensor = senslist->first; sensor; sensor = sensor->next) {
+               func(sensor, (ID **)&sensor->ob, userdata, IDWALK_NOP);
+
+               switch (sensor->type) {
+                       case SENS_TOUCH:  /* DEPRECATED */
+                       {
+                               bTouchSensor *ts = sensor->data;
+                               func(sensor, (ID **)&ts->ma, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case SENS_MESSAGE:
+                       {
+                               bMessageSensor *ms = sensor->data;
+                               func(sensor, (ID **)&ms->fromObject, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case SENS_ALWAYS:
+                       case SENS_NEAR:
+                       case SENS_KEYBOARD:
+                       case SENS_PROPERTY:
+                       case SENS_MOUSE:
+                       case SENS_COLLISION:
+                       case SENS_RADAR:
+                       case SENS_RANDOM:
+                       case SENS_RAY:
+                       case SENS_JOYSTICK:
+                       case SENS_ACTUATOR:
+                       case SENS_DELAY:
+                       case SENS_ARMATURE:
+                       default:
+                               break;
+               }
+       }
+}
+
+void BKE_sca_controllers_id_loop(ListBase *contlist, SCAControllerIDFunc func, void *userdata)
+{
+       bController *controller;
+
+       for (controller = contlist->first; controller; controller = controller->next) {
+               switch (controller->type) {
+                       case CONT_PYTHON:
+                       {
+                               bPythonCont *pc = controller->data;
+                               func(controller, (ID **)&pc->text, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case CONT_LOGIC_AND:
+                       case CONT_LOGIC_OR:
+                       case CONT_EXPRESSION:
+                       case CONT_LOGIC_NAND:
+                       case CONT_LOGIC_NOR:
+                       case CONT_LOGIC_XOR:
+                       case CONT_LOGIC_XNOR:
+                       default:
+                               break;
+               }
+       }
+}
+
+void BKE_sca_actuators_id_loop(ListBase *actlist, SCAActuatorIDFunc func, void *userdata)
+{
+       bActuator *actuator;
+
+       for (actuator = actlist->first; actuator; actuator = actuator->next) {
+               func(actuator, (ID **)&actuator->ob, userdata, IDWALK_NOP);
+
+               switch (actuator->type) {
+                       case ACT_ADD_OBJECT:  /* DEPRECATED */
+                       {
+                               bAddObjectActuator *aoa = actuator->data;
+                               func(actuator, (ID **)&aoa->ob, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_ACTION:
+                       {
+                               bActionActuator *aa = actuator->data;
+                               func(actuator, (ID **)&aa->act, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_SOUND:
+                       {
+                               bSoundActuator *sa = actuator->data;
+                               func(actuator, (ID **)&sa->sound, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_EDIT_OBJECT:
+                       {
+                               bEditObjectActuator *eoa = actuator->data;
+                               func(actuator, (ID **)&eoa->ob, userdata, IDWALK_NOP);
+                               func(actuator, (ID **)&eoa->me, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_SCENE:
+                       {
+                               bSceneActuator *sa = actuator->data;
+                               func(actuator, (ID **)&sa->scene, userdata, IDWALK_NOP);
+                               func(actuator, (ID **)&sa->camera, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_PROPERTY:
+                       {
+                               bPropertyActuator *pa = actuator->data;
+                               func(actuator, (ID **)&pa->ob, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_OBJECT:
+                       {
+                               bObjectActuator *oa = actuator->data;
+                               func(actuator, (ID **)&oa->reference, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_CAMERA:
+                       {
+                               bCameraActuator *ca = actuator->data;
+                               func(actuator, (ID **)&ca->ob, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_MESSAGE:
+                       {
+                               bMessageActuator *ma = actuator->data;
+                               func(actuator, (ID **)&ma->toObject, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_2DFILTER:
+                       {
+                               bTwoDFilterActuator *tdfa = actuator->data;
+                               func(actuator, (ID **)&tdfa->text, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_PARENT:
+                       {
+                               bParentActuator *pa = actuator->data;
+                               func(actuator, (ID **)&pa->ob, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_ARMATURE:
+                       {
+                               bArmatureActuator *aa = actuator->data;
+                               func(actuator, (ID **)&aa->target, userdata, IDWALK_NOP);
+                               func(actuator, (ID **)&aa->subtarget, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       case ACT_STEERING:
+                       {
+                               bSteeringActuator *sa = actuator->data;
+                               func(actuator, (ID **)&sa->target, userdata, IDWALK_NOP);
+                               func(actuator, (ID **)&sa->navmesh, userdata, IDWALK_NOP);
+                               break;
+                       }
+                       /* Note: some types seems to be non-implemented? ACT_LAMP, ACT_MATERIAL... */
+                       case ACT_IPO:  /* DEPRECATED */
+                       case ACT_LAMP:
+                       case ACT_MATERIAL:
+                       case ACT_END_OBJECT:  /* DEPRECATED */
+                       case ACT_CONSTRAINT:
+                       case ACT_GROUP:
+                       case ACT_RANDOM:
+                       case ACT_GAME:
+                       case ACT_VISIBILITY:
+                       case ACT_SHAPEACTION:
+                       case ACT_STATE:
+                       case ACT_MOUSE:
+                       default:
+                               break;
+               }
+       }
+}
+
 const char *sca_state_name_get(Object *ob, short bit)
 {
        bController *cont;