diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-10-08 16:04:09 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-10-08 16:05:37 +0300 |
commit | 3ab5075cf9f0d3ab466e97691bfe6d84c2dffb80 (patch) | |
tree | ec56f10f8cbdb227a08bd11396ffd77eeea74fd4 | |
parent | 4f0f0d1bcede8f307c4601a7e94b36c179d4d5a8 (diff) |
Add logicbricks to ID looper.
-rw-r--r-- | source/blender/blenkernel/BKE_sca.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library_query.c | 29 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sca.c | 174 |
3 files changed, 213 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_sca.h b/source/blender/blenkernel/BKE_sca.h index ebdd159b40c..fa448aa97b8 100644 --- a/source/blender/blenkernel/BKE_sca.h +++ b/source/blender/blenkernel/BKE_sca.h @@ -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 diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index a1b84324496..a800b3d8834 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -30,10 +30,12 @@ #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; } diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index c902659c039..88a28228639 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -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; |