fix: pedantic warnings

This commit is contained in:
2025-01-24 19:50:31 +01:00
parent 591d09b610
commit 85f3a73409
8 changed files with 48 additions and 23 deletions

View File

@@ -1,8 +1,9 @@
#include "errors.h"
#include <SDL.h>
#include <SDL_messagebox.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_STR_LEN 128

View File

@@ -1,10 +1,14 @@
#include "game.h"
#include <SDL_scancode.h>
#include <stdint.h>
#include "../main.h"
// called every time the game's state is updated
void game_update(GameData game_data, const Uint8* keys) {
void game_update(GameData game_data, const uint8_t* keys) {
(void)game_data;
if (keys[SDL_SCANCODE_ESCAPE]) {
stop();
}

View File

@@ -1,9 +1,10 @@
#pragma once
#include <SDL.h>
#include <stdint.h>
// stores the data used in the game
typedef struct {
void* val;
} GameData;
// updates the game's state
void game_update(GameData game_data, const Uint8* keys);
void game_update(GameData game_data, const uint8_t* keys);

View File

@@ -1,14 +1,20 @@
#include "main.h"
#include <SDL.h>
#include <SDL_error.h>
#include <SDL_events.h>
#include <SDL_keyboard.h>
#include <SDL_render.h>
#include <SDL_video.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "errors.h"
#include "game/game.h"
#include "window/audio.h"
// #include "window/audio.h"
#include "window/renderer.h"
#ifdef __EMSCRIPTEN__ // for web builds
@@ -36,8 +42,8 @@ static void init(void) {
}
// initialize audio
AudioDevice* audio_device = audio_device_init(32000, AUDIO_S16, 1, 255);
//AudioData audio1 = audio_load_wav(audio_device, "FILE NAME");
// AudioDevice* audio_device = audio_device_init(32000, AUDIO_S16, 1, 255);
// AudioData audio1 = audio_load_wav(audio_device, "FILE NAME");
}
// handles game application updating
@@ -55,7 +61,7 @@ static void update(void) {
}
// updates the game
game_update((GameData){}, SDL_GetKeyboardState(NULL));
game_update((GameData){NULL}, SDL_GetKeyboardState(NULL));
// updates the render
RenderData render_data = {window, renderer};
@@ -69,6 +75,8 @@ void stop(void) {
// entry point of the application
int32_t main(int32_t argc, char** argv) {
(void)argc;
(void)argv;
init();
while (playing)

View File

@@ -1,6 +1,11 @@
#include "audio.h"
#include <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"
@@ -18,7 +23,7 @@ static void audio_mixer(void* userdata, uint8_t* stream, int32_t len) {
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;
@@ -35,13 +40,14 @@ static void audio_mixer(void* userdata, uint8_t* stream, int32_t 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;
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);
// suddenly becomes signed
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
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
@@ -56,8 +62,8 @@ static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec w
// loads a WAV file and returns the relevant information
AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path) {
SDL_AudioSpec wav_spec;
AudioData audio;
SDL_AudioSpec wav_spec = {0};
AudioData audio = {0};
SDL_LoadWAV(file_path, &wav_spec, &audio.buffer, &audio.length);
convert_audio(audio_device, wav_spec, &audio.buffer, &audio.length);
@@ -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 int32_t freq, const SDL_AudioFormat format, const uint8_t channels, const uint8_t 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,7 +106,7 @@ AudioDevice* audio_device_init(const int32_t freq, const SDL_AudioFormat format,
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

View File

@@ -1,5 +1,7 @@
#pragma once
#include <SDL.h>
#include <SDL_audio.h>
#include <stdint.h>
typedef struct {
uint32_t length;
@@ -17,5 +19,5 @@ typedef struct {
AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path);
AudioDevice* audio_device_init(const int32_t freq, const SDL_AudioFormat format, const uint8_t channels, const uint8_t 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

@@ -1,7 +1,9 @@
// initializes the window and renderer
#include "renderer.h"
#include <SDL.h>
#include <SDL_error.h>
#include <SDL_render.h>
#include <SDL_video.h>
#include <stdio.h>
#include "../errors.h"

View File

@@ -1,5 +1,6 @@
#pragma once
#include <SDL.h>
#include <SDL_render.h>
#include <SDL_video.h>
typedef struct {
SDL_Window* window;