diff options
| -rw-r--r-- | include/rodeo/input.h | 6 | ||||
| -rw-r--r-- | src/audio/rodeo_audio.c | 29 | ||||
| -rw-r--r-- | src/input/rodeo_input.c | 36 | ||||
| -rw-r--r-- | src/rodeo.c | 8 | ||||
| -rw-r--r-- | src/window/rodeo_window.c | 27 |
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, |
