Repository navigation
Expand file tree
/
Copy pathproperty_animator.cpp
More file actions
132 lines (110 loc) · 3.83 KB
/
Copy pathproperty_animator.cpp
File metadata and controls
132 lines (110 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "scriptengine/property_animator.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_presentation.hpp"
#include "utils/log.hpp"
AnimatedProperty::AnimatedProperty(AnimatablePropery property,
int values_count, double* values_from, double* values_to,
double duration, void* data)
{
m_property = property;
m_remaining_time = m_total_time = duration;
m_data = data;
m_values_count = values_count;
m_values_from = values_from;
m_values_to = values_to;
m_new_values = new double[values_count];
}
// ----------------------------------------------------------------------------
bool AnimatedProperty::update(double dt)
{
bool done = false;
m_remaining_time -= dt;
if (m_remaining_time < 0)
{
m_remaining_time = 0;
done = true;
}
double ratio = 1.0 - m_remaining_time / m_total_time;
for (int i = 0; i < m_values_count; i++)
{
m_new_values[i] = m_values_from[i] + (m_values_to[i] - m_values_from[i]) * ratio;
}
switch (m_property)
{
case AnimatablePropery::AP_LIGHT_ENERGY:
{
TrackObjectPresentationLight* light = (TrackObjectPresentationLight*)m_data;
light->setEnergy((float)m_new_values[0]);
break;
}
case AnimatablePropery::FOG_RANGE:
{
Track* track = (Track*)m_data;
track->setFogStart((float)m_new_values[0]);
track->setFogEnd((float)m_new_values[1]);
break;
}
case AnimatablePropery::FOG_MAX:
{
Track* track = (Track*)m_data;
track->setFogMax((float)m_new_values[0]);
break;
}
case AnimatablePropery::FOG_COLOR:
{
Track* track = (Track*)m_data;
video::SColor color(255, (int)m_new_values[0], (int)m_new_values[1], (int)m_new_values[2]);
track->setFogColor(color);
break;
}
default:
Log::error("PropertyAnimator", "Unknown properry %i", (int)m_property);
break;
}
return done;
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
PropertyAnimator* PropertyAnimator::s_instance = NULL;
PropertyAnimator* PropertyAnimator::get()
{
if (s_instance == NULL)
s_instance = new PropertyAnimator();
return s_instance;
}
// ----------------------------------------------------------------------------
void PropertyAnimator::add(AnimatedProperty* prop)
{
m_properties.push_back(prop);
}
// ----------------------------------------------------------------------------
void PropertyAnimator::update(double dt)
{
for (int i = m_properties.size() - 1; i >= 0; i--)
{
bool done = m_properties[i].update(dt);
if (done)
m_properties.erase(i);
}
}
// ----------------------------------------------------------------------------
void PropertyAnimator::clear()
{
m_properties.clearAndDeleteAll();
}