~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/gameengine/Converter/BL_ActionActuator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
* $Id: BL_ActionActuator.cpp,v 1.5 2004/03/22 22:01:25 jesterking Exp $
 
2
* $Id: BL_ActionActuator.cpp,v 1.12 2004/12/05 02:50:57 kester Exp $
3
3
*
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
30
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
31
31
*/
32
32
 
 
33
#if defined (__sgi)
 
34
#include <math.h>
 
35
#else
 
36
#include <cmath>
 
37
#endif
 
38
 
33
39
#include "SCA_LogicManager.h"
34
40
#include "BL_ActionActuator.h"
35
41
#include "BL_ArmatureObject.h"
77
83
        
78
84
        m_pose = NULL;
79
85
        m_blendpose = NULL;
80
 
        m_localtime=m_starttime;
 
86
        m_localtime=m_startframe;
81
87
        m_lastUpdate=-1;
82
88
        
83
89
}
93
99
        // this will copy properties and so on...
94
100
        CValue::AddDataToReplica(replica);
95
101
        return replica;
96
 
};
97
 
 
98
 
bool BL_ActionActuator::Update(double curtime,double deltatime)
 
102
}
 
103
 
 
104
bool BL_ActionActuator::ClampLocalTime()
 
105
{
 
106
        if (m_startframe < m_endframe)
 
107
        {
 
108
                if (m_localtime < m_startframe)
 
109
                {
 
110
                        m_localtime = m_startframe;
 
111
                        return true;
 
112
                } 
 
113
                else if (m_localtime > m_endframe)
 
114
                {
 
115
                        m_localtime = m_endframe;
 
116
                        return true;
 
117
                }
 
118
        } else {
 
119
                if (m_localtime > m_startframe)
 
120
                {
 
121
                        m_localtime = m_startframe;
 
122
                        return true;
 
123
                }
 
124
                else if (m_localtime < m_endframe)
 
125
                {
 
126
                        m_localtime = m_endframe;
 
127
                        return true;
 
128
                }
 
129
        }
 
130
        return false;
 
131
}
 
132
 
 
133
void BL_ActionActuator::SetStartTime(float curtime)
 
134
{
 
135
        float direction = m_startframe < m_endframe ? 1.0 : -1.0;
 
136
        
 
137
        if (!(m_flag & ACT_FLAG_REVERSE))
 
138
                m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_FIXED_FRAME_PER_SEC;
 
139
        else
 
140
                m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_FIXED_FRAME_PER_SEC;
 
141
}
 
142
 
 
143
void BL_ActionActuator::SetLocalTime(float curtime)
 
144
{
 
145
        float delta_time = (curtime - m_starttime)*KX_FIXED_FRAME_PER_SEC;
 
146
        
 
147
        if (m_endframe < m_startframe)
 
148
                delta_time = -delta_time;
 
149
 
 
150
        if (!(m_flag & ACT_FLAG_REVERSE))
 
151
                m_localtime = m_startframe + delta_time;
 
152
        else
 
153
                m_localtime = m_endframe - delta_time;
 
154
}
 
