mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
fix: the system was entirely unusable, just make the user input the constants themselves
This commit is contained in:
@@ -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, ...);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user