From 3af8cb9435db89a87d83e6c1c12d3320840023e9 Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 4 Mar 2025 14:39:54 +0100 Subject: [PATCH] fix: the system was entirely unusable, just make the user input the constants themselves --- src/error.h | 3 +-- src/main.c | 2 +- src/window/audio.c | 10 +++++----- src/window/render.c | 6 +++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/error.h b/src/error.h index d6c1cef..6506126 100644 --- a/src/error.h +++ b/src/error.h @@ -35,5 +35,4 @@ void info(char const*, ...); // prints an info message to stdout void warn(char const*, ...); // prints a warning message to stderr // prints an error message to stderr before exiting -#define error(status, fmt, ...) i_error(status, __LINE__, __FILE__, fmt, __VA_ARGS__) -noreturn void i_error(gamestatus, uint32_t, char const*, char const*, ...); +noreturn void error(gamestatus, char const* file_name, uint32_t line, char const* fmt, ...); diff --git a/src/main.c b/src/main.c index e47a758..f20af14 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ static renderdata rdat; static void init(void) { // initialize SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) - error(ERROR_SDL_INIT, "SDL could not initialize! SDL Error: %s", SDL_GetError()); + error(ERROR_SDL_INIT, __FILE_NAME__, __LINE__, "SDL could not initialize! SDL Error: %s", SDL_GetError()); // initialize other game components gt = gametime_new(); diff --git a/src/window/audio.c b/src/window/audio.c index 65588e9..ce472b0 100644 --- a/src/window/audio.c +++ b/src/window/audio.c @@ -56,23 +56,23 @@ static void audio_cvt(audiodevice const* dev, SDL_AudioSpec const* spec, uint8_t cvt.buf = realloc(*bufptr, cvt.len * cvt.len_mult); // grow the inputted buffer for the conversion if (cvt.buf == NULL) - error(ERROR_STD_MEMORY, "something went wrong whilst growing the audio buffer whilst converting! (ln:%u)", __LINE__); + error(ERROR_STD_MEMORY, __FILE_NAME__, __LINE__, "something went wrong whilst growing the audio buffer whilst converting!"); // converts the audio to the new format if (!SDL_ConvertAudio(&cvt)) - error(ERROR_SDL_AUDIO_INIT, "something went wrong when loading/converting an audio buffer! (ln:%u) SDL Error: %s", __LINE__, SDL_GetError()); + error(ERROR_SDL_AUDIO_INIT, __FILE_NAME__, __LINE__, "something went wrong when loading/converting an audio buffer! SDL Error: %s", SDL_GetError()); *len = cvt.len; *bufptr = realloc(cvt.buf, cvt.len_cvt); if (*bufptr == NULL) - error(ERROR_STD_MEMORY, "something went wrong whilst shrinking the audio buffer whilst converting! (ln:%u)", __LINE__); + error(ERROR_STD_MEMORY, __FILE_NAME__, __LINE__, "something went wrong whilst shrinking the audio buffer whilst converting!"); } audiodevice* audio_device_init(int32_t freq, SDL_AudioFormat fmt, uint8_t channels, uint16_t samples) { audiodevice* dev = malloc(sizeof(audiodevice)); if (dev == NULL) - error(ERROR_STD_INIT, "null pointer when allocating memory for the audio device! (ln:%u)", __LINE__); + error(ERROR_STD_INIT, __FILE_NAME__, __LINE__, "null pointer when allocating memory for the audio device!"); // define the audio specification SDL_AudioSpec spec = {freq, fmt, channels, 0, samples, 0, 0, NULL, NULL}; @@ -90,7 +90,7 @@ audiodevice* audio_device_init(int32_t freq, SDL_AudioFormat fmt, uint8_t channe // if the audio device isn't set, cause an error if (dev->id < 1) - error(ERROR_SDL_AUDIO_INIT, "audio device failed to open! (ln:%u) SDL Error: %s", __LINE__, SDL_GetError()); + error(ERROR_SDL_AUDIO_INIT, __FILE_NAME__, __LINE__, "audio device failed to open! SDL Error: %s", SDL_GetError()); // default state of the device is paused, so we unpause it here SDL_PauseAudioDevice(dev->id, 0); diff --git a/src/window/render.c b/src/window/render.c index 6a52fe9..33ea568 100644 --- a/src/window/render.c +++ b/src/window/render.c @@ -12,14 +12,14 @@ #include "colour/colour32.h" void render_init(renderdata* const rdat, gamedata const* const gdat) { - SDL_Window* const window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 100, 100, SDL_WINDOW_SHOWN); + SDL_Window* const window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN); if (window == NULL) - error(ERROR_SDL_RENDERING_INIT, "failed to create a window. SDL Error: %s", SDL_GetError()); + error(ERROR_SDL_RENDERING_INIT, __FILE_NAME__, __LINE__, "failed to create a window. SDL Error: %s", SDL_GetError()); // rendere using vsync to limit updates to the refresh rate of the monitor SDL_Renderer* const renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); if (renderer == NULL) - error(ERROR_SDL_RENDERING_INIT, "failed to create a renderer. SDL Error: %s", SDL_GetError()); + error(ERROR_SDL_RENDERING_INIT, __FILE_NAME__, __LINE__, "failed to create a renderer. SDL Error: %s", SDL_GetError()); *rdat = (renderdata){ window,