ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
AudioTrack.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
3#include <memory>
4
5struct MIX_Track;
6
7namespace Shit {
8
10
11// SHIT_API:AudioPlayer 在引擎外被按值持有(EngineContext),
12// 析构/移动需要跨 DLL 导出符号
14public:
15 AudioTrack(const AudioTrack&) = delete;
16 AudioTrack& operator=(const AudioTrack&) = delete;
18 AudioTrack& operator=(AudioTrack&&) noexcept;
20
21 void pause();
22 void resume();
23 void stop();
24 void setVolume(float gain);
25 float getVolume() const;
26 void setLooping(int loopCount); // -1 = 无限, 0 = 不循环, N = N 次
27 int getLooping() const { return m_loops; }
28
29 bool isPlaying() const;
30 bool isPaused() const;
31 bool isFinished() const;
32
33private:
34 friend class AudioPlayer;
35 friend class AudioTrackGroup;
36 AudioTrack() = default;
37 explicit AudioTrack(MIX_Track* handle);
38
39 MIX_Track* m_handle = nullptr;
40 float m_gain = 1.0f;
41 int m_loops = 0;
42 AudioTrackGroup* m_group = nullptr;
43 // 组生命周期令牌:本 track 仍存活期间持有组引用,组对象不会先于 track 销毁,
44 // 析构时 m_group->unregisterTrack(this) 不会访问已释放的组内存
45 std::shared_ptr<AudioTrackGroup> m_groupOwner;
46 bool m_started = false;
47 bool m_paused = false;
48};
49
50} // namespace Shit
#define SHIT_API
定义 Core.h:14
定义 AudioPlayer.h:14
void setLooping(int loopCount)
friend class AudioTrackGroup
定义 AudioTrack.h:35
bool isPlaying() const
bool isFinished() const
bool isPaused() const
friend class AudioPlayer
定义 AudioTrack.h:34
AudioTrack(AudioTrack &&) noexcept
void setVolume(float gain)
float getVolume() const
AudioTrack(const AudioTrack &)=delete
int getLooping() const
定义 AudioTrack.h:27
AudioTrack & operator=(const AudioTrack &)=delete
定义 AnimationClip.h:12