Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarAmbient.hpp
blob: 1b36cc38dc4230d8e0b520afe5e166a996fde956 (plain)
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
#pragma once

#include "StarJson.hpp"

namespace Star {

STAR_CLASS(AudioInstance);
STAR_STRUCT(AmbientTrackGroup);
STAR_STRUCT(AmbientNoisesDescription);
STAR_CLASS(AmbientManager);

struct AmbientTrackGroup {
  AmbientTrackGroup();
  AmbientTrackGroup(StringList tracks);
  AmbientTrackGroup(Json const& config, String const& directory = "");

  Json toJson() const;

  StringList tracks;
};

// represents the ambient sounds data for a biome
struct AmbientNoisesDescription {
  AmbientNoisesDescription();
  AmbientNoisesDescription(AmbientTrackGroup day, AmbientTrackGroup night);
  AmbientNoisesDescription(Json const& config, String const& directory = "");

  Json toJson() const;

  AmbientTrackGroup daySounds;
  AmbientTrackGroup nightSounds;
};

typedef AmbientTrackGroup WeatherNoisesDescription;
typedef shared_ptr<WeatherNoisesDescription> WeatherNoisesDescriptionPtr;

// manages the running ambient sounds
class AmbientManager {
public:
  // Automatically calls cancelAll();
  ~AmbientManager();

  void setTrackSwitchGrace(float grace);
  void setTrackFadeInTime(float fadeInTime);

  // Returns a new AudioInstance if a new ambient sound is to be started.
  AudioInstancePtr updateAmbient(AmbientNoisesDescriptionPtr current, bool dayTime = false);
  AudioInstancePtr updateWeather(WeatherNoisesDescriptionPtr current);
  void cancelAll();

  void setVolume(float volume, float delay, float duration);

private:
  AudioInstancePtr m_currentTrack;
  AudioInstancePtr m_weatherTrack;
  String m_currentTrackName;
  String m_weatherTrackName;
  float m_trackFadeInTime = 0.0f;
  float m_trackSwitchGrace = 0.0f;
  double m_trackGraceTimestamp = 0;
  Deque<String> m_recentTracks;
  float m_volume = 1.0f;
  float m_delay = 0.0f;
  float m_duration = 0.0f;
  bool m_volumeChanged = false;
};

}