VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
AudioSystem.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <unordered_map>
10#include <memory>
11#include <string>
12
13#include <SDL3/SDL.h>
15
19
20namespace vex {
21
28public:
34
42
52 void Update(vex::Entity cameraEntity);
53
58 void Shutdown();
59
68 void PlaySound2D(const std::string& filePath, float volume = 1.0f, float pitch = 1.0f, bool loop = false);
69
70private:
71 SDL_AudioDeviceID deviceID;
72 VirtualFileSystem* vfs = nullptr;
73 vex::Registry& registry;
74
76 std::unordered_map<std::string, std::unique_ptr<AudioClip>> clipCache;
77
79 std::unordered_map<vex::Entity, SDL_AudioStream*> streamMap;
80
88
90 SDL_AudioStream* stream;
91 AudioClip* clip;
92 bool loop;
93 };
94 std::vector<StandaloneAudio> standaloneStreams;
95};
96
97}
Defines the AudioSourceComponent struct.
Contains basic components like transform, camera, name components..
Main header for the Entity Component System (ECS) framework.
This file defines VirtualFileSystem and VPKStream classes.
AudioSystem(vex::Registry &reg)
Constructor for AudioSystem.
std::unordered_map< vex::Entity, SDL_AudioStream * > streamMap
Map linking entities to their active SDL audio streams.
void PlaySound2D(const std::string &filePath, float volume=1.0f, float pitch=1.0f, bool loop=false)
Quickly plays a 2D sound without requiring an entity or AudioSourceComponent.
void Shutdown()
Shuts down the audio system.
void Init(vex::VirtualFileSystem *vfs)
Initializes the audio subsystem and binding to the VFS.
std::unordered_map< std::string, std::unique_ptr< AudioClip > > clipCache
Cache of loaded audio clips to prevent reloading the same file multiple times. Key is the file path.
void Update(vex::Entity cameraEntity)
Main update loop for the audio system.
void OnAudioComponentDestroyed(vex::Registry &registry, vex::Entity entity)
Callback triggered when an AudioSourceComponent is destroyed.
Central registry for managing entities and their components in the ECS system.
Definition Registry.hpp:29
This class provides abstraction of file system needed for loading packed and unpacked assets.
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
Definition Types.hpp:11