This commit is contained in:
@@ -51,19 +51,20 @@ namespace game::resource
|
|||||||
|
|
||||||
Audio::Audio(const std::filesystem::path& path)
|
Audio::Audio(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto key = std::string("fs:") + path.string();
|
auto pathString = path.string();
|
||||||
|
auto key = std::string("fs:") + pathString;
|
||||||
internal = cache_get(key);
|
internal = cache_get(key);
|
||||||
if (internal)
|
if (internal)
|
||||||
{
|
{
|
||||||
logger.info(std::format("Using cached audio: {}", path.string()));
|
logger.info(std::format("Using cached audio: {}", pathString));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal = audio_make(MIX_LoadAudio(mixer_get(), path.c_str(), true));
|
internal = audio_make(MIX_LoadAudio(mixer_get(), pathString.c_str(), true));
|
||||||
cache_set(key, internal);
|
cache_set(key, internal);
|
||||||
if (internal) logger.info(std::format("Initialized audio: {}", path.string()));
|
if (internal) logger.info(std::format("Initialized audio: {}", pathString));
|
||||||
|
|
||||||
if (!internal) logger.info(std::format("Failed to intialize audio: {} ({})", path.string(), SDL_GetError()));
|
if (!internal) logger.info(std::format("Failed to intialize audio: {} ({})", pathString, SDL_GetError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::Audio(const physfs::Path& path)
|
Audio::Audio(const physfs::Path& path)
|
||||||
|
|||||||
@@ -8,15 +8,17 @@ namespace game::resource
|
|||||||
{
|
{
|
||||||
Font::Font(const std::filesystem::path& path, float size)
|
Font::Font(const std::filesystem::path& path, float size)
|
||||||
{
|
{
|
||||||
|
auto pathString = path.string();
|
||||||
|
|
||||||
ImFontConfig config;
|
ImFontConfig config;
|
||||||
config.FontDataOwnedByAtlas = false;
|
config.FontDataOwnedByAtlas = false;
|
||||||
|
|
||||||
internal = ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size, &config);
|
internal = ImGui::GetIO().Fonts->AddFontFromFileTTF(pathString.c_str(), size, &config);
|
||||||
|
|
||||||
if (internal)
|
if (internal)
|
||||||
logger.info(std::format("Initialized font: {}", path.c_str()));
|
logger.info(std::format("Initialized font: {}", pathString));
|
||||||
else
|
else
|
||||||
logger.error(std::format("Failed to initialize font: {}", path.c_str()));
|
logger.error(std::format("Failed to initialize font: {}", pathString));
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::Font(const physfs::Path& path, float size)
|
Font::Font(const physfs::Path& path, float size)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace game::resource
|
|||||||
glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, &logLength);
|
glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
std::string log(logLength, '\0');
|
std::string log(logLength, '\0');
|
||||||
if (logLength > 0) glGetShaderInfoLog(shaderHandle, logLength, nullptr, log.data());
|
if (logLength > 0) glGetShaderInfoLog(shaderHandle, logLength, nullptr, log.data());
|
||||||
logger.error(std::format("Failed to compile shader: {}", log));
|
logger.error(std::format("Failed to compile {} shader: {}", stage, log));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -136,14 +136,15 @@ namespace game::resource
|
|||||||
|
|
||||||
Texture::Texture(const std::filesystem::path& path)
|
Texture::Texture(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto key = std::string("fs:") + path.string();
|
auto pathString = path.string();
|
||||||
|
auto key = std::string("fs:") + pathString;
|
||||||
if (cache_get(key, idShared, id, size, channels))
|
if (cache_get(key, idShared, id, size, channels))
|
||||||
{
|
{
|
||||||
logger.info(std::format("Using cached texture: {}", path.string()));
|
logger.info(std::format("Using cached texture: {}", pathString));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto surface = SDL_LoadPNG(path.c_str()))
|
if (auto surface = SDL_LoadPNG(pathString.c_str()))
|
||||||
{
|
{
|
||||||
auto rgbaSurface = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
|
auto rgbaSurface = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
|
||||||
SDL_DestroySurface(surface);
|
SDL_DestroySurface(surface);
|
||||||
@@ -152,10 +153,10 @@ namespace game::resource
|
|||||||
init((const uint8_t*)surface->pixels);
|
init((const uint8_t*)surface->pixels);
|
||||||
SDL_DestroySurface(surface);
|
SDL_DestroySurface(surface);
|
||||||
cache_set(key, idShared, this->size, channels);
|
cache_set(key, idShared, this->size, channels);
|
||||||
logger.info(std::format("Initialized texture: {}", path.string()));
|
logger.info(std::format("Initialized texture: {}", pathString));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
logger.error(std::format("Failed to initialize texture: {} ({})", path.string(), SDL_GetError()));
|
logger.error(std::format("Failed to initialize texture: {} ({})", pathString, SDL_GetError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(const physfs::Path& path)
|
Texture::Texture(const physfs::Path& path)
|
||||||
|
|||||||
Reference in New Issue
Block a user