00001 /* 00002 00003 ************************************************************************* 00004 00005 ArmageTron -- Just another Tron Lightcycle Game in 3D. 00006 Copyright (C) 2000 Manuel Moos (manuel@moosnet.de) 00007 00008 ************************************************************************** 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00023 00024 *************************************************************************** 00025 00026 */ 00027 00028 #include "vCore.h" 00029 #include "vRegistry.h" 00030 #include "vebCFunction.h" 00031 #include "veMath.h" 00032 00033 long int ve_math_random() 00034 { 00035 return (long int)tRandomizer::GetInstance().Get(RAND_MAX); 00036 } 00037 00038 00039 using namespace vValue::Registry; 00040 00041 namespace vValue { 00042 namespace Expr { 00043 namespace Math { 00044 00047 Variant 00048 Add::GetValue(void) const { 00049 const Variant lvalue = m_lvalue->GetValue(); 00050 const Variant rvalue = m_rvalue->GetValue(); 00051 //return boost::apply_visitor(AddVisitor(), lvalue, rvalue); 00052 /* 00053 if (boost::get<tString>(&lvalue) || boost::get<tString>(&rvalue)) 00054 return boost::lexical_cast<tString>lvalue 00055 + boost::lexical_cast<tString>rvalue; 00056 else 00057 */ 00058 if (boost::get<int>(&lvalue) && boost::get<int>(&rvalue)) 00059 return boost::get<int>(lvalue) + boost::get<int>(rvalue); 00060 /* 00061 else 00062 if (boost::get<float>(&lvalue) || boost::get<float>(&rvalue)) 00063 return boost::lexical_cast<float>(lvalue) 00064 + boost::lexical_cast<float>(rvalue); 00065 else 00066 throw(1);*/ 00067 return m_lvalue->GetFloat() + m_rvalue->GetFloat(); 00068 } 00069 00070 Base *Add::copy(void) const { 00071 return new Add(*this); 00072 } 00073 00076 Variant 00077 Subtract::GetValue(void) const { 00078 const Variant lvalue = m_lvalue->GetValue(); 00079 const Variant rvalue = m_rvalue->GetValue(); 00080 if (boost::get<int>(&lvalue) && boost::get<int>(&rvalue)) 00081 return boost::get<int>(lvalue) - boost::get<int>(rvalue); 00082 return m_lvalue->GetFloat() - m_rvalue->GetFloat(); 00083 /* 00084 if (boost::get<float>(&lvalue) || boost::get<float>(&rvalue)) 00085 return boost::lexical_cast<float>(lvalue) 00086 - boost::lexical_cast<float>(rvalue); 00087 else 00088 if (boost::get<int>(&lvalue) && boost::get<int>(&rvalue)) 00089 return boost::get<int>(lvalue) - boost::get<int>(rvalue); 00090 else 00091 throw(1); 00092 */ 00093 } 00094 00095 Base *Subtract::copy(void) const { 00096 return new Subtract(*this); 00097 } 00098 00101 Variant 00102 Multiply::GetValue(void) const { 00103 const Variant lvalue = m_lvalue->GetValue(); 00104 const Variant rvalue = m_rvalue->GetValue(); 00105 if (boost::get<int>(&lvalue) && boost::get<int>(&rvalue)) 00106 return boost::get<int>(lvalue) * boost::get<int>(rvalue); 00107 return m_lvalue->GetFloat() * m_rvalue->GetFloat(); 00108 } 00109 00110 Base *Multiply::copy(void) const { 00111 return new Multiply(*this); 00112 } 00113 00116 Variant 00117 Divide::GetValue(void) const { 00118 // Operate on both values as floats, because this is division 00119 return m_lvalue->GetFloat() / m_rvalue->GetFloat(); 00120 } 00121 00122 Base *Divide::copy(void) const { 00123 return new Divide(*this); 00124 } 00125 00126 00127 Registration register_sin("func\nmath", "sin", 1, (Registration::fptr) 00128 ( ctor::a1* )& Creator<Trig::Sin>::create<BasePtr> ); 00129 00130 00131 } 00132 } 00133 }