1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
|
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
* these all are linked to objects (listbase)
* all data is 'direct data', not Blender lib data.
*/
#include <stdio.h>
#include <string.h>
#include <float.h>
#include "MEM_guardedalloc.h"
#include "DNA_controller_types.h"
#include "DNA_sensor_types.h"
#include "DNA_actuator_types.h"
#include "DNA_object_types.h"
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_library.h"
#include "BKE_sca.h"
/* ******************* SENSORS ************************ */
void free_sensor(bSensor *sens)
{
if(sens->links) MEM_freeN(sens->links);
if(sens->data) MEM_freeN(sens->data);
MEM_freeN(sens);
}
void free_sensors(ListBase *lb)
{
bSensor *sens;
while((sens= lb->first)) {
BLI_remlink(lb, sens);
free_sensor(sens);
}
}
bSensor *copy_sensor(bSensor *sens)
{
bSensor *sensn;
sensn= MEM_dupallocN(sens);
sensn->flag |= SENS_NEW;
if(sens->data) {
sensn->data= MEM_dupallocN(sens->data);
}
if(sens->links) sensn->links= MEM_dupallocN(sens->links);
return sensn;
}
void copy_sensors(ListBase *lbn, ListBase *lbo)
{
bSensor *sens, *sensn;
lbn->first= lbn->last= 0;
sens= lbo->first;
while(sens) {
sensn= copy_sensor(sens);
BLI_addtail(lbn, sensn);
sens= sens->next;
}
}
void init_sensor(bSensor *sens)
{
/* also use when sensor changes type */
bNearSensor *ns;
bMouseSensor *ms;
bJoystickSensor *js;
bRaySensor *rs;
if(sens->data) MEM_freeN(sens->data);
sens->data= NULL;
sens->pulse = 0;
switch(sens->type) {
case SENS_ALWAYS:
sens->pulse = 0;
break;
case SENS_TOUCH:
sens->data= MEM_callocN(sizeof(bTouchSensor), "touchsens");
break;
case SENS_NEAR:
ns=sens->data= MEM_callocN(sizeof(bNearSensor), "nearsens");
ns->dist= 1.0;
ns->resetdist= 2.0;
break;
case SENS_KEYBOARD:
sens->data= MEM_callocN(sizeof(bKeyboardSensor), "keysens");
break;
case SENS_PROPERTY:
sens->data= MEM_callocN(sizeof(bPropertySensor), "propsens");
break;
case SENS_ARMATURE:
sens->data= MEM_callocN(sizeof(bArmatureSensor), "armsens");
break;
case SENS_ACTUATOR:
sens->data= MEM_callocN(sizeof(bActuatorSensor), "actsens");
break;
case SENS_DELAY:
sens->data= MEM_callocN(sizeof(bDelaySensor), "delaysens");
break;
case SENS_MOUSE:
ms=sens->data= MEM_callocN(sizeof(bMouseSensor), "mousesens");
ms->type= 1; // LEFTMOUSE workaround because Mouse Sensor types enum starts in 1
break;
case SENS_COLLISION:
sens->data= MEM_callocN(sizeof(bCollisionSensor), "colsens");
break;
case SENS_RADAR:
sens->data= MEM_callocN(sizeof(bRadarSensor), "radarsens");
break;
case SENS_RANDOM:
sens->data= MEM_callocN(sizeof(bRandomSensor), "randomsens");
break;
case SENS_RAY:
sens->data= MEM_callocN(sizeof(bRaySensor), "raysens");
rs = sens->data;
rs->range = 0.01f;
break;
case SENS_MESSAGE:
sens->data= MEM_callocN(sizeof(bMessageSensor), "messagesens");
break;
case SENS_JOYSTICK:
sens->data= MEM_callocN(sizeof(bJoystickSensor), "joysticksens");
js= sens->data;
js->hatf = SENS_JOY_HAT_UP;
js->axis = 1;
js->hat = 1;
break;
default:
; /* this is very severe... I cannot make any memory for this */
/* logic brick... */
}
}
bSensor *new_sensor(int type)
{
bSensor *sens;
sens= MEM_callocN(sizeof(bSensor), "Sensor");
sens->type= type;
sens->flag= SENS_SHOW;
init_sensor(sens);
strcpy(sens->name, "sensor");
// XXX make_unique_prop_names(sens->name);
return sens;
}
/* ******************* CONTROLLERS ************************ */
void unlink_controller(bController *cont)
{
bSensor *sens;
Object *ob;
/* check for controller pointers in sensors */
ob= G.main->object.first;
while(ob) {
sens= ob->sensors.first;
while(sens) {
unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
sens= sens->next;
}
ob= ob->id.next;
}
}
void unlink_controllers(ListBase *lb)
{
bController *cont;
for (cont= lb->first; cont; cont= cont->next)
unlink_controller(cont);
}
void free_controller(bController *cont)
{
if(cont->links) MEM_freeN(cont->links);
/* the controller itself */
if(cont->data) MEM_freeN(cont->data);
MEM_freeN(cont);
}
void free_controllers(ListBase *lb)
{
bController *cont;
while((cont= lb->first)) {
BLI_remlink(lb, cont);
if(cont->slinks) MEM_freeN(cont->slinks);
free_controller(cont);
}
}
bController *copy_controller(bController *cont)
{
bController *contn;
cont->mynew=contn= MEM_dupallocN(cont);
contn->flag |= CONT_NEW;
if(cont->data) {
contn->data= MEM_dupallocN(cont->data);
}
if(cont->links) contn->links= MEM_dupallocN(cont->links);
contn->slinks= NULL;
contn->totslinks= 0;
return contn;
}
void copy_controllers(ListBase *lbn, ListBase *lbo)
{
bController *cont, *contn;
lbn->first= lbn->last= 0;
cont= lbo->first;
while(cont) {
contn= copy_controller(cont);
BLI_addtail(lbn, contn);
cont= cont->next;
}
}
void init_controller(bController *cont)
{
/* also use when controller changes type, leave actuators... */
if(cont->data) MEM_freeN(cont->data);
cont->data= 0;
switch(cont->type) {
case CONT_EXPRESSION:
cont->data= MEM_callocN(sizeof(bExpressionCont), "expcont");
break;
case CONT_PYTHON:
cont->data= MEM_callocN(sizeof(bPythonCont), "pycont");
break;
}
}
bController *new_controller(int type)
{
bController *cont;
cont= MEM_callocN(sizeof(bController), "Controller");
cont->type= type;
cont->flag= CONT_SHOW;
init_controller(cont);
strcpy(cont->name, "cont");
// XXX make_unique_prop_names(cont->name);
return cont;
}
/* ******************* ACTUATORS ************************ */
void unlink_actuator(bActuator *act)
{
bController *cont;
Object *ob;
/* check for actuator pointers in controllers */
ob= G.main->object.first;
while(ob) {
cont= ob->controllers.first;
while(cont) {
unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
cont= cont->next;
}
ob= ob->id.next;
}
}
void unlink_actuators(ListBase *lb)
{
bActuator *act;
for (act= lb->first; act; act= act->next)
unlink_actuator(act);
}
void free_actuator(bActuator *act)
{
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);
}
void free_actuators(ListBase *lb)
{
bActuator *act;
while((act= lb->first)) {
BLI_remlink(lb, act);
free_actuator(act);
}
}
bActuator *copy_actuator(bActuator *act)
{
bActuator *actn;
bSoundActuator *sa;
act->mynew=actn= MEM_dupallocN(act);
actn->flag |= ACT_NEW;
if(act->data) {
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;
}
void copy_actuators(ListBase *lbn, ListBase *lbo)
{
bActuator *act, *actn;
lbn->first= lbn->last= 0;
act= lbo->first;
while(act) {
actn= copy_actuator(act);
BLI_addtail(lbn, actn);
act= act->next;
}
}
void init_actuator(bActuator *act)
{
/* also use when actuator changes type */
bCameraActuator *ca;
bObjectActuator *oa;
bRandomActuator *ra;
bSoundActuator *sa;
bSteeringActuator *sta;
if(act->data) MEM_freeN(act->data);
act->data= 0;
switch(act->type) {
case ACT_ACTION:
case ACT_SHAPEACTION:
act->data= MEM_callocN(sizeof(bActionActuator), "actionact");
break;
case ACT_SOUND:
sa = act->data= MEM_callocN(sizeof(bSoundActuator), "soundact");
sa->volume = 1.0f;
sa->sound3D.rolloff_factor = 1.0f;
sa->sound3D.reference_distance = 1.0f;
sa->sound3D.max_gain = 1.0f;
sa->sound3D.cone_inner_angle = 360.0f;
sa->sound3D.cone_outer_angle = 360.0f;
sa->sound3D.max_distance = FLT_MAX;
break;
case ACT_OBJECT:
act->data= MEM_callocN(sizeof(bObjectActuator), "objectact");
oa= act->data;
oa->flag= 15;
break;
case ACT_IPO:
act->data= MEM_callocN(sizeof(bIpoActuator), "ipoact");
break;
case ACT_PROPERTY:
act->data= MEM_callocN(sizeof(bPropertyActuator), "propact");
break;
case ACT_CAMERA:
act->data= MEM_callocN(sizeof(bCameraActuator), "camact");
ca = act->data;
ca->axis = ACT_CAMERA_X;
break;
case ACT_EDIT_OBJECT:
act->data= MEM_callocN(sizeof(bEditObjectActuator), "editobact");
break;
case ACT_CONSTRAINT:
act->data= MEM_callocN(sizeof(bConstraintActuator), "cons act");
break;
case ACT_SCENE:
act->data= MEM_callocN(sizeof(bSceneActuator), "scene act");
break;
case ACT_GROUP:
act->data= MEM_callocN(sizeof(bGroupActuator), "group act");
break;
case ACT_RANDOM:
act->data= MEM_callocN(sizeof(bRandomActuator), "random act");
ra=act->data;
ra->float_arg_1 = 0.1f;
break;
case ACT_MESSAGE:
act->data= MEM_callocN(sizeof(bMessageActuator), "message act");
break;
case ACT_GAME:
act->data= MEM_callocN(sizeof(bGameActuator), "game act");
break;
case ACT_VISIBILITY:
act->data= MEM_callocN(sizeof(bVisibilityActuator), "visibility act");
break;
case ACT_2DFILTER:
act->data = MEM_callocN(sizeof( bTwoDFilterActuator ), "2d filter act");
break;
case ACT_PARENT:
act->data = MEM_callocN(sizeof( bParentActuator ), "parent act");
break;
case ACT_STATE:
act->data = MEM_callocN(sizeof( bStateActuator ), "state act");
break;
case ACT_ARMATURE:
act->data = MEM_callocN(sizeof( bArmatureActuator ), "armature act");
break;
case ACT_STEERING:
act->data = MEM_callocN(sizeof( bSteeringActuator), "steering act");
sta = act->data;
sta->acceleration = 3;
sta->turnspeed = 120;
default:
; /* this is very severe... I cannot make any memory for this */
/* logic brick... */
}
}
bActuator *new_actuator(int type)
{
bActuator *act;
act= MEM_callocN(sizeof(bActuator), "Actuator");
act->type= type;
act->flag= ACT_SHOW;
init_actuator(act);
strcpy(act->name, "act");
// XXX make_unique_prop_names(act->name);
return act;
}
/* ******************** GENERAL ******************* */
void clear_sca_new_poins_ob(Object *ob)
{
bSensor *sens;
bController *cont;
bActuator *act;
sens= ob->sensors.first;
while(sens) {
sens->flag &= ~SENS_NEW;
sens= sens->next;
}
cont= ob->controllers.first;
while(cont) {
cont->mynew= NULL;
cont->flag &= ~CONT_NEW;
cont= cont->next;
}
act= ob->actuators.first;
while(act) {
act->mynew= NULL;
act->flag &= ~ACT_NEW;
act= act->next;
}
}
void clear_sca_new_poins()
{
Object *ob;
ob= G.main->object.first;
while(ob) {
clear_sca_new_poins_ob(ob);
ob= ob->id.next;
}
}
void set_sca_new_poins_ob(Object *ob)
{
bSensor *sens;
bController *cont;
bActuator *act;
int a;
sens= ob->sensors.first;
while(sens) {
if(sens->flag & SENS_NEW) {
for(a=0; a<sens->totlinks; a++) {
if(sens->links[a] && sens->links[a]->mynew)
sens->links[a]= sens->links[a]->mynew;
}
}
sens= sens->next;
}
cont= ob->controllers.first;
while(cont) {
if(cont->flag & CONT_NEW) {
for(a=0; a<cont->totlinks; a++) {
if( cont->links[a] && cont->links[a]->mynew)
cont->links[a]= cont->links[a]->mynew;
}
}
cont= cont->next;
}
act= ob->actuators.first;
while(act) {
if(act->flag & ACT_NEW) {
if(act->type==ACT_EDIT_OBJECT) {
bEditObjectActuator *eoa= act->data;
ID_NEW(eoa->ob);
}
else if(act->type==ACT_SCENE) {
bSceneActuator *sca= act->data;
ID_NEW(sca->camera);
}
else if(act->type==ACT_CAMERA) {
bCameraActuator *ca= act->data;
ID_NEW(ca->ob);
}
else if(act->type==ACT_OBJECT) {
bObjectActuator *oa= act->data;
ID_NEW(oa->reference);
}
else if(act->type==ACT_SCENE) {
bSceneActuator *sca= act->data;
ID_NEW(sca->camera);
}
}
act= act->next;
}
}
void set_sca_new_poins()
{
Object *ob;
ob= G.main->object.first;
while(ob) {
set_sca_new_poins_ob(ob);
ob= ob->id.next;
}
}
void sca_remove_ob_poin(Object *obt, Object *ob)
{
bSensor *sens;
bMessageSensor *ms;
bActuator *act;
bCameraActuator *ca;
bObjectActuator *oa;
bSceneActuator *sa;
bEditObjectActuator *eoa;
bPropertyActuator *pa;
bMessageActuator *ma;
bParentActuator *para;
bArmatureActuator *aa;
bSteeringActuator *sta;
sens= obt->sensors.first;
while(sens) {
switch(sens->type) {
case SENS_MESSAGE:
ms= sens->data;
if(ms->fromObject==ob) ms->fromObject= NULL;
}
sens= sens->next;
}
act= obt->actuators.first;
while(act) {
switch(act->type) {
case ACT_CAMERA:
ca= act->data;
if(ca->ob==ob) ca->ob= NULL;
break;
case ACT_OBJECT:
oa= act->data;
if(oa->reference==ob) oa->reference= NULL;
break;
case ACT_PROPERTY:
pa= act->data;
if(pa->ob==ob) pa->ob= NULL;
break;
case ACT_SCENE:
sa= act->data;
if(sa->camera==ob) sa->camera= NULL;
break;
case ACT_EDIT_OBJECT:
eoa= act->data;
if(eoa->ob==ob) eoa->ob= NULL;
break;
case ACT_MESSAGE:
ma= act->data;
if(ma->toObject==ob) ma->toObject= NULL;
break;
case ACT_PARENT:
para = act->data;
if (para->ob==ob) para->ob = NULL;
break;
case ACT_ARMATURE:
aa = act->data;
if (aa->target == ob) aa->target = NULL;
if (aa->subtarget == ob) aa->subtarget = NULL;
break;
case ACT_STEERING:
sta = act->data;
if (sta->target==ob) sta->target = NULL;
if (sta->navmesh==ob) sta->navmesh = NULL;
break;
}
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);
}
}
}
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;
}
}
|