ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
ResourceManager.h
浏览该文件的文档.
1
#pragma once
2
3
#include <memory>
4
#include <string>
5
6
#include "
ShitEngine/Core/Core.h
"
7
#include "
TextureManager.h
"
8
#include "
AudioManager.h
"
9
#include "
FontManager.h
"
10
11
struct
SDL_Texture;
12
struct
MIX_Audio;
13
struct
TTF_Font;
14
15
namespace
Shit
{
23
class
SHIT_API
ResourceManager
final {
24
public
:
25
ResourceManager
();
26
~ResourceManager
();
27
28
ResourceManager
(
const
ResourceManager
&) =
delete
;
29
ResourceManager
&
operator=
(
const
ResourceManager
&) =
delete
;
30
ResourceManager
(
ResourceManager
&&) =
delete
;
31
ResourceManager
&
operator=
(
ResourceManager
&&) =
delete
;
32
33
// --- 静态API ---
34
static
ResourceManager
&
GetInstance
();
35
inline
static
void
Init
() {
GetInstance
().init(); }
36
inline
static
void
Destroy
() {
GetInstance
().clear(); }
37
38
// --- 纹理 ---
39
static
SDL_Texture*
LoadTexture
(
const
std::string& filePath) {
return
GetInstance
().m_textureManager->loadTexture(filePath); }
40
static
SDL_Texture*
GetTexture
(
const
std::string& filePath) {
return
GetInstance
().m_textureManager->getTexture(filePath); }
41
static
void
UnloadTexture
(
const
std::string& filePath) {
GetInstance
().m_textureManager->unloadTexture(filePath); }
42
static
void
ClearAllTextures
() {
GetInstance
().m_textureManager->clearTexture(); }
43
static
void
ClearTexture
() {
GetInstance
().m_textureManager->clearTexture(); }
44
45
// --- 音频 ---
46
static
MIX_Audio*
LoadAudio
(
const
std::string& filePath) {
return
GetInstance
().m_audioManager->loadAudio(filePath); }
47
static
MIX_Audio*
GetAudio
(
const
std::string& filePath) {
return
GetInstance
().m_audioManager->getAudio(filePath); }
48
static
void
UnloadAudio
(
const
std::string& filePath) {
GetInstance
().m_audioManager->unloadAudio(filePath); }
49
static
void
ClearAudio
() {
GetInstance
().m_audioManager->clearAudio(); }
50
51
// --- 字体(按路径+字号缓存) ---
52
static
TTF_Font*
LoadFont
(
const
std::string& filePath,
float
fontSize) {
return
GetInstance
().m_fontManager->loadFont(filePath, fontSize); }
53
static
TTF_Font*
GetFont
(
const
std::string& filePath,
float
fontSize) {
return
GetInstance
().m_fontManager->getFont(filePath, fontSize); }
54
static
void
ClearAllFonts
() {
GetInstance
().m_fontManager->clearFont(); }
55
static
void
ClearFont
() {
GetInstance
().m_fontManager->clearFont(); }
56
57
// 内部接口(供 AudioPlayer 注入混音器)
58
static
void
SetAudioMixer
(
struct
MIX_Mixer* mixer) {
GetInstance
().m_audioManager->setMixer(mixer); }
59
60
private
:
61
void
init();
62
void
clear();
63
64
std::unique_ptr<TextureManager> m_textureManager;
65
std::unique_ptr<AudioManager> m_audioManager;
66
std::unique_ptr<FontManager> m_fontManager;
67
bool
m_ttfInitialized =
false
;
68
};
69
}
AudioManager.h
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
FontManager.h
TextureManager.h
Shit::ResourceManager::LoadAudio
static MIX_Audio * LoadAudio(const std::string &filePath)
定义
ResourceManager.h:46
Shit::ResourceManager::UnloadTexture
static void UnloadTexture(const std::string &filePath)
定义
ResourceManager.h:41
Shit::ResourceManager::ClearAudio
static void ClearAudio()
定义
ResourceManager.h:49
Shit::ResourceManager::Init
static void Init()
定义
ResourceManager.h:35
Shit::ResourceManager::ResourceManager
ResourceManager(ResourceManager &&)=delete
Shit::ResourceManager::ClearAllTextures
static void ClearAllTextures()
定义
ResourceManager.h:42
Shit::ResourceManager::UnloadAudio
static void UnloadAudio(const std::string &filePath)
定义
ResourceManager.h:48
Shit::ResourceManager::ClearFont
static void ClearFont()
定义
ResourceManager.h:55
Shit::ResourceManager::ClearTexture
static void ClearTexture()
定义
ResourceManager.h:43
Shit::ResourceManager::GetFont
static TTF_Font * GetFont(const std::string &filePath, float fontSize)
定义
ResourceManager.h:53
Shit::ResourceManager::Destroy
static void Destroy()
释放所有资源缓存(必须在 SDL_Quit 之前调用)
定义
ResourceManager.h:36
Shit::ResourceManager::ResourceManager
ResourceManager()
Shit::ResourceManager::ClearAllFonts
static void ClearAllFonts()
定义
ResourceManager.h:54
Shit::ResourceManager::SetAudioMixer
static void SetAudioMixer(struct MIX_Mixer *mixer)
定义
ResourceManager.h:58
Shit::ResourceManager::LoadFont
static TTF_Font * LoadFont(const std::string &filePath, float fontSize)
定义
ResourceManager.h:52
Shit::ResourceManager::GetAudio
static MIX_Audio * GetAudio(const std::string &filePath)
定义
ResourceManager.h:47
Shit::ResourceManager::GetTexture
static SDL_Texture * GetTexture(const std::string &filePath)
定义
ResourceManager.h:40
Shit::ResourceManager::GetInstance
static ResourceManager & GetInstance()
Shit::ResourceManager::ResourceManager
ResourceManager(const ResourceManager &)=delete
Shit::ResourceManager::operator=
ResourceManager & operator=(ResourceManager &&)=delete
Shit::ResourceManager::LoadTexture
static SDL_Texture * LoadTexture(const std::string &filePath)
定义
ResourceManager.h:39
Shit::ResourceManager::~ResourceManager
~ResourceManager()
Shit::ResourceManager::operator=
ResourceManager & operator=(const ResourceManager &)=delete
Shit
定义
AudioPlayer.h:10
include
ShitEngine
Resource
ResourceManager.h
制作者
1.17.0