svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r20849:20855
[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 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 //////////////////////////////////////////////////////////////////////
23 // Construction/Destruction
24 //////////////////////////////////////////////////////////////////////
25
26 COperator1Expr::COperator1Expr()
27 /*
28 pre:
29 effect: constucts an empty COperator1Expr
30 */
31 {
32         m_lhs = NULL;
33 }
34
35 COperator1Expr::COperator1Expr(VALUE_OPERATOR op, CExpression * lhs)
36 /*
37 pre:
38 effect: constucts a COperator1Expr with op and lhs in it
39 */
40 {
41         m_lhs = lhs;
42         m_op = op;
43 }
44
45 COperator1Expr::~COperator1Expr()
46 /*
47 pre:
48 effect: deletes the object
49 */
50 {
51         if (m_lhs) m_lhs->Release();
52 }
53
54 CValue * COperator1Expr::Calculate()
55 /*
56 pre:
57 ret: a new object containing the result of applying the operator m_op to the
58          value of m_lhs
59 */
60 {
61         CValue *ret;
62         CValue *temp = m_lhs->Calculate();
63         CValue* empty = new CEmptyValue();
64         ret = empty->Calc(m_op, temp);
65         empty->Release();
66         temp->Release();
67         
68         return ret;
69 }
70
71 /*
72 bool COperator1Expr::IsInside(float x, float y, float z,bool bBorderInclude)
73 {
74
75         bool result = true;
76         switch (m_op)
77         {
78                 
79         case VALUE_ADD_OPERATOR:
80                 {
81                         
82                         if (m_lhs)
83                         {
84                                 result = result || m_lhs->IsInside(x,y,z,bBorderInclude);
85                         }
86                         break;
87                 }
88         case VALUE_SUB_OPERATOR:
89                 {
90                         result = true;
91                         if (m_lhs)
92                         {
93                                 result = result && (!m_lhs->IsInside(x,y,z,bBorderInclude));
94                         }
95                         break;
96                 }
97         }
98         return result;
99 }
100
101 */
102 bool COperator1Expr::NeedsRecalculated() {
103         
104         return m_lhs->NeedsRecalculated();
105
106 }
107
108 CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) {
109
110         CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
111
112         if (newlhs)
113         {
114                 if (newlhs==m_lhs) {
115                         // not changed
116                 } else {
117                         // changed
118                         //numchanges++;
119                         newlhs->AddRef();
120                         
121                         //m_lhs->Release();
122                         brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
123
124                         m_lhs = newlhs;
125                 }
126                 return this;
127         } else {
128                 //numchanges++;
129                 AddRef();
130
131                 return Release();
132         }
133         
134 }
135
136 void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op)
137 {
138         if (m_lhs)
139                 m_lhs->BroadcastOperators(m_op);
140 }
141
142
143
144
145 bool COperator1Expr::MergeExpression(CExpression *otherexpr)
146 {
147         if (m_lhs)
148                 return m_lhs->MergeExpression(otherexpr);
149         
150         assertd(false); // should not get here, expression is not compatible for merge
151         return false;
152 }