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