void MainManager::initSDLmixer() { log_.i("Initializing SDL_mixer"); int mixFlags = MIX_INIT_FLAC; int mixFlagsInit = Mix_Init(mixFlags); if ((mixFlagsInit & mixFlags) != mixFlags) throw log_.exception("Failed to initialize SDL_mixer", Mix_GetError); if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 ) throw log_.exception("Failed to aquire sound device", Mix_GetError); atexit(Mix_CloseAudio); atexit(Mix_Quit); // Write version information to log SDL_version compiled; SDL_MIXER_VERSION(&compiled); logSDLVersion("SDL_mixer", compiled, *Mix_Linked_Version()); // Write music decoder information to log const int nMusicDecoders = Mix_GetNumMusicDecoders(); std::stringstream ss; if (nMusicDecoders > 0) ss << Mix_GetMusicDecoder(0); for (int i = 1 ; i < nMusicDecoders ; ++i) { ss << ", " << Mix_GetMusicDecoder(i) << Log::end; } log_.d() << "Music decoders (" << nMusicDecoders << "): " << ss.str() << Log::end; // Write audio decoder information to log const int nChunkDecoders = Mix_GetNumChunkDecoders(); ss.str(std::string("")); if (nChunkDecoders > 0) ss << Mix_GetChunkDecoder(0); for (int i = 1 ; i < nChunkDecoders ; ++i) { ss << ", " << Mix_GetChunkDecoder(i) << Log::end; } log_.d() << "Audio decoders (" << nChunkDecoders << "): " << ss.str() << Log::end; (void)Mix_VolumeMusic(MIX_MAX_VOLUME); (void)Mix_Volume(-1, MIX_MAX_VOLUME); // (void)Mix_VolumeMusic(MIX_MAX_VOLUME); log_.d() << "Music Volume level: " << 100.0f * (float)Mix_VolumeMusic(-1) / MIX_MAX_VOLUME << "%" << Log::end; // TODO swarminglogic, 2014-02-08: Move to audio configuration setting. // Setting 64 channels to be played simulatenously Mix_AllocateChannels(64); }
static void test_versions(void) { SDL_version compiled; const SDL_version *linked; SDL_VERSION(&compiled); linked = SDL_Linked_Version(); output_versions("SDL", &compiled, linked); SDL_MIXER_VERSION(&compiled); linked = Mix_Linked_Version(); output_versions("SDL_mixer", &compiled, linked); }
int SDL_mixver(){ SDL_version compile_version; const SDL_version *link_version=Mix_Linked_Version(); SDL_MIXER_VERSION(&compile_version); printf("compiled with SDL_mixer version: %d.%d.%d\n", compile_version.major, compile_version.minor, compile_version.patch); printf("running with SDL_mixer version: %d.%d.%d\n", link_version->major, link_version->minor, link_version->patch); }
void eir_snd_api_init() { SDL_version compile_version; const SDL_version * link_version = Mix_Linked_Version(); SDL_MIXER_VERSION(&compile_version); EIR_KER_LOG_MESSAGE( "SDL mixer compile vers: %d.%d.%d", compile_version.major, compile_version.minor, compile_version.patch ); EIR_KER_LOG_MESSAGE( "SDL mixer link vers: %d.%d.%d", link_version->major, link_version->minor, link_version->patch ); if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { EIR_KER_LOG_ERROR("SDL mixer open audio init failed: %s", Mix_GetError()); } }
/* rcg06192001 get linked library's version. */ const SDL_version *Mix_Linked_Version(void) { static SDL_version linked_version; SDL_MIXER_VERSION(&linked_version); return(&linked_version); }
int main(int argc, char *argv[]) { (void) argc; (void) argv; if (SDL_Init(SDL_INIT_EVERYTHING) == -1) std::cout << "Failed to initialize SDL" << SDL_GetError() << std::endl; std::cout << "Hello SDL!" << std::endl; // Display SDL version information SDL_version compiled; SDL_version linked; SDL_VERSION(&compiled); SDL_GetVersion(&linked); logSDLVersion(std::cout, "SDL", compiled, linked, SDL_GetRevision()); // Initialize SDL_image and display version information int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG; int imgFlagsInit = IMG_Init(imgFlags); if ((imgFlagsInit & imgFlags) != imgFlags) std::cout << "Failed to initialize SDL_image:" << IMG_GetError() << std::endl; std::cout << "Hello SDL_image!" << std::endl; SDL_IMAGE_VERSION(&compiled); logSDLVersion(std::cout, "SDL_image", compiled, *IMG_Linked_Version(), ""); // Initialize SDL_mixer and display version information int mixFlags = MIX_INIT_OGG; int mixFlagsInit = Mix_Init(mixFlags); if ((mixFlagsInit & mixFlags) != mixFlags) { std::cout << "Failed to initialize SDL_mixer" << Mix_GetError() << std::endl; } if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { std::cout << "Failed to acquire sound device" << Mix_GetError() << std::endl; } std::cout << "Hello SDL_mixer!" << std::endl; SDL_MIXER_VERSION(&compiled); logSDLVersion(std::cout, "SDL_mixer", compiled, *Mix_Linked_Version(), ""); logSDLMixerMediaInfo(std::cout); // Initialize SDL_mixer and display version information if (TTF_Init() != 0) std::cout << "Failed to initialize SDL_ttf:" << SDL_GetError() << std::endl; std::cout << "Hello SDL_ttf!" << std::endl; SDL_TTF_VERSION(&compiled); logSDLVersion(std::cout, "SDL_ttf", compiled, *TTF_Linked_Version(), ""); // Create a window and OpenGL glContext using SDL and GLEW SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_Window* window = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); SDL_GLContext glContext = nullptr; const std::pair<int, int> glVersions[11] {{4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}, {3, 1}, {3, 0}, {2, 1}, {2, 0} }; const std::string glName = "OpenGL"; for (auto& glVersion : glVersions) { std::cout << "Trying to create " << glName << " " << glVersion.first << "." << glVersion.second << " glContext" << std::endl; SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, glVersion.first); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, glVersion.second); glContext = SDL_GL_CreateContext(window); if (glContext != nullptr) break; } if (glContext == nullptr) std::cout << "Failed to create OpenGL Context " << std::endl; bool isOk = SDL_GL_MakeCurrent(window, glContext) <= 0; if (!isOk) std::cout << "Failed to set OpenGL context" << SDL_GetError() << std::endl; glewExperimental = true; if (glewInit() != GLEW_OK) std::cout << "Failed to initialize GLEW" << std::endl; logAcquiredGlVersion(std::cout, glName); logOpenGLContextInfo(std::cout); logGraphicsDriverInfo(std::cout); glClearColor(0.1f, 0.2f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapWindow(window); // Wait for user event before closing bool isRunning = true; SDL_Event event; while (isRunning) { while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) isRunning = false; else if (event.type == SDL_QUIT) isRunning = false; } SDL_Delay(30); } // Cleanup SDL_DestroyWindow(window); SDL_GL_DeleteContext(glContext); IMG_Quit(); const int nOpenAudio = Mix_QuerySpec(nullptr, nullptr, nullptr); for (int i = 0 ; i < nOpenAudio ; ++i) Mix_CloseAudio(); while (Mix_Init(0)) Mix_Quit(); TTF_Quit(); SDL_Quit(); return 0; }
bool SDLWrapper::initialize(){ bool successSDL = false; bool successIMG = false; bool successMixer = false; bool successTTF = false; SDL_version compiled; Log(DEBUG) << "Initializing systems..."; // Initializing SDL_TTF. const int ttfInit = TTF_Init(); if(ttfInit == 0){ successTTF = true; SDL_TTF_VERSION(&compiled); SDLWrapper::logSDLVersion("SDL_TTF", compiled); } else{ Log(ERROR) << "Could not initialize TTF." << TTF_GetError(); } // Initializing SDL with initFlags. const Uint32 initFlags = SDL_INIT_EVERYTHING; const int sdlInit = SDL_Init(initFlags); if(sdlInit == 0){ successSDL = true; SDL_version linked; SDL_VERSION(&compiled); SDL_GetVersion(&linked); SDLWrapper::logSDLVersion("SDL", compiled, SDL_GetRevision()); } else{ Log(ERROR) << "Could not initialize SDL." << SDL_GetError(); } // Initializing SDL_image with imgFlags. const Uint32 imgFlags = IMG_INIT_PNG; if((IMG_Init(imgFlags) & imgFlags)){ successIMG = true; SDL_IMAGE_VERSION(&compiled); SDLWrapper::logSDLVersion("SDL_image", compiled); } else{ Log(ERROR) << "Could not initialize SDL_Image." << IMG_GetError(); } // Initializing SDL_mixer. const int frequency = 44100; const int channels = 2; const int chunksize = 4096; const int initialized = Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, channels, chunksize); if(initialized == 0){ successMixer = true; SDL_MIXER_VERSION(&compiled); SDLWrapper::logSDLVersion("SDL_mixer", compiled); } else{ Log(ERROR) << "Could not initialize SDL_Mixer" << Mix_GetError(); } // If even one system fails to initialize, returns false. return (successSDL && successIMG && successMixer && successTTF); }
static int main(int argc, char *argv[]) { if (!PHYSFSX_init(argc, argv)) return 1; con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (CGameArg.SysShowCmdHelp) { print_commandline_help(); return(0); } printf("\nType '%s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); #if defined(DXX_BUILD_DESCENT_I) if (! PHYSFSX_contfile_init("descent.hog", 1)) #define DXX_NAME_NUMBER "1" #define DXX_HOGFILE_NAMES "descent.hog" #elif defined(DXX_BUILD_DESCENT_II) if (! PHYSFSX_contfile_init("descent2.hog", 1) && ! PHYSFSX_contfile_init("d2demo.hog", 1)) #define DXX_NAME_NUMBER "2" #define DXX_HOGFILE_NAMES "descent2.hog or d2demo.hog" #endif { #if defined(__unix__) && !defined(__APPLE__) #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n" \ "\t" SHAREPATH "\n" #else #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tDirectory containing D" DXX_NAME_NUMBER "X\n" #endif #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) #define DXX_HOGFILE_APPLICATION_BUNDLE \ "\tIn 'Resources' inside the application bundle\n" #else #define DXX_HOGFILE_APPLICATION_BUNDLE "" #endif #define DXX_MISSING_HOGFILE_ERROR_TEXT \ "Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n" \ DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tIn a subdirectory called 'Data'\n" \ DXX_HOGFILE_APPLICATION_BUNDLE \ "Or use the -hogdir option to specify an alternate location." UserError(DXX_MISSING_HOGFILE_ERROR_TEXT); } #if defined(DXX_BUILD_DESCENT_I) switch (PHYSFSX_fsize("descent.hog")) { case D1_MAC_SHARE_MISSION_HOGSIZE: case D1_MAC_MISSION_HOGSIZE: MacHog = 1; // used for fonts and the Automap break; } #endif load_text(); //print out the banner title #if defined(DXX_BUILD_DESCENT_I) con_printf(CON_NORMAL, "%s %s", DESCENT_VERSION, g_descent_build_datetime); // D1X version con_puts(CON_NORMAL, "This is a MODIFIED version of Descent, based on " BASED_VERSION "."); con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK); con_puts(CON_NORMAL, "Copyright (C) 2005-2013 Christian Beckhaeuser, 2013-2017 Kp"); #elif defined(DXX_BUILD_DESCENT_II) con_printf(CON_NORMAL, "%s%s %s", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? " Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version con_puts(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on " BASED_VERSION "."); con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK); con_puts(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2013 Christian Beckhaeuser, 2013-2017 Kp"); #endif if (CGameArg.DbgVerbose) { { PHYSFS_Version vc, vl; PHYSFS_VERSION(&vc); PHYSFS_getLinkedVersion(&vl); con_printf(CON_VERBOSE, "D" DXX_NAME_NUMBER "X-Rebirth built with PhysFS %u.%u.%u; loaded with PhysFS %u.%u.%u", vc.major, vc.minor, vc.patch, vl.major, vl.minor, vl.patch); } { SDL_version vc; SDL_VERSION(&vc); #if SDL_MAJOR_VERSION == 1 const auto vl = SDL_Linked_Version(); #else SDL_version vlv; const auto vl = &vlv; SDL_GetVersion(vl); #endif con_printf(CON_VERBOSE, "D" DXX_NAME_NUMBER "X-Rebirth built with libSDL %u.%u.%u; loaded with libSDL %u.%u.%u", vc.major, vc.minor, vc.patch, vl->major, vl->minor, vl->patch); } #if DXX_USE_SDLMIXER { SDL_version vc; SDL_MIXER_VERSION(&vc); const auto vl = Mix_Linked_Version(); con_printf(CON_VERBOSE, "D" DXX_NAME_NUMBER "X-Rebirth built with SDL_mixer %u.%u.%u; loaded with SDL_mixer %u.%u.%u", vc.major, vc.minor, vc.patch, vl->major, vl->minor, vl->patch); } #endif con_puts(CON_VERBOSE, TXT_VERBOSE_1); } ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); #if !DXX_USE_OGL select_tmap(CGameArg.DbgTexMap); #if defined(DXX_BUILD_DESCENT_II) Lighting_on = 1; #endif #endif con_puts(CON_VERBOSE, "Going into graphics mode..."); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_puts(CON_DEBUG, "Initializing palette system..."); #if defined(DXX_BUILD_DESCENT_I) gr_use_palette_table( "PALETTE.256" ); #elif defined(DXX_BUILD_DESCENT_II) gr_use_palette_table(D2_DEFAULT_PALETTE ); #endif con_puts(CON_DEBUG, "Initializing font system..."); gamefont_init(); // must load after palette data loaded. #if defined(DXX_BUILD_DESCENT_II) con_puts(CON_DEBUG, "Initializing movie libraries..."); init_movies(); //init movie libraries #endif show_titles(); set_screen_mode(SCREEN_MENU); #ifdef DEBUG_MEMORY_ALLOCATIONS /* Memdebug runs before global destructors, so it incorrectly * reports as leaked any allocations that would be freed by a global * destructor. This local will force the newmenu globals to be * reset before memdebug scans, which prevents memdebug falsely * reporting them as leaked. * * External tools, such as Valgrind, know to run global destructors * before checking for leaks, so this hack is only necessary when * memdebug is used. */ struct hack_free_global_backgrounds { ~hack_free_global_backgrounds() { newmenu_free_background(); } }; hack_free_global_backgrounds hack_free_global_background; #endif con_puts(CON_DEBUG, "Doing gamedata_init..."); gamedata_init(); #if defined(DXX_BUILD_DESCENT_II) #if DXX_USE_EDITOR if (GameArg.EdiSaveHoardData) { save_hoard_data(); exit(1); } #endif #endif if (CGameArg.DbgNoRun) return(0); con_puts(CON_DEBUG, "Initializing texture caching system..."); texmerge_init(); // 10 cache bitmaps #if defined(DXX_BUILD_DESCENT_II) piggy_init_pigfile("groupa.pig"); //get correct pigfile #endif con_puts(CON_DEBUG, "Running game..."); init_game(); get_local_player().callsign = {}; #if defined(DXX_BUILD_DESCENT_I) key_flush(); #elif defined(DXX_BUILD_DESCENT_II) // If built with editor, option to auto-load a level and quit game // to write certain data. #ifdef EDITOR if (!GameArg.EdiAutoLoad.empty()) { Players[0u].callsign = "dummy"; } else #endif #endif { if (!CGameArg.SysPilot.empty()) { char filename[sizeof(PLAYER_DIRECTORY_TEXT) + CALLSIGN_LEN + 4]; /* Step over the literal PLAYER_DIRECTORY_TEXT when it is * present. Point at &filename[0] when * PLAYER_DIRECTORY_TEXT is absent. */ const auto b = &filename[-CGameArg.SysUsePlayersDir]; snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.12s"), CGameArg.SysPilot.c_str()); /* The pilot name is never used after this. Clear it to * free the allocated memory, if any. */ CGameArg.SysPilot.clear(); auto p = b; for (const auto &facet = std::use_facet<std::ctype<char>>(std::locale::classic()); char &c = *p; ++p) { c = facet.tolower(static_cast<uint8_t>(c)); } auto j = p - filename; if (j < sizeof(filename) - 4 && (j <= 4 || strcmp(&filename[j - 4], ".plr"))) // if player hasn't specified .plr extension in argument, add it { strcpy(&filename[j], ".plr"); j += 4; } if(PHYSFSX_exists(filename,0)) { get_local_player().callsign.copy(b, std::distance(b, &filename[j - 4])); read_player_file(); WriteConfigFile(); } } } #if defined(DXX_BUILD_DESCENT_II) #if DXX_USE_EDITOR if (!GameArg.EdiAutoLoad.empty()) { /* Any number >= FILENAME_LEN works */ Level_names[0].copy_if(GameArg.EdiAutoLoad.c_str(), GameArg.EdiAutoLoad.size()); LoadLevel(1, 1); } else #endif #endif { Game_mode = GM_GAME_OVER; DoMenu(); } while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_puts(CON_DEBUG, "Cleanup..."); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); Current_mission.reset(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }