fix pedantic warnings

This commit is contained in:
2025-01-24 19:35:13 +01:00
parent ec77c6958f
commit 3190bb4732
12 changed files with 112 additions and 77 deletions

View File

@@ -1,6 +1,11 @@
#include "audio.h"
#include <SDL2/SDL.h>
#include <SDL_audio.h>
#include <SDL_error.h>
#include <SDL_stdinc.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "../errors.h"
@@ -13,19 +18,19 @@ typedef struct {
} AudioCallbackData;
// audio callback from SDL_AudioSpec; called when the audio device needs more data
static void audio_mixer(void* userdata, Uint8* stream, int len) {
static void audio_mixer(void* userdata, uint8_t* stream, int32_t len) {
memset(stream, 0, len); // clear the playing audio
AudioDevice* device = userdata; // get the callback data
AudioData* audio = device->playing_audio;
for (int i = 0; i < MAX_SOUNDS; i++) {
for (int32_t i = 0; i < MAX_SOUNDS; i++) {
// skip if the audio doesn't conain any further data
if (audio[i].length <= 0) {
continue;
}
// get the length of which we shall be mixing
Uint32 mix_length = SDL_min(audio[i].length, len);
uint32_t mix_length = SDL_min(audio[i].length, len);
// mix the audio with the stream
SDL_MixAudioFormat(stream, audio[i].buffer, device->format, mix_length, SDL_MIX_MAXVOLUME);
@@ -35,14 +40,15 @@ static void audio_mixer(void* userdata, Uint8* stream, int len) {
}
// converts the audio to the format of the audio device
static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec wav_spec, Uint8** wav_buffer, Uint32* wav_length) {
static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec wav_spec, uint8_t** wav_buffer, uint32_t* wav_length) {
// build the audio converter with the audio given
SDL_AudioCVT cvt = {0};
SDL_BuildAudioCVT(&cvt, wav_spec.format, wav_spec.channels, wav_spec.freq, audio_device->format, audio_device->channels, audio_device->freq);
cvt.len = (*wav_length) * wav_spec.channels; // the buffer length
cvt.buf = (Uint8*)SDL_malloc(cvt.len * cvt.len_mult); // allocate size for the new buffer
memcpy(cvt.buf, *wav_buffer, *wav_length); // copy wav data to cvt buffer;
// suddenly becomes signed
cvt.len = (*wav_length) * wav_spec.channels; // the buffer length
cvt.buf = (uint8_t*)SDL_malloc(cvt.len * cvt.len_mult); // allocate size for the new buffer
memcpy(cvt.buf, *wav_buffer, *wav_length); // copy wav data to cvt buffer;
// convert
SDL_ConvertAudio(&cvt);
@@ -67,7 +73,7 @@ AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path)
}
// initializes the audio device
AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const Uint8 channels, const Uint16 samples) {
AudioDevice* audio_device_init(const int32_t freq, const SDL_AudioFormat format, const uint8_t channels, const Uint16 samples) {
// allocate memory for the audio device
AudioDevice* audio_device = malloc(sizeof(AudioDevice));
@@ -100,10 +106,9 @@ AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, con
void audio_play(const AudioDevice* audio_device, const AudioData audio) {
AudioData* playing_audio = audio_device->playing_audio;
for (int i = 0; i < MAX_SOUNDS; i++) {
for (int32_t i = 0; i < MAX_SOUNDS; i++) {
// overrite audio that has been deallocated
if (playing_audio[i].length <= 0) {
// override the audio
playing_audio[i] = audio;
break; // don't continue. :3

View File

@@ -1,21 +1,23 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL_audio.h>
#include <stdint.h>
typedef struct {
Uint32 length;
Uint32 mixed_amount;
Uint8* buffer;
uint32_t length;
uint32_t mixed_amount;
uint8_t* buffer;
} AudioData;
typedef struct {
SDL_AudioDeviceID id;
int freq;
int32_t freq;
SDL_AudioFormat format;
Uint8 channels;
uint8_t channels;
AudioData* playing_audio;
} AudioDevice;
AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path);
AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const Uint8 channels, const Uint16 samples);
AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const uint8_t channels, const uint16_t samples);
void audio_play(const AudioDevice* audio_device, const AudioData audio);

View File

@@ -13,27 +13,24 @@ typedef union {
} Colour;
#define RED ((uint8_t)0b11000011)
#define YELLOW ((uint8_t)0b11110011)
#define ORANGE ((uint8_t)0b11100011)
#define GREEN ((uint8_t)0b00110011)
#define CYAN ((uint8_t)0b00111111)
#define BLUE ((uint8_t)0b00001111)
#define MAGENTA ((uint8_t)0b11001111)
#define NONE ((uint8_t)0)
#define BLACK ((uint8_t)3)
#define RED ((uint8_t)0xC0 | BLACK)
#define YELLOW ((uint8_t)0xF0 | BLACK)
#define ORANGE ((uint8_t)0xE0 | BLACK)
#define GREEN ((uint8_t)0x30 | BLACK)
#define CYAN ((uint8_t)0x3C | BLACK)
#define BLUE ((uint8_t)0x0C | BLACK)
#define MAGENTA ((uint8_t)0xCC | BLACK)
#define WHITE ((uint8_t)0xFF)
#define NONE ((uint8_t)0)
#define BLACK ((uint8_t)3)
#define WHITE ((uint8_t)0xFF)
#define COLOUR_RED ((Colour){RED})
#define COLOUR_YELLOW ((Colour){YELLOW})
#define COLOUR_ORANGE ((Colour){ORANGE})
#define COLOUR_GREEN ((Colour){GREEN})
#define COLOUR_CYAN ((Colour){CYAN})
#define COLOUR_BLUE ((Colour){BLUE})
#define COLOUR_NONE ((Colour){NONE})
#define COLOUR_BLACK ((Colour){BLACK})
#define COLOUR_RED ((Colour){RED})
#define COLOUR_YELLOW ((Colour){YELLOW})
#define COLOUR_ORANGE ((Colour){ORANGE})
#define COLOUR_GREEN ((Colour){GREEN})
#define COLOUR_CYAN ((Colour){CYAN})
#define COLOUR_BLUE ((Colour){BLUE})
#define COLOUR_MAGENTA ((Colour){MAGENTA})
#define COLOUR_NONE ((Colour){NONE})
#define COLOUR_BLACK ((Colour){BLACK})
#define COLOUR_WHITE ((Colour){WHITE})
#define COLOUR_WHITE ((Colour){WHITE})

View File

@@ -1,10 +1,15 @@
// initializes the window and renderer
#include "renderer.h"
#include <SDL2/SDL.h>
#include <SDL_error.h>
#include <SDL_rect.h>
#include <SDL_render.h>
#include <SDL_video.h>
#include <stdint.h>
#include <stdio.h>
#include "../errors.h"
#include "../game/game.h"
#include "colour.h"
#include "renderer.h"

View File

@@ -1,13 +1,14 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL_render.h>
#include <SDL_video.h>
#include <stdint.h>
#include "../game/game.h"
#define SCREEN_WIDTH 256
#define SCREEN_WIDTH 256
#define SCREEN_HEIGHT (SCREEN_WIDTH * 2)
#define BLOCK_WIDTH (SCREEN_WIDTH / COLUMNS)
#define BLOCK_HEIGHT (SCREEN_HEIGHT / ROWS)
#define BLOCK_WIDTH (SCREEN_WIDTH / COLUMNS)
#define BLOCK_HEIGHT (SCREEN_HEIGHT / ROWS)
typedef struct {
SDL_Window* window;