Skip to content

Commit

Permalink
refactor: 🎨 standardize naming
Browse files Browse the repository at this point in the history
  • Loading branch information
shangfengh committed Mar 26, 2024
1 parent d9d6914 commit 298b35a
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 181 deletions.
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public bool Construct(int constructSpeed, ConstructionType constructionType, Shi
{
if (this.constructionType == ConstructionType.Null || HP == 0)
{
TeamID.SetReturnOri(ship.TeamID);
TeamID.SetROri(ship.TeamID);
this.constructionType = constructionType;
switch (constructionType)
{
Expand Down
6 changes: 3 additions & 3 deletions logic/GameClass/GameObj/MoneyPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class MoneyPool : IMoneyPool
public AtomicLong Score { get; } = new AtomicLong(0);
public MoneyPool()
{
Money.SetScore(Score);
Money.Score = Score;
}
public long AddMoney(long add)
{
return Money.Add(add);
return Money.AddRNow(add);
}
public long SubMoney(long sub)
{
return Money.Sub(sub);
return Money.SubRNow(sub);
}
}
4 changes: 2 additions & 2 deletions logic/Gaming/ShipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ private class ShipManager(Map gameMap)
{
Ship newShip = new(GameData.ShipRadius, shipType, moneyPool);
gameMap.Add(newShip);
newShip.TeamID.SetReturnOri(teamID);
newShip.PlayerID.SetReturnOri(playerID);
newShip.TeamID.SetROri(teamID);
newShip.PlayerID.SetROri(playerID);
return newShip;
}
public bool ActivateShip(Ship ship, XY pos)
Expand Down
25 changes: 25 additions & 0 deletions logic/Preparation/Utility/Value/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Value

---

用于为游戏引擎提供预先写好的通用类。

- 类的部分方法遵循下面原则:

```
Set //返回值为void,类似有Add,Sub
SetRNow //返回操作后的值
SetRChange //返回操作后减去操作前的差值
SetROri //返回操作前的值
```



## SafeValue

所有类型的操作是线程安全的

- 不能保证不出现死锁
6 changes: 3 additions & 3 deletions logic/Preparation/Utility/Value/SafeValue/Atomic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Preparation.Utility
//其对应属性不应当有set访问器,避免不安全的=赋值
public abstract class Atomic
{
}
}

public class AtomicT<T>(T? x) : Atomic where T : class?
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public class AtomicDouble(double x) : Atomic
public double CompareExROri(double newV, double compareTo) => Interlocked.CompareExchange(ref v, newV, compareTo);
}

public class AtomicBool(bool x) : Atomic , ISafeConvertible<bool>
public class AtomicBool(bool x) : Atomic, ISafeAddable<bool>
{
private int v = x ? 1 : 0;//v&1==0为false,v&1==1为true

Expand All @@ -44,7 +44,7 @@ public class AtomicBool(bool x) : Atomic , ISafeConvertible<bool>

/// <returns>返回操作前的值</returns>
public bool SetROri(bool value) => ((Interlocked.Exchange(ref v, value ? 1 : 0) & 1) == 1);
public void Set(bool value) =>Interlocked.Exchange(ref v, value ? 1 : 0);
public void Set(bool value) => Interlocked.Exchange(ref v, value ? 1 : 0);

/// <returns>赋值前的值是否与将赋予的值不相同</returns>
public bool TrySet(bool value)
Expand Down
Loading

0 comments on commit 298b35a

Please sign in to comment.