Blender V2.61 - r43446

SCA_TimeEventManager.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #if defined(WIN32) && !defined(FREE_WINDOWS)
00034 // This warning tells us about truncation of __long__ stl-generated names.
00035 // It can occasionally cause DevStudio to have internal compiler warnings.
00036 #pragma warning( disable : 4786 )     
00037 #endif
00038 
00039 #include "SCA_TimeEventManager.h"
00040 
00041 #include "SCA_LogicManager.h"
00042 #include "FloatValue.h"
00043 
00044 SCA_TimeEventManager::SCA_TimeEventManager(SCA_LogicManager* logicmgr)
00045 : SCA_EventManager(NULL, TIME_EVENTMGR)
00046 {
00047 }
00048 
00049 
00050 
00051 SCA_TimeEventManager::~SCA_TimeEventManager()
00052 {
00053     for (vector<CValue*>::iterator it = m_timevalues.begin();
00054             !(it == m_timevalues.end()); ++it)
00055     {
00056         (*it)->Release();
00057     }   
00058 }
00059 
00060 
00061 
00062 void SCA_TimeEventManager::RegisterSensor(SCA_ISensor* sensor)
00063 {
00064     // not yet
00065 }
00066 
00067 void SCA_TimeEventManager::RemoveSensor(SCA_ISensor* sensor)
00068 {
00069     // empty
00070 }
00071 
00072 
00073 
00074 void SCA_TimeEventManager::NextFrame(double curtime, double fixedtime)
00075 {
00076     if (m_timevalues.size() > 0 && fixedtime > 0.0)
00077     {
00078         CFloatValue* floatval = new CFloatValue(curtime);
00079         
00080         // update sensors, but ... need deltatime !
00081         for (vector<CValue*>::iterator it = m_timevalues.begin();
00082         !(it == m_timevalues.end()); ++it)
00083         {
00084             float newtime = (*it)->GetNumber() + fixedtime;
00085             floatval->SetFloat(newtime);
00086             (*it)->SetValue(floatval);
00087         }
00088         
00089         floatval->Release();
00090     }
00091 }
00092 
00093 
00094 
00095 void SCA_TimeEventManager::AddTimeProperty(CValue* timeval)
00096 {
00097     timeval->AddRef();
00098     m_timevalues.push_back(timeval);
00099 }
00100 
00101 
00102 
00103 void SCA_TimeEventManager::RemoveTimeProperty(CValue* timeval)
00104 {
00105     for (vector<CValue*>::iterator it = m_timevalues.begin();
00106             !(it == m_timevalues.end()); ++it)
00107     {
00108         if ((*it) == timeval)
00109         {
00110             this->m_timevalues.erase(it);
00111             timeval->Release();
00112             break;
00113         }
00114     }
00115 }
00116 
00117 vector<CValue*> SCA_TimeEventManager::GetTimeValues()
00118 {
00119     return m_timevalues;
00120 }
00121