155
 
 
156
 
 
157
bool BL_ActionActuator::Update(double curtime, bool frame)
99
158
{
100
159
        bool bNegativeEvent = false;
101
160
        bool bPositiveEvent = false;
107
166
        
108
167
        // result = true if animation has to be continued, false if animation stops
109
168
        // maybe there are events for us in the queue !
110
 
        
111
 
        for (vector<CValue*>::iterator i=m_events.end(); !(i==m_events.begin());)
 
169
        if (frame)
112
170
        {
113
 
                i--;
114
 
                if ((*i)->GetNumber() == 0.0f)
115
 
                {
116
 
                        bNegativeEvent = true;
117
 
                }
118
 
                else
119
 
                        bPositiveEvent= true;
120
 
                (*i)->Release();
121
 
                m_events.pop_back();
 
171
                for (vector<CValue*>::iterator i=m_events.end(); !(i==m_events.begin());)
 
172
                {
 
173
                        i--;
 
174
                        if ((*i)->GetNumber() == 0.0f)
 
175
                                bNegativeEvent = true;
 
176
                        else
 
177
                                bPositiveEvent= true;
 
178
                        (*i)->Release();
 
179
                        m_events.pop_back();
 
180
                }
 
181
                
 
182
                if (bPositiveEvent)
 
183
                        m_flag |= ACT_FLAG_ACTIVE;
 
184
                
 
185
                if (bNegativeEvent)
 
186
                {
 
187
                        if (!(m_flag & ACT_FLAG_ACTIVE))
 
188
                                return false;
 
189
                        m_flag &= ~ACT_FLAG_ACTIVE;
 
190
                }
122
191
        }
123
192
        
124
193
        /*      We know that action actuators have been discarded from all non armature objects:
125
194
        if we're being called, we're attached to a BL_ArmatureObject */
126
195
        BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
127
 
        float length = m_endtime - m_starttime;
 
196
        float length = m_endframe - m_startframe;
128
197
        
129
198
        priority = m_priority;
130
199
        
148
217
                                m_flag &= ~ACT_FLAG_KEYUP;
149
218
                                m_flag &= ~ACT_FLAG_REVERSE;
150
219
                                m_flag |= ACT_FLAG_LOCKINPUT;
151
 
                                m_localtime = m_starttime;
 
220
                                m_localtime = m_startframe;
 
221
                                m_starttime = curtime;
152
222
                        }
153
223
                }
154
224
                if (bNegativeEvent){
159
229
                if (bPositiveEvent){
160
230
                        if (!(m_flag & ACT_FLAG_LOCKINPUT)){
161
231
                                m_flag &= ~ACT_FLAG_REVERSE;
 
232
                                m_flag &= ~ACT_FLAG_KEYUP;
 
233
                                m_flag |= ACT_FLAG_LOCKINPUT;
 
234
                                SetStartTime(curtime);
162
235
                        }
163
236
                }
164
237
                if (bNegativeEvent){
 
238
                        m_flag |= ACT_FLAG_KEYUP;
 
239
                        m_flag &= ~ACT_FLAG_LOCKINPUT;
165
240
                        keepgoing=false;
166
241
                        apply=false;
167
242
                }
170
245
                if (bPositiveEvent){
171
246
                        if (!(m_flag & ACT_FLAG_LOCKINPUT)){
172
247
                                m_flag &= ~ACT_FLAG_REVERSE;
 
248
                                m_flag |= ACT_FLAG_LOCKINPUT;
 
249
                                SetStartTime(curtime);
173
250
                        }
174
251
                }
175
252
                else if (bNegativeEvent){
176
253
                        m_flag |= ACT_FLAG_REVERSE;
 
254
                        m_flag &= ~ACT_FLAG_LOCKINPUT;
 
255
                        SetStartTime(curtime);
177
256
                }
178
257
                break;
179
258
        case ACT_ACTION_PLAY:
181
260
                        if (!(m_flag & ACT_FLAG_LOCKINPUT)){
182
261
                                m_flag &= ~ACT_FLAG_REVERSE;
183
262
                                m_localtime = m_starttime;
 
263
                                m_starttime = curtime;
184
264
                                m_flag |= ACT_FLAG_LOCKINPUT;
185
265
                        }
186
266
                }
203
283
                        m_lastpos = newpos;
204
284
                }
205
285
                else{
206
 
                        if (m_flag & ACT_FLAG_REVERSE)
207
 
                                m_localtime -= deltatime* KX_FIXED_FRAME_PER_SEC;
208
 
                        else
209
 
                                m_localtime += deltatime* KX_FIXED_FRAME_PER_SEC;
 
286
                        SetLocalTime(curtime);
210
287
                }
211
288
        }
212
289
        
213
290
        /* Check if a wrapping response is needed */
