fix for error when changing DISBALE_PYTHON -> WITH_PYTHON,
[blender.git] / source / gameengine / Expressions / Operator1Expr.cpp
1 // Operator1Expr.cpp: implementation of the COperator1Expr class.
2 /*
3  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
4  *
5  * Permission to use, copy, modify, distribute and sell this software
6  * and its documentation for any purpose is hereby granted without fee,
7  * provided that the above copyright notice appear in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation.  Erwin Coumans makes no
10  * representations about the suitability of this software for any
11  * purpose.  It is provided "as is" without express or implied warranty.
12  *
13  */
14
15 #include "Operator1Expr.h"
16 #include "EmptyValue.h"
17
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
21
22 COperator1Expr::COperator1Expr()
23 /*
24 pre:
25 effect: constucts an empty COperator1Expr
26 */
27 {
28         m_lhs = NULL;
29 }
30
31 COperator1Expr::COperator1Expr(VALUE_OPERATOR op, CExpression * lhs)
32 /*
33 pre:
34 effect: constucts a COperator1Expr with op and lhs in it
35 */
36 {
37         m_lhs = lhs;
38         m_op = op;
39 }
40
41 COperator1Expr::~COperator1Expr()
42 /*
43 pre:
44 effect: deletes the object
45 */
46 {
47         if (m_lhs) m_lhs->Release();
48 }
49
50 CValue * COperator1Expr::Calculate()
51 /*
52 pre:
53 ret: a new object containing the result of applying the operator m_op to the
54          value of m_lhs
55 */
56 {
57         CValue *ret;
58         CValue *temp = m_lhs->Calculate();
59         CValue* empty = new CEmptyValue();
60         ret = empty->Calc(m_op, temp);
61         empty->Release();
62         temp->Release();
63         
64         return ret;
65 }
66
67 /*
68 bool COperator1Expr::IsInside(float x, float y, float z,bool bBorderInclude)
69 {
70
71         bool result = true;
72         switch (m_op)
73         {
74                 
75         case VALUE_ADD_OPERATOR:
76                 {
77                         
78                         if (m_lhs)
79                         {
80                                 result = result || m_lhs->IsInside(x,y,z,bBorderInclude);
81                         }
82                         break;
83                 }
84         case VALUE_SUB_OPERATOR:
85                 {
86                         result = true;
87                         if (m_lhs)
88                         {
89                                 result = result && (!m_lhs->IsInside(x,y,z,bBorderInclude));
90                         }
91                         break;
92                 }
93         }
94         return result;
95 }
96
97 */
98 bool COperator1Expr::NeedsRecalculated() {
99         
100         return m_lhs->NeedsRecalculated();
101
102 }
103
104 CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) {
105
106         CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
107
108         if (newlhs)
109         {
110                 if (newlhs==m_lhs) {
111                         // not changed
112                 } else {
113                         // changed
114                         //numchanges++;
115                         newlhs->AddRef();
116                         
117                         //m_lhs->Release();
118                         brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
119
120                         m_lhs = newlhs;
121                 }
122                 return this;
123         } else {
124                 //numchanges++;
125                 AddRef();
126
127                 return Release();
128         }
129         
130 }
131
132 void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op)
133 {
134         if (m_lhs)
135                 m_lhs->BroadcastOperators(m_op);
136 }
137
138
139
140
141 bool COperator1Expr::MergeExpression(CExpression *otherexpr)
142 {
143         if (m_lhs)
144                 return m_lhs->MergeExpression(otherexpr);
145         
146         assertd(false); // should not get here, expression is not compatible for merge
147         return false;
148 }