-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attributes to use zig zag encoding (#897)
* feat: attributes to use zig zag encoding * setting up tests and bitcountfinder * fixing weaver tests * fixxing tests * implementing read/write for zigzagencode * updating tests * updating template
- Loading branch information
1 parent
82d7e51
commit ccef5fb
Showing
43 changed files
with
1,171 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Mirage.Serialization; | ||
using Mirage.Serialization; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Mirage.Serialization; | ||
using Mono.Cecil; | ||
|
||
namespace Mirage.Weaver.SyncVars | ||
{ | ||
public static class ZigZagFinder | ||
{ | ||
public static bool HasZigZag(FieldDefinition syncVar, bool hasBitCount) | ||
{ | ||
bool hasAttribute = syncVar.HasCustomAttribute<ZigZagEncodeAttribute>(); | ||
if (!hasAttribute) | ||
return false; | ||
|
||
if (!hasBitCount) | ||
throw new ZigZagException($"[ZigZagEncode] can only be used with [BitCount]", syncVar); | ||
|
||
ThrowIfUnsignedType(syncVar.FieldType, syncVar); | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Any Int or enum based type is valid | ||
/// </summary> | ||
/// <param name="type"></param> | ||
/// <param name="syncVar"></param> | ||
static void ThrowIfUnsignedType(TypeReference type, FieldDefinition syncVar) | ||
{ | ||
// throw if unsigned | ||
if (type.Is<byte>() | ||
|| type.Is<ushort>() | ||
|| type.Is<uint>() | ||
|| type.Is<ulong>()) | ||
throw new ZigZagException($"[ZigZagEncode] can only be used on a signed type", syncVar); | ||
|
||
if (type.Resolve().IsEnum) | ||
{ | ||
// check underlying field is signed | ||
TypeReference enumType = type.Resolve().GetEnumUnderlyingType(); | ||
ThrowIfUnsignedType(enumType, syncVar); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Mirage/Weaver/Processors/SyncVars/ZigZagFinder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.