From e4530c47f04556bb0387eebc7acf0652eedde342 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Thu, 27 May 2010 08:34:32 +0000 Subject: Logic Editor: fix for datablock counting when copying/deleting sound actuator ("bug" from 2.49) --- source/blender/blenkernel/intern/sca.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/sca.c') diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index 5a06c251b88..3102d4b054b 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -44,6 +44,7 @@ #include "BKE_utildefines.h" #include "BKE_global.h" #include "BKE_main.h" +#include "BKE_library.h" /* ******************* SENSORS ************************ */ @@ -348,7 +349,19 @@ void unlink_actuators(ListBase *lb) void free_actuator(bActuator *act) { - if(act->data) MEM_freeN(act->data); + bSoundActuator *sa; + + if(act->data) { + switch (act->type) { + case ACT_SOUND: + sa = (bSoundActuator *) act->data; + if(sa->sound) + id_us_min((ID *) sa->sound); + break; + } + + MEM_freeN(act->data); + } MEM_freeN(act); } @@ -365,6 +378,7 @@ void free_actuators(ListBase *lb) bActuator *copy_actuator(bActuator *act) { bActuator *actn; + bSoundActuator *sa; act->mynew=actn= MEM_dupallocN(act); actn->flag |= ACT_NEW; @@ -372,6 +386,13 @@ bActuator *copy_actuator(bActuator *act) actn->data= MEM_dupallocN(act->data); } + switch (act->type) { + case ACT_SOUND: + sa= (bSoundActuator *)act->data; + if(sa->sound) + id_us_plus((ID *) sa->sound); + break; + } return actn; } -- cgit v1.2.3 From 1f019c23fd11aefc363bb1694b94d0aee34501a1 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 9 Jul 2010 00:14:46 +0000 Subject: Logic Editor UI: move s/c/a operators and interface buttons Tchatcharantcharan ... Three new operators: bpy.ops.logic.sensor_move bpy.ops.logic.controller_move bpy.ops.logic.actuator_move direction is a parameter (UP,DOWN) Moved some interface code to sca.c instead of logic_window.c. (and changed accordingly). One note: as in 2.49, the move up/down button is only available in non-expanded mode. However instead of one button with two options we have 2 buttons (as we had originally in 2.50). That also means the s/c/a header is getting more clunky. Design, thoughts, ideas are appreciated. For the time been functionality back is still the priority (mine at least ;) --- source/blender/blenkernel/intern/sca.c | 124 +++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) (limited to 'source/blender/blenkernel/intern/sca.c') diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index 3102d4b054b..02b66dd9b32 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -683,3 +683,127 @@ void sca_remove_ob_poin(Object *obt, Object *ob) act= act->next; } } + +/* ******************** INTERFACE ******************* */ +void sca_move_sensor(bSensor *sens_to_move, Object *ob, int *move_up) +{ + bSensor *sens, *tmp; + + int val; + val = move_up ? 1:2; + + /* make sure this sensor belongs to this object */ + sens= ob->sensors.first; + while(sens) { + if(sens == sens_to_move) break; + sens= sens->next; + } + if(!sens) return; + + /* move up */ + if( val==1 && sens->prev) { + for (tmp=sens->prev; tmp; tmp=tmp->prev) { + if (tmp->flag & SENS_VISIBLE) + break; + } + if (tmp) { + BLI_remlink(&ob->sensors, sens); + BLI_insertlinkbefore(&ob->sensors, tmp, sens); + } + } + /* move down */ + else if( val==2 && sens->next) { + for (tmp=sens->next; tmp; tmp=tmp->next) { + if (tmp->flag & SENS_VISIBLE) + break; + } + if (tmp) { + BLI_remlink(&ob->sensors, sens); + BLI_insertlink(&ob->sensors, tmp, sens); + } + } +} + +void sca_move_controller(bController *cont_to_move, Object *ob, int move_up) +{ + bController *cont, *tmp; + + int val; + val = move_up ? 1:2; + + /* make sure this controller belongs to this object */ + cont= ob->controllers.first; + while(cont) { + if(cont == cont_to_move) break; + cont= cont->next; + } + if(!cont) return; + + /* move up */ + if( val==1 && cont->prev) { + /* locate the controller that has the same state mask but is earlier in the list */ + tmp = cont->prev; + while(tmp) { + if(tmp->state_mask & cont->state_mask) + break; + tmp = tmp->prev; + } + if (tmp) { + BLI_remlink(&ob->controllers, cont); + BLI_insertlinkbefore(&ob->controllers, tmp, cont); + } + } + + /* move down */ + else if( val==2 && cont->next) { + tmp = cont->next; + while(tmp) { + if(tmp->state_mask & cont->state_mask) + break; + tmp = tmp->next; + } + BLI_remlink(&ob->controllers, cont); + BLI_insertlink(&ob->controllers, tmp, cont); + } +} + +void sca_move_actuator(bActuator *act_to_move, Object *ob, int move_up) +{ + bActuator *act, *tmp; + int val; + + val = move_up ? 1:2; + + /* make sure this actuator belongs to this object */ + act= ob->actuators.first; + while(act) { + if(act == act_to_move) break; + act= act->next; + } + if(!act) return; + + /* move up */ + if( val==1 && act->prev) { + /* locate the first visible actuators before this one */ + for (tmp = act->prev; tmp; tmp=tmp->prev) { + if (tmp->flag & ACT_VISIBLE) + break; + } + if (tmp) { + BLI_remlink(&ob->actuators, act); + BLI_insertlinkbefore(&ob->actuators, tmp, act); + } + } + /* move down */ + else if( val==2 && act->next) { + /* locate the first visible actuators after this one */ + for (tmp=act->next; tmp; tmp=tmp->next) { + if (tmp->flag & ACT_VISIBLE) + break; + } + if (tmp) { + BLI_remlink(&ob->actuators, act); + BLI_insertlink(&ob->actuators, tmp, act); + } + } +} -- cgit v1.2.3 From 96a7e478b6ef0c9f4b15e27ab22db548bbab1fe5 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Sat, 10 Jul 2010 21:15:10 +0000 Subject: 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 --- source/blender/blenkernel/intern/sca.c | 85 ++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 29 deletions(-) (limited to 'source/blender/blenkernel/intern/sca.c') 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; atotlinks; 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; atotlinks; 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; + } +} -- cgit v1.2.3 From f91f4d317615889d086d79161c9906b11879e9d3 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Sat, 10 Jul 2010 23:21:25 +0000 Subject: Fix type mismatch. --- source/blender/blenkernel/intern/sca.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/sca.c') diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index 12d1dfc83b0..61e98ce9d45 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -659,7 +659,7 @@ void sca_remove_ob_poin(Object *obt, Object *ob) } /* ******************** INTERFACE ******************* */ -void sca_move_sensor(bSensor *sens_to_move, Object *ob, int *move_up) +void sca_move_sensor(bSensor *sens_to_move, Object *ob, int move_up) { bSensor *sens, *tmp; -- cgit v1.2.3