void SoundEngine::initSound() { if( !Configuration::soundenabled ) return; // This seems to be done, but since I found it in the library documentation it might be code // needed for a higher version of SDL_Mixer //int flags = MIX_INIT_OGG; //int initedFlags = Mix_Init( flags ); //if ( initedFlags != flags ) //{ // dawn_debug_fatal( "Could not initialize all sound modes (Mix_Init left error message \"%s\")", Mix_GetError() ); //} // Chunksize is 256 since this is the smallest my system can handle. // Higher chunk sizes seem to make time between click and click sound noticable if( Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 256) == -1 ) { dawn_debug_fatal( "Could not open audio (Mix_OpenAudio exited with error message \"%s\")", Mix_GetError() ); } // this should be enough for the beginning, but we might need to group the channels so each group can take care of // and fade out old channels if more are needed. const int totalNumChannels = 64; int numChannels = Mix_AllocateChannels(totalNumChannels); dawn_debug_info( "Currently allocated channels for sound = %d", numChannels ); }
void SoundEngine::playSound( std::string soundFile ) { if( !Configuration::soundenabled ) return; Mix_Chunk *soundSample = soundCache->getSoundFromCache( soundFile ); int curChannel = Mix_PlayChannel( -1, soundSample, 0 ); if( curChannel == -1 ) { dawn_debug_fatal( "Could not play sound %s: %s", soundFile.c_str(), Mix_GetError() ); } logChannelUsage( curChannel ); }
Resolution Resolution::getBestResolution( bool fullscreenPreferred ) { for ( std::vector<Resolution>::iterator it=possibleResolutions.begin(); it!=possibleResolutions.end(); ++it ) { Resolution &curRes = *it; if ( curRes.fullscreen == fullscreenPreferred ) return curRes; } // no resolution with wanted fullscreen-mode found. Return first resolution available if ( possibleResolutions.size() > 0 ) { return possibleResolutions[0]; } dawn_debug_fatal("no working resolutions found"); abort(); }
std::string getItemReferenceRestore( CallIndirection *eventHandler ) { if ( eventHandler == NULL ) { return "nil;"; } for ( std::map< std::string, CZone* >::iterator it = Globals::allZones.begin(); it != Globals::allZones.end(); ++it ) { CZone *curZone = it->second; bool found; size_t foundPos; curZone->findEventHandler( eventHandler, found, foundPos ); if ( found ) { std::ostringstream oss; oss << "DawnInterface.restoreEventHandlerReference( \"" << curZone->getZoneName() << "\", " << foundPos << " )"; return oss.str(); } } // not found dawn_debug_fatal( "could not find event handler in any of the zones" ); abort(); }
void SoundEngine::playMusic( std::string musicFile, bool playInLoop ) { if( !Configuration::soundenabled ) return; if( currentlyPlayedMusic == musicFile && currentMusicInLoop == playInLoop ) return; Mix_HaltMusic(); // halts the current played music stream so we don't mix music. Perhaps should be handled in other manners. Mix_Music *musicSample = musicCache->getMusicFromCache( musicFile ); int loops = 1; if ( playInLoop ) loops = -1; if ( Mix_PlayMusic( musicSample, loops ) == -1 ) { dawn_debug_fatal( "Could not play music %s: %s", musicFile.c_str(), Mix_GetError() ); } currentlyPlayedMusic = musicFile; currentMusicInLoop = playInLoop; }
EquipPosition::EquipPosition Inventory::getEquipType( ItemSlot::ItemSlot itemSlot ) { switch ( itemSlot ) { case ItemSlot::HEAD: return EquipPosition::HEAD; case ItemSlot::AMULET: return EquipPosition::AMULET; case ItemSlot::MAIN_HAND: return EquipPosition::MAIN_HAND; case ItemSlot::OFF_HAND: return EquipPosition::OFF_HAND; case ItemSlot::BELT: return EquipPosition::BELT; case ItemSlot::LEGS: return EquipPosition::LEGS; case ItemSlot::SHOULDER: return EquipPosition::SHOULDER; case ItemSlot::CHEST: return EquipPosition::CHEST; case ItemSlot::GLOVES: return EquipPosition::GLOVES; case ItemSlot::CLOAK: return EquipPosition::CLOAK; case ItemSlot::BOOTS: return EquipPosition::BOOTS; case ItemSlot::RING_ONE: return EquipPosition::RING; case ItemSlot::RING_TWO: return EquipPosition::RING; case ItemSlot::COUNT: return EquipPosition::NONE; } dawn_debug_fatal("Reached end of Inventory::getEquipType without finding the given ItemSlot. This should not be."); abort(); }
void SoundEngine::useWalkingSound( bool enabled ) { if ( ! Configuration::soundenabled ) return; if ( !enabled && walkingChannel >= 0 ) { if ( ! Mix_Paused( walkingChannel ) ) { Mix_Pause( walkingChannel ); } } else if ( enabled ) { if ( walkingChannel == -1 ) { std::string soundFile = "data/sound/walking.ogg"; Mix_Chunk *soundSample = soundCache->getSoundFromCache( soundFile.c_str() ); walkingChannel = Mix_PlayChannel( -1, soundSample, -1 ); if ( walkingChannel == -1 ) { dawn_debug_fatal( "Could not play sound %s: %s", soundFile.c_str(), Mix_GetError() ); } dawn_debug_info("using channel %d for walking sound", walkingChannel); logChannelUsage( walkingChannel ); } else if ( Mix_Paused( walkingChannel ) ) { Mix_Resume( walkingChannel ); } } }