23#define __WIZARD_ENGINE_INTERNAL__
29void wze::assets::combine_hash(
size_t& seed,
size_t value) {
31 seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
34std::shared_ptr<wze::image> wze::assets::load_image(std::string
const& path) {
35 std::shared_ptr<image> image;
38 IMG_Load(std::filesystem::relative(_assets + path).
string().c_str()),
41 throw exception(IMG_GetError());
47std::shared_ptr<wze::image>
48wze::assets::create_image(std::string
const& text,
49 std::shared_ptr<font>
const& font,
50 uint32_t wrap_length) {
51 std::shared_ptr<image> image;
53 image = {TTF_RenderUTF8_LCD_Wrapped(font.get(), text.c_str(),
54 {std::numeric_limits<uint8_t>::max(),
55 std::numeric_limits<uint8_t>::max(),
56 std::numeric_limits<uint8_t>::max(),
57 std::numeric_limits<uint8_t>::max()},
58 {0, 0, 0, 0}, wrap_length),
61 throw exception(TTF_GetError());
67size_t wze::assets::hash_image(std::shared_ptr<image>
const& image) {
69 std::hash<uint8_t> hash;
77 static_cast<uint8_t*
>(image->pixels),
79 static_cast<uint8_t*
>(image->pixels) +
80 image->w * image->h * image->format->BytesPerPixel,
81 [&](uint8_t pixel) ->
void {
82 combine_hash(seed, hash(pixel));
88std::shared_ptr<wze::texture>
89wze::assets::create_texture(std::shared_ptr<image>
const& image) {
90 std::shared_ptr<texture> texture;
92 texture = {SDL_CreateTextureFromSurface(renderer::base(), image.get()),
95 throw exception(SDL_GetError());
101std::shared_ptr<wze::sound> wze::assets::load_sound(std::string
const& path) {
102 std::shared_ptr<sound> sound;
105 Mix_LoadWAV(std::filesystem::relative(_assets + path).
string().c_str()),
108 throw exception(Mix_GetError());
114size_t wze::assets::hash_sound(std::shared_ptr<sound>
const& sound) {
116 std::hash<uint8_t> hash;
124 std::for_each(sound->abuf, sound->abuf + sound->alen,
125 [&](uint8_t sample) ->
void {
126 combine_hash(seed, hash(sample));
132std::shared_ptr<wze::font> wze::assets::load_font(std::string
const& path,
136 std::shared_ptr<font> font;
139 TTF_OpenFont(std::filesystem::relative(_assets + path).
string().c_str(),
143 throw exception(TTF_GetError());
145 TTF_SetFontStyle(font.get(), style);
146 TTF_SetFontWrappedAlign(font.get(), alignment);
147 TTF_SetFontHinting(font.get(), TTF_HINTING_LIGHT_SUBPIXEL);
152std::unique_ptr<wze::cursor, std::function<void(wze::cursor*)>>
154 std::unique_ptr<cursor, std::function<void(cursor*)>> cursor;
156 cursor = {SDL_CreateSystemCursor((SDL_SystemCursor)
system_cursor),
159 throw exception(SDL_GetError());
165std::unique_ptr<wze::cursor, std::function<void(wze::cursor*)>>
166wze::assets::create_cursor(std::shared_ptr<image>
const& image, uint16_t hot_x,
168 std::unique_ptr<cursor, std::function<void(cursor*)>> cursor;
170 cursor = {SDL_CreateColorCursor(image.get(), hot_x, hot_y), SDL_FreeCursor};
172 throw exception(SDL_GetError());
Image file in host memory.
system_cursor
System cursors.
font_alignment
Font alignments.
Subsystem to handle graphics.