Browse Source

fix: 🎨 deprecate moveReaderWriterLock

tags/v0.1.0
shangfengh 2 years ago
parent
commit
361a30e359
11 changed files with 38 additions and 115 deletions
  1. +5
    -5
      CAPI/cpp/API/include/constants.h
  2. +8
    -10
      CAPI/python/PyAPI/constants.py
  3. +1
    -1
      logic/GameClass/GameObj/Bullet/Bullet.cs
  4. +1
    -1
      logic/GameClass/GameObj/Character/Character.Skill.cs
  5. +4
    -12
      logic/GameClass/GameObj/Character/Character.cs
  6. +4
    -21
      logic/GameClass/GameObj/GameObj.cs
  7. +8
    -58
      logic/GameClass/GameObj/Moveable.cs
  8. +1
    -1
      logic/GameClass/GameObj/Prop/Gadget.cs
  9. +1
    -1
      logic/GameClass/GameObj/Prop/Item.cs
  10. +4
    -4
      logic/GameEngine/MoveEngine.cs
  11. +1
    -1
      logic/Preparation/Interface/IMoveable.cs

+ 5
- 5
CAPI/cpp/API/include/constants.h View File

@@ -138,13 +138,13 @@ namespace Constants
SCCI int moveSpeed = basicStudentSpeed * 9 / 10;
SCCI int maxHp = basicHp * 10;
SCCI int maxAddiction = basicMaxGamingAddiction * 10;
SCCI int fixSpeed = (int)(basicFixSpeed * 0.4);
SCCI int fixSpeed = (int)(basicFixSpeed * 50 / 123);
SCCI int encourageSpeed = basicEncourageSpeed * 8 / 10;
SCCI double concealment = 0.5;
SCCI int alertnessRadius = basicStudentAlertnessRadius * 3 / 4;
SCCI int alertnessRadius = basicStudentAlertnessRadius * 2 / 3;
SCCI int viewRange = basicStudentViewRange * 8 / 10;
SCCI int speedOfOpeningOrLocking = basicSpeedOfOpeningOrLocking;
SCCI int speedOfClimbingThroughWindows = (int)(basicStudentSpeedOfClimbingThroughWindows * 0.82);
SCCI int speedOfClimbingThroughWindows = (int)(basicStudentSpeedOfClimbingThroughWindows * 1000 / 1222);
SCCI int speedOfOpenChest = basicSpeedOfOpenChest;
};

@@ -377,7 +377,7 @@ namespace Constants
struct Strike
{
SCCI double BulletBombRange = 0;
SSC double BulletAttackRange = basicAttackShortRange;
SCCI double BulletAttackRange = basicAttackShortRange;
SCCI int ap = basicApOfTricker * 16 / 15;
SCCI int Speed = basicBulletMoveSpeed * 125 / 148;
SCCI bool IsRemoteAttack = false;
@@ -385,7 +385,7 @@ namespace Constants
SCCI int CastTime = basicCastTime * 16 / 25;
SCCI int Backswing = basicBackswing;
SCCI int RecoveryFromHit = basicRecoveryFromHit;
SCCI int cd = basicBackswing * 3 / 4;
SCCI int cd = basicBackswing;
SCCI int maxBulletNum = 1;
};
} // namespace Constants


+ 8
- 10
CAPI/python/PyAPI/constants.py View File

