File: PlaySoundAction.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (65 lines) | stat: -rw-r--r-- 1,811 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
//
//

#include "PlaySoundAction.h"

#include "ship/ship.h"

#include <utility>

namespace actions {
namespace types {

flagset<ProgramContextFlags> PlaySoundAction::getRequiredExecutionContextFlags()
{
	return flagset<ProgramContextFlags>{ProgramContextFlags::HasObject};
}

PlaySoundAction::PlaySoundAction(expression::TypedActionExpression<ValueType> soundIdExpression)
	: m_soundIdExpression(std::move(soundIdExpression))
{
}
PlaySoundAction::~PlaySoundAction() = default;

ActionResult PlaySoundAction::execute(ProgramLocals& locals) const
{
	vec3d local_pos;
	matrix local_orient;
	if (locals.hostSubobject != -1) {
		auto instance = object_get_model_instance(locals.host.objp());
		Assertion(instance != -1, "Model instances are required if a host subobject is specified.");

		auto pmi = model_get_instance(instance);
		auto pm = model_get(pmi->model_num);

		model_instance_local_to_global_point_orient(&local_pos,
			&local_orient,
			&locals.localPosition,
			&locals.localOrient,
			pm,
			pmi,
			locals.hostSubobject);
	} else {
		local_pos = locals.localPosition;
		local_orient = locals.localOrient;
	}

	local_pos += locals.variables.getValue({"locals", "position"}).getVector();

	vec3d global_pos;
	vm_vec_unrotate(&global_pos, &local_pos, &locals.host.objp()->orient);
	global_pos += locals.host.objp()->pos;

	const auto soundId = gamesnd_get_by_name(m_soundIdExpression.execute(locals.variables).c_str());

	// Sound is not attached to the host but the object sound system currently only supports persistent sounds
	snd_play_3d(gamesnd_get_game_sound(soundId), &global_pos, &Eye_position);

	return ActionResult::Finished;
}
std::unique_ptr<Action> PlaySoundAction::clone() const
{
	return std::unique_ptr<Action>(new PlaySoundAction(*this));
}
} // namespace types
} // namespace actions