def __destroyDestructible(self, chunkID, dmgType, destData, isNeedAnimation, explosionInfo=None): if self.forceNoAnimation: isNeedAnimation = False if dmgType == DESTR_TYPE_FALLING_ATOM: destrIndex, fallDirYaw, fallSpeed = decodeFallenColumn(destData) pitchConstr, collisionFlags = BigWorld.wg_getDestructibleFallPitchConstr( self.__spaceID, chunkID, destrIndex, fallDirYaw ) if pitchConstr is None: pitchConstr = math.pi / 2.0 self.__dropDestructible( chunkID, destrIndex, fallDirYaw, pitchConstr, fallSpeed, isNeedAnimation, collisionFlags ) if dmgType == DESTR_TYPE_TREE: destrIndex, fallDirYaw, pitchConstr, fallSpeed = decodeFallenTree(destData) _, collisionFlags = BigWorld.wg_getDestructibleFallPitchConstr( self.__spaceID, chunkID, destrIndex, fallDirYaw ) self.__dropDestructible( chunkID, destrIndex, fallDirYaw, pitchConstr, fallSpeed, isNeedAnimation, collisionFlags ) if FMOD.enabled: FMOD.lightSoundRemove(self.__spaceID, chunkID, destrIndex) elif dmgType == DESTR_TYPE_FRAGILE: destrIndex, isShotDamage = decodeFragile(destData) self.__destroyFragile(chunkID, destrIndex, isNeedAnimation, isShotDamage, explosionInfo) if FMOD.enabled: FMOD.lightSoundRemove(self.__spaceID, chunkID, destrIndex) elif dmgType == DESTR_TYPE_STRUCTURE: destrIndex, matKind, isShotDamage = decodeDestructibleModule(destData) self.__destroyModule(chunkID, destrIndex, matKind, isNeedAnimation, isShotDamage, explosionInfo)
def setMasterVolume(self, volume): self.__masterVolume = volume self.__muffledVolume = self.__masterVolume * self.getVolume('masterFadeVivox') FMOD.setMasterVolume(self.__muffledVolume if self.__muffled else self.__masterVolume) self.savePreferences() self.onMusicVolumeChanged('music', self.__masterVolume, self.getVolume('music')) self.onMusicVolumeChanged('ambient', self.__masterVolume, self.getVolume('ambient'))
def stopAmbient(self): ambientEvent = self.__musicEvents[MusicController._AMBIENT_EVENT] if ambientEvent is not None: ambientEvent.destroy() if FMOD.enabled: FMOD.enableLightSound(0) return
def applyPreferences(self): if not self.__isWindowVisible: FMOD.setMasterVolume(0) return self.setMasterVolume(self.__masterVolume) for categoryName in self.__volumeByCategory.keys(): self.setVolume(categoryName, self.__volumeByCategory[categoryName], updatePrefs=False)
def __setMode(self, modeName): if modeName not in self.__modes: LOG_DEBUG('Sound mode %s does not exist' % modeName) return False if self.__currentMode == modeName: return True self.__modes[self.__currentMode].unloadBanksManually() self.__currentMode = modeName modeDesc = self.__modes[modeName] if FMOD.enabled: languageSet = FMOD.setLanguage(modeDesc.voiceLanguage, self.modifiedSoundGroups) if not languageSet: LOG_DEBUG('Internal FMOD error in FMOD::setLanguage') return False if not self.__modes[self.__currentMode].loadBanksManually(): LOG_DEBUG('Error while manual banks loading') return False if FMOD.enabled: loadedSoundBanks = FMOD.getSoundBanks() for bankName, bankPath in modeDesc.banksToBeLoaded: found = False for loadedBank in loadedSoundBanks: if bankName == loadedBank: found = True break if not found: LOG_DEBUG('Bank %s was not loaded while loading %s sound mode' % (bankName, modeName)) return False return True
def __setMode(self, modeName): if modeName not in self.__modes: LOG_DEBUG('Sound mode %s does not exist' % modeName) return False if self.__currentMode == modeName: return True self.__modes[self.__currentMode].unloadBanksManually() self.__currentMode = modeName modeDesc = self.__modes[modeName] languageSet = FMOD.setLanguage(modeDesc.fmodLanguage, self.modifiedSoundGroups) if not languageSet: LOG_DEBUG('Internal FMOD error in FMOD::setLanguage') return False if not self.__modes[self.__currentMode].loadBanksManually(): LOG_DEBUG('Error while manual banks loading') return False loadedSoundBanks = FMOD.getSoundBanks() for bankName, bankPath in modeDesc.banksToBeLoaded: found = False for loadedBank in loadedSoundBanks: if bankName == loadedBank: found = True break if not found: LOG_DEBUG( 'Bank %s was not loaded while loading %s sound mode' % (bankName, modeName)) return False return True
def setMasterVolume(self, volume): self.__masterVolume = volume self.__muffledVolume = self.__masterVolume * self.getVolume('masterFadeVivox') if FMOD.enabled: FMOD.setMasterVolume(self.__muffledVolume if self.__muffled else self.__masterVolume) self.savePreferences() self.onMusicVolumeChanged('music', self.__masterVolume, self.getVolume('music')) self.onMusicVolumeChanged('ambient', self.__masterVolume, self.getVolume('ambient'))
def applyPreferences(self): if not self.__isWindowVisible: if FMOD.enabled: FMOD.setMasterVolume(0) return self.setMasterVolume(self.__masterVolume) for categoryName in self.__volumeByCategory.keys(): newVolume = self.__volumeByCategory[categoryName] if self.__muffledByReplay and categoryName in ('vehicles', 'effects', 'ambient'): newVolume = 0.0 self.setVolume(categoryName, newVolume, updatePrefs=False)
def changePlayMode(self, mode): FMOD.setEventsParam('viewPlayMode', mode) if self.__handleInside == None: self.__handleInside = FMOD.DSPgetHandleByNameAndCategory('FMOD Lowpass Simple', 'inside') if self.__handleOutside == None: self.__handleOutside = FMOD.DSPgetHandleByNameAndCategory('FMOD Lowpass Simple', 'outside') if self.__ceilLess == True: FMOD.DSPsetParamEx(self.__handleInside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED) FMOD.DSPsetParamEx(self.__handleOutside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED) elif mode == 1: FMOD.DSPsetParamEx(self.__handleInside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED) FMOD.DSPsetParamEx(self.__handleOutside, 0, DSP_LOWPASS_LOW, -DSP_SEEKSPEED) else: FMOD.DSPsetParamEx(self.__handleInside, 0, DSP_LOWPASS_LOW, -DSP_SEEKSPEED) FMOD.DSPsetParamEx(self.__handleOutside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED)
def __init__(self, soundName, autoPlay = False, useDummy = True): self.__fmodSound = FMOD.playSound(soundName) if not self.__fmodSound and useDummy: self.__fmodSound = DummySound() if not autoPlay: self.__fmodSound.stop() return
def __loadConfig(self): eventNames = {} xmlPath = 'gui/music_events.xml' section = ResMgr.openSection(xmlPath) if section is None: _xml.raiseWrongXml(None, xmlPath, 'can not open or read') for i in section.items(): s = i[1] if i[0] == 'music': eventNames[MUSIC_EVENT_LOGIN] = s.readString('login') eventNames[MUSIC_EVENT_LOBBY] = (s.readString('lobby'), s.readString('lobby_premium')) eventNames[MUSIC_EVENT_COMBAT_VICTORY] = s.readString('combat_victory') eventNames[MUSIC_EVENT_COMBAT_LOSE] = s.readString('combat_lose') eventNames[MUSIC_EVENT_COMBAT_DRAW] = s.readString('combat_draw') elif i[0] == 'ambient': eventNames[AMBIENT_EVENT_LOBBY] = (s.readString('lobby'), s.readString('lobby_premium')) eventNames[AMBIENT_EVENT_SHOP] = (s.readString('shop'), s.readString('shop_premium')) eventNames[AMBIENT_EVENT_STATISTICS] = (s.readString('rating'), s.readString('rating_premium')) fallbackEventNames = eventNames.copy() for eventId, overriddenNames in self.__overriddenEvents.iteritems(): eventNames[eventId] = overriddenNames soundsByName = {} for eventId, names in eventNames.items(): lstEvents = [] if not isinstance(names, tuple): names = (names,) fallbackNames = fallbackEventNames[eventId] if not isinstance(fallbackNames, tuple): fallbackNames = (fallbackNames,) for i in xrange(len(names)): eventName = names[i] fallbackEventName = fallbackNames[i] sound = soundsByName.get(eventName) if sound is None: sound = FMOD.getSound(eventName) if eventName != '' else None if sound is None: sound = FMOD.getSound(fallbackEventName) if fallbackEventName != '' else None soundsByName[eventName] = sound lstEvents.append(sound) if sound is not None: sound.stop() self.__soundEvents[eventId] = lstEvents return
def loadBanksManually(self): for (bankName, bankPath,) in self.banksToBeLoaded: if bankPath != '': loadSuccessfully = FMOD.loadSoundBankIntoMemoryFromPath(bankPath) if not loadSuccessfully: return False return True
def changePlayMode(self, mode): if FMOD.enabled: FMOD.setEventsParam('viewPlayMode', mode) if FMOD.enabled: if self.__handleInside == None: self.__handleInside = FMOD.DSPgetHandleByNameAndCategory('FMOD Lowpass Simple', 'inside') if self.__handleOutside == None: self.__handleOutside = FMOD.DSPgetHandleByNameAndCategory('FMOD Lowpass Simple', 'outside') if self.__ceilLess == True: FMOD.DSPsetParamEx(self.__handleInside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED) FMOD.DSPsetParamEx(self.__handleOutside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED) elif mode == 1: FMOD.DSPsetParamEx(self.__handleInside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED) FMOD.DSPsetParamEx(self.__handleOutside, 0, DSP_LOWPASS_LOW, -DSP_SEEKSPEED) else: FMOD.DSPsetParamEx(self.__handleInside, 0, DSP_LOWPASS_LOW, -DSP_SEEKSPEED) FMOD.DSPsetParamEx(self.__handleOutside, 0, DSP_LOWPASS_HI, DSP_SEEKSPEED)
def setMode(self, modeName): languageSet = False try: languageSet = self._SoundModes__setMode(modeName) except: LOG_CURRENT_EXCEPTION() if not languageSet: defaultFmodLanguage = '' if SoundModes.DEFAULT_MODE_NAME in self._SoundModes__modes: defaultFmodLanguage = self._SoundModes__modes[SoundModes.DEFAULT_MODE_NAME].fmodLanguage try: FMOD.setLanguage(defaultFmodLanguage, self.modifiedSoundGroups) self._SoundModes__modes[SoundModes.DEFAULT_MODE_NAME].loadBanksManually() except: LOG_CURRENT_EXCEPTION() self._SoundModes__currentMode = SoundModes.DEFAULT_MODE_NAME return languageSet
def stop(self): self.__isStarted = False FMOD.setEventsParam('viewPlayMode', 0) self.__removeBattleCtrlListeners() for control in self.__ctrls.itervalues(): control.destroy() replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isRecording: replayCtrl.setPlayerVehicleID(0) self.onCameraChanged = None self.__targeting.enable(False) self.__killerVehicleID = None g_guiResetters.remove(self.__onRecreateDevice) BigWorld.player().arena.onPeriodChange -= self.__onArenaStarted from account_helpers.settings_core.SettingsCore import g_settingsCore g_settingsCore.onSettingsChanged -= self.__onSettingsChanged CallbackDelayer.destroy(self)
def loadBanksManually(self): for bankName, bankPath in self.banksToBeLoaded: if bankPath != '': loadSuccessfully = FMOD.loadSoundBankIntoMemoryFromPath( bankPath) if not loadSuccessfully: return False return True
def preloadSoundGroups(self, arenaName): if not FMOD.enabled: return self.groupList = [] settings = ResMgr.openSection('scripts/arena_defs/' + arenaName + '.xml/preloadSoundGroups') if settings is not None: self.groupList = settings.readStrings('groupName') for sg in self.groupList: result = FMOD.WG_loadSoundGroup(sg) if not result: LOG_NOTE('Loading failed for arena sound group ', sg)
def setMode(self, modeName): languageSet = False try: languageSet = self.__setMode(modeName) except: LOG_CURRENT_EXCEPTION() if not languageSet: defaultFmodLanguage = '' if SoundModes.DEFAULT_MODE_NAME in self.__modes: defaultFmodLanguage = self.__modes[ SoundModes.DEFAULT_MODE_NAME].fmodLanguage try: FMOD.setLanguage(defaultFmodLanguage, self.modifiedSoundGroups) self.__modes[SoundModes.DEFAULT_MODE_NAME].loadBanksManually() except: LOG_CURRENT_EXCEPTION() self.__currentMode = SoundModes.DEFAULT_MODE_NAME return languageSet
def _playGUI(self, event): if self.__ignoreNext: self.__ignoreNext = False return if event is context.SOUND_EVENT.NEXT_CHAPTER: self.__ignoreNext = True sndID = self.__guiSounds[event] sound = FMOD.getSound(sndID) if sound: sound.play() else: LOG_ERROR('Sound not found', sndID)
def _playGUI(self, event): if self.__ignoreNext: self.__ignoreNext = False return if event is context.SOUND_EVENT.NEXT_CHAPTER: self.__ignoreNext = True sndID = self.__guiSounds[event] sound = FMOD.getSound(sndID) if sound: sound.play() else: LOG_ERROR("Sound not found", sndID)
def loadLightSoundsDB(): ENVIRONMENT_EFFECTS_CONFIG_FILE = 'scripts/environment_effects.xml' section = ResMgr.openSection(ENVIRONMENT_EFFECTS_CONFIG_FILE) if section is None: return lightSoundDB = [] if section['lightSounds'] is None: return for propertyName, propertySection in section['lightSounds'].items(): DBitem = [] DBitem.append(propertySection.readString('modelName')) DBitem.append(propertySection.readVector3('offset')) if FMOD.enabled: DBitem.append(propertySection.readStrings('event')) DBitem.append(propertySection.readString('hardPoint')) lightSoundDB.append(DBitem) if FMOD.enabled: FMOD.LSloadEventsDB(lightSoundDB) lightSoundDB = None
def loadPluginDB(): ENVIRONMENT_EFFECTS_CONFIG_FILE = 'scripts/audioplugins.xml' section = ResMgr.openSection(ENVIRONMENT_EFFECTS_CONFIG_FILE) pluginDB = [] for propertyName, propertySection in section.items(): DBplugin = [] DBplugin.append(propertySection.readString('name')) DBplugin.append(propertySection.readString('category')) for propertyName2, propertySection2 in propertySection['parameters'].items(): DBparam = [] DBparam.append(propertySection2.readInt('index')) DBparam.append(propertySection2.readFloat('value')) DBplugin.append(DBparam) DBparam = None pluginDB.append(DBplugin) DBitem = None if FMOD.enabled: FMOD.DSPloadPluginDB(pluginDB) pluginDB = None
def __getArenaSoundEvent(self, eventId): player = BigWorld.player() soundEvent = None soundEventName = None if not isPlayerAvatar(): return elif player.arena is None: return else: arenaType = player.arena.arenaType if eventId == MUSIC_EVENT_COMBAT: soundEventName = arenaType.music elif eventId == MUSIC_EVENT_COMBAT_LOADING: soundEventName = arenaType.loadingMusic elif eventId == AMBIENT_EVENT_COMBAT: soundEventName = arenaType.ambientSound if soundEventName is not None: soundEvent = FMOD.getSound(soundEventName) if soundEvent is not None: soundEvent.stop() return soundEvent
def _speak(self, sndID): if sndID in self.__prevSpeaks: LOG_DEBUG('Speaking played, ignore', sndID) return elif sndID is None: LOG_WARNING('Sound ID for speaking is not defined') return elif self.__speakSnd is not None: self.__nextSndID = sndID return else: sound = FMOD.getSound(sndID) if not sound: LOG_ERROR('Sound not found', sndID) return self.__nextSndID = None self.__speakSnd = sound self.__prevSpeaks.add(sndID) sound.setCallback('EVENTFINISHED', self.__onSpeakingStop) sound.play() return
def _speak(self, sndID): if sndID in self.__prevSpeaks: LOG_DEBUG("Speaking played, ignore", sndID) return elif sndID is None: LOG_WARNING("Sound ID for speaking is not defined") return elif self.__speakSnd is not None: self.__nextSndID = sndID return else: sound = FMOD.getSound(sndID) if not sound: LOG_ERROR("Sound not found", sndID) return self.__nextSndID = None self.__speakSnd = sound self.__prevSpeaks.add(sndID) sound.setCallback("EVENTFINISHED", self.__onSpeakingStop) sound.play() return
def __init__(self, channelsMgr): self.channelsMgr = channelsMgr self.vivoxDomain = '' self.testChannel = '' self.inTesting = False self.__activateMicByVoice = False self.__enableVoiceNormalization = False self.usersRoster = {} self.channelUsers = {} self.captureDevices = [] self.currentCaptureDevice = '' self.OnCaptureDevicesUpdated = Event.Event() self.onParticipantMute = Event.Event() self.onPlayerSpeaking = Event.Event() self.channelsMgr.onCaptureDevicesArrived += self._onCaptureDevicesArrived self.channelsMgr.onParticipantAdded += self._onParticipantAdded self.channelsMgr.onParticipantRemoved += self._onParticipantRemoved self.channelsMgr.onParticipantUpdated += self._onParticipantUpdated self.channelsMgr.onJoinedChannel += self._onJoinedChannel self.channelsMgr.onLeftChannel += self.onLeftChannel self.channelsMgr.onLogined += self.onLogined self.channelsMgr.onStateChanged += self.onStateChanged self.oldMasterVolume = FMOD.getMasterVolume()
def onLeaveArena(self): self.__isOnArena = False BigWorld.player().arena.onPeriodChange -= self.__onArenaStateChanged FMOD.enableLightSound(0)
def playSound3D(self, node, event): if FMOD.enabled: s = FMOD.getSound3D(self.checkAndReplace(event), node) if s is not None: s.play()
def unloadSounds(self, groupName): for group in self.__groups[groupName]: try: FMOD.unloadSoundGroup(group) except Exception: LOG_CURRENT_EXCEPTION()
def unloadBanksManually(self): if FMOD.enabled: for bankName, bankPath in self.banksToBeLoaded: if bankPath != '': FMOD.unloadSoundBankFromMemory(bankName)
def setMasterVolume(self, volume): self.__masterVolume = volume FMOD.setMasterVolume(volume) self.savePreferences()
def reloadSoundBanks(): import MusicController if FMOD.enabled: FMOD.reloadSoundbanks() MusicController.g_musicController.restart()
def playSound3D(self, node, event): if FMOD.enabled: return FMOD.getSound3D(self.checkAndReplace(event), node)
def __init__(self): self.__volumeByCategory = {} self.__masterVolume = 1.0 self.__replace = {} self.__isWindowVisible = BigWorld.isWindowVisible() self.__handleInside = None self.__handleOutside = None self.__ceilLess = None self.__activeStinger = None self.__activeTrack = None self.__activeStingerPriority = None self.__muffled = False self.__muffledByReplay = False PlayerEvents.g_playerEvents.onAvatarReady += self.onAvatarReady self.__categories = {'voice': ('ingame_voice',), 'vehicles': ('outside/vehicles', 'vehicles', 'inside/vehicles'), 'effects': ('hits', 'outside/hits', 'inside/hits', 'weapons', 'inside/weapons', 'outside/weapons', 'environment', 'inside/environment', 'outside/environment', 'battle_gui'), 'gui': ('gui',), 'music': ('music',), 'ambient': ('outside/ambient', 'hangar_v2', 'ambientUR'), 'masterVivox': (), 'micVivox': (), 'masterFadeVivox': ()} defMasterVolume = 0.5 defCategoryVolumes = {'music': 0.5, 'masterVivox': 0.7, 'micVivox': 0.4} userPrefs = Settings.g_instance.userPrefs soundModeName = SoundModes.DEFAULT_MODE_NAME nationalMapping = None self.__soundModes = None if not userPrefs.has_key(Settings.KEY_SOUND_PREFERENCES): userPrefs.write(Settings.KEY_SOUND_PREFERENCES, '') self.__masterVolume = defMasterVolume for categoryName in self.__categories.keys(): self.__volumeByCategory[categoryName] = defCategoryVolumes.get(categoryName, 1.0) self.savePreferences() else: ds = userPrefs[Settings.KEY_SOUND_PREFERENCES] self.__masterVolume = ds.readFloat('masterVolume', defMasterVolume) for categoryName in self.__categories.keys(): volume = ds.readFloat('volume_' + categoryName, defCategoryVolumes.get(categoryName, 1.0)) self.__volumeByCategory[categoryName] = volume soundModeSec = ds['soundMode'] if soundModeSec is not None: soundModeName = soundModeSec.asString if soundModeName == '': soundModeName = SoundModes.DEFAULT_MODE_NAME if ds['soundMode'].has_key('nationalPreset'): nationalMapping = ds.readString('soundMode/nationalPreset', '') else: nationsSec = soundModeSec['nations'] if nationsSec is not None: nationalMapping = {} for nation, sec in nationsSec.items(): nationalMapping[nation] = sec.asString self.__soundModes = SoundModes(SoundModes.DEFAULT_MODE_NAME) if isinstance(nationalMapping, str): self.__soundModes.setNationalMappingByPreset(nationalMapping) elif isinstance(nationalMapping, dict): self.__soundModes.setNationalMapping(nationalMapping) else: self.__soundModes.setNationalMappingByMode(soundModeName) self.applyPreferences() self.__muteCallbackID = BigWorld.callback(0.25, self.__muteByWindowVisibility) self.defaultGroupList = [] settings = ResMgr.openSection('scripts/arena_defs/_default_.xml/preloadSoundGroups') if settings is not None: self.defaultGroupList = settings.readStrings('groupName') if FMOD.enabled: for sg in self.defaultGroupList: result = FMOD.WG_loadSoundGroup(sg) if not result: LOG_NOTE('Loading failed for default sound group ', sg) FMOD.WG_unloadAll() g_replayEvents.onMuteSound += self.__onReplayMute
def setMasterVolume(self, volume): self.__masterVolume = volume self.__muffledVolume = self.__masterVolume * self.getVolume('masterFadeVivox') FMOD.setMasterVolume(self.__muffledVolume if self.__muffled else self.__masterVolume) self.savePreferences()
def restoreMasterVolume(self): FMOD.setMasterVolume(SoundGroups.g_instance.getMasterVolume())
def muffleMasterVolume(self): masterVolume = SoundGroups.g_instance.getMasterVolume( ) * SoundGroups.g_instance.getVolume('masterFadeVivox') FMOD.setMasterVolume(masterVolume)
def unloadAll(self, path = None): if FMOD.enabled: FMOD.WG_unloadAll() import MusicController MusicController.g_musicController.destroy() MusicController.g_musicController.init(path)
def onEnterArena(self): BigWorld.player().arena.onPeriodChange += self.__onArenaStateChanged self.__isOnArena = True self.__onArenaStateChanged() if FMOD.enabled: FMOD.enableLightSound(1)
def playSound3D(self, node, event): if FMOD.enabled: s = FMOD.getSound3D(self.checkAndReplace(event), node) if s is not None: s.play() return
def onLeaveArena(self): self.__isOnArena = False BigWorld.player().arena.onPeriodChange -= self.__onArenaStateChanged if FMOD.enabled: FMOD.enableLightSound(0)
def playSound2D(self, event): if FMOD.enabled: return FMOD.playSound(self.checkAndReplace(event))
def stopAmbient(self): if self.__sndEventAmbient is not None: self.__sndEventAmbient.stop(True) self.__sndEventAmbient = None self.__eventAmbientId = None FMOD.enableLightSound(0)
def onEnterArena(self): BigWorld.player().arena.onPeriodChange += self.__onArenaStateChanged self.__isOnArena = True self.__onArenaStateChanged() FMOD.enableLightSound(1)
def FMODplaySound(self, event): return FMOD.playSound(self.checkAndReplace(event))
def __init__(self, soundPath): self.__sndTick = FMOD.getSound(soundPath) self.__isPlaying = True self.stop()
def FMODgetSound(self, event): return FMOD.getSound(self.checkAndReplace(event))