From 9828acc7dc2fe760c4f099a035dff4b9b6f1d4f4 Mon Sep 17 00:00:00 2001
From: shangfengh <3495281661@qq.com>
Date: Sat, 13 Apr 2024 21:45:29 +0800
Subject: [PATCH] delete a log in RPC
---
.../SafeValue/LockedValue/InRangeTimeBased.cs | 32 +++++++++----
logic/Server/RpcServices.cs | 45 ++++++++++---------
2 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/logic/Preparation/Utility/Value/SafeValue/LockedValue/InRangeTimeBased.cs b/logic/Preparation/Utility/Value/SafeValue/LockedValue/InRangeTimeBased.cs
index 5c4eb018..b8707037 100644
--- a/logic/Preparation/Utility/Value/SafeValue/LockedValue/InRangeTimeBased.cs
+++ b/logic/Preparation/Utility/Value/SafeValue/LockedValue/InRangeTimeBased.cs
@@ -100,19 +100,33 @@ public void SetAndStop(long value = 0)
public class TimeBasedProgressAtVariableSpeed
{
private readonly LongInVariableRangeWithStartTime progress;
- public AtomicDouble speed;
+ private IDouble speed;
+ ///
+ /// 注意:set操作(即=)的真正意义是改变其引用,单纯改变值不应当使用该操作
+ ///
+ public IDouble Speed
+ {
+ get
+ {
+ return Interlocked.CompareExchange(ref speed!, null, null);
+ }
+ set
+ {
+ Interlocked.Exchange(ref speed, value);
+ }
+ }
#region 构造
public TimeBasedProgressAtVariableSpeed(long needProgress, double speed = 1.0)
{
progress = new LongInVariableRangeWithStartTime(0, needProgress);
if (needProgress <= 0) Debugger.Output("Bug:TimeBasedProgressAtVariableSpeed.needProgress (" + needProgress.ToString() + ") is less than 0.");
- this.speed = new(speed);
+ this.speed = new AtomicDouble(speed);
}
public TimeBasedProgressAtVariableSpeed()
{
progress = new LongInVariableRangeWithStartTime(0, 0);
- this.speed = new(1.0);
+ this.speed = new AtomicDouble(1.0);
}
#endregion
@@ -125,8 +139,8 @@ public override string ToString()
+ " ; LastStartTime: " + lastStartTime.ToString() + "ms"
+ " ; Speed: " + speed.ToString();
}
- public long GetProgressNow() => progress.AddStartTimeToMaxV((double)speed).Item1;
- public (long, long, long) GetProgressNowAndNeedTimeAndLastStartTime() => progress.AddStartTimeToMaxV((double)speed);
+ public long GetProgressNow() => progress.AddStartTimeToMaxV(speed.ToDouble()).Item1;
+ public (long, long, long) GetProgressNowAndNeedTimeAndLastStartTime() => progress.AddStartTimeToMaxV(speed.ToDouble());
public long GetProgressStored() => progress.GetValue();
public (long, long) GetProgressStoredAndNeedTime() => progress.GetValueAndMaxV();
public (long, long, long) GetProgressStoredAndNeedTimeAndLastStartTime() => progress.GetValueAndMaxVWithStartTime();
@@ -134,13 +148,13 @@ public override string ToString()
public bool IsFinished()
{
long progressNow, needTime;
- (progressNow, needTime, _) = progress.AddStartTimeToMaxV((double)speed);
+ (progressNow, needTime, _) = progress.AddStartTimeToMaxV(speed.ToDouble());
return progressNow == needTime;
}
public bool IsProgressing()
{
long progressNow, needTime, startT;
- (progressNow, needTime, startT) = progress.AddStartTimeToMaxV((double)speed);
+ (progressNow, needTime, startT) = progress.AddStartTimeToMaxV(speed.ToDouble());
return (startT != long.MaxValue && progressNow != needTime);
}
#endregion
@@ -172,14 +186,14 @@ public void Set0()
///
public void TryStop()
{
- progress.Set0IfNotAddStartTimeToMaxV(speed);
+ progress.Set0IfNotAddStartTimeToMaxV(speed.ToDouble());
}
///
/// 使进度条暂停
///
public bool Pause()
{
- return progress.AddStartTime((double)speed) != 0;
+ return progress.AddStartTime(speed.ToDouble()) != 0;
}
///
/// 使进度条进度为满
diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs
index a0903685..0b46c60c 100755
--- a/logic/Server/RpcServices.cs
+++ b/logic/Server/RpcServices.cs
@@ -177,41 +177,44 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter()?.Find(
+ ship => ship.PlayerID == request.PlayerId);
do
{
if (request.TeamId == 0)
semaDict0[request.PlayerId].Item1.Wait();
else if (request.TeamId == 1)
semaDict1[request.PlayerId].Item1.Wait();
- try
+ if (ship == null || ship.IsRemoved == true)
+ { }
+ else
{
- if (currentGameInfo != null && !exitFlag)
+ try
{
- await responseStream.WriteAsync(currentGameInfo);
- Console.WriteLine("Send!");
+ if (currentGameInfo != null && !exitFlag)
+ {
+ await responseStream.WriteAsync(currentGameInfo);
+ Console.WriteLine("Send!");
+ }
}
- }
- catch
- {
- if (!exitFlag)
+ catch
+ {
+ if (!exitFlag)
+ {
+ Console.WriteLine($"The client {request.PlayerId} exited");
+ exitFlag = true;
+ }
+ }
+ finally
{
- Console.WriteLine($"The client {request.PlayerId} exited");
- exitFlag = true;
+ if (request.TeamId == 0)
+ semaDict0[request.PlayerId].Item2.Release();
+ else if (request.TeamId == 1)
+ semaDict1[request.PlayerId].Item2.Release();
}
}
- finally
- {
- if (request.TeamId == 0)
- semaDict0[request.PlayerId].Item2.Release();
- else if (request.TeamId == 1)
- semaDict1[request.PlayerId].Item2.Release();
- }
} while (game.GameMap.Timer.IsGaming);
-#if DEBUG
- Console.WriteLine("END Add Player");
-#endif
}
public override Task GetMap(NullRequest request, ServerCallContext context)