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 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}
#define SHIT_API
定义 Core.h:14
static MIX_Audio * LoadAudio(const std::string &filePath)
定义 ResourceManager.h:46
static void UnloadTexture(const std::string &filePath)
定义 ResourceManager.h:41
static void ClearAudio()
定义 ResourceManager.h:49
static void Init()
定义 ResourceManager.h:35
ResourceManager(ResourceManager &&)=delete
static void ClearAllTextures()
定义 ResourceManager.h:42
static void UnloadAudio(const std::string &filePath)
定义 ResourceManager.h:48
static void ClearFont()
定义 ResourceManager.h:55
static void ClearTexture()
定义 ResourceManager.h:43
static TTF_Font * GetFont(const std::string &filePath, float fontSize)
定义 ResourceManager.h:53
static void Destroy()
释放所有资源缓存(必须在 SDL_Quit 之前调用)
定义 ResourceManager.h:36
static void ClearAllFonts()
定义 ResourceManager.h:54
static void SetAudioMixer(struct MIX_Mixer *mixer)
定义 ResourceManager.h:58
static TTF_Font * LoadFont(const std::string &filePath, float fontSize)
定义 ResourceManager.h:52
static MIX_Audio * GetAudio(const std::string &filePath)
定义 ResourceManager.h:47
static SDL_Texture * GetTexture(const std::string &filePath)
定义 ResourceManager.h:40
static ResourceManager & GetInstance()
ResourceManager(const ResourceManager &)=delete
ResourceManager & operator=(ResourceManager &&)=delete
static SDL_Texture * LoadTexture(const std::string &filePath)
定义 ResourceManager.h:39
ResourceManager & operator=(const ResourceManager &)=delete
定义 AudioPlayer.h:10