mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-07-16 08:55:18 +00:00
an attempt to space out the player upstream
This commit is contained in:
parent
53e3f9a08d
commit
a49a485222
4 changed files with 136 additions and 34 deletions
|
|
@ -177,6 +177,41 @@ game {
|
||||||
variable = 30
|
variable = 30
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Limits the dispatch of PlayerStateMessage packets from a session to its client.
|
||||||
|
# Specifically, a packet will only be dispatched based on whether
|
||||||
|
# it is to be dispatched over a threshold time after the previous dispatch time.
|
||||||
|
# The delay between packets is determined by a distance between the observer player and the target player.
|
||||||
|
# Only affects PlayerStateMessage.
|
||||||
|
player-draw = {
|
||||||
|
# Minimum number of players within a given region before scaling down the range.
|
||||||
|
# Total population - population threshold = overpopulation
|
||||||
|
population-threshold = 20
|
||||||
|
# Number of players over threshold before the reduction in range is scaled down.
|
||||||
|
# Population step / overpopulation = range step factor (integer)
|
||||||
|
population-step = 5
|
||||||
|
# Always send packets regarding target players within the given distance.
|
||||||
|
range-min = 50
|
||||||
|
# Do not send packets regarding target players beyond this distance. (sq.m)
|
||||||
|
# Treat this as an absolute render distance.
|
||||||
|
range-max = 550
|
||||||
|
# Number of meters reduced from range based on population count over threshold value. (m)
|
||||||
|
# Range step * range step factor = total distance to remove from actual distance
|
||||||
|
range-step = 25
|
||||||
|
# The distances above min-range where different delays are allowed before a successful packet must be dispatched. [m]
|
||||||
|
# Test distances against entries to find the last one that is not more than the sample distance.
|
||||||
|
# Use the index of that sample distance from this sequence in the sequence `delays` below.
|
||||||
|
ranges = [150, 300, 400]
|
||||||
|
# The absolute time delay before a successful packet must be dispatched regardless of distance. (s)
|
||||||
|
delay-max = 1000
|
||||||
|
# The time delays for each distance range before a successful packet must be dispatched. [s]
|
||||||
|
# The index for an entry in this sequence is expected to be discovered using the `ranges` sequence above.
|
||||||
|
# Delays between packets may not be as precise as desired
|
||||||
|
# as the heartbeat of upstream packets are measured in quanta of 250ms usually.
|
||||||
|
# As a consequence, additional entries with proper time spacing will push back the next proper update considerably
|
||||||
|
# while additional entries with insufficient time spacing may result in no change in behavior.
|
||||||
|
delays = [350, 600, 800]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
anti-cheat {
|
anti-cheat {
|
||||||
|
|
|
||||||
|
|
@ -70,31 +70,74 @@ class SessionAvatarHandlers(
|
||||||
jumpThrust,
|
jumpThrust,
|
||||||
isCloaking,
|
isCloaking,
|
||||||
spectating,
|
spectating,
|
||||||
_
|
canSeeReallyFar
|
||||||
) if isNotSameTarget =>
|
) if isNotSameTarget =>
|
||||||
val now = System.currentTimeMillis()
|
val (lastMsg, lastTime, lastPosition, wasSpectating) = lastSeenStreamMessage(guid.guid) match {
|
||||||
val (location, time, distanceSq): (Vector3, Long, Float) = if (spectating) {
|
case SessionAvatarHandlers.LastUpstream(Some(msg), time) => (Some(msg), time, msg.pos, msg.spectator)
|
||||||
val r2 = 2 + hidingPlayerRandomizer.nextInt(4000).toFloat
|
case _ => (None, 0L, Vector3.Zero, false)
|
||||||
(Vector3(r2, r2, 1f), 0L, 0f)
|
|
||||||
} else {
|
|
||||||
val before = lastSeenStreamMessage(guid.guid).time
|
|
||||||
val dist = Vector3.DistanceSquared(player.Position, pos)
|
|
||||||
(pos, now - before, dist)
|
|
||||||
}
|
}
|
||||||
if (distanceSq < 302500 || time > 5000) { // Render distance seems to be approx 525m. Reduce update rate at ~550m to be safe
|
val drawConfig = Config.app.game.playerDraw
|
||||||
|
val maxRange = drawConfig.rangeMax * drawConfig.rangeMax //sq.m
|
||||||
|
val ourPosition = player.Position
|
||||||
|
val currentDistance = Vector3.DistanceSquared(ourPosition, pos) //sq.m
|
||||||
|
val inVisibleRange = currentDistance <= maxRange
|
||||||
|
val wasInVisibleRange = Vector3.DistanceSquared(lastPosition, pos) <= maxRange
|
||||||
|
val now = System.currentTimeMillis() //ms
|
||||||
|
val durationSince = now - lastTime //ms
|
||||||
|
if ((!spectating && inVisibleRange && !lastMsg.contains(reply)) ||
|
||||||
|
(inVisibleRange && wasSpectating && !spectating)) { //this condition is unlikely, but ...
|
||||||
|
lazy val targetDelay = {
|
||||||
|
val populationOver = math.max(
|
||||||
|
0,
|
||||||
|
continent.blockMap.sector(ourPosition, range=drawConfig.rangeMax.toFloat).livePlayerList.size - drawConfig.populationThreshold
|
||||||
|
)
|
||||||
|
val distanceAdjustment = math.pow(populationOver / drawConfig.populationStep * drawConfig.rangeStep, 2) //sq.m
|
||||||
|
val adjustedDistance = currentDistance + distanceAdjustment //sq.m
|
||||||
|
drawConfig.ranges.lastIndexWhere { dist => adjustedDistance > dist * dist } match {
|
||||||
|
case -1 => 1
|
||||||
|
case index => drawConfig.delays(index)
|
||||||
|
}
|
||||||
|
} //ms
|
||||||
|
if (canSeeReallyFar ||
|
||||||
|
currentDistance < drawConfig.rangeMin * drawConfig.rangeMin ||
|
||||||
|
durationSince > drawConfig.delayMax ||
|
||||||
|
sessionData.canSeeReallyFar ||
|
||||||
|
durationSince > targetDelay) {
|
||||||
|
//must draw
|
||||||
|
sendResponse(
|
||||||
|
PlayerStateMessage(
|
||||||
|
guid,
|
||||||
|
pos,
|
||||||
|
vel,
|
||||||
|
yaw,
|
||||||
|
pitch,
|
||||||
|
yawUpper,
|
||||||
|
timestamp = 0, //is this okay?
|
||||||
|
isCrouching,
|
||||||
|
isJumping,
|
||||||
|
jumpThrust,
|
||||||
|
isCloaking
|
||||||
|
)
|
||||||
|
)
|
||||||
|
lastSeenStreamMessage(guid.guid) = SessionAvatarHandlers.LastUpstream(Some(pstate), now)
|
||||||
|
} else {
|
||||||
|
lastSeenStreamMessage(guid.guid) = SessionAvatarHandlers.LastUpstream(Some(pstate), lastTime)
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
(inVisibleRange && !wasSpectating && spectating) ||
|
||||||
|
(!spectating && wasInVisibleRange && !inVisibleRange)) {
|
||||||
|
//must hide
|
||||||
|
val lat = (1 + hidingPlayerRandomizer.nextInt(continent.map.scale.height.toInt)).toFloat
|
||||||
sendResponse(
|
sendResponse(
|
||||||
PlayerStateMessage(
|
PlayerStateMessage(
|
||||||
guid,
|
guid,
|
||||||
location,
|
Vector3(1f, lat, 1f),
|
||||||
vel,
|
vel=None,
|
||||||
yaw,
|
facingYaw=0f,
|
||||||
pitch,
|
facingPitch=0f,
|
||||||
yawUpper,
|
facingYawUpper=0f,
|
||||||
timestamp = 0,
|
timestamp=0, //is this okay?
|
||||||
isCrouching,
|
is_cloaked = isCloaking
|
||||||
isJumping,
|
|
||||||
jumpThrust,
|
|
||||||
isCloaking
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
lastSeenStreamMessage(guid.guid) = SessionAvatarHandlers.LastUpstream(Some(pstate), now)
|
lastSeenStreamMessage(guid.guid) = SessionAvatarHandlers.LastUpstream(Some(pstate), now)
|
||||||
|
|
|
||||||
|
|
@ -2908,19 +2908,28 @@ class SessionData(
|
||||||
}
|
}
|
||||||
|
|
||||||
def canSeeReallyFar: Boolean = {
|
def canSeeReallyFar: Boolean = {
|
||||||
findEquipment().exists {
|
shooting.FindContainedWeapon match {
|
||||||
case weapon: Tool
|
case (Some(_: Vehicle), weapons) if weapons.nonEmpty =>
|
||||||
if weapon.Size == EquipmentSize.Rifle &&
|
player.avatar
|
||||||
(weapon.Projectile ne GlobalDefinitions.no_projectile) &&
|
.implants
|
||||||
player.Crouching &&
|
.exists { p =>
|
||||||
player.avatar
|
p.collect { implant => implant.definition.implantType == ImplantType.RangeMagnifier && implant.active }.nonEmpty
|
||||||
.implants
|
}
|
||||||
.exists { p =>
|
case (Some(_: Player), weapons) if weapons.nonEmpty =>
|
||||||
p.collect { implant => implant.definition.implantType == ImplantType.RangeMagnifier && implant.initialized }.nonEmpty
|
val wep = weapons.head
|
||||||
} =>
|
wep.Definition == GlobalDefinitions.bolt_driver ||
|
||||||
true
|
wep.Definition == GlobalDefinitions.heavy_sniper ||
|
||||||
case item =>
|
(
|
||||||
item.Definition == GlobalDefinitions.bolt_driver || item.Definition == GlobalDefinitions.heavy_sniper
|
(wep.Projectile ne GlobalDefinitions.no_projectile) &&
|
||||||
|
player.Crouching &&
|
||||||
|
player.avatar
|
||||||
|
.implants
|
||||||
|
.exists { p =>
|
||||||
|
p.collect { implant => implant.definition.implantType == ImplantType.RangeMagnifier && implant.active }.nonEmpty
|
||||||
|
}
|
||||||
|
)
|
||||||
|
case _ =>
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,8 @@ case class GameConfig(
|
||||||
baseCertifications: Seq[Certification],
|
baseCertifications: Seq[Certification],
|
||||||
warpGates: WarpGateConfig,
|
warpGates: WarpGateConfig,
|
||||||
cavernRotation: CavernRotationConfig,
|
cavernRotation: CavernRotationConfig,
|
||||||
savedMsg: SavedMessageEvents
|
savedMsg: SavedMessageEvents,
|
||||||
|
playerDraw: PlayerStateDrawSettings
|
||||||
)
|
)
|
||||||
|
|
||||||
case class NewAvatar(
|
case class NewAvatar(
|
||||||
|
|
@ -216,3 +217,17 @@ case class SavedMessageTimings(
|
||||||
fixed: Long,
|
fixed: Long,
|
||||||
variable: Long
|
variable: Long
|
||||||
)
|
)
|
||||||
|
|
||||||
|
case class PlayerStateDrawSettings(
|
||||||
|
populationThreshold: Int,
|
||||||
|
populationStep: Int,
|
||||||
|
rangeMin: Int,
|
||||||
|
rangeMax: Int,
|
||||||
|
rangeStep: Int,
|
||||||
|
ranges: Seq[Int],
|
||||||
|
delayMax: Long,
|
||||||
|
delays: Seq[Long]
|
||||||
|
) {
|
||||||
|
assert(ranges.nonEmpty)
|
||||||
|
assert(ranges.size == delays.size)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue