ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
ResourceManager.h
浏览该文件的文档.
1#pragma once
2
3#include <memory>
4#include <string>
5
7#include "TextureManager.h"
8#include "AudioManager.h"
9#include "FontManager.h"
10
11struct SDL_Texture;
12struct MIX_Audio;
13struct TTF_Font;
14
15namespace Shit {
24 public:
27
32
33 // --- 静态API ---
35 inline static void Init() { GetInstance().init(); }
36
37 // --- 纹理 ---
38 static SDL_Texture* LoadTexture(const std::string& filePath) { return GetInstance().m_textureManager->loadTexture(filePath); }
39 static SDL_Texture* GetTexture(const std::string& filePath) { return GetInstance().m_textureManager->getTexture(filePath); }
40 static void UnloadTexture(const std::string& filePath) { GetInstance().m_textureManager->unloadTexture(filePath); }
41 static void ClearTexture() { GetInstance().m_textureManager->clearTexture(); }
42
43 // --- 音频 ---
44 static MIX_Audio* LoadAudio(const std::string& filePath) { return GetInstance().m_audioManager->loadAudio(filePath); }
45 static MIX_Audio* GetAudio(const std::string& filePath) { return GetInstance().m_audioManager->getAudio(filePath); }
46 static void UnloadAudio(const std::string& filePath) { GetInstance().m_audioManager->unloadAudio(filePath); }
47 static void ClearAudio() { GetInstance().m_audioManager->clearAudio(); }
48
49 // --- 字体 ---
50 static TTF_Font* LoadFont(const std::string& filePath) { return GetInstance().m_fontManager->loadFont(filePath); }
51 static TTF_Font* GetFont(const std::string& filePath) { return GetInstance().m_fontManager->getFont(filePath); }
52 static void UnloadFont(const std::string& filePath) { return GetInstance().m_fontManager->unloadFont(filePath); }
53 static void ClearFont() { GetInstance().m_fontManager->clearFont(); }
54
55 // 内部接口(供 AudioPlayer 注入混音器)
56 static void SetAudioMixer(struct MIX_Mixer* mixer) { GetInstance().m_audioManager->setMixer(mixer); }
57
58 private:
59 void clear();
60 void init();
61
62 std::unique_ptr<TextureManager> m_textureManager;
63 std::unique_ptr<AudioManager> m_audioManager;
64 std::unique_ptr<FontManager> m_fontManager;
65 };
66}
#define SHIT_API
定义 Core.h:12
static MIX_Audio * LoadAudio(const std::string &filePath)
定义 ResourceManager.h:44
static TTF_Font * GetFont(const std::string &filePath)
定义 ResourceManager.h:51
static void UnloadTexture(const std::string &filePath)
定义 ResourceManager.h:40
static void ClearAudio()
定义 ResourceManager.h:47
static void Init()
定义 ResourceManager.h:35
ResourceManager(ResourceManager &&)=delete
static TTF_Font * LoadFont(const std::string &filePath)
定义 ResourceManager.h:50
static void UnloadAudio(const std::string &filePath)
定义 ResourceManager.h:46
static void ClearFont()
定义 ResourceManager.h:53
static void UnloadFont(const std::string &filePath)
定义 ResourceManager.h:52
static void ClearTexture()
定义 ResourceManager.h:41
static void SetAudioMixer(struct MIX_Mixer *mixer)
定义 ResourceManager.h:56
static MIX_Audio * GetAudio(const std::string &filePath)
定义 ResourceManager.h:45
static SDL_Texture * GetTexture(const std::string &filePath)
定义 ResourceManager.h:39
static ResourceManager & GetInstance()
ResourceManager(const ResourceManager &)=delete
ResourceManager & operator=(ResourceManager &&)=delete
static SDL_Texture * LoadTexture(const std::string &filePath)
定义 ResourceManager.h:38
ResourceManager & operator=(const ResourceManager &)=delete
定义 AudioPlayer.h:9