Initial revision
[blender.git] / source / gameengine / Ketsji / KX_TouchEventManager.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  */
31
32 #include "KX_TouchEventManager.h"
33
34 #include "SCA_ISensor.h"
35 #include "KX_TouchSensor.h"
36 #include "KX_GameObject.h"
37
38 #ifdef PHYSICS_NOT_YET
39
40 KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr,
41                                                                                    DT_RespTableHandle resphandle,
42                                                                                    DT_SceneHandle scenehandle)
43         : SCA_EventManager(TOUCH_EVENTMGR),
44           m_resphandle(resphandle),
45           m_scenehandle(scenehandle),
46           m_logicmgr(logicmgr) {}
47
48 void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
49 {
50
51
52         KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
53         m_sensors.push_back(touchsensor);
54
55         touchsensor->RegisterSumo();//this,m_resphandle);
56
57         //KX_GameObject* gameobj = ((KX_GameObject*)sensor->GetParent());
58 //      SM_Object* smobj = touchsensor->GetSumoObject();//gameobj->GetSumoObject();
59 //      if (smobj)
60 //      {
61 //              smobj->calcXform();
62 //              DT_AddObject(m_scenehandle,
63 //                               smobj->getObjectHandle()); 
64 //      }
65 }
66
67
68
69 void KX_TouchEventManager::EndFrame()
70 {
71         vector<SCA_ISensor*>::iterator it;
72         for ( it = m_sensors.begin();
73         !(it==m_sensors.end());it++)
74         {
75                 ((KX_TouchSensor*)*it)->EndFrame();
76
77         }
78 }
79
80
81
82 void KX_TouchEventManager::NextFrame(double curtime,double deltatime)
83 {
84         if (m_sensors.size() > 0)
85         {
86                 vector<SCA_ISensor*>::iterator it;
87                 
88                 for (it = m_sensors.begin();!(it==m_sensors.end());it++)
89                         ((KX_TouchSensor*)*it)->SynchronizeTransform();
90                 
91                 if (DT_Test(m_scenehandle,m_resphandle))
92                         int i = 0;
93                 
94                 for (it = m_sensors.begin();!(it==m_sensors.end());it++)
95                         (*it)->Activate(m_logicmgr,NULL);
96         }
97 }
98
99
100
101 void KX_TouchEventManager::RemoveSensor(class SCA_ISensor* sensor)
102 {
103         std::vector<SCA_ISensor*>::iterator i =
104         std::find(m_sensors.begin(), m_sensors.end(), sensor);
105         if (!(i == m_sensors.end()))
106         {
107                 //std::swap(*i, m_sensors.back());
108                 //m_sensors.pop_back();
109                 //SM_Object* smobj = ((KX_TouchSensor*)*i)->GetSumoObject();
110                 //DT_RemoveObject(m_scenehandle,
111                 //               smobj->getObjectHandle()); 
112         }
113         // remove the sensor forever :)
114         SCA_EventManager::RemoveSensor(sensor);
115 }
116
117 #endif