Browse Source

fix: 🐛 add some lock

tags/v0.1.0
shangfengh 2 years ago
parent
commit
ff4ca4a959
10 changed files with 32 additions and 29 deletions
  1. +1
    -1
      docs/游戏机制与平衡性调整更新草案.md
  2. +1
    -1
      docs/版本更新说明.md
  3. +2
    -0
      logic/GameClass/GameObj/GameObj.cs
  4. +3
    -4
      logic/GameClass/GameObj/Map/Chest.cs
  5. +0
    -1
      logic/GameClass/GameObj/Map/Map.cs
  6. +9
    -11
      logic/GameClass/GameObj/Moveable.cs
  7. +13
    -3
      logic/GameClass/GameObj/ObjOfCharacter.cs
  8. +2
    -7
      logic/GameClass/GameObj/PickedProp.cs
  9. +0
    -1
      logic/GameClass/GameObj/Tile.cs
  10. +1
    -0
      logic/Server/CopyInfo.cs

+ 1
- 1
docs/游戏机制与平衡性调整更新草案.md View File

@@ -6,7 +6,7 @@ v1.3
- 有任何问题都可以在选手群中提出建议和讨论

## 游戏接口
删除structures.h中Player的属性place
- 删除structures.h中Player的属性place

## 游戏规则



+ 1
- 1
docs/版本更新说明.md View File

@@ -3,7 +3,7 @@
# 说明
- 只说明对于选手较为重要的修改

# 5.6更新的更改
# 5月6日更新
- docs:添加了 游戏机制与平衡性调整更新草案.pdf
- docs:添加了 版本更新说明.pdf
- docs&hotfix: 修正了GameRules.pdf中学生翻窗速度的错误

+ 2
- 0
logic/GameClass/GameObj/GameObj.cs View File

