~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/SCA_IActuator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: SCA_IActuator.cpp 15444 2008-07-05 17:05:05Z lukep $
 
2
 * $Id: SCA_IActuator.cpp 20286 2009-05-20 08:45:42Z ben2610 $
3
3
 * ***** BEGIN GPL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
36
36
 
37
37
SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj,
38
38
                                                         PyTypeObject* T) :
 
39
        SCA_ILogicBrick(gameobj,T),
39
40
        m_links(0),
40
 
        SCA_ILogicBrick(gameobj,T) 
 
41
        m_posevent(false),
 
42
        m_negevent(false)
41
43
{
42
44
        // nothing to do
43
45
}
44
46
 
45
 
 
46
 
 
47
 
void SCA_IActuator::AddEvent(CValue* event)
48
 
{
49
 
        m_events.push_back(event);
50
 
}
51
 
 
52
 
 
53
 
 
54
 
void SCA_IActuator::RemoveAllEvents()
55
 
{       // remove event queue!
56
 
        for (vector<CValue*>::iterator i=m_events.begin(); !(i==m_events.end());i++)
57
 
        {
58
 
                (*i)->Release();
59
 
        }
60
 
        m_events.clear();
61
 
}
62
 
 
63
 
 
64
 
 
65
 
 
66
 
 
67
 
bool SCA_IActuator::IsNegativeEvent() const
68
 
{
69
 
        bool bPositiveEvent(false);
70
 
        bool bNegativeEvent(false);
71
 
 
72
 
        for (vector<CValue*>::const_iterator i=m_events.begin(); i!=m_events.end();++i)
73
 
        {
74
 
                if ((*i)->GetNumber() == 0.0f)
75
 
                {
76
 
                        bNegativeEvent = true;
77
 
                } else {
78
 
                        bPositiveEvent = true;
79
 
                }
80
 
        }
81
 
 
82
 
        // if at least 1 positive event, return false
83
 
        
84
 
        return !bPositiveEvent && bNegativeEvent;
85
 
}
86
 
 
87
47
bool SCA_IActuator::Update(double curtime, bool frame)
88
48
{
89
49
        if (frame)
98
58
        return false;
99
59
}
100
60
 
 
61
void SCA_IActuator::Activate(SG_DList& head)
 
62
{
 
63
        if (QEmpty())
 
64
        {
 
65
                InsertActiveQList(m_gameobj->m_activeActuators);
 
66
                head.AddBack(&m_gameobj->m_activeActuators);
 
67
        }
 
68
}
 
69
 
 
70
// this function is only used to deactivate actuators outside the logic loop
 
71
// e.g. when an object is deleted.
 
72
void SCA_IActuator::Deactivate()
 
73
{
 
74
        if (QDelink())
 
75
        {
 
76
                // the actuator was in the active list
 
77
                if (m_gameobj->m_activeActuators.QEmpty())
 
78
                        // the owner object has no more active actuators, remove it from the global list
 
79
                        m_gameobj->m_activeActuators.Delink();
 
80
        }
 
81
}
 
82
 
 
83
 
101
84
void SCA_IActuator::ProcessReplica()
102
85
{
103
 
        m_events.clear();
 
86
        SCA_ILogicBrick::ProcessReplica();
 
87
        RemoveAllEvents();
 
88
        m_linkedcontrollers.clear();
104
89
}
105
90
 
106
91
 
119
104
                m_links = 0;
120
105
        }
121
106
}
 
107
 
 
108
void SCA_IActuator::LinkToController(SCA_IController* controller)
 
109
{
 
110
        m_linkedcontrollers.push_back(controller);
 
111
}
 
112
 
 
113
void SCA_IActuator::UnlinkController(SCA_IController* controller)
 
114
{
 
115
        std::vector<class SCA_IController*>::iterator contit;
 
116
        for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
 
117
        {
 
118
                if ((*contit) == controller)
 
119
                {
 
120
                        *contit = m_linkedcontrollers.back();
 
121
                        m_linkedcontrollers.pop_back();
 
122
                        return;
 
123
                }
 
124
        }
 
125
        printf("Missing link from actuator %s:%s to controller %s:%s\n", 
 
126
                m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(), 
 
127
                controller->GetParent()->GetName().ReadPtr(), controller->GetName().ReadPtr());
 
128
}
 
129
 
 
130
void SCA_IActuator::UnlinkAllControllers()
 
131
{
 
132
        std::vector<class SCA_IController*>::iterator contit;
 
133
        for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
 
134
        {
 
135
                (*contit)->UnlinkActuator(this);
 
136
        }
 
137
        m_linkedcontrollers.clear();
 
138
}
 
139