Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <set>
8#include <string>
9#include "util/serialize.h"
11
20{
21 SoundSpec(std::string_view name = "", float gain = 1.0f,
22 bool loop = false, float fade = 0.0f, float pitch = 1.0f,
23 float start_time = 0.0f) :
25 loop(loop)
26 {
27 }
28
29 bool exists() const { return !name.empty(); }
30
34 void serializeSimple(std::ostream &os, u16 protocol_version) const
35 {
37 writeF32(os, gain);
38 writeF32(os, pitch);
39 writeF32(os, fade);
40 }
41
45 void deSerializeSimple(std::istream &is, u16 protocol_version)
46 {
48 gain = readF32(is);
49 pitch = readF32(is);
50 fade = readF32(is);
51 }
52
53 // Name of the sound-group
54 std::string name;
55 float gain = 1.0f;
56 float fade = 0.0f;
57 float pitch = 1.0f;
58 float start_time = 0.0f;
59 bool loop = false;
60 // If true, a local fallback (ie. from the user's sound pack) is used if the
61 // sound-group does not exist.
62 bool use_local_fallback = true;
63};
64
65
66// The order must not be changed. This is sent over the network.
67enum class SoundLocation : u8 {
68 Local,
70 Object
71};
std::string serializeString16(std::string_view plain)
Definition serialize.cpp:22
std::string deSerializeString16(std::istream &is)
Definition serialize.cpp:38
void writeF32(u8 *data, f32 i)
Definition serialize.h:308
f32 readF32(const u8 *data)
Definition serialize.h:190
SoundLocation
Definition sound.h:67
Describes the sound information for playback.
Definition sound.h:20
std::string name
Definition sound.h:54
bool use_local_fallback
Definition sound.h:62
bool loop
Definition sound.h:59
void deSerializeSimple(std::istream &is, u16 protocol_version)
Deserialize a SimpleSoundSpec.
Definition sound.h:45
float gain
Definition sound.h:55
bool exists() const
Definition sound.h:29
void serializeSimple(std::ostream &os, u16 protocol_version) const
Serialize a SimpleSoundSpec.
Definition sound.h:34
SoundSpec(std::string_view name="", float gain=1.0f, bool loop=false, float fade=0.0f, float pitch=1.0f, float start_time=0.0f)
Definition sound.h:21
float start_time
Definition sound.h:58
float pitch
Definition sound.h:57
float fade
Definition sound.h:56