214
291
        if (length){
215
 
                if (m_flag & ACT_FLAG_REVERSE){
216
 
                        if (m_localtime < m_starttime){
217
 
                                m_localtime = m_endtime+(
218
 
                                        (int)((m_localtime - m_starttime)/length)
219
 
                                        *(int)length);
220
 
                                wrap = true;
221
 
                        }                       
222
 
                }
223
 
                else{
224
 
                        if (m_localtime > m_endtime){
225
 
                                m_localtime = m_starttime+(
226
 
                                        (int)((m_localtime - m_endtime)/length)
227
 
                                        *(int)length);
228
 
                                wrap = true;
229
 
                        }
230
 
                }
231
 
                
 
292
                if (m_localtime < m_startframe || m_localtime > m_endframe)
 
293
                {
 
294
                        m_localtime = m_startframe + fmod(m_localtime, length);
 
295
                        wrap = true;
 
296
                }
232
297
        }
233
298
        else
234
 
                m_localtime = m_starttime;
 
299
                m_localtime = m_startframe;
235
300
        
236
301
        /* Perform post-increment tasks */
237
302
        switch (m_playtype){
238
303
        case ACT_ACTION_FROM_PROP:
239
304
                {
240
305
                        CValue* propval = GetParent()->GetProperty(m_propname);
241
 
                        if (propval)             {
 
306
                        if (propval)
242
307
                                m_localtime = propval->GetNumber();
243
 
                        };
244
308
                        
245
309
                        if (bNegativeEvent){
246
310
                                keepgoing=false;
254
318
        case ACT_ACTION_FLIPPER:
255
319
                if (wrap){
256
320
                        if (!(m_flag & ACT_FLAG_REVERSE)){
257
 
                                m_localtime=m_endtime;
258
 
                                keepgoing = false;
 
321
                                m_localtime=m_endframe;
 
322
                                //keepgoing = false;
259
323
                        }
260
324
                        else {
261
 
                                m_localtime=m_starttime;
 
325
                                m_localtime=m_startframe;
262
326
                                keepgoing = false;
263
327
                        }
264
328
                }
267
331
                if (wrap){
268
332
                        if (m_flag & ACT_FLAG_KEYUP){
269
333
                                keepgoing = false;
270
 
                                m_localtime = m_endtime;
 
334
                                m_localtime = m_endframe;
271
335
                                m_flag &= ~ACT_FLAG_LOCKINPUT;
272
336
                        }
 
337
                        SetStartTime(curtime);
273
338
                }
274
339
                break;
275
340
        case ACT_ACTION_PLAY:
276
341
                if (wrap){
277
 
                        m_localtime = m_endtime;
 
342
                        m_localtime = m_endframe;
278
343
                        keepgoing = false;
279
344
                        m_flag &= ~ACT_FLAG_LOCKINPUT;
280
345
                }
285
350
        }
286
351
        
287
352
        
288
 
        if (bNegativeEvent){
 
353
        if (bNegativeEvent)
289
354
                m_blendframe=0.0;
290
 
                
291
 
        }
292
 
        
293
355
        
294
356
        /* Apply the pose if necessary*/
295
357
        if (apply){
316
378
                                /* If this is the start of a blending sequence... */
317
379
                                if ((m_blendframe==0.0) || (!m_blendpose)){
318
380
                                        obj->GetMRDPose(&m_blendpose);
 
381
                                        m_blendstart = curtime;
319
382
                                }
320
383
                                
321
384
                                /* Find percentages */
323
386
                                blend_poses(m_pose, m_blendpose, 1.0 - newweight, POSE_BLEND);
324
387
 
325
388
                                /* Increment current blending percentage */
326
 
                                m_blendframe+=(deltatime*KX_FIXED_FRAME_PER_SEC);
 
389
                                m_blendframe = (curtime - m_blendstart)*KX_FIXED_FRAME_PER_SEC;
327
390
                                if (m_blendframe>m_blendin)
328
391
                                        m_blendframe = m_blendin;
329
392
                                
395
458
        {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc},
396
459
        {"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc},
397
460
//      {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS},
398
 
        
 
461
        {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},    
 
462
        {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, SetType_doc},
399
463
        {NULL,NULL} //Sentinel
400
464
};
401
465
 
402
 
PyObject* BL_ActionActuator::_getattr(char* attr) {
 
466
PyObject* BL_ActionActuator::_getattr(const STR_String& attr) {
403
467
        _getattr_up(SCA_IActuator);
404
468
}
405
469
 
464
528
                                                                          PyObject* kwds) {
465
529
        PyObject *result;
466
530
        
467
 
        result = Py_BuildValue("f", m_endtime);
 
531
        result = Py_BuildValue("f", m_endframe);
468
532
        
469
533
        return result;
470
534
}
479
543
                                                                                PyObject* kwds) {
480
544
        PyObject *result;
481
545
        
482
 
        result = Py_BuildValue("f", m_starttime);
 
546
        result = Py_BuildValue("f", m_startframe);
483
547
        
484
548
        return result;
485
549
}
565
629
        
566
630
        if (PyArg_ParseTuple(args,"f",&start))
567
631
        {
568
 
                m_starttime = start;
 
632
                m_startframe = start;
569
633
        }
570
634
        
571
635
        Py_INCREF(Py_None);
584
648
        
585
649
        if (PyArg_ParseTuple(args,"f",&end))
586
650
        {
587
 
                m_endtime = end;
 
651
                m_endframe = end;
588
652
        }
589
653
        
590
654
        Py_INCREF(Py_None);
670
734
        if (PyArg_ParseTuple(args,"f",&frame))
671
735
        {
672
736
                m_localtime = frame;
673
 
                if (m_localtime<m_starttime)
674
 
                        m_localtime=m_starttime;
675
 
                else if (m_localtime>m_endtime)
676
 
                        m_localtime=m_endtime;
 
737
                if (m_localtime<m_startframe)
 
738
                        m_localtime=m_startframe;
 
739
                else if (m_localtime>m_endframe)
 
740
                        m_localtime=m_endframe;
677
741
        }
678
742
        
679
743
        Py_INCREF(Py_None);
805
869
        return Py_None;
806
870
}
807
871
 
 
872
/* getType */
 
873
char BL_ActionActuator::GetType_doc[] =
 
874
"getType()\n"
 
875
"\tReturns the operation mode of the actuator.\n";
 
876
PyObject* BL_ActionActuator::PyGetType(PyObject* self,
 
877
                                       PyObject* args, 
 
878
                                       PyObject* kwds) {
 
879
    return Py_BuildValue("h", m_playtype);
 
880
}
 
881
 
 
882
/* setType */
 
883
char BL_ActionActuator::SetType_doc[] =
 
884
"setType(mode)\n"
 
885
"\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n"
 
886
"\tSet the operation mode of the actuator.\n";
 
887
PyObject* BL_ActionActuator::PySetType(PyObject* self,
 
888
                                       PyObject* args,
 
889
                                       PyObject* kwds) {
 
890
        short typeArg;
 
891
                                                                                                             
 
892
    if (!PyArg_ParseTuple(args, "h", &typeArg)) {
 
893
        return NULL;
 
894
    }
 
895
 
 
896
        switch (typeArg) {
 
897
        case KX_ACT_ACTION_PLAY:
 
898
        case KX_ACT_ACTION_FLIPPER:
 
899
        case KX_ACT_ACTION_LOOPSTOP:
 
900
        case KX_ACT_ACTION_LOOPEND:
 
901
        case KX_ACT_ACTION_PROPERTY:
 
902
                m_playtype = typeArg;
 
903
                break;
 
904
        default:
 
905
                printf("Invalid type for action actuator: %d\n", typeArg); /* error */
 
906
    }
 
907
        
 
908
    Py_Return;
 
909
}
 
910