Spatial config
This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using Server.Redis;
|
||||
using System.Text.Json;
|
||||
using GameServer.Dungeon;
|
||||
|
||||
namespace GameServices.Admin.Pages.Server;
|
||||
|
||||
@@ -10,15 +11,17 @@ public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IRedisManager _redis;
|
||||
private readonly DungeonHandler? _dungeonHandler;
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
private static readonly List<BroadcastRecord> _recentBroadcasts = new();
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public IndexModel(GameDbContext db, IRedisManager redis, ILogger<IndexModel> logger)
|
||||
public IndexModel(GameDbContext db, IRedisManager redis, ILogger<IndexModel> logger, DungeonHandler? dungeonHandler = null)
|
||||
{
|
||||
_db = db;
|
||||
_redis = redis;
|
||||
_logger = logger;
|
||||
_dungeonHandler = dungeonHandler;
|
||||
}
|
||||
|
||||
public int ActiveConnections { get; set; }
|
||||
@@ -28,6 +31,9 @@ public class IndexModel : AdminPageModel
|
||||
public int TrackedAssets { get; set; }
|
||||
|
||||
public List<BroadcastRecord> RecentBroadcasts { get; set; } = new();
|
||||
public bool SpatialFilterEnabled { get; set; } = true;
|
||||
public float SpatialRadiusPx { get; set; } = 896f;
|
||||
public int SpatialIntervalTicks { get; set; } = 1;
|
||||
|
||||
[TempData]
|
||||
public string? Message { get; set; }
|
||||
@@ -60,6 +66,43 @@ public class IndexModel : AdminPageModel
|
||||
{
|
||||
RecentBroadcasts = _recentBroadcasts.OrderByDescending(b => b.SentAt).Take(10).ToList();
|
||||
}
|
||||
|
||||
if (_dungeonHandler != null)
|
||||
{
|
||||
var tuning = _dungeonHandler.GetSpatialUpdateTuning();
|
||||
SpatialFilterEnabled = tuning.enabled;
|
||||
SpatialRadiusPx = tuning.radiusPx;
|
||||
SpatialIntervalTicks = tuning.intervalTicks;
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnPostUpdateSpatialAsync(bool spatialFilterEnabled, float spatialRadiusPx, int spatialIntervalTicks)
|
||||
{
|
||||
if (_dungeonHandler == null)
|
||||
{
|
||||
Message = "DungeonHandler is not available on this pod.";
|
||||
IsError = true;
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_dungeonHandler.SetSpatialFilterEnabled(spatialFilterEnabled);
|
||||
_dungeonHandler.SetSpatialUpdateRangePx(spatialRadiusPx);
|
||||
_dungeonHandler.SetSpatialUpdateIntervalTicks(spatialIntervalTicks);
|
||||
|
||||
var updated = _dungeonHandler.GetSpatialUpdateTuning();
|
||||
Message = $"Spatial tuning updated: enabled={updated.enabled}, radius={updated.radiusPx:0}px, interval={updated.intervalTicks} tick(s)";
|
||||
IsError = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update spatial tuning");
|
||||
Message = $"Failed to update spatial tuning: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostBroadcastAsync(string message, string messageType)
|
||||
|
||||
Reference in New Issue
Block a user