summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-06-16 02:17:51 -0400
committerrealtradam <[email protected]>2023-06-16 02:17:51 -0400
commit4cb44499b27cd8fe4955a16a9af46cf97ecf06e3 (patch)
tree51cbcfb7a5328dc3fbc9dbc5a502ed70ed7c951d
parenta47cc44ef7191d03f8ca1b8d4e6b9dd34fba1807 (diff)
downloadRodeoKit-4cb44499b27cd8fe4955a16a9af46cf97ecf06e3.tar.gz
RodeoKit-4cb44499b27cd8fe4955a16a9af46cf97ecf06e3.zip
switch SDL_Init to use SDL_InitSubSystem and move to where relevant
-rw-r--r--include/rodeo/input.h6
-rw-r--r--src/audio/rodeo_audio.c29
-rw-r--r--src/input/rodeo_input.c36
-rw-r--r--src/rodeo.c8
-rw-r--r--src/window/rodeo_window.c27
5 files changed, 84 insertions, 22 deletions
diff --git a/include/rodeo/input.h b/include/rodeo/input.h
index dac70e9..db41633 100644
--- a/include/rodeo/input.h
+++ b/include/rodeo/input.h
@@ -3,6 +3,12 @@
// public
#include "rodeo/input_t.h"
+void
+rodeo_input_init(void);
+
+void
+rodeo_input_deinit(void);
+
bool
rodeo_input_poll(void);
diff --git a/src/audio/rodeo_audio.c b/src/audio/rodeo_audio.c
index 485ddfd..78cef3d 100644
--- a/src/audio/rodeo_audio.c
+++ b/src/audio/rodeo_audio.c
@@ -19,17 +19,42 @@
void
rodeo_audio_init(uint32_t channels)
{
- if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Initializing SDL Audio..."
+ );
+ if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{
rodeo_log(
rodeo_logLevel_error,
"Failed to initialize SDL Audio. SDL_Error: %s",
SDL_GetError()
);
+ exit(EXIT_FAILURE);
+ }
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Success initializing SDL Audio"
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Initializing SDL Mixer..."
+ );
+ if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
+ {
+ rodeo_log(
+ rodeo_logLevel_error,
+ "Failed to initialize SDL Mixer. SDL_Error: %s",
+ SDL_GetError()
+ );
}
else
{
- Mix_AllocateChannels((int32_t)channels);
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Success initializing SDL Mixer"
+ );
+ Mix_AllocateChannels((int32_t)channels);
/*
irodeo_audio_channelPool_num = 1; //num_sound_pools;
irodeo_audio_channelPool_size = channels; //size_sound_pools;
diff --git a/src/input/rodeo_input.c b/src/input/rodeo_input.c
index 8d5c1bd..0ea511e 100644
--- a/src/input/rodeo_input.c
+++ b/src/input/rodeo_input.c
@@ -105,6 +105,35 @@ irodeo_input_screen_to_world_dy(float input)
}
}
+void
+rodeo_input_init(void)
+{
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Initializing SDL Events and Game Controller..."
+ );
+ if(SDL_InitSubSystem(SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER) < 0)
+ {
+ rodeo_log(
+ rodeo_logLevel_error,
+ "Failed to initialize SDL Events or Game Controller. SDL_Error: %s",
+ SDL_GetError()
+ );
+ exit(EXIT_FAILURE);
+ }
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Success initializing SDL Events and Game Controller"
+ );
+}
+
+void
+rodeo_input_deinit(void)
+{
+ // everything is deinited with SDL window already because of the way SDL works.
+ // need to investigate this more...
+}
+
bool
rodeo_input_poll(void)
{
@@ -689,3 +718,10 @@ irodeo_input_controller_unregister(int32_t id)
SDL_GameControllerClose(controller);
cmap_SDL_GameController_erase(&icontrollers, id);
}
+
+#define mrodeo_input_do() \
+ mrodeo_defer_do( \
+ rodeo_input_init(), \
+ rodeo_input_deinit() \
+ )
+
diff --git a/src/rodeo.c b/src/rodeo.c
index 4131bc5..dae2c43 100644
--- a/src/rodeo.c
+++ b/src/rodeo.c
@@ -19,6 +19,7 @@ void
rodeo_init(float width, float height, cstr window_name, uint32_t audio_channels)
{
rodeo_window_init((uint32_t)width, (uint32_t)height, window_name);
+ rodeo_input_init();
rodeo_math_rng_init();
rodeo_audio_init(audio_channels);
rodeo_gfx_init(width, height);
@@ -28,10 +29,11 @@ rodeo_init(float width, float height, cstr window_name, uint32_t audio_channels)
void
rodeo_deinit(void)
{
- rodeo_window_deinit();
- rodeo_math_rng_deinit();
- rodeo_audio_deinit();
rodeo_gfx_deinit();
+ rodeo_audio_deinit();
+ rodeo_math_rng_deinit();
+ rodeo_input_deinit();
+ rodeo_window_deinit();
}
void
diff --git a/src/window/rodeo_window.c b/src/window/rodeo_window.c
index 40c1ccf..0c7899e 100644
--- a/src/window/rodeo_window.c
+++ b/src/window/rodeo_window.c
@@ -26,29 +26,22 @@ rodeo_window_init(
rodeo_log(
rodeo_logLevel_info,
- "Initializing SDL..."
+ "Initializing SDL Video..."
);
+ if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
- uint32_t init_flags_sdl = 0;
- init_flags_sdl = init_flags_sdl | SDL_INIT_VIDEO;
- init_flags_sdl = init_flags_sdl | SDL_INIT_AUDIO;
- init_flags_sdl = init_flags_sdl | SDL_INIT_GAMECONTROLLER;
-
- if(SDL_Init(init_flags_sdl) < 0)
- {
- rodeo_log(
- rodeo_logLevel_error,
- "Failed to initialize SDL. SDL_Error: %s",
- SDL_GetError()
- );
- exit(EXIT_FAILURE);
- }
rodeo_log(
- rodeo_logLevel_info,
- "Success initializing SDL"
+ rodeo_logLevel_error,
+ "Failed to initialize SDL Video. SDL_Error: %s",
+ SDL_GetError()
);
+ exit(EXIT_FAILURE);
}
+ rodeo_log(
+ rodeo_logLevel_info,
+ "Success initializing SDL Video"
+ );
rodeo_log(
rodeo_logLevel_info,