44#include < SDL2/SDL_ttf.h>
55#include < SFG/Own2dEngine/Game/audioManager.h>
66#include < SFG/Own2dEngine/Game/inputManager.h>
7+ #include < SFG/Own2dEngine/Game/options.h>
78#include < SFG/Own2dEngine/Game/performance.h>
89#include < SFG/Own2dEngine/Game/ui/button.h>
910#include < SFG/Own2dEngine/Game/ui/label.h>
@@ -19,82 +20,6 @@ namespace SFGO2DL = SFG::Own2dEngine::Logger;
1920namespace SFGO2DG = SFG::Own2dEngine::Game;
2021namespace SFGO2DU = SFG::Own2dEngine::Utils;
2122
22- struct TempAudioStruct {
23- SFGO2DG::UI::Label* audioInputLabel = nullptr ;
24- SFGO2DG::UI::Label* audioOutputLabel = nullptr ;
25- PaDeviceIndex inputDeviceIndex = paNoDevice;
26- PaDeviceIndex outputDeviceIndex = paNoDevice;
27- std::pair< std::vector< PaDeviceIndex >, std::vector< PaDeviceIndex > > devices;
28-
29- void SetAudioDeviceIndexes ( int32_t inputIndex, int32_t outputIndex ) {
30- spdlog::trace ( " [TempAudioStruct] SetAudioDeviceIndexes( inputIndex: {}, outputIndex: {} )" , inputIndex, outputIndex );
31- inputIndex = SFGO2DU::mod< int32_t >( inputIndex + 1 , this ->devices .first .size () + 1 ) - 1 ;
32- outputIndex = SFGO2DU::mod< int32_t >( outputIndex + 1 , this ->devices .second .size () + 1 ) - 1 ;
33-
34- PaDeviceIndex tmpInput;
35- PaDeviceIndex tmpOutput;
36- if ( inputIndex < 0 ) {
37- tmpInput = Pa_GetDefaultInputDevice ();
38- } else {
39- tmpInput = this ->devices .first [inputIndex];
40- }
41- if ( outputIndex < 0 ) {
42- tmpOutput = Pa_GetDefaultOutputDevice ();
43- } else {
44- tmpOutput = this ->devices .second [outputIndex];
45- }
46-
47- {
48- PaDeviceInfo const * deviceInfo = nullptr ;
49- PaHostApiInfo const * hostApiInfo = nullptr ;
50- std::string deviceName = " __UNKNOWN__" ;
51- std::string apiName = " __UNKNOWN__" ;
52-
53- deviceInfo = Pa_GetDeviceInfo ( tmpInput );
54- if ( deviceInfo ) {
55- deviceName = deviceInfo->name ;
56- hostApiInfo = Pa_GetHostApiInfo ( deviceInfo->hostApi );
57- if ( hostApiInfo ) {
58- apiName = hostApiInfo->name ;
59- }
60- }
61- if ( this ->audioInputLabel ) {
62- this ->audioInputLabel ->SetText ( fmt::format ( " Audio Input: ({}) {}" , apiName, deviceName ) );
63- }
64-
65- deviceInfo = nullptr ;
66- hostApiInfo = nullptr ;
67- deviceName = " __UNKNOWN__" ;
68- apiName = " __UNKNOWN__" ;
69-
70- deviceInfo = Pa_GetDeviceInfo ( tmpOutput );
71- if ( deviceInfo ) {
72- deviceName = deviceInfo->name ;
73- hostApiInfo = Pa_GetHostApiInfo ( deviceInfo->hostApi );
74- if ( hostApiInfo ) {
75- apiName = hostApiInfo->name ;
76- }
77- }
78- if ( this ->audioOutputLabel ) {
79- this ->audioOutputLabel ->SetText ( fmt::format ( " Audio Output: ({}) {}" , apiName, deviceName ) );
80- }
81- }
82-
83- this ->inputDeviceIndex = inputIndex;
84- this ->outputDeviceIndex = outputIndex;
85-
86- SFGO2DG::AudioManager::StopAudio ( " Background Music" );
87-
88- SFGO2DG::AudioManager::Start ( tmpInput, tmpOutput );
89-
90- SFGO2DG::AudioManager::LoadAudioFile ( " Background Music" , SFGO2DG::AudioManager::AudioType::BGM, " Resources/Audio/8Bit 01 w.wav" );
91- }
92- void PrevInput () { this ->SetAudioDeviceIndexes ( this ->inputDeviceIndex - 1 , this ->outputDeviceIndex ); }
93- void NextInput () { this ->SetAudioDeviceIndexes ( this ->inputDeviceIndex + 1 , this ->outputDeviceIndex ); }
94- void PrevOutput () { this ->SetAudioDeviceIndexes ( this ->inputDeviceIndex , this ->outputDeviceIndex - 1 ); }
95- void NextOutput () { this ->SetAudioDeviceIndexes ( this ->inputDeviceIndex , this ->outputDeviceIndex + 1 ); }
96- };
97-
9823int main ( int argc, char ** argv ) noexcept {
9924 int better_main ( std::vector< std::string > const & ) noexcept ;
10025 std::vector< std::string > args ( argv, std::next ( argv, static_cast < std::ptrdiff_t >( argc ) ) );
@@ -114,15 +39,15 @@ int better_main( std::vector< std::string > const& args ) noexcept {
11439#pragma region Initialize Audio
11540 SFGO2DG::AudioManager::init ();
11641 SFGO2DG::AudioManager::GetAudioInfos ();
117-
118- TempAudioStruct* audioStruct = new TempAudioStruct ();
119- audioStruct->inputDeviceIndex = paNoDevice;
120- audioStruct->outputDeviceIndex = paNoDevice;
121- audioStruct->devices = SFGO2DG::AudioManager::TestABunchOfShit ();
122-
123- audioStruct->SetAudioDeviceIndexes ( -1 , -1 );
12442#pragma endregion Initialize Audio
12543
44+ #pragma region Initialize Options
45+ SFGO2DG::Options* options = new SFGO2DG::Options ();
46+ options->SetAudioDevices ( SFGO2DG::AudioManager::TestABunchOfShit () );
47+ // having this later would be funny
48+ // options->SetAudioIndexes( -1, -1 );
49+ #pragma endregion Initialize Options
50+
12651#pragma region Initialize SDL
12752 int sdlErrorCode;
12853 spdlog::trace ( " better_main - initializing sdl" );
@@ -197,39 +122,39 @@ int better_main( std::vector< std::string > const& args ) noexcept {
197122#pragma region Options UI
198123 float optionsMenuButtonHeight = 0 .0625f ;
199124 float optionsMenuYOffset = 0 .5f ;
125+ SFGO2DG::UI::Label* audioInputLabel;
126+ SFGO2DG::UI::Label* audioOutputLabel;
200127 {
201- std::function< void () > func = [audioStruct ]() { audioStruct-> PrevInput (); };
128+ std::function< void () > func = [options ]() { options-> AudioSelectPrevInput (); };
202129 SFGO2DG::UI::Button* tmp = new SFGO2DG::UI::Button ( func, " <" , optionsPage, SDL_FRect{ 0 .25f , optionsMenuYOffset, 0 .0625f , optionsMenuButtonHeight } );
203130 tmp->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
204131 tmp->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
205132 }
206133 {
207- audioStruct->audioInputLabel
208- = new SFGO2DG::UI::Label ( " Input Device Name" , optionsPage, SDL_FRect{ 0 .3125f , optionsMenuYOffset, 0 .375f , optionsMenuButtonHeight } );
209- audioStruct->audioInputLabel ->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
210- audioStruct->audioInputLabel ->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
134+ audioInputLabel = new SFGO2DG::UI::Label ( " Input Device Name" , optionsPage, SDL_FRect{ 0 .3125f , optionsMenuYOffset, 0 .375f , optionsMenuButtonHeight } );
135+ audioInputLabel->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
136+ audioInputLabel->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
211137 }
212138 {
213- std::function< void () > func = [audioStruct ]() { audioStruct-> NextInput (); };
139+ std::function< void () > func = [options ]() { options-> AudioSelectNextInput (); };
214140 SFGO2DG::UI::Button* tmp = new SFGO2DG::UI::Button ( func, " >" , optionsPage, SDL_FRect{ 0 .6875f , optionsMenuYOffset, 0 .0625f , optionsMenuButtonHeight } );
215141 tmp->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
216142 tmp->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
217143 }
218144 optionsMenuYOffset += optionsMenuButtonHeight;
219145 {
220- std::function< void () > func = [audioStruct ]() { audioStruct-> PrevOutput (); };
146+ std::function< void () > func = [options ]() { options-> AudioSelectPrevOutput (); };
221147 SFGO2DG::UI::Button* tmp = new SFGO2DG::UI::Button ( func, " <" , optionsPage, SDL_FRect{ 0 .25f , optionsMenuYOffset, 0 .0625f , optionsMenuButtonHeight } );
222148 tmp->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
223149 tmp->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
224150 }
225151 {
226- audioStruct->audioOutputLabel
227- = new SFGO2DG::UI::Label ( " Output Device Name" , optionsPage, SDL_FRect{ 0 .3125f , optionsMenuYOffset, 0 .375f , optionsMenuButtonHeight } );
228- audioStruct->audioOutputLabel ->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
229- audioStruct->audioOutputLabel ->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
152+ audioOutputLabel = new SFGO2DG::UI::Label ( " Output Device Name" , optionsPage, SDL_FRect{ 0 .3125f , optionsMenuYOffset, 0 .375f , optionsMenuButtonHeight } );
153+ audioOutputLabel->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
154+ audioOutputLabel->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
230155 }
231156 {
232- std::function< void () > func = [audioStruct ]() { audioStruct-> NextOutput (); };
157+ std::function< void () > func = [options ]() { options-> AudioSelectNextOutput (); };
233158 SFGO2DG::UI::Button* tmp = new SFGO2DG::UI::Button ( func, " >" , optionsPage, SDL_FRect{ 0 .6875f , optionsMenuYOffset, 0 .0625f , optionsMenuButtonHeight } );
234159 tmp->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
235160 tmp->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
@@ -244,6 +169,7 @@ int better_main( std::vector< std::string > const& args ) noexcept {
244169 tmp->SetHorizontalAlignment ( SFGO2DG::UI::Label::HorizontalAlignment::Centered );
245170 tmp->SetVerticalAlignment ( SFGO2DG::UI::Label::VerticalAlignment::Centered );
246171 }
172+ options->SetAudioDisplayLabels ( audioInputLabel, audioOutputLabel );
247173#pragma endregion Options UI
248174
249175 for ( int i = 0 ; i < widgetsToCycle.size (); i++ ) {
@@ -272,6 +198,11 @@ int better_main( std::vector< std::string > const& args ) noexcept {
272198 }
273199 SDL_SetRenderDrawBlendMode ( mainWindowRenderer, SDL_BlendMode::SDL_BLENDMODE_BLEND );
274200
201+ #pragma region Rest of options
202+ // rest of options?
203+ options->SetAudioIndexes ( -1 , -1 );
204+ #pragma endregion Rest of options
205+
275206 SDL_ShowWindow ( mainWindow );
276207
277208 bool running = true ;
@@ -360,7 +291,7 @@ int better_main( std::vector< std::string > const& args ) noexcept {
360291#pragma endregion Quit SDL
361292
362293 SFGO2DG::AudioManager::Shutdown ();
363- delete audioStruct ;
294+ delete options ;
364295
365296 SFGO2DG::Performance::endProgram ();
366297
0 commit comments