Skip to content

Commit

Permalink
Merge branch 'eesast:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLOX authored Apr 27, 2024
2 parents 3f87380 + 4138b5e commit af69cc5
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 59 deletions.
4 changes: 4 additions & 0 deletions logic/GameClass/GameObj/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public partial class Map : IMap
public readonly PlaceType[,] protoGameMap;
public PlaceType[,] ProtoGameMap => protoGameMap;

// xfgg说:爱因斯坦说,每个坐标系都有与之绑定的时钟,(x, y, z, ict) 构成四维时空坐标,在洛伦兹变换下满足矢量性(狗头)
private readonly MyTimer timer = new();
public IMyTimer Timer => timer;

#region 大本营相关
public List<Home> Homes { get; }
private readonly long currentHomeNum = 0;
Expand Down
33 changes: 0 additions & 33 deletions logic/GameClass/GameObj/Map/MapGameTimer.cs

This file was deleted.

3 changes: 1 addition & 2 deletions logic/GameEngine/MoveEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Threading;
using Timothy.FrameRateTask;
using ITimer = Preparation.Interface.ITimer;

namespace GameEngine
{
Expand Down Expand Up @@ -41,7 +40,7 @@ public enum AfterCollision
Destroyed = 2 // 物体已经毁坏
}

private readonly ITimer gameTimer = gameMap.Timer;
private readonly IMyTimer gameTimer = gameMap.Timer;
private readonly Action<IMovable> EndMove = EndMove;

public IGameObj? CheckCollision(IMovable obj, XY Pos)
Expand Down
11 changes: 1 addition & 10 deletions logic/Gaming/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,7 @@ public bool StartGame(int milliSeconds)
actionManager.AddMoneyNaturally(team);
ActivateShip(team.TeamID, ShipType.CivilShip);
}
new Thread
(
() =>
{
if (!gameMap.Timer.StartGame(milliSeconds))
return;
EndGame(); // 游戏结束时要做的事
}
)
{ IsBackground = true }.Start();
gameMap.Timer.Start(() => { }, () => EndGame(), milliSeconds);
return true;
}
public void EndGame()
Expand Down
2 changes: 1 addition & 1 deletion logic/Preparation/Interface/IMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Preparation.Interface
{
public interface IMap
{
ITimer Timer { get; }
IMyTimer Timer { get; }

// the two dicts must have same keys
Dictionary<GameObjType, LockedClassList<IGameObj>> GameObjDict { get; }
Expand Down
11 changes: 0 additions & 11 deletions logic/Preparation/Interface/ITimer.cs

This file was deleted.

65 changes: 65 additions & 0 deletions logic/Preparation/Utility/Value/SafeValue/MyTimer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Preparation.Utility.Value.SafeValue.Atomic;
using System;
using System.Threading;

namespace Preparation.Utility.Value.SafeValue
{
public class MyTimer : IMyTimer
{
private readonly AtomicLong startTime = new(long.MaxValue);
public int NowTime() => (int)(Environment.TickCount64 - startTime);
public bool IsGaming => startTime != long.MaxValue;

public bool Start(Action start, Action endBefore, Action endAfter, int timeInMilliseconds)
{
start();
if (startTime.CompareExROri(Environment.TickCount64, long.MaxValue) != long.MaxValue)
return false;
try
{
new Thread
(
() =>
{
Thread.Sleep(timeInMilliseconds);
endBefore();
startTime.SetROri(long.MaxValue);
endAfter();
}
)
{ IsBackground = true }.Start();
}
catch (Exception ex)
{
startTime.SetROri(long.MaxValue);
Console.WriteLine(ex.Message);
}
return true;
}
public bool Start(Action start, Action end, int timeInMilliseconds)
{
start();
if (startTime.CompareExROri(Environment.TickCount64, long.MaxValue) != long.MaxValue)
return false;
try
{
new Thread
(
() =>
{
Thread.Sleep(timeInMilliseconds);
startTime.SetROri(long.MaxValue);
end();
}
)
{ IsBackground = true }.Start();
}
catch (Exception ex)
{
startTime.SetROri(long.MaxValue);
Console.WriteLine(ex.Message);
}
return true;
}
}
}
2 changes: 1 addition & 1 deletion logic/Preparation/Utility/Value/ValueInterface/IAddable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Preparation.Interface
namespace Preparation.Utility
{
public interface IAddable<T>
{
Expand Down
2 changes: 1 addition & 1 deletion logic/Preparation/Utility/Value/ValueInterface/IDouble.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Preparation.Interface
namespace Preparation.Utility
{
public interface IDouble
{
Expand Down
11 changes: 11 additions & 0 deletions logic/Preparation/Utility/Value/ValueInterface/IMyTimer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Preparation.Utility
{
public interface IMyTimer
{
bool IsGaming { get; }
public int NowTime();
public bool Start(Action start, Action end, int timeInMilliseconds);
}
}

0 comments on commit af69cc5

Please sign in to comment.