z_mirror/sdl-osu

git clone https://git.raiguard.me/z_mirror/sdl-osu

Caleb HeuerUse custom log categories instead of internal SDL categories4bbec0e

trunk
1.5 KiB39 linesraw
1#pragma once
2#include <SDL3/SDL_log.h>
3#include <stdbool.h>
4
5struct SDL_Texture;
6
7bool Osu_HasPrefix(const char* str, const char* prefix);
8bool Osu_HasSuffix(const char* str, const char* suffix);
9
10struct SDL_FRect Osu_GetTextureRect(struct SDL_Texture* texture);
11
12void Osu_Panic(const char* title, const char* description);
13
14int Osu_Random(int min, int max);
15
16enum {
17    OSU_LOG_CATEGORY_AUDIO = SDL_LOG_CATEGORY_CUSTOM,
18    OSU_LOG_CATEGORY_BEATMAP_PARSER,
19};
20
21#define OSU_LOG_TRACEF(fmt, ...)                                                                                 \
22    {                                                                                                            \
23        char realFmt[512];                                                                                       \
24        snprintf(realFmt, 512, "%s: %s", "(%u) %s:%u", fmt);                                                     \
25        SDL_LogTrace(OSU_LOG_CATEGORY_BEATMAP_PARSER, realFmt, SDL_GetTicks(), __FILE__, __LINE__, __VA_ARGS__); \
26    }
27
28#define OSU_LOG_TRACE(msg) OSU_LOG_TRACEF("%s", msg)
29
30#define SDL_SAFEASSN(target, funcname, ...)                 \
31    {                                                       \
32        target = funcname(__VA_ARGS__);                     \
33        if (!target)                                        \
34            Osu_Panic(#funcname " failed", SDL_GetError()); \
35    }
36
37#define SDL_SAFECALL(funcname, ...) \
38    if (!funcname(__VA_ARGS__))     \
39        Osu_Panic(#funcname " failed", SDL_GetError());