Files
devilutionX/Source/engine/load_clx.cpp
T
Gleb Mazovetskiy 9db80ef5d7 Assets: Load files directly for UNPACKED_MPQS
When using `UNPACKED_MPQS`, avoid all the SDL machinery for reading
files.

This is beneficial not only due to reduced indirection but also because
we can test for the file's existence and get the file size without
opening it, which is much faster.
2022-11-22 02:44:25 +01:00

37 lines
936 B
C++

#include "engine/load_clx.hpp"
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif
#include "engine/assets.hpp"
#include "engine/load_file.hpp"
namespace devilution {
OptionalOwnedClxSpriteListOrSheet LoadOptionalClxListOrSheet(const char *path)
{
AssetRef ref = FindAsset(path);
if (!ref.ok())
return std::nullopt;
const size_t size = ref.size();
std::unique_ptr<uint8_t[]> data { new uint8_t[size] };
{
AssetHandle handle = OpenAsset(std::move(ref));
if (!handle.ok() || !handle.read(data.get(), size))
return std::nullopt;
}
return OwnedClxSpriteListOrSheet::FromBuffer(std::move(data), size);
}
OwnedClxSpriteListOrSheet LoadClxListOrSheet(const char *path)
{
size_t size;
std::unique_ptr<uint8_t[]> data = LoadFileInMem<uint8_t>(path, &size);
return OwnedClxSpriteListOrSheet::FromBuffer(std::move(data), size);
}
} // namespace devilution