fix: the system was entirely unusable, just make the user input the constants themselves

This commit is contained in:
2025-03-04 14:39:54 +01:00
parent c0bdc6ca17
commit 3af8cb9435
4 changed files with 10 additions and 11 deletions

View File

@@ -35,5 +35,4 @@ void info(char const*, ...); // prints an info message to stdout
void warn(char const*, ...); // prints a warning message to stderr void warn(char const*, ...); // prints a warning message to stderr
// prints an error message to stderr before exiting // prints an error message to stderr before exiting
#define error(status, fmt, ...) i_error(status, __LINE__, __FILE__, fmt, __VA_ARGS__) noreturn void error(gamestatus, char const* file_name, uint32_t line, char const* fmt, ...);
noreturn void i_error(gamestatus, uint32_t, char const*, char const*, ...);

View File

@@ -17,7 +17,7 @@ static renderdata rdat;
static void init(void) { static void init(void) {
// initialize SDL // initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) 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 // initialize other game components
gt = gametime_new(); gt = gametime_new();

View File

@@ -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 cvt.buf = realloc(*bufptr, cvt.len * cvt.len_mult); // grow the inputted buffer for the conversion
if (cvt.buf == NULL) 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 // converts the audio to the new format
if (!SDL_ConvertAudio(&cvt)) 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; *len = cvt.len;
*bufptr = realloc(cvt.buf, cvt.len_cvt); *bufptr = realloc(cvt.buf, cvt.len_cvt);
if (*bufptr == NULL) 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* audio_device_init(int32_t freq, SDL_AudioFormat fmt, uint8_t channels, uint16_t samples) {
audiodevice* dev = malloc(sizeof(audiodevice)); audiodevice* dev = malloc(sizeof(audiodevice));
if (dev == NULL) 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 // define the audio specification
SDL_AudioSpec spec = {freq, fmt, channels, 0, samples, 0, 0, NULL, NULL}; 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 the audio device isn't set, cause an error
if (dev->id < 1) 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 // default state of the device is paused, so we unpause it here
SDL_PauseAudioDevice(dev->id, 0); SDL_PauseAudioDevice(dev->id, 0);

View File

@@ -12,14 +12,14 @@
#include "colour/colour32.h" #include "colour/colour32.h"
void render_init(renderdata* const rdat, gamedata const* const gdat) { 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) 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 // 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); SDL_Renderer* const renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
if (renderer == NULL) 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){ *rdat = (renderdata){
window, window,