Refactor player entry initialization and optimize building state update logic
This commit is contained in:
7
Main.cs
7
Main.cs
@@ -141,13 +141,6 @@ namespace KCM
|
||||
}
|
||||
|
||||
// Destroy persistent managers
|
||||
if (KCMSteamManager != null)
|
||||
{
|
||||
helper.Log("Destroying KCMSteamManager.");
|
||||
Destroy(KCMSteamManager.gameObject);
|
||||
KCMSteamManager = null;
|
||||
}
|
||||
|
||||
if (lobbyManager != null)
|
||||
{
|
||||
helper.Log("Destroying LobbyManager.");
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace KCM.ServerLobby
|
||||
|
||||
public void Start()
|
||||
{
|
||||
banner = transform.Find("PlayerBanner").GetComponent<RawImage>();
|
||||
|
||||
SetValues();
|
||||
|
||||
InvokeRepeating("SetValues", 0, 0.25f);
|
||||
|
||||
banner = transform.Find("PlayerBanner").GetComponent<RawImage>();
|
||||
|
||||
transform.Find("PlayerBanner").GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
Main.TransitionTo(MenuState.NameAndBanner);//ChooseBannerUI Hooks required, as well as townnameui
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using KCM.Packets;
|
||||
using KCM.Packets;
|
||||
using KCM.Packets.State;
|
||||
using KCM.StateManagement.Observers;
|
||||
using System;
|
||||
@@ -6,12 +6,15 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using static KCM.StateManagement.Observers.Observer;
|
||||
|
||||
namespace KCM.StateManagement.BuildingState
|
||||
{
|
||||
public class BuildingStateManager
|
||||
{
|
||||
private static readonly Dictionary<Guid, float> lastUpdateTime = new Dictionary<Guid, float>();
|
||||
private const float UpdateInterval = 0.1f; // 10 times per second
|
||||
|
||||
public static void BuildingStateChanged(object sender, StateUpdateEventArgs args)
|
||||
{
|
||||
@@ -23,10 +26,18 @@ namespace KCM.StateManagement.BuildingState
|
||||
try
|
||||
{
|
||||
Observer observer = (Observer)sender;
|
||||
|
||||
Building building = (Building)observer.state;
|
||||
Guid guid = building.guid;
|
||||
|
||||
//Main.helper.Log("Should send building network update for: " + building.UniqueName);
|
||||
if (lastUpdateTime.ContainsKey(guid) && Time.time < lastUpdateTime[guid] + UpdateInterval)
|
||||
{
|
||||
return; // Not time to update yet
|
||||
}
|
||||
|
||||
if (!lastUpdateTime.ContainsKey(guid))
|
||||
lastUpdateTime.Add(guid, Time.time);
|
||||
else
|
||||
lastUpdateTime[guid] = Time.time;
|
||||
|
||||
new BuildingStatePacket()
|
||||
{
|
||||
@@ -57,4 +68,4 @@ namespace KCM.StateManagement.BuildingState
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user