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

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/SCA_ExpressionController.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
2
 * 'Expression Controller enables to calculate an expression that wires inputs to output
3
3
 *
4
 
 * $Id: SCA_ExpressionController.cpp 15444 2008-07-05 17:05:05Z lukep $
 
4
 * $Id: SCA_ExpressionController.cpp 20130 2009-05-10 20:53:58Z ben2610 $
5
5
 *
6
6
 * ***** BEGIN GPL LICENSE BLOCK *****
7
7
 *
49
49
                                                                                                   const STR_String& exprtext,
50
50
                                                                                                   PyTypeObject* T)
51
51
        :SCA_IController(gameobj,T),
52
 
        m_exprText(exprtext)
 
52
        m_exprText(exprtext),
 
53
        m_exprCache(NULL)
53
54
{
54
55
}
55
56
 
57
58
 
58
59
SCA_ExpressionController::~SCA_ExpressionController()
59
60
{
 
61
        if (m_exprCache)
 
62
                m_exprCache->Release();
60
63
}
61
64
 
62
65
 
65
68
{
66
69
        SCA_ExpressionController* replica = new SCA_ExpressionController(*this);
67
70
        replica->m_exprText = m_exprText;
 
71
        replica->m_exprCache = NULL;
68
72
        // this will copy properties and so on...
69
 
        CValue::AddDataToReplica(replica);
 
73
        replica->ProcessReplica();
70
74
 
71
75
        return replica;
72
76
}
73
77
 
74
78
 
 
79
// Forced deletion of precalculated expression to break reference loop
 
80
// Use this function when you know that you won't use the sensor anymore
 
81
void SCA_ExpressionController::Delete()
 
82
{
 
83
        if (m_exprCache)
 
84
        {
 
85
                m_exprCache->Release();
 
86
                m_exprCache = NULL;
 
87
        }
 
88
        Release();
 
89
}
 
90
 
75
91
 
76
92
void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
77
93
{
78
94
 
79
95
        bool expressionresult = false;
80
 
 
81
 
        CParser parser;
82
 
        parser.SetContext(this->AddRef());
83
 
        CExpression* expr = parser.ProcessText(m_exprText);
84
 
        if (expr)
85
 
        {
86
 
                CValue* value = expr->Calculate();
 
96
        if (!m_exprCache)
 
97
        {
 
98
                CParser parser;
 
99
                parser.SetContext(this->AddRef());
 
100
                m_exprCache = parser.ProcessText(m_exprText);
 
101
        }
 
102
        if (m_exprCache)
 
103
        {
 
104
                CValue* value = m_exprCache->Calculate();
87
105
                if (value)
88
106
                {
89
107
                        if (value->IsError())
91
109
                                printf(value->GetText());
92
110
                        } else
93
111
                        {
94
 
                                float num = value->GetNumber();
 
112
                                float num = (float)value->GetNumber();
95
113
                                expressionresult = !MT_fuzzyZero(num);
96
114
                        }
97
115
                        value->Release();
98
116
 
99
117
                }
100
 
                expr->Release();
101
 
        }
102
 
 
103
 
        /*
104
 
 
105
 
        for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
106
 
        !(is==m_linkedsensors.end());is++)
107
 
        {
108
 
                SCA_ISensor* sensor = *is;
109
 
                if (!sensor->IsPositiveTrigger())
110
 
                {
111
 
                        sensorresult = false;
112
 
                        break;
113
 
                }
114
 
        }
115
 
        
116
 
          */
117
 
        
118
 
        CValue* newevent = new CBoolValue(expressionresult);
 
118
        }
119
119
 
120
120
        for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
121
121
        !(i==m_linkedactuators.end());i++)
122
122
        {
123
123
                SCA_IActuator* actua = *i;
124
 
                logicmgr->AddActiveActuator(actua,newevent);
 
124
                logicmgr->AddActiveActuator(actua,expressionresult);
125
125
        }
126
 
        //printf("expr %d.",expressionresult);
127
 
        // every actuator that needs the event, has a it's own reference to it now so
128
 
        // release it (so to be clear: if there is no actuator, it's deleted right now)
129
 
        newevent->Release();
130
126
}
131
127
 
132
128
 
142
138
                SCA_ISensor* sensor = *is;
143
139
                if (sensor->GetName() == identifiername)
144
140
                {
145
 
                        identifierval = new CBoolValue(sensor->IsPositiveTrigger());
 
141
                        identifierval = new CBoolValue(sensor->GetState());
146
142
                        //identifierval = sensor->AddRef();
147
143
                }
148
144