@@ -159,14 +159,14 @@ class Teacher:
moveSpeed = (int)(0.9 * Constants.basicStudentSpeed)
maxHp = (int)(10.0 * Constants.basicHp)
maxAddiction = (int)(10.0 * Constants.basicMaxGamingAddiction)
LearnSpeed = (int)(0.4 * Constants.basicLearnSpeed)
LearnSpeed = (int)( Constants.basicLearnSpeed* 50//123)
EncourageSpeed = (int)(0.8 * Constants.basicEncourageSpeed)
concealment = 0.5 * Constants.basicConcealment
alertnessRadius = (int)(0.75 * Constants.basicStudentAlertnessRadius)
alertnessRadius = (int)(Constants.basicStudentAlertnessRadius * 2 // 3)
viewRange = (int)(0.8 * Constants.basicStudentViewRange)
speedOfOpeningOrLocking = (int)(1.0 * Constants.basicSpeedOfOpeningOrLocking)
speedOfClimbingThroughWindows = (int)(
0.82 * Constants.basicStudentSpeedOfClimbingThroughWindows
Constants.basicStudentSpeedOfClimbingThroughWindows* 1000 // 1222
)
speedOfOpenChest = (int)(1.0 * Constants.basicSpeedOfOpenChest)

@@ -197,9 +197,7 @@ class Robot:
alertnessRadius = (int)(0.0 * Constants.basicStudentAlertnessRadius)
viewRange = (int)(0.0 * Constants.basicStudentViewRange)
speedOfOpeningOrLocking = (int)(0.0 * Constants.basicSpeedOfOpeningOrLocking)
speedOfClimbingThroughWindows = (int)(
0.0008 * Constants.basicStudentSpeedOfClimbingThroughWindows
)
speedOfClimbingThroughWindows = 1
speedOfOpenChest = (int)(0.8 * Constants.basicSpeedOfOpenChest)


@@ -209,7 +207,7 @@ class TechOtaku:
maxAddiction = (int)(1.0 * Constants.basicMaxGamingAddiction)
LearnSpeed = (int)(0.9 * Constants.basicLearnSpeed)
EncourageSpeed = (int)(1.0 * Constants.basicEncourageSpeed)
concealment = 1.0 * Constants.basicConcealment
concealment = 1.1 * Constants.basicConcealment
alertnessRadius = (int)(1.0 * Constants.basicStudentAlertnessRadius)
viewRange = (int)(0.9 * Constants.basicStudentViewRange)
speedOfOpeningOrLocking = (int)(1.0 * Constants.basicSpeedOfOpeningOrLocking)
@@ -296,7 +294,7 @@ class UseKnife:


class UseRobot:
skillCD = (int)(0.0667 * Constants.commonSkillCD)
skillCD = (int)(2 * Constants.commonSkillCD // 30)
durationTime = (int)(0.0 * Constants.commonSkillTime)


@@ -306,7 +304,7 @@ class WriteAnswers:


class SummonGolem:
skillCD = (int)(1.25 * Constants.commonSkillCD)
skillCD = (int)(4 * Constants.commonSkillCD//3)
durationTime = (int)(6.0 * Constants.commonSkillTime)


@@ -366,5 +364,5 @@ class Strike:
CastTime = Constants.basicCastTime * 16 // 25
Backswing = Constants.basicBackswing
RecoveryFromHit = Constants.basicRecoveryFromHit
cd = Constants.basicBackswing * 3 // 4
cd = Constants.basicBackswing
maxBulletNum = 1

+ 1
- 1
logic/GameClass/GameObj/Bullet/Bullet.cs View File

@@ -52,7 +52,7 @@ namespace GameClass.GameObj
public Bullet(Character player, int radius, XY Position) :
base(Position, radius, GameObjType.Bullet)
{
this.canMove = true;
this.ReSetCanMove(true);
this.MoveSpeed = this.Speed;
this.hasSpear = player.TryUseSpear();
this.Parent = player;


+ 1
- 1
logic/GameClass/GameObj/Character/Character.Skill.cs View File

@@ -50,7 +50,7 @@ namespace GameClass.GameObj
protected Character(XY initPos, int initRadius, CharacterType characterType) :
base(initPos, initRadius, GameObjType.Character)
{
this.canMove = true;
this.ReSetCanMove(true);
this.score = 0;
this.buffManager = new BuffManager();
this.occupation = OccupationFactory.FindIOccupation(characterType);


+ 4
- 12
logic/GameClass/GameObj/Character/Character.cs View File

@@ -362,7 +362,7 @@ namespace GameClass.GameObj
lock (actionLock)
{
if (playerState == PlayerStateType.Moving)
return (IsMoving == 1) ? PlayerStateType.Moving : PlayerStateType.Null;
return (IsMoving) ? PlayerStateType.Moving : PlayerStateType.Null;
return playerState;
}
}
@@ -594,17 +594,9 @@ namespace GameClass.GameObj
{
lock (actionLock)
{
MoveReaderWriterLock.EnterWriteLock();
try
{
canMove = false;
isRemoved = true;
}
finally
{
MoveReaderWriterLock.ExitWriteLock();
}
playerState = playerStateType;
TryToRemove();
ReSetCanMove(false);
SetPlayerState(playerStateType);
position = GameData.PosWhoDie;
}
}


+ 4
- 21
logic/GameClass/GameObj/GameObj.cs View File

@@ -29,40 +29,23 @@ namespace GameClass.GameObj
protected XY facingDirection = new(1, 0);
public abstract XY FacingDirection { get; }

protected bool canMove;
public abstract bool CanMove { get; }

public abstract bool IsRigid { get; }

public abstract ShapeType Shape { get; }

protected bool isRemoved = false;
public virtual bool IsRemoved
protected int isRemoved = 0;
public bool IsRemoved
{
get
{
gameObjReaderWriterLock.EnterReadLock();
try
{
return isRemoved;
}
finally
{
gameObjReaderWriterLock.ExitReadLock();
}
return (Interlocked.CompareExchange(ref isRemoved, 0, 0) == 1);
}
}
public virtual void TryToRemove()
{
gameObjReaderWriterLock.EnterWriteLock();
try
{
isRemoved = true;
}
finally
{
gameObjReaderWriterLock.ExitWriteLock();
}
Interlocked.Exchange(ref isRemoved, 1);
}

public int Radius { get; }


+ 8
- 58
logic/GameClass/GameObj/Moveable.cs View File

@@ -48,10 +48,10 @@ namespace GameClass.GameObj
}

private int isMoving = 0;
public int IsMoving
public bool IsMoving
{
get => Interlocked.CompareExchange(ref isMoving, 0, 0);
set => Interlocked.Exchange(ref isMoving, value);
get => (Interlocked.CompareExchange(ref isMoving, 0, 0) == 1);
set => Interlocked.Exchange(ref isMoving, value ? 1 : 0);
}

// 移动,改变坐标
@@ -62,15 +62,7 @@ namespace GameClass.GameObj
{
lock (actionLock)
{
moveReaderWriterLock.EnterReadLock();
try
{
if (!canMove || isRemoved) return -1;
}
finally
{
moveReaderWriterLock.ExitReadLock();
}
if (!CanMove || IsRemoved) return -1;
if (stateNo != stateNum) return -1;
facingDirection = moveVec;
this.position += moveVec;
@@ -87,49 +79,15 @@ namespace GameClass.GameObj
}
}

private int canMove;
public override bool CanMove
{
get
{
moveReaderWriterLock.EnterReadLock();
try
{
return canMove;
}
finally
{
moveReaderWriterLock.ExitReadLock();
}
}
get => (Interlocked.CompareExchange(ref canMove, 0, 0) == 1);
}

public void ReSetCanMove(bool value)
{
moveReaderWriterLock.EnterWriteLock();
try
{
canMove = value;
}
finally
{
moveReaderWriterLock.ExitWriteLock();
}
}

public override bool IsRemoved
{
get
{
moveReaderWriterLock.EnterReadLock();
try
{
return isRemoved;
}
finally
{
moveReaderWriterLock.ExitReadLock();
}
}
Interlocked.Exchange(ref canMove, (value ? 1 : 0));
}

public bool IsAvailableForMove // 是否能接收移动指令
@@ -138,15 +96,7 @@ namespace GameClass.GameObj
{
lock (actionLock)
{
moveReaderWriterLock.EnterReadLock();
try
{
return isMoving == 0 && canMove && !isRemoved;
}
finally
{
moveReaderWriterLock.ExitReadLock();
}
return !IsMoving && CanMove && !IsRemoved;
}
}
}


+ 1
- 1
logic/GameClass/GameObj/Prop/Gadget.cs View File

@@ -24,7 +24,7 @@ namespace GameClass.GameObj
public Gadget(XY initPos, int radius = GameData.propRadius) :
base(initPos, radius, GameObjType.Gadget)
{
this.canMove = false;
this.ReSetCanMove(false);
this.MoveSpeed = GameData.propMoveSpeed;
}
}


+ 1
- 1
logic/GameClass/GameObj/Prop/Item.cs View File

@@ -17,7 +17,7 @@ namespace GameClass.GameObj
public Item(XY initPos, int radius = GameData.propRadius) :
base(initPos, radius, GameObjType.Item)
{
this.canMove = false;
this.ReSetCanMove(false);
this.MoveSpeed = 0;
}
}


+ 4
- 4
logic/GameEngine/MoveEngine.cs View File

@@ -102,7 +102,7 @@ namespace GameEngine
lock (obj.ActionLock)
{
if (!obj.IsAvailableForMove) { EndMove(obj); return; }
obj.IsMoving = 1;
obj.IsMoving = true;
}

new Thread
@@ -139,7 +139,7 @@ namespace GameEngine

if (isEnded)
{
obj.IsMoving = 0;
obj.IsMoving = false;
EndMove(obj);
return;
}
@@ -184,7 +184,7 @@ namespace GameEngine
}
if (isEnded)
{
obj.IsMoving = 0;
obj.IsMoving = false;
EndMove(obj);
return;
}
@@ -224,7 +224,7 @@ namespace GameEngine
}
} while (flag);
}
obj.IsMoving = 0; // 结束移动
obj.IsMoving = false; // 结束移动
EndMove(obj);
}
}


+ 1
- 1
logic/Preparation/Interface/IMoveable.cs View File

@@ -8,7 +8,7 @@ namespace Preparation.Interface
{
object ActionLock { get; }
public int MoveSpeed { get; }
public int IsMoving { get; set; }
public bool IsMoving { get; set; }
public bool IsRemoved { get; }
public bool IsAvailableForMove { get; }
public long StateNum { get; }


Loading…
Cancel
Save