Skip to content

Commit

Permalink
fix: create new instance of source and player positions on each sourc…
Browse files Browse the repository at this point in the history
…e packet send to avoid race conditions

#422
  • Loading branch information
Apehum committed Oct 12, 2024
1 parent b79a385 commit cfef164
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ class VoiceServerEntitySource(
) : VoiceServerProximitySource<EntitySourceInfo>(voiceServer, addon, UUID.randomUUID(), line, decoderInfo, stereo),
ServerEntitySource {

override val position: ServerPos3d = entity.getServerPosition()
get() {
return entity.getServerPosition(field)
}
override val position: ServerPos3d
get() = entity.getServerPosition()

override val sourceInfo: EntitySourceInfo
get() = EntitySourceInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ class VoiceServerPlayerSource(
) : VoiceServerProximitySource<PlayerSourceInfo>(voiceServer, addon, UUID.randomUUID(), line, decoderInfo, stereo),
ServerPlayerSource {

private val playerPosition = ServerPos3d()

override val position: ServerPos3d
get() = player.instance.getServerPosition(playerPosition)
get() = player.instance.getServerPosition()

override val sourceInfo: PlayerSourceInfo
get() = PlayerSourceInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ abstract class VoiceServerProximitySource<S : SourceInfo>(
stereo: Boolean
) : BaseServerAudioSource<S>(addon, id, serverSourceLine, decoderInfo, stereo), ServerProximitySource<S> {

private val playerPosition = ServerPos3d()

override var angle: Int = 0
get() = field
set(value) {
Expand All @@ -50,6 +48,7 @@ abstract class VoiceServerProximitySource<S : SourceInfo>(
if (dirty.compareAndSet(true, false))
sendPacket(SourceInfoPacket(sourceInfo), listenersDistance.toShort())

val playerPosition = ServerPos3d()
val sourcePosition = position
val distanceSquared = (listenersDistance * listenersDistance).toDouble()

Expand All @@ -74,6 +73,7 @@ abstract class VoiceServerProximitySource<S : SourceInfo>(

val listenersDistance = event.distance * DISTANCE_MULTIPLIER

val playerPosition = ServerPos3d()
val sourcePosition = position
val distanceSquared = (listenersDistance * listenersDistance).toDouble()

Expand Down

0 comments on commit cfef164

Please sign in to comment.