File: animation_handle.cpp

package info (click to toggle)
freespace2 25.0.0~rc11%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (83 lines) | stat: -rw-r--r-- 2,566 bytes parent folder | download
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
#include "animation_handle.h"

namespace scripting {
namespace api {

//**********HANDLE: Animation Handle
ADE_OBJ(l_AnimationHandle, animation_handle_h, "animation_handle", "A handle for animation instances");

ADE_FUNC(start, l_AnimationHandle, "[boolean forwards = true, boolean resetOnStart = false, boolean completeInstant = false, boolean pause = false]",
	"Triggers an animation. Forwards controls the direction of the animation. ResetOnStart will cause the animation to play from its initial state, "
	"as opposed to its current state. CompleteInstant will immediately complete the animation. Pause will instead stop the animation at the current state.",
	"boolean",
	"True if successful, false if no animation was started or nil on failure")
{
	animation_handle_h* anim_set;
	bool forwards = true;
	bool forced = false;
	bool instant = false;
	bool pause = false;

	if (!ade_get_args(L, "o|bbbb", l_AnimationHandle.GetPtr(&anim_set), &forwards, &forced, &instant, &pause))
		return ADE_RETURN_NIL;

	if (anim_set == nullptr)
		return ADE_RETURN_NIL;

	return ade_set_args(L, "b", anim_set->start(forwards ? animation::ModelAnimationDirection::FWD : animation::ModelAnimationDirection::RWD, forced || instant, instant, pause));
}

ADE_FUNC(getTime, l_AnimationHandle, nullptr,
	"Returns the total duration of this animation, unaffected by the speed set, in seconds.",
	"number",
	"The time this animation will take to complete")
{
	animation_handle_h* anim_set;

	if (!ade_get_args(L, "o", l_AnimationHandle.GetPtr(&anim_set)))
		return ADE_RETURN_NIL;

	if (anim_set == nullptr)
		return ADE_RETURN_NIL;

	return ade_set_args(L, "f", ((float)anim_set->getTime()) * 0.001f);
}

ADE_FUNC(setSpeed, l_AnimationHandle, "[number speedMultiplier = 1.0]",
	"Sets the speed multiplier at which an animation runs. Anything other than 1 will not work in multiplayer.",
	nullptr,
	nullptr)
{
	animation_handle_h* anim_set;
	float speed = 1.0f;

	if (!ade_get_args(L, "o|f", l_AnimationHandle.GetPtr(&anim_set), &speed))
		return ADE_RETURN_NIL;

	if (anim_set == nullptr)
		return ADE_RETURN_NIL;

	anim_set->setSpeed(speed);

	return ADE_RETURN_NIL;
}

ADE_FUNC(stopNextLoop, l_AnimationHandle, nullptr,
	"Will stop this looping animation on its next repeat.",
	nullptr, nullptr)
{
	animation_handle_h* anim_set;

	if (!ade_get_args(L, "o", l_AnimationHandle.GetPtr(&anim_set)))
		return ADE_RETURN_NIL;

	if (anim_set == nullptr)
		return ADE_RETURN_NIL;

	anim_set->setFlag(animation::Animation_Instance_Flags::Stop_after_next_loop);

	return ADE_RETURN_NIL;
}

}
}