@@ -9,6 +9,8 @@ namespace GameClass.GameObj
/// </summary>
public abstract class GameObj : IGameObj
{
private ReaderWriterLockSlim gameObjReaderWriterLock = new();
public ReaderWriterLockSlim GameObjReaderWriterLock => gameObjReaderWriterLock;
protected readonly object gameObjLock = new();
public object GameLock => gameObjLock;



+ 3
- 4
logic/GameClass/GameObj/Map/Chest.cs View File

@@ -1,5 +1,4 @@
using Preparation.Utility;
using System.Collections.Generic;

namespace GameClass.GameObj
{
@@ -16,7 +15,7 @@ namespace GameClass.GameObj
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;

private Prop[] propInChest = new Prop[GameData.maxNumOfPropInChest] { new NullProp(), new NullProp() };
private readonly Prop[] propInChest = new Prop[GameData.maxNumOfPropInChest] { new NullProp(), new NullProp() };
public Prop[] PropInChest => propInChest;

private int openStartTime = 0;
@@ -25,7 +24,7 @@ namespace GameClass.GameObj
public Character? WhoOpen => whoOpen;
public void Open(int startTime, Character character)
{
lock (gameObjLock)
lock (GameObjReaderWriterLock)
{
openStartTime = startTime;
whoOpen = character;
@@ -33,7 +32,7 @@ namespace GameClass.GameObj
}
public void StopOpen()
{
lock (gameObjLock)
lock (GameObjReaderWriterLock)
{
openStartTime = 0;
whoOpen = null;


+ 0
- 1
logic/GameClass/GameObj/Map/Map.cs View File

@@ -8,7 +8,6 @@ namespace GameClass.GameObj
{
public partial class Map : IMap
{

private readonly Dictionary<uint, XY> birthPointList; // 出生点列表
public Dictionary<uint, XY> BirthPointList => birthPointList;



+ 9
- 11
logic/GameClass/GameObj/Moveable.cs View File

@@ -1,17 +1,15 @@
using Preparation.Interface;
using Preparation.Utility;
using Protobuf;
using System.Threading;

namespace GameClass.GameObj
{
/// <summary>
/// 一切游戏元素的总基类,与THUAI4不同,继承IMoveable接口(出于一切物体其实都是可运动的指导思想)——LHR
/// </summary>
public abstract class Moveable : GameObj, IMoveable
{
protected readonly object moveObjLock = new();
public object MoveLock => moveObjLock;
private ReaderWriterLockSlim moveReaderWriterLock = new();
public ReaderWriterLockSlim MoveReaderWriterLock => moveReaderWriterLock;

public override XY Position
{
@@ -60,7 +58,7 @@ namespace GameClass.GameObj
return moveVec * moveVec;
}

public void ReSetPos(XY position)
public void ReSetPos(XY position)
{
lock (moveObjLock)
{
@@ -72,12 +70,12 @@ namespace GameClass.GameObj
{
get
{
lock (gameObjLock)
lock (moveReaderWriterLock)
return canMove;
}
set
{
lock (gameObjLock)
lock (moveReaderWriterLock)
{
canMove = value;
}
@@ -89,12 +87,12 @@ namespace GameClass.GameObj
{
get
{
lock (gameObjLock)
lock (moveReaderWriterLock)
return isResetting;
}
set
{
lock (gameObjLock)
lock (moveReaderWriterLock)
{
isResetting = value;
}
@@ -111,12 +109,12 @@ namespace GameClass.GameObj
{
get
{
lock (gameObjLock)
lock (moveReaderWriterLock)
return moveSpeed;
}
set
{
lock (gameObjLock)
lock (moveReaderWriterLock)
{
moveSpeed = value;
}


+ 13
- 3
logic/GameClass/GameObj/ObjOfCharacter.cs View File

@@ -1,5 +1,7 @@
using Preparation.Interface;
using Google.Protobuf.WellKnownTypes;
using Preparation.Interface;
using Preparation.Utility;
using System.Threading;

namespace GameClass.GameObj
{
@@ -8,13 +10,21 @@ namespace GameClass.GameObj
/// </summary>
public abstract class ObjOfCharacter : Moveable, IObjOfCharacter
{
private ReaderWriterLockSlim objOfCharacterReaderWriterLock = new();
public ReaderWriterLockSlim ObjOfCharacterReaderWriterLock => objOfCharacterReaderWriterLock;
private ICharacter? parent = null; // 主人
public ICharacter? Parent
{
get => parent;
get
{
lock (objOfCharacterReaderWriterLock)
{
return parent;
}
}
set
{
lock (gameObjLock)
lock (objOfCharacterReaderWriterLock)
{
parent = value;
}


+ 2
- 7
logic/GameClass/GameObj/PickedProp.cs View File

@@ -1,10 +1,5 @@
using Preparation.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameClass.GameObj
{
// 为方便界面组做道具拾起特效,现引入“被捡起的道具”,在每帧发送给界面组
@@ -13,11 +8,11 @@ namespace GameClass.GameObj
public override ShapeType Shape => ShapeType.Circle;
public override bool IsRigid => false;
public long MappingID { get; }
public Prop PropHasPicked;
public readonly Prop propHasPicked;
public PickedProp(Prop prop) :
base(prop.Position, prop.Radius, GameObjType.PickedProp)
{
this.PropHasPicked = prop;
this.propHasPicked = prop;
this.MappingID = prop.ID;
}
}


+ 0
- 1
logic/GameClass/GameObj/Tile.cs View File

@@ -1,6 +1,5 @@
using Preparation.Interface;
using Preparation.Utility;
using System.Threading;

namespace GameClass.GameObj
{


+ 1
- 0
logic/Server/CopyInfo.cs View File

@@ -268,6 +268,7 @@ namespace Server
Y = chest.Position.y
}
};
Debugger.Output(chest, chest.OpenStartTime.ToString());
int progress = (chest.WhoOpen != null) ? ((time - chest.OpenStartTime) * chest.WhoOpen.SpeedOfOpenChest) : 0;
msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
return msg;


Loading…
Cancel
Save