mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-11 06:24:38 +00:00
moved polling of blockmap from psm callback to upstream handling (#1121)
This commit is contained in:
parent
2b6edc25fb
commit
663cfdc90a
5 changed files with 35 additions and 9 deletions
|
|
@ -94,7 +94,7 @@ class SessionAvatarHandlers(
|
||||||
lazy val targetDelay = {
|
lazy val targetDelay = {
|
||||||
val populationOver = math.max(
|
val populationOver = math.max(
|
||||||
0,
|
0,
|
||||||
continent.blockMap.sector(ourPosition, range=drawConfig.rangeMax.toFloat).livePlayerList.size - drawConfig.populationThreshold
|
sessionData.localSector.livePlayerList.size - drawConfig.populationThreshold
|
||||||
)
|
)
|
||||||
val distanceAdjustment = math.pow(populationOver / drawConfig.populationStep * drawConfig.rangeStep, 2) //sq.m
|
val distanceAdjustment = math.pow(populationOver / drawConfig.populationStep * drawConfig.rangeStep, 2) //sq.m
|
||||||
val adjustedDistance = currentDistance + distanceAdjustment //sq.m
|
val adjustedDistance = currentDistance + distanceAdjustment //sq.m
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package net.psforever.actors.session.support
|
||||||
import akka.actor.typed.scaladsl.adapter._
|
import akka.actor.typed.scaladsl.adapter._
|
||||||
import akka.actor.{ActorContext, ActorRef, Cancellable, typed}
|
import akka.actor.{ActorContext, ActorRef, Cancellable, typed}
|
||||||
import net.psforever.objects.sourcing.{PlayerSource, SourceEntry}
|
import net.psforever.objects.sourcing.{PlayerSource, SourceEntry}
|
||||||
|
import net.psforever.objects.zones.blockmap.{SectorGroup, SectorPopulation}
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.concurrent.ExecutionContext.Implicits.global
|
import scala.concurrent.ExecutionContext.Implicits.global
|
||||||
|
|
@ -137,6 +138,12 @@ class SessionData(
|
||||||
def squad: SessionSquadHandlers = squadResponseOpt.orNull
|
def squad: SessionSquadHandlers = squadResponseOpt.orNull
|
||||||
def zoning: ZoningOperations = zoningOpt.orNull
|
def zoning: ZoningOperations = zoningOpt.orNull
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updated when an upstream packet arrives;
|
||||||
|
* allow to be a little stale for a short while
|
||||||
|
*/
|
||||||
|
private[support] var localSector: SectorPopulation = SectorGroup(Nil)
|
||||||
|
|
||||||
def session: Session = theSession
|
def session: Session = theSession
|
||||||
|
|
||||||
def session_=(session: Session): Unit = {
|
def session_=(session: Session): Unit = {
|
||||||
|
|
@ -206,7 +213,7 @@ class SessionData(
|
||||||
)= pkt
|
)= pkt
|
||||||
persist()
|
persist()
|
||||||
turnCounterFunc(avatarGuid)
|
turnCounterFunc(avatarGuid)
|
||||||
updateBlockMap(player, continent, pos)
|
updateBlockMap(player, pos)
|
||||||
val isMoving = WorldEntity.isMoving(vel)
|
val isMoving = WorldEntity.isMoving(vel)
|
||||||
val isMovingPlus = isMoving || isJumping || jumpThrust
|
val isMovingPlus = isMoving || isJumping || jumpThrust
|
||||||
if (isMovingPlus) {
|
if (isMovingPlus) {
|
||||||
|
|
@ -2665,16 +2672,22 @@ class SessionData(
|
||||||
middlewareActor ! MiddlewareActor.Teardown()
|
middlewareActor ! MiddlewareActor.Teardown()
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateBlockMap(target: BlockMapEntity, zone: Zone, newCoords: Vector3): Unit = {
|
def updateBlockMap(target: BlockMapEntity, newCoords: Vector3): Unit = {
|
||||||
target.blockMapEntry.foreach { entry =>
|
target.blockMapEntry.foreach { entry =>
|
||||||
if (BlockMap.findSectorIndices(continent.blockMap, newCoords, entry.rangeX, entry.rangeY).toSet.equals(entry.sectors)) {
|
val sectorIndices = BlockMap.findSectorIndices(continent.blockMap, newCoords, entry.rangeX, entry.rangeY).toSet
|
||||||
|
if (sectorIndices.equals(entry.sectors)) {
|
||||||
target.updateBlockMapEntry(newCoords) //soft update
|
target.updateBlockMapEntry(newCoords) //soft update
|
||||||
|
localSector = continent.blockMap.sector(sectorIndices, Config.app.game.playerDraw.rangeMax.toFloat)
|
||||||
} else {
|
} else {
|
||||||
zone.actor ! ZoneActor.UpdateBlockMap(target, newCoords) //hard update
|
continent.actor ! ZoneActor.UpdateBlockMap(target, newCoords) //hard update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updateLocalBlockMap(pos: Vector3): Unit = {
|
||||||
|
localSector = continent.blockMap.sector(pos, Config.app.game.playerDraw.rangeMax.toFloat)
|
||||||
|
}
|
||||||
|
|
||||||
private[support] var oldRefsMap: mutable.HashMap[PlanetSideGUID, String] = new mutable.HashMap[PlanetSideGUID, String]()
|
private[support] var oldRefsMap: mutable.HashMap[PlanetSideGUID, String] = new mutable.HashMap[PlanetSideGUID, String]()
|
||||||
def updateOldRefsMap(): Unit = {
|
def updateOldRefsMap(): Unit = {
|
||||||
if(player.HasGUID) {
|
if(player.HasGUID) {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ class SessionVehicleHandlers(
|
||||||
player.Position = pos
|
player.Position = pos
|
||||||
player.Orientation = orient
|
player.Orientation = orient
|
||||||
player.Velocity = vel
|
player.Velocity = vel
|
||||||
|
sessionData.updateLocalBlockMap(pos)
|
||||||
|
|
||||||
case VehicleResponse.VehicleState(
|
case VehicleResponse.VehicleState(
|
||||||
vehicleGuid,
|
vehicleGuid,
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class VehicleOperations(
|
||||||
sessionData.turnCounterFunc(player.GUID)
|
sessionData.turnCounterFunc(player.GUID)
|
||||||
sessionData.fallHeightTracker(pos.z)
|
sessionData.fallHeightTracker(pos.z)
|
||||||
if (obj.MountedIn.isEmpty) {
|
if (obj.MountedIn.isEmpty) {
|
||||||
sessionData.updateBlockMap(obj, continent, pos)
|
sessionData.updateBlockMap(obj, pos)
|
||||||
}
|
}
|
||||||
player.Position = pos //convenient
|
player.Position = pos //convenient
|
||||||
if (obj.WeaponControlledFromSeat(0).isEmpty) {
|
if (obj.WeaponControlledFromSeat(0).isEmpty) {
|
||||||
|
|
@ -127,7 +127,7 @@ class VehicleOperations(
|
||||||
sessionData.turnCounterFunc(player.GUID)
|
sessionData.turnCounterFunc(player.GUID)
|
||||||
val (position, angle, velocity, notMountedState) = continent.GUID(obj.MountedIn) match {
|
val (position, angle, velocity, notMountedState) = continent.GUID(obj.MountedIn) match {
|
||||||
case Some(v: Vehicle) =>
|
case Some(v: Vehicle) =>
|
||||||
sessionData.updateBlockMap(obj, continent, pos)
|
sessionData.updateBlockMap(obj, pos)
|
||||||
(pos, v.Orientation - Vector3.z(value = 90f) * Vehicles.CargoOrientation(obj).toFloat, v.Velocity, false)
|
(pos, v.Orientation - Vector3.z(value = 90f) * Vehicles.CargoOrientation(obj).toFloat, v.Velocity, false)
|
||||||
case _ =>
|
case _ =>
|
||||||
(pos, ang, vel, true)
|
(pos, ang, vel, true)
|
||||||
|
|
@ -243,7 +243,7 @@ class VehicleOperations(
|
||||||
obj.Position = pos
|
obj.Position = pos
|
||||||
obj.Orientation = ang
|
obj.Orientation = ang
|
||||||
obj.Velocity = vel
|
obj.Velocity = vel
|
||||||
sessionData.updateBlockMap(obj, continent, pos)
|
sessionData.updateBlockMap(obj, pos)
|
||||||
obj.zoneInteractions()
|
obj.zoneInteractions()
|
||||||
continent.VehicleEvents ! VehicleServiceMessage(
|
continent.VehicleEvents ! VehicleServiceMessage(
|
||||||
continent.id,
|
continent.id,
|
||||||
|
|
|
||||||
|
|
@ -74,13 +74,25 @@ class BlockMap(fullMapWidth: Int, fullMapHeight: Int, desiredSpanSize: Int) {
|
||||||
* find the sector conglomerate to which this range allocates.
|
* find the sector conglomerate to which this range allocates.
|
||||||
* @see `BlockMap.findSectorIndices`
|
* @see `BlockMap.findSectorIndices`
|
||||||
* @see `BlockMap.quickToSectorGroup`
|
* @see `BlockMap.quickToSectorGroup`
|
||||||
|
* @see `BlockMap::sector(Iterable[Int], Float)`
|
||||||
* @param p the game world coordinates
|
* @param p the game world coordinates
|
||||||
* @param range the axis distance from the provided coordinates
|
* @param range the axis distance from the provided coordinates
|
||||||
* @return a conglomerate sector which lists all of the entities in the discovered sector(s)
|
* @return a conglomerate sector which lists all of the entities in the discovered sector(s)
|
||||||
*/
|
*/
|
||||||
def sector(p: Vector3, range: Float): SectorPopulation = {
|
def sector(p: Vector3, range: Float): SectorPopulation = {
|
||||||
val indices = BlockMap.findSectorIndices(blockMap = this, p, range)
|
sector(BlockMap.findSectorIndices(blockMap = this, p, range), range)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a coordinate position within representable space and a range from that representable space,
|
||||||
|
* find the sector conglomerate to which this range allocates.
|
||||||
|
* @see `BlockMap.findSectorIndices`
|
||||||
|
* @see `BlockMap.quickToSectorGroup`
|
||||||
|
* @param indices an enumeration that directly associates with the structure of the block map
|
||||||
|
* @param range the axis distance from the provided coordinates
|
||||||
|
* @return a conglomerate sector which lists all of the entities in the discovered sector(s)
|
||||||
|
*/
|
||||||
|
def sector(indices: Iterable[Int], range: Float): SectorPopulation = {
|
||||||
if (indices.max < blocks.size) {
|
if (indices.max < blocks.size) {
|
||||||
BlockMap.quickToSectorGroup(range, BlockMap.sectorsOnlyWithinBlockStructure(indices, blocks) )
|
BlockMap.quickToSectorGroup(range, BlockMap.sectorsOnlyWithinBlockStructure(indices, blocks) )
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue