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