Controlling Sound Loss Across Portals

From The DarkMod Wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Submitted by grayman.

Overview

Note: This page describes functionality available in TDM 2.00.

We can control how sound loses volume (occludes) across a portal (door, window, etc.) by using spawnargs on certain entities (doors, info_locationSeparators) touching that portal.

In TDM revisions prior to 2.00, these spawnargs were only used to occlude sounds propagated to AI. Occlusion of a Player-heard sound across a portal had only two settings: occlusion when the portal was open, and occlusion when the portal was closed.

This led to odd situations. For example, if the Player was in a building, and looking through a window at AI patrolling in the street outside, there was no sound occlusion, because the window's portal was open. (It had to be, otherwise the Player wouldn't see through the window.) So patrolling AI sounded like they were right in the room with the Player.

In Rev. 2.00, we've made changes to eliminate this type of odd situation. Now, visportals can occlude sound separately from whether they block the view through them.

Doors and Windows

The sound-occluding objects we're most familiar with are doors and windows. Windows are just see-through doors. For the purpose of this discussion, I'll refer to them both as "doors".

These spawnargs can be used to control sound occlusion on doors:

  • "loss_closed" "Acoustical loss applied to sounds going through the door when it is completely closed (default 10 dB)"
  • "loss_open" "Acoustical loss applied to sounds going through the door when it is open (default 1 dB)"
  • "loss_double_open" "Acoustical loss applied to sounds going through a set of double doors when one is open and the other is closed (default 1 dB)"

These values are used for both propagated sounds (the sounds that AI "hear") and Player-heard sounds.

As a door opens, any sound coming through it at the time will experience an occlusion ramp from "loss_closed" to "loss_open". This means the sound gets louder as the door opens and softer as the door closes.

It used to be that visportals needed to be kept from touching see-through doors, since closing a touching door closed the portal, cutting off the view through the door.

No longer. Now you can place this spawnarg on a see-through door that touches a visportal:

  • "transparent" "If set to 1 (0 by default), a see-through door can touch a visportal and the visportal won't close when the door is closed."

Now that a window can be marked "transparent", we can change the amount of sound occlusion through its portal when it's open or closed. Closing the window doesn't cut off the view through the window. Now sounds coming from our street-patrolling AI are muffled through a closed window, and have normal volume through an open window.

info_locationSeparator

We use an info_locationSeparator on a portal to mark the boundary between two location zones. These spawnargs on the separator are available to control sound occlusion across the portal:

  • "sound_loss" "Loss incurred when a sound travels through this portal. Cumulative with door loss if a door is present."
  • "apply_loss_to_AI" "Apply (1) or don't apply (0) sound loss to propagated sounds. Default is 1."
  • "apply_loss_to_Player" "Apply (1) or don't apply (0) sound loss to what the Player hears. Default is 1."

Sound occlusion across a portal can be made to be AI- or Player-specific. This lets you differ what the Player hears compared to what the AI hear.

Sound occlusion controlled by a separator is independent of whether the portal is open or closed. This lets us control the sound volume coming through a small opening that has no door on it.

As the second sentence in the sound_loss description suggests, a separator's sound occlusion is added to a door's sound occlusion on the same portal. This lets us define a base occlusion on the door, and any extra occlusion--depending on how the door is being used--on a separator.

info_portalSettings

This is a new entity that acts like a separator, but doesn't mark the boundary of a location zone. It provides the same sound occlusion behavior as a separator, using the same spawnargs. Use these on portals inside a location zone.

Script Access to Occlusion

If you want to adjust a portal's sound occlusion from a script, you can use these routines on the sys object:

void    setPortSoundLoss( float handle, float value ) (Sets sound_loss for both AI and the Player)
float   getPortSoundLoss( float handle ) (Gets sound_loss)
void    setPortAISoundLoss( float handle, float value) (Sets AI-only sound_loss w/o affecting any Player-only sound_loss)
void    setPortPlayerSoundLoss( float handle, float value) (Sets Player-only sound_loss w/o affecting any AI-only sound_loss)
float   getPortAISoundLoss( float handle ) (Gets AI-only sound_loss)
float   getPortPlayerSoundLoss( float handle ) (Gets Player-only sound_loss)

"handle" is the portal number, which you can obtain by querying an info_locationSeparator or info_portalSettings touching the portal:

float handle = $NameOfTouchingEntity.getPortalHandle();