Skip to content

Commit

Permalink
4.1.1
Browse files Browse the repository at this point in the history
- Added check for server connection start failure (#14).
- Fixed collection modified error on server (#13).
- Added package.json file (#11).
  • Loading branch information
FirstGearGames committed Aug 26, 2024
1 parent 8e8da4e commit 21e8582
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 196 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!*SteamManager.unitypackage
!/Assets/FishNet/Plugins/FishySteamworks/
!/Assets/FishNet/Plugins/FishySteamworks/package.json
*/
*.meta
/Assets/DefaultPrefabObject.asset
2 changes: 1 addition & 1 deletion FishNet/Plugins/FishySteamworks.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions FishNet/Plugins/FishySteamworks/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
4.1.1
- Added check for server connection start failure (#14).
- Fixed collection modified error on server (#13).
- Added package.json file (#11).

4.1.0
- Fish-Networking 4.1.0 support.

Expand Down
2 changes: 1 addition & 1 deletion FishNet/Plugins/FishySteamworks/CHANGELOG.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FishNet/Plugins/FishySteamworks/Core.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 31 additions & 130 deletions FishNet/Plugins/FishySteamworks/Core/BidirectionalDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,49 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;

namespace FishySteamworks
{
public class BidirectionalDictionary<T1, T2> : IEnumerable<KeyValuePair<T1, T2>>
public class BidirectionalDictionary<T1, T2> : IEnumerable
{
private readonly Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>();
private readonly Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>();
private int lockCount = 0;
private readonly List<PendingOperation> pendingOperations = new List<PendingOperation>();
private Dictionary<T1, T2> t1ToT2Dict = new Dictionary<T1, T2>();
private Dictionary<T2, T1> t2ToT1Dict = new Dictionary<T2, T1>();

public Enumerator GetEnumerator()
{
return new Enumerator(this);
}
public IEnumerable<T1> FirstTypes => t1ToT2Dict.Keys;
public IEnumerable<T2> SecondTypes => t2ToT1Dict.Keys;

IEnumerator<KeyValuePair<T1, T2>> IEnumerable<KeyValuePair<T1, T2>>.GetEnumerator()
{
return new Enumerator(this);
}

IEnumerator IEnumerable.GetEnumerator()
{
return new Enumerator(this);
}
public IEnumerator GetEnumerator() => t1ToT2Dict.GetEnumerator();

public int Count => t1ToT2Dict.Count;

public Dictionary<T1, T2> First => t1ToT2Dict;
public Dictionary<T2, T1> Second => t2ToT1Dict;

public void Add(T1 key, T2 value)
{
if (lockCount > 0)
if (t1ToT2Dict.ContainsKey(key))
{
pendingOperations.Add(new PendingOperation(isAdd: true, key, value));
return;
Remove(key);
}

Remove(key);

t1ToT2Dict[key] = value;
t2ToT1Dict[value] = key;
}

public void Add(T2 key, T1 value)
{
Add(value, key);
}
if (t2ToT1Dict.ContainsKey(key))
{
Remove(key);
}

public void Clear()
{
t1ToT2Dict.Clear();
t2ToT1Dict.Clear();
t2ToT1Dict[key] = value;
t1ToT2Dict[value] = key;
}

public T2 Get(T1 key) => t1ToT2Dict[key];

public T1 Get(T2 key) => t2ToT1Dict[key];

public bool TryGetValue(T1 key, out T2 value) => t1ToT2Dict.TryGetValue(key, out value);

public bool TryGetValue(T2 key, out T1 value) => t2ToT1Dict.TryGetValue(key, out value);
Expand All @@ -63,36 +54,21 @@ public void Clear()

public void Remove(T1 key)
{
if (!t1ToT2Dict.TryGetValue(key, out T2 val))
{
return;
}

if (lockCount > 0)
if (Contains(key))
{
pendingOperations.Add(new PendingOperation(isAdd: false, key, val));
return;
T2 val = t1ToT2Dict[key];
t1ToT2Dict.Remove(key);
t2ToT1Dict.Remove(val);
}

t1ToT2Dict.Remove(key);
t2ToT1Dict.Remove(val);
}

public void Remove(T2 key)
{
if (!t2ToT1Dict.TryGetValue(key, out T1 val))
{
return;
}

if (lockCount > 0)
if (Contains(key))
{
pendingOperations.Add(new PendingOperation(isAdd: false, val, key));
return;
T1 val = t2ToT1Dict[key];
t1ToT2Dict.Remove(val);
t2ToT1Dict.Remove(key);
}

t1ToT2Dict.Remove(val);
t2ToT1Dict.Remove(key);
}

public T1 this[T2 key]
Expand All @@ -112,80 +88,5 @@ public T2 this[T1 key]
Add(key, value);
}
}

private void Lock()
{
++lockCount;
}

private void Unlock()
{
if (lockCount == 0)
{
throw new InvalidOperationException("Unlock called without a corresponding lock");
}
if (--lockCount == 0)
{
foreach (var operation in pendingOperations)
{
if (operation.AddOperation)
{
Add(operation.Key, operation.Value);
}
else
{
Remove(operation.Key);
}
}
pendingOperations.Clear();
};
}

public struct Enumerator : IEnumerator<KeyValuePair<T1, T2>>, IDisposable
{
private readonly BidirectionalDictionary<T1, T2> _dictionary;
private Dictionary<T1, T2>.Enumerator _enumerator;

public Enumerator(BidirectionalDictionary<T1, T2> dictionary)
{
_dictionary = dictionary;
_enumerator = dictionary.t1ToT2Dict.GetEnumerator();
_dictionary.Lock();
}

public void Reset()
{
throw new InvalidOperationException("Enumerator reset during enumeration");
}

public KeyValuePair<T1, T2> Current => _enumerator.Current;

object IEnumerator.Current => _enumerator.Current;

public bool MoveNext()
{
return _enumerator.MoveNext();
}

public void Dispose()
{
_enumerator.Dispose();
_dictionary.Unlock();
}
}

private readonly struct PendingOperation
{
public readonly bool AddOperation;
public readonly T1 Key;
public readonly T2 Value;

public PendingOperation(bool isAdd, T1 key, T2 value)
{
AddOperation = isAdd;
Key = key;
Value = value;
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FishNet/Plugins/FishySteamworks/Core/ClientSocket.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FishNet/Plugins/FishySteamworks/Core/CommonSocket.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FishNet/Plugins/FishySteamworks/Core/LocalPacket.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 21e8582

Please sign in to comment.