ScummVM API documentation
motor.h
1
2
/* ScummVM - Graphic Adventure Engine
3
*
4
* ScummVM is the legal property of its developers, whose names
5
* are too numerous to list here. Please refer to the COPYRIGHT
6
* file distributed with this source distribution.
7
*
8
* This program is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
20
*
21
*/
22
23
#ifndef TWP_MOTOR_H
24
#define TWP_MOTOR_H
25
26
#include "math/vector2d.h"
27
#include "twp/camera.h"
28
#include "twp/util.h"
29
#include "twp/lip.h"
30
31
namespace
Twp
{
32
33
template
<
typename
T>
34
struct
Tween
{
35
public
:
36
Tween
(T f, T t,
float
d,
InterpolationMethod
im)
37
: frm(f), to(t), delta(t - f), duration(d), value(f), easing_f(easing(im.kind)), swing(im.swing), loop(im.loop) {
38
}
39
40
bool
running() {
41
if
(swing || loop) {
42
return
true
;
43
}
44
return
elapsed < duration;
45
}
46
47
void
update(
float
el) {
48
if
(enabled && running()) {
49
elapsed += el;
50
float
f =
CLIP
(elapsed / duration, 0.0f, 1.0f);
51
if
(!dir_forward)
52
f = 1.0f - f;
53
if
((elapsed > duration) && (swing || loop)) {
54
elapsed = elapsed - duration;
55
if
(swing)
56
dir_forward = !dir_forward;
57
}
58
if
(easing_f.func) {
59
f = easing_f.func(f);
60
value = frm + delta * f;
61
}
62
}
else
{
63
value = to;
64
}
65
}
66
67
T current()
const
{
return
value; }
68
69
public
:
70
T frm, to, delta;
71
float
elapsed = 0.f;
72
float
duration = 0.f;
// duration in ms
73
T value;
74
EasingFunc_t
easing_f;
75
bool
enabled =
true
;
76
bool
dir_forward =
true
;
77
bool
swing =
false
;
78
bool
loop =
false
;
79
};
80
81
class
Motor
{
82
public
:
83
virtual
~
Motor
() {}
84
virtual
void
disable() {
85
_enabled =
false
;
86
}
87
virtual
bool
isEnabled()
const
{
return
_enabled; }
88
void
update(
float
elapsed);
89
90
protected
:
91
virtual
void
onUpdate(
float
elapsed) = 0;
92
93
protected
:
94
bool
_enabled =
true
;
95
};
96
97
class
Object
;
98
class
OffsetTo
:
public
Motor
{
99
public
:
100
virtual
~
OffsetTo
();
101
OffsetTo
(
float
duration,
Common::SharedPtr<Object>
obj,
const
Math::Vector2d &pos,
InterpolationMethod
im);
102
103
private
:
104
virtual
void
onUpdate(
float
elasped)
override
;
105
106
private
:
107
Common::SharedPtr<Object>
_obj;
108
Tween<Math::Vector2d>
_tween;
109
};
110
111
class
MoveTo
:
public
Motor
{
112
public
:
113
virtual
~
MoveTo
();
114
MoveTo
(
float
duration,
Common::SharedPtr<Object>
obj,
const
Math::Vector2d &pos,
InterpolationMethod
im);
115
116
private
:
117
virtual
void
onUpdate(
float
elasped)
override
;
118
119
private
:
120
Common::SharedPtr<Object>
_obj;
121
Tween<Math::Vector2d>
_tween;
122
};
123
124
class
AlphaTo
:
public
Motor
{
125
public
:
126
virtual
~
AlphaTo
();
127
AlphaTo
(
float
duration,
Common::SharedPtr<Object>
obj,
float
to,
InterpolationMethod
im);
128
129
private
:
130
virtual
void
onUpdate(
float
elasped)
override
;
131
132
private
:
133
Common::SharedPtr<Object>
_obj;
134
Tween<float>
_tween;
135
};
136
137
class
Node
;
138
class
RotateTo
:
public
Motor
{
139
public
:
140
virtual
~
RotateTo
();
141
RotateTo
(
float
duration,
Node
*obj,
float
to,
InterpolationMethod
im);
142
143
private
:
144
virtual
void
onUpdate(
float
elasped)
override
;
145
146
private
:
147
Node
*_node =
nullptr
;
148
Tween<float>
_tween;
149
};
150
151
class
RoomRotateTo
:
public
Motor
{
152
public
:
153
virtual
~
RoomRotateTo
();
154
RoomRotateTo
(
Common::SharedPtr<Room>
room,
float
to);
155
156
private
:
157
virtual
void
onUpdate(
float
elasped)
override
;
158
159
private
:
160
Common::SharedPtr<Room>
_room;
161
Tween<float>
_tween;
162
};
163
164
class
ScaleTo
:
public
Motor
{
165
public
:
166
virtual
~
ScaleTo
();
167
ScaleTo
(
float
duration,
Node
*node,
float
to,
InterpolationMethod
im);
168
169
private
:
170
virtual
void
onUpdate(
float
elasped)
override
;
171
172
private
:
173
Node
*_node =
nullptr
;
174
Tween<float>
_tween;
175
};
176
177
class
Shake
:
public
Motor
{
178
public
:
179
virtual
~
Shake
();
180
Shake
(
Node
*node,
float
amount);
181
182
private
:
183
virtual
void
onUpdate(
float
elasped)
override
;
184
185
private
:
186
Node
*_node =
nullptr
;
187
float
_amount = 0.f;
188
float
_shakeTime = 0.f;
189
float
_elapsed = 0.f;
190
};
191
192
class
OverlayTo
:
public
Motor
{
193
public
:
194
virtual
~
OverlayTo
();
195
OverlayTo
(
float
duration,
Common::SharedPtr<Room>
room,
const
Color
&to);
196
197
virtual
void
onUpdate(
float
elapsed)
override
;
198
199
private
:
200
Common::SharedPtr<Room>
_room;
201
Color
_to;
202
Tween<Color>
_tween;
203
};
204
205
class
ReachAnim
:
public
Motor
{
206
public
:
207
virtual
~
ReachAnim
();
208
ReachAnim
(
Common::SharedPtr<Object>
actor,
Common::SharedPtr<Object>
obj);
209
210
virtual
void
onUpdate(
float
elasped)
override
;
211
212
private
:
213
void
playReachAnim();
214
215
private
:
216
Common::SharedPtr<Object>
_actor;
217
Common::SharedPtr<Object>
_obj;
218
int
_state = 0;
219
float
_elapsed = 0.f;
220
};
221
222
enum
WalkToState {
223
kWalking,
224
kArrived,
225
kReach
226
};
227
228
class
WalkTo
:
public
Motor
{
229
public
:
230
WalkTo
(
Common::SharedPtr<Object>
obj,
const
Math::Vector2d &dest,
int
facing = 0);
231
void
disable()
override
;
232
233
const
Common::Array<Math::Vector2d>
&getPath()
const
{
return
_path; }
234
235
private
:
236
void
actorArrived();
237
void
onUpdate(
float
elapsed)
override
;
238
239
private
:
240
Common::SharedPtr<Object>
_obj;
241
Common::Array<Math::Vector2d>
_path;
242
int
_facing = 0;
243
float
_wsd;
244
WalkToState _state = kWalking;
245
};
246
247
class
TextNode
;
248
249
class
TalkingBase
:
public
Motor
{
250
protected
:
251
TalkingBase
(
Common::SharedPtr<Object>
actor,
float
duration);
252
253
public
:
254
virtual
~
TalkingBase
() {}
255
256
protected
:
257
Common::String
talkieKey();
258
int
onTalkieId(
int
id
);
259
int
loadActorSpeech(
const
Common::String
&name);
260
void
setDuration(
const
Common::String
&text);
261
float
getTalkSpeed()
const
;
262
263
protected
:
264
Common::SharedPtr<Object>
_actor;
265
float
_duration = 0.f;
266
float
_elapsed = 0.f;
267
};
268
269
// Creates a talking animation for a specified object.
270
class
Talking
:
public
TalkingBase
{
271
public
:
272
Talking
(
Common::SharedPtr<Object>
obj,
const
Common::StringArray
&texts,
const
Color
&color);
273
virtual
~
Talking
() {}
274
275
void
append(
const
Common::StringArray
&texts,
const
Color
&color);
276
277
virtual
void
onUpdate(
float
elapsed)
override
;
278
virtual
void
disable()
override
;
279
280
private
:
281
void
say(
const
Common::String
&text);
282
283
private
:
284
Common::SharedPtr<TextNode>
_node;
285
Lip
_lip;
286
Color
_color;
287
Common::StringArray
_texts;
288
};
289
290
class
SayLineAt
:
public
TalkingBase
{
291
public
:
292
SayLineAt
(
const
Math::Vector2d &pos,
const
Color
&color,
Common::SharedPtr<Object>
actor,
float
duration,
const
Common::String
&text);
293
virtual
~
SayLineAt
() {}
294
295
virtual
void
onUpdate(
float
elapsed)
override
;
296
virtual
void
disable()
override
;
297
298
private
:
299
void
say(
const
Common::String
&text);
300
301
private
:
302
const
Math::Vector2d _pos;
303
Color
_color;
304
Common::String
_text;
305
Common::SharedPtr<TextNode>
_node;
306
};
307
308
class
Jiggle
:
public
Motor
{
309
public
:
310
Jiggle
(
Node
*node,
float
amount);
311
virtual
~
Jiggle
();
312
313
private
:
314
virtual
void
onUpdate(
float
elapsed)
override
;
315
316
private
:
317
Node
*_node =
nullptr
;
318
float
_amount = 0.f;
319
float
_jiggleTime = 0.f;
320
};
321
322
class
MoveCursorTo
:
public
Motor
{
323
public
:
324
MoveCursorTo
(
const
Math::Vector2d &pos,
float
time);
325
virtual
~
MoveCursorTo
() {}
326
327
private
:
328
virtual
void
onUpdate(
float
elapsed)
override
;
329
330
private
:
331
Tween<Math::Vector2d>
_tween;
332
Math::Vector2d _pos;
333
};
334
335
}
// namespace Twp
336
337
#endif
Twp::MoveTo
Definition:
motor.h:111
Common::String
Definition:
str.h:59
Twp::Jiggle
Definition:
motor.h:308
Twp::ScaleTo
Definition:
motor.h:164
Twp::TalkingBase
Definition:
motor.h:249
Common::Array< Math::Vector2d >
Twp::EasingFunc_t
Definition:
easing.h:33
Twp::OverlayTo
Definition:
motor.h:192
CLIP
T CLIP(T v, T amin, T amax)
Definition:
util.h:65
Twp::Tween
Definition:
motor.h:34
Twp::AlphaTo
Definition:
motor.h:124
Twp::Lip
Definition:
lip.h:41
Twp::Talking
Definition:
motor.h:270
Twp::Color
Definition:
gfx.h:35
Twp::TextNode
Definition:
scenegraph.h:200
Twp::OffsetTo
Definition:
motor.h:98
Twp::WalkTo
Definition:
motor.h:228
Twp::Object
Definition:
object.h:115
Twp::Motor
Definition:
motor.h:81
Twp::ReachAnim
Definition:
motor.h:205
Twp::InterpolationMethod
Definition:
easing.h:46
Twp::Node
Definition:
scenegraph.h:41
Twp::RoomRotateTo
Definition:
motor.h:151
Common::SharedPtr
Definition:
ptr.h:159
Twp::Shake
Definition:
motor.h:177
Twp::SayLineAt
Definition:
motor.h:290
Twp::RotateTo
Definition:
motor.h:138
Twp
Definition:
achievements_tables.h:27
Twp::MoveCursorTo
Definition:
motor.h:322
engines
twp
motor.h
Generated on Fri Aug 30 2024 09:19:50 for ScummVM API documentation by
1.8.13