Skip to content

Commit

Permalink
Merge branch 'dev' into xiangmy21-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLOX authored Apr 27, 2024
2 parents 2305866 + 6e92d4c commit c61f911
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 68 deletions.
2 changes: 1 addition & 1 deletion logic/Client/Util/UtilFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static int getCellIndex(int i, int j)
}
public static int getGridIndex(float i, float j)
{
return 50 * (49 - (int)i / 1000) + (49 - (int)j / 1000);
return 50 * ((int)i / 1000) + ((int)j / 1000);
}

public static PointF Grid2CellPoint(float i, float j)
Expand Down
4 changes: 2 additions & 2 deletions logic/Client/View/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<Label x:Name="RedScore" Grid.Row="0" Grid.Column="3" Text="{Binding RedPlayer.Score, StringFormat='🚩: {0}'}" Style="{StaticResource littleAttributes}" />
</Grid>

<Grid x:Name="RedShipStatusAttributesGrid" Grid.Row="1">
<Grid x:Name="RedShipStatusAttributesGrid" Grid.Row="1" IsVisible="{Binding RedShipsLabelIsBusy}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
Expand Down Expand Up @@ -194,7 +194,7 @@
<Label x:Name="BlueShipHp" Grid.Row="1" Grid.Column="7" Text="血量❤️" Style="{x:StaticResource shipStatusTagAttributes}"/>
</Grid>

<CollectionView ItemsSource="{Binding BluePlayer.Ships}" Grid.Row="2">
<CollectionView ItemsSource="{Binding BluePlayer.Ships}" Grid.Row="2" IsVisible="{Binding BlueShipsLabelIsBusy}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Ship">
<Grid>
Expand Down
84 changes: 78 additions & 6 deletions logic/Client/ViewModel/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,44 @@ Show the error message
}
}

public bool redShipsLabelIsBusy = true;

public bool RedShipsLabelIsBusy
{
get
{
return redShipsLabelIsBusy;
}

set
{
redShipsLabelIsBusy = value;
}
}

public bool blueShipsLabelIsBusy = true;

public bool BlueShipsLabelIsBusy
{
get
{
return blueShipsLabelIsBusy;
}

set
{
blueShipsLabelIsBusy = value;
}
}


private void Refresh(object sender, EventArgs e)
{
try
{
lock (drawPicLock)
{

//if (UIinitiated)
//{
// redPlayer.SlideLengthSet();
Expand Down Expand Up @@ -500,6 +532,8 @@ private void Refresh(object sender, EventArgs e)

//RedPlayer.Ships.Clear();
//BluePlayer.Ships.Clear();
redShipsLabelIsBusy = true;
blueShipsLabelIsBusy = true;
int RedShipCount = 0;
int BlueShipCount = 0;
for (int i = 0; i < listOfShip.Count; i++)
Expand All @@ -520,15 +554,40 @@ private void Refresh(object sender, EventArgs e)
ConstuctorModule = data.ConstructorType,
};
myLogger.LogInfo(String.Format("RedShipCount:{0}, Redplayers.ships.count:{1}", RedShipCount, RedPlayer.Ships.Count));
if (RedShipCount < RedPlayer.Ships.Count && UtilFunctions.IsShipEqual(ship, RedPlayer.Ships[RedShipCount]))
//if (listOfShip.Count >= RedPlayer.Ships.Count)
{
myLogger.LogInfo(String.Format("listOfShip.Count:{0}, RedPlayer.Ships.Count:{1}", listOfShip.Count, RedPlayer.Ships.Count));

if (RedShipCount < RedPlayer.Ships.Count && UtilFunctions.IsShipEqual(ship, RedPlayer.Ships[RedShipCount]))
{
RedShipCount++;
continue;
}
else if (RedShipCount < RedPlayer.Ships.Count && !UtilFunctions.IsShipEqual(ship, RedPlayer.Ships[RedShipCount]))
RedPlayer.Ships[RedShipCount] = ship;
else RedPlayer.Ships.Add(ship);
RedShipCount++;
continue;
}
else if (RedShipCount < RedPlayer.Ships.Count && !UtilFunctions.IsShipEqual(ship, RedPlayer.Ships[RedShipCount]))
RedPlayer.Ships[RedShipCount] = ship;
else RedPlayer.Ships.Add(ship);
RedShipCount++;
//else
//{
// myLogger.LogInfo("listOfShip.Count < RedPlayer.Ships.Count");
// myLogger.LogInfo(String.Format("listOfShip.Count:{0}, RedPlayer.Ships.Count:{1}", listOfShip.Count, RedPlayer.Ships.Count));
// if (RedShipCount < listOfShip.Count && UtilFunctions.IsShipEqual(ship, RedPlayer.Ships[RedShipCount]))
// {
// RedShipCount++;
// continue;
// }
// else if (RedShipCount < listOfShip.Count && !UtilFunctions.IsShipEqual(ship, RedPlayer.Ships[RedShipCount]))
// {
// RedPlayer.Ships[RedShipCount] = ship;
// RedShipCount++;
// }
// else
// {
// for (int index = listOfShip.Count; index < RedPlayer.Ships.Count - 1; index++)
// RedPlayer.Ships.RemoveAt(index);
// }
//}
}
// else if (data.TeamId == (long)PlayerTeam.Blue)
else if (data.TeamId == 1)
Expand Down Expand Up @@ -556,6 +615,7 @@ private void Refresh(object sender, EventArgs e)
else BluePlayer.Ships.Add(ship);
BlueShipCount++;
}

//else
//{
// Ship ship = new Ship
Expand Down Expand Up @@ -584,6 +644,18 @@ private void Refresh(object sender, EventArgs e)
// else RedPlayer.Ships.Add(ship);
//}
}
for (int index = RedShipCount; index < RedPlayer.Ships.Count; index++)
{
RedPlayer.Ships.RemoveAt(index);
myLogger.LogInfo(String.Format("redRemoveIndex: {0}", index));
}
for (int index = BlueShipCount; index < BluePlayer.Ships.Count; index++)
{
BluePlayer.Ships.RemoveAt(index);
myLogger.LogInfo(String.Format("blueRemoveIndex: {0}", index));
}
redShipsLabelIsBusy = false;
blueShipsLabelIsBusy = false;
myLogger.LogInfo("============= Draw Ship list ================");

for (int i = 0; i < RedPlayer.Ships.Count; i++)
Expand Down
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 c61f911

Please sign in to comment.