Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

refactor: use dict instead of lists#126

Merged
Timothy-Liuxf merged 6 commits intoeesast:devfrom
TCL606:TCL
Feb 7, 2022
Merged

refactor: use dict instead of lists#126
Timothy-Liuxf merged 6 commits intoeesast:devfrom
TCL606:TCL

Conversation

@TCL606
Copy link
Copy Markdown
Member

@TCL606 TCL606 commented Feb 7, 2022

Discriptions of this pull request:

No additional discription.

Comment thread logic/GameClass/GameObj/Map/Map.cs Outdated
public Dictionary<uint, BirthPoint> BirthPointList => birthPointList;

private Dictionary<String, IList<IGameObj>> gameObjDict;
public Dictionary<String, IList<IGameObj>> GameObjDict => gameObjDict;
Copy link
Copy Markdown
Member

@Timothy-Liuxf Timothy-Liuxf Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉,这里用一个枚举去作为索引会不会比字符串好一些,例如字符串可能会写错一个字母之类的,编译的时候检查不出来;另外用字符串作为索引也会稍慢

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以,我现在去改成一个枚举

public ReaderWriterLockSlim GemListLock => gemListLock;

private readonly Dictionary<uint, BirthPoint> birthPointList; // 出生点列表
public Dictionary<uint, BirthPoint> BirthPointList => birthPointList;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是用数组大概就够了

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

忘了,毕竟是copy的)

@Timothy-Liuxf Timothy-Liuxf added architecture Code architecture logic Game logic labels Feb 7, 2022
Timothy-Liuxf
Timothy-Liuxf previously approved these changes Feb 7, 2022
Timothy-Liuxf
Timothy-Liuxf previously approved these changes Feb 7, 2022
Comment thread logic/GameClass/GameObj/Map/Map.cs Outdated
gameObjDict.Add(GameObjIdx.Gem, new List<IGameObj>());
gameObjLockDict.Add(GameObjIdx.Gem, new ReaderWriterLockSlim());
gameObjDict.Add(GameObjIdx.Map, new List<IGameObj>());
gameObjLockDict.Add(GameObjIdx.Map, new ReaderWriterLockSlim());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实这里有一种更方便的方式:

foreach (GameObjIdx idx in Enum.GetValues(typeof(GameObjIdx)))
{
    if (idx != GameObjIdx.Null)
    {
        gameObjDict.Add(idx, new List<IGameObj>());
        gameObjLockDict.Add(idx, new ReaderWriterLockSlim());
    }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Timothy-Liuxf Timothy-Liuxf merged commit e239070 into eesast:dev Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

architecture Code architecture logic Game logic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants