Ken's 64bit patches weren't merged over to orange for some reason.
[blender-staging.git] / source / gameengine / Ketsji / KX_LightIpoSGController.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_LightIpoSGController.h"
33 #include "KX_ScalarInterpolator.h"
34 #include "KX_Light.h"
35 #include "RAS_LightObject.h"
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 #if defined(_WIN64)
42 typedef unsigned __int64 uint_ptr;
43 #else
44 typedef unsigned long uint_ptr;
45 #endif
46
47 bool KX_LightIpoSGController::Update(double currentTime)
48 {
49         if (m_modified)
50         {
51                 T_InterpolatorList::iterator i;
52                 for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
53                         (*i)->Execute(m_ipotime);//currentTime);
54                 }
55                 
56                 RAS_LightObject *lightobj;
57
58                 SG_Spatial* ob = (SG_Spatial*)m_pObject;
59                 KX_LightObject* kxlight = (KX_LightObject*) ob->GetSGClientObject();
60                 lightobj = kxlight->GetLightData();
61                 //lightobj = (KX_Light*) 
62
63                 if (m_modify_energy) {
64                         lightobj->m_energy = m_energy;
65                 }
66
67                 if (m_modify_color) {
68                         lightobj->m_red   = m_col_rgb[0];
69                         lightobj->m_green = m_col_rgb[1];
70                         lightobj->m_blue  = m_col_rgb[2];
71                 }
72
73                 if (m_modify_dist) {
74                         lightobj->m_distance = m_dist;
75                 }
76
77                 m_modified=false;
78         }
79         return false;
80 }
81
82
83 void KX_LightIpoSGController::AddInterpolator(KX_IInterpolator* interp)
84 {
85         this->m_interpolators.push_back(interp);
86 }
87
88 SG_Controller*  KX_LightIpoSGController::GetReplica(class SG_Node* destnode)
89 {
90         KX_LightIpoSGController* iporeplica = new KX_LightIpoSGController(*this);
91         // clear object that ipo acts on
92         iporeplica->ClearObject();
93
94         // dirty hack, ask Gino for a better solution in the ipo implementation
95         // hacken en zagen, in what we call datahiding, not written for replication :(
96
97         T_InterpolatorList oldlist = m_interpolators;
98         iporeplica->m_interpolators.clear();
99
100         T_InterpolatorList::iterator i;
101         for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
102                 KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
103                 iporeplica->AddInterpolator(copyipo);
104
105                 MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
106                 uint_ptr orgbase = (uint_ptr)this;
107                 uint_ptr orgloc = (uint_ptr)scaal;
108                 uint_ptr offset = orgloc-orgbase;
109                 uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
110                 MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
111                 copyipo->SetNewTarget((MT_Scalar*)blaptr);
112         }
113         
114         return iporeplica;
115 }
116
117 KX_LightIpoSGController::~KX_LightIpoSGController()
118 {
119
120         T_InterpolatorList::iterator i;
121         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
122                 delete (*i);
123         }
124         
125 }