svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22717:22875
[blender.git] / source / gameengine / Ketsji / KX_WorldIpoController.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL 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.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "KX_WorldIpoController.h"
30 #include "KX_ScalarInterpolator.h"
31 #include "KX_WorldInfo.h"
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36
37 #if defined(_WIN64)
38 typedef unsigned __int64 uint_ptr;
39 #else
40 typedef unsigned long uint_ptr;
41 #endif
42
43 bool KX_WorldIpoController::Update(double currentTime)
44 {
45         if (m_modified)
46         {
47                 T_InterpolatorList::iterator i;
48                 for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
49                         (*i)->Execute(m_ipotime);//currentTime);
50                 }
51                 
52                 KX_WorldInfo *world = NULL;
53
54                 if (m_modify_mist_start) {
55                         world->setMistStart(m_mist_start);
56                 }
57
58                 if (m_modify_mist_color) {
59                         world->setMistColorRed(m_mist_rgb[0]);
60                         world->setMistColorGreen(m_mist_rgb[1]);
61                         world->setMistColorBlue(m_mist_rgb[2]);
62                 }
63
64                 if (m_modify_mist_dist) {
65                         world->setMistDistance(m_mist_dist);
66                 }
67
68                 m_modified=false;
69         }
70         return false;
71 }
72
73
74 void KX_WorldIpoController::AddInterpolator(KX_IInterpolator* interp)
75 {
76         this->m_interpolators.push_back(interp);
77 }
78
79
80 SG_Controller*  KX_WorldIpoController::GetReplica(class SG_Node* destnode)
81 {
82         KX_WorldIpoController* iporeplica = new KX_WorldIpoController(*this);
83         // clear object that ipo acts on
84         iporeplica->ClearObject();
85
86         // dirty hack, ask Gino for a better solution in the ipo implementation
87         // hacken en zagen, in what we call datahiding, not written for replication :(
88
89         T_InterpolatorList oldlist = m_interpolators;
90         iporeplica->m_interpolators.clear();
91
92         T_InterpolatorList::iterator i;
93         for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
94                 KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
95                 iporeplica->AddInterpolator(copyipo);
96
97                 MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
98                 uint_ptr orgbase = (uint_ptr)this;
99                 uint_ptr orgloc = (uint_ptr)scaal;
100                 uint_ptr offset = orgloc-orgbase;
101                 uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
102                 MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
103                 copyipo->SetNewTarget((MT_Scalar*)blaptr);
104         }
105         
106         return iporeplica;
107 }
108
109 KX_WorldIpoController::~KX_WorldIpoController()
110 {
111
112         T_InterpolatorList::iterator i;
113         for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
114                 delete (*i);
115         }
116         
117 }