OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
worldsound.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/SoundDevice>
4#include <Tempest/SoundEffect>
5#include <Tempest/Point>
6
7#include <zenkit/vobs/Zone.hh>
8#include <zenkit/vobs/Sound.hh>
9
10#include <mutex>
11
12#include "gamemusic.h"
13
14class GameSession;
15class TriggerEvent;
16class World;
17class Npc;
18class Sound;
19class SoundFx;
20
21class WorldSound final {
22 public:
23 WorldSound(GameSession& game, World& world);
25
26 void setDefaultZone(const zenkit::VZoneMusic& vob);
27 void addZone (const zenkit::VZoneMusic& vob);
28 void addSound (const zenkit::VSound& vob);
29
30 Sound addDlgSound(std::string_view s, const Tempest::Vec3& pos, float range, uint64_t &timeLen);
31
32 void aiOutput(const Tempest::Vec3& pos, std::string_view outputname);
33
34 void tick(Npc& player);
35 bool execTriggerEvent(const TriggerEvent& e);
36
37 bool isInListenerRange(const Tempest::Vec3& pos, float sndRgn) const;
38 bool canSeeSource(const Tempest::Vec3& npc) const;
39
40 static const float talkRange;
41
42 private:
43 struct WSound;
44 struct Zone;
45
46 struct Effect {
47 Tempest::SoundEffect eff;
48 Tempest::Vec3 pos;
49 float vol = 1.f;
50 float occ = 1.f;
51 float maxDist = 0.f;
52 bool loop = false;
53 bool active = true;
54 bool ambient = false;
55
56 void setOcclusion(float occ);
57 void setVolume(float v);
58 };
59
60 using PEffect = std::shared_ptr<Effect>;
61
62 void tickSoundZone(Npc& player);
63 void tickSlot(std::vector<PEffect>& eff);
64 void tickSlot(Effect& slot);
65 void initSlot(Effect& slot);
66 bool setMusic(std::string_view zone, GameMusic::Tags tags);
67
68 Sound implAddSound(const SoundFx& s, const Tempest::Vec3& pos, float rangeMax);
69 Sound implAddSound(Tempest::SoundEffect&& s, const Tempest::Vec3& pos, float rangeMax);
70
71 GameSession& game;
72 World& owner;
73
74 std::vector<Zone> zones;
75 std::unique_ptr<Zone> def;
76
77 uint64_t nextSoundUpdate=0;
78 Zone* currentZone = nullptr;
80
81 Tempest::Vec3 plPos;
82
83 std::unordered_map<std::string,PEffect> freeSlot;
84 std::vector<PEffect> effect;
85 std::vector<PEffect> effect3d; // snd_play3d
86 std::vector<WSound> worldEff;
87
88 std::mutex sync;
89
90 static const float maxDist;
91
92 friend class Sound;
93 };
Definition npc.h:25
Definition sound.h:5
void tick(Npc &player)
bool canSeeSource(const Tempest::Vec3 &npc) const
Sound addDlgSound(std::string_view s, const Tempest::Vec3 &pos, float range, uint64_t &timeLen)
void setDefaultZone(const zenkit::VZoneMusic &vob)
bool isInListenerRange(const Tempest::Vec3 &pos, float sndRgn) const
bool execTriggerEvent(const TriggerEvent &e)
static const float talkRange
Definition worldsound.h:40
void addSound(const zenkit::VSound &vob)
void addZone(const zenkit::VZoneMusic &vob)
void aiOutput(const Tempest::Vec3 &pos, std::string_view outputname)
Definition world.h:31