Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SCA_ExpressionController.cpp

Go to the documentation of this file.
00001 
00006 
00007 
00008 #include "SCA_ExpressionController.h"
00009 #include "SCA_ISensor.h"
00010 #include "SCA_LogicManager.h"
00011 #include "BoolValue.h"
00012 #include "InputParser.h"
00013 
00014 #include "MT_Transform.h" // for fuzzyZero
00015 
00016 /* ------------------------------------------------------------------------- */
00017 /* Native functions                                                          */
00018 /* ------------------------------------------------------------------------- */
00019 
00020 void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)

00021 {
00022 
00023         bool expressionresult = false;
00024 
00025         CParser parser;
00026         parser.SetContext(this->AddRef());
00027         CExpression* expr = parser.ProcessText(m_exprText);
00028         if (expr)
00029         {
00030                 CValue* value = expr->Calculate();
00031                 if (value)
00032                 {
00033                         if (value->IsError())
00034                         {
00035                                 printf(value->GetText());
00036                         } else
00037                         {
00038                                 float num = value->GetNumber();
00039                                 expressionresult = !MT_fuzzyZero(num);
00040                         }
00041                         value->Release();
00042 
00043                 }
00044                 expr->Release();
00045         }
00046 
00047         /*
00048 
00049         for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();

00050         !(is==m_linkedsensors.end());is++)

00051         {

00052                 SCA_ISensor* sensor = *is;

00053                 if (!sensor->IsPositiveTrigger())

00054                 {

00055                         sensorresult = false;

00056                         break;

00057                 }

00058         }

00059         

00060           */
00061         
00062         CValue* newevent = new CBoolValue(expressionresult);
00063 
00064         for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
00065         !(i==m_linkedactuators.end());i++)
00066         {
00067                 SCA_IActuator* actua = *i;
00068                 logicmgr->AddActiveActuator(actua,newevent);
00069         }
00070         //printf("expr %d.",expressionresult);
00071         // every actuator that needs the event, has a it's own reference to it now so
00072         // release it (so to be clear: if there is no actuator, it's deleted right now)
00073         newevent->Release();
00074 
00075 }
00076 
00077 
00078 CValue* SCA_ExpressionController::FindIdentifier(const CCString& identifiername)

00079 {
00080 
00081         CValue* identifierval = NULL;
00082 
00083         for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
00084         !(is==m_linkedsensors.end());is++)
00085         {
00086                 SCA_ISensor* sensor = *is;
00087                 if (sensor->GetName() == identifiername)
00088                 {
00089                         identifierval = new CBoolValue(sensor->IsPositiveTrigger());
00090                         //identifierval = sensor->AddRef();
00091                 }
00092 
00093                 //if (!sensor->IsPositiveTrigger())
00094                 //{
00095                 //      sensorresult = false;
00096                 //      break;
00097                 //}
00098         }
00099 
00100         if (identifierval)
00101                 return identifierval;
00102 
00103         return  GetParent()->FindIdentifier(identifiername);
00104 
00105 }

Generated at Thu Feb 1 13:03:09 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000