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:
authorDalai Felinto <dfelinto@gmail.com>2010-07-11 01:15:10 +0400
committerDalai Felinto <dfelinto@gmail.com>2010-07-11 01:15:10 +0400
commit96a7e478b6ef0c9f4b15e27ab22db548bbab1fe5 (patch)
treec1c326457af385fbe455e310f16d77c7daaf8238 /source/blender/blenkernel/intern/sca.c
parente531f3736df13d9143f4b4c7589d65b12df1ff1b (diff)
Logic Editor Python API: link/unlink logics through python
After initial talk with Matt (awhile ago) we realzed that rna_api would fit well for this instead of an operator. The next step would be to move the current UI code to use the rna funcs instead. Note: it takes the s/c/a as argument, not its name. (e.g. cont.link(actuator=act) ) Sample code to link all the logic bricks between each other: ob = bpy.context.object for cont in ob.game.controllers: for sens in ob.game.sensors: cont.link(sensor=sens) for act in ob.game.actuators: cont.link(actuator=act) For a script to create bricks, link bricks, unlink bricks and remove them: http://www.pasteall.org/14266
Diffstat (limited to 'source/blender/blenkernel/intern/sca.c')
-rw-r--r--source/blender/blenkernel/intern/sca.c85
1 files changed, 56 insertions, 29 deletions
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
index 02b66dd9b32..12d1dfc83b0 100644
--- a/source/blender/blenkernel/intern/sca.c
+++ b/source/blender/blenkernel/intern/sca.c
@@ -45,6 +45,7 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_library.h"
+#include "BKE_sca.h"
/* ******************* SENSORS ************************ */
@@ -189,26 +190,13 @@ void unlink_controller(bController *cont)
{
bSensor *sens;
Object *ob;
- int a, removed;
/* check for controller pointers in sensors */
ob= G.main->object.first;
while(ob) {
sens= ob->sensors.first;
while(sens) {
- removed= 0;
- for(a=0; a<sens->totlinks; a++) {
- if(removed) (sens->links)[a-1] = (sens->links)[a];
- else if((sens->links)[a] == cont) removed= 1;
- }
- if(removed) {
- sens->totlinks--;
-
- if(sens->totlinks==0) {
- MEM_freeN(sens->links);
- sens->links= NULL;
- }
- }
+ unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
sens= sens->next;
}
ob= ob->id.next;
@@ -313,26 +301,13 @@ void unlink_actuator(bActuator *act)
{
bController *cont;
Object *ob;
- int a, removed;
/* check for actuator pointers in controllers */
ob= G.main->object.first;
while(ob) {
cont= ob->controllers.first;
while(cont) {
- removed= 0;
- for(a=0; a<cont->totlinks; a++) {
- if(removed) (cont->links)[a-1] = (cont->links)[a];
- else if((cont->links)[a] == act) removed= 1;
- }
- if(removed) {
- cont->totlinks--;
-
- if(cont->totlinks==0) {
- MEM_freeN(cont->links);
- cont->links= NULL;
- }
- }
+ unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
cont= cont->next;
}
ob= ob->id.next;
@@ -512,7 +487,6 @@ bActuator *new_actuator(int type)
}
/* ******************** GENERAL ******************* */
-
void clear_sca_new_poins_ob(Object *ob)
{
bSensor *sens;
@@ -807,3 +781,56 @@ void sca_move_actuator(bActuator *act_to_move, Object *ob, int move_up)
}
}
}
+
+void link_logicbricks(void **poin, void ***ppoin, short *tot, short size)
+{
+ void **old_links= NULL;
+
+ int ibrick;
+
+ /* check if the bricks are already linked */
+ for (ibrick=0; ibrick < *tot; ibrick++) {
+ if ((*ppoin)[ibrick] == *poin)
+ return;
+ }
+
+ if (*ppoin) {
+ old_links= *ppoin;
+
+ (*tot) ++;
+ *ppoin = MEM_callocN((*tot)*size, "new link");
+
+ for (ibrick=0; ibrick < *tot - 1; ibrick++) {
+ (*ppoin)[ibrick] = old_links[ibrick];
+ }
+ (*ppoin)[ibrick] = *poin;
+
+ if(old_links) MEM_freeN(old_links);
+ }
+ else {
+ (*tot) = 1;
+ *ppoin = MEM_callocN((*tot)*size, "new link");
+ (*ppoin)[0] = *poin;
+ }
+}
+
+void unlink_logicbricks(void **poin, void ***ppoin, short *tot)
+{
+ int ibrick, removed;
+
+ removed= 0;
+ for (ibrick=0; ibrick < *tot; ibrick++) {
+ if(removed) (*ppoin)[ibrick - removed] = (*ppoin)[ibrick];
+ else if((*ppoin)[ibrick] == *poin) removed = 1;
+ }
+
+ if (removed) {
+ (*tot) --;
+
+ if(*tot == 0) {
+ MEM_freeN(*ppoin);
+ (*ppoin)= NULL;
+ }
+ return;
+ }
+}