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