#include "util.h" #include #include #include bool Osu_HasPrefix(const char* str, const char* prefix) { if (!str || !prefix) { return false; } int strLen = strlen(str); int prefixLen = strlen(prefix); if (strLen < prefixLen) { return false; } return strncmp(str, prefix, prefixLen) == 0; } bool Osu_HasSuffix(const char* str, const char* suffix) { if (!str || !suffix) { return false; } int strLen = strlen(str); int suffixLen = strlen(suffix); if (strLen < suffixLen) { return false; } return strncmp(str + strLen - suffixLen, suffix, suffixLen) == 0; } struct SDL_FRect Osu_GetTextureRect(struct SDL_Texture* texture) { float texW, texH; SDL_GetTextureSize(texture, &texW, &texH); SDL_assert(texW > 0); SDL_assert(texH > 0); return (SDL_FRect){ .x = 0, .y = 0, .w = texW, .h = texH, }; } void Osu_Panic(const char* title, const char* description) { char* descriptionCopy; SDL_asprintf(&descriptionCopy, "%s", description); fprintf(stderr, "%s: %s\n", title, descriptionCopy); if (!SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, descriptionCopy, NULL)) { fprintf(stderr, "Failed to show message box: %s\n", SDL_GetError()); } free(descriptionCopy); exit(EXIT_FAILURE); } int Osu_Random(int min, int max) { return rand() % (max + 1 - min) + min; }