Skip to content

Commit

Permalink
fixes webgl build by removing the 'dynamic' keyword. fixes TriggerAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Sep 23, 2020
1 parent ea658ea commit 836fc69
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 31 deletions.
35 changes: 19 additions & 16 deletions Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public class DataChange
public byte Op;
public string Field;
public object DynamicIndex;
public dynamic Value;
public dynamic PreviousValue;
public object Value;
public object PreviousValue;
}

public delegate void OnChangeEventHandler(List<DataChange> changes);
Expand All @@ -93,7 +93,7 @@ public interface ISchemaCollection
void Clear(ReferenceTracker refs);

System.Type GetChildType();
dynamic GetTypeDefaultValue();
object GetTypeDefaultValue();
bool ContainsKey(object key);

bool HasSchemaChild { get; }
Expand All @@ -102,8 +102,8 @@ public interface ISchemaCollection
int Count { get; }
object this[object key] { get; set; }

void SetIndex(int index, dynamic dynamicIndex);
dynamic GetIndex(int index);
void SetIndex(int index, object dynamicIndex);
object GetIndex(int index);
void SetByIndex(int index, object dynamicIndex, object value);

ISchemaCollection Clone();
Expand All @@ -112,7 +112,6 @@ public interface ISchemaCollection
public interface IRef
{
int __refId { get; set; }
IRef __parent { get; set; }

object GetByIndex(int index);
void DeleteByIndex(int index);
Expand All @@ -129,7 +128,6 @@ public class Schema : IRef
public event OnRemoveEventHandler OnRemove;

public int __refId { get; set; }
public IRef __parent { get; set; }

private ReferenceTracker refs;

Expand Down Expand Up @@ -159,7 +157,7 @@ public Schema()
}

/* allow to retrieve property values by its string name */
public dynamic this[string propertyName]
public object this[string propertyName]
{
get
{
Expand Down Expand Up @@ -427,7 +425,6 @@ public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = nul
if (value is IRef)
{
((IRef)value).__refId = refId;
((IRef)value).__parent = _ref;
}

if (_ref is Schema)
Expand All @@ -453,16 +450,22 @@ public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = nul
}
}

TriggerChanges(allChanges);
TriggerChanges(ref allChanges);

refs.GarbageCollection();
}

public void TriggerAll()
{
//
// first state not received from the server yet.
// nothing to trigger.
//
if (refs == null) { return; }

var allChanges = new OrderedDictionary();
TriggerAllFillChanges(this, ref allChanges);
TriggerChanges(allChanges);
TriggerChanges(ref allChanges);
}

protected void TriggerAllFillChanges(IRef currentRef, ref OrderedDictionary allChanges)
Expand All @@ -487,7 +490,7 @@ protected void TriggerAllFillChanges(IRef currentRef, ref OrderedDictionary allC

if (value is IRef)
{
TriggerAllFillChanges(value, ref allChanges);
TriggerAllFillChanges((IRef)value, ref allChanges);
}
}
} else
Expand All @@ -513,13 +516,13 @@ protected void TriggerAllFillChanges(IRef currentRef, ref OrderedDictionary allC
}
}

protected void TriggerChanges(OrderedDictionary allChanges)
protected void TriggerChanges(ref OrderedDictionary allChanges)
{
foreach (object key in allChanges.Keys)
foreach (object refId in allChanges.Keys)
{
List<DataChange> changes = (List<DataChange>)allChanges[key];
List<DataChange> changes = (List<DataChange>)allChanges[refId];

IRef _ref = refs.Get((int)key);
IRef _ref = refs.Get((int)refId);
bool isSchema = _ref is Schema;

foreach (DataChange change in changes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ArraySchema<T> : ISchemaCollection, IRef
protected Dictionary<int, int> Indexes = new Dictionary<int, int>();

public int __refId { get; set; }
public IRef __parent { get; set; }

public ArraySchema()
{
Expand All @@ -27,17 +26,17 @@ public ArraySchema(Dictionary<int, T> items = null)
Items = items ?? new Dictionary<int, T>();
}

public void SetIndex(int index, dynamic dynamicIndex)
public void SetIndex(int index, object dynamicIndex)
{
Indexes[index] = dynamicIndex;
Indexes[index] = (int)dynamicIndex;
}

public void SetByIndex(int index, object dynamicIndex, object value)
{
Items[(int)dynamicIndex] = (T)value;
}

public dynamic GetIndex(int index)
public object GetIndex(int index)
{
int dynamicIndex;

Expand Down Expand Up @@ -99,7 +98,7 @@ public System.Type GetChildType()
return typeof(T);
}

public dynamic GetTypeDefaultValue()
public object GetTypeDefaultValue()
{
return default(T);
}
Expand Down
13 changes: 6 additions & 7 deletions Assets/Plugins/Colyseus/Serializer/Schema/Types/MapSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class MapSchema<T> : ISchemaCollection, IRef
protected Dictionary<int, string> Indexes = new Dictionary<int, string>();

public int __refId { get; set; }
public IRef __parent { get; set; }

public MapSchema()
{
Expand All @@ -28,9 +27,9 @@ public MapSchema(OrderedDictionary items = null)
Items = items ?? new OrderedDictionary();
}

public void SetIndex(int index, dynamic dynamicIndex)
public void SetIndex(int index, object dynamicIndex)
{
Indexes[index] = dynamicIndex;
Indexes[index] = (string) dynamicIndex;
}

public void SetByIndex(int index, object dynamicIndex, object value)
Expand All @@ -39,7 +38,7 @@ public void SetByIndex(int index, object dynamicIndex, object value)
Items[dynamicIndex] = (T)value;
}

public dynamic GetIndex(int index)
public object GetIndex(int index)
{
string dynamicIndex;

Expand All @@ -50,15 +49,15 @@ public dynamic GetIndex(int index)

public object GetByIndex(int index)
{
string dynamicIndex = GetIndex(index);
string dynamicIndex = (string) GetIndex(index);
return (dynamicIndex != null && Items.Contains(dynamicIndex))
? Items[dynamicIndex]
: GetTypeDefaultValue();
}

public void DeleteByIndex(int index)
{
string dynamicIndex = GetIndex(index);
string dynamicIndex = (string) GetIndex(index);
if (Items.Contains(dynamicIndex))
{
Items.Remove(dynamicIndex);
Expand All @@ -82,7 +81,7 @@ public System.Type GetChildType()
return typeof(T);
}

public dynamic GetTypeDefaultValue()
public object GetTypeDefaultValue()
{
return default(T);
}
Expand Down
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2020.1.4f1
m_EditorVersionWithRevision: 2020.1.4f1 (fa717bb873ec)
m_EditorVersion: 2020.1.6f1
m_EditorVersionWithRevision: 2020.1.6f1 (fc477ca6df10)
Binary file modified ProjectSettings/UnityConnectSettings.asset
Binary file not shown.
2 changes: 1 addition & 1 deletion Server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@colyseus/social": "^0.10.0",
"colyseus": "^0.14.0-alpha.11",
"colyseus": "^0.14.0-alpha.16",
"cors": "^2.8.5",
"express": "^4.13.3",
"express-jwt": "^5.3.1",
Expand Down

0 comments on commit 836fc69

Please sign in to comment.