Commit Graph

2606 Commits

Author SHA1 Message Date
Paul Pacheco
fb49d19793
breaking: Use SyncLists directly (delete overrides) (#2307)
* feat: Use SyncLists directly

Previously,  you had to write an intermediary class to use synclists, syncsets and syncdictionaries.
The weaver would populate that intermediary class with a serialization and deserialization method

This PR gets rid of 90% of the weaver code for synclists.
There is no need to generate these methods anymore.
Instead the lists use `writer.Write<T>` and `read.read<T>` to serialize their Data.

Since there is no code generate in synclists, you can now use the synclists directly instead
of subclassing them.

BEFORE:

```cs
public class MyComponent : NetworkBehaviour {
    // nonsense class to make the weaver happy
    class SyncListData : Synclist<Data> {}

    SyncListData mySyncList;
}
```

AFTER:

```cs
public class MyComponent : NetworkBehaviour {
    Synclist<Data> mySyncList;
}
```

* linting

* feat: Use SyncLists directly (no overrides)

Previously,  you had to write an intermediary class to use synclists and syncdictionaries.

The weaver would populate that intermediary class with a serialization and deserialization method

This PR gets rid of 90% of the weaver code for synclists.
There is no need to generate these methods anymore.
Instead the lists use `writer.Write<T>` and `read.read<T>` to serialize their Data.

Since there is no code generate in synclists, you can now use the synclists directly instead
of subclassing them.

Same as #2305 ,but it removes the deprecated Serialize and Deserialize methods from syncobjects,
This way you get a nice compiler error for the code that no longer works, instead of a warning you might accidentally ignore.

BEFORE:

```cs
public class MyComponent : NetworkBehaviour {
    // nonsense class to make the weaver happy
    class SyncListData : Synclist<Data> {}

    SyncListData mySyncList;
}
```

AFTER:

```cs
public class MyComponent : NetworkBehaviour {
    Synclist<Data> mySyncList;
}
```

BREAKING CHANGE: Serialize and Deserialize methods in synclists don't do anything anymore

* Remove old comment

* Fix compilatio error
2020-10-02 09:12:25 +02:00
Paul Pacheco
85252c3d84
feat: new generic Read and Write methods for all types (#2301)
Currently in mirror,  there is no way for Mirror itself to invoke
readers and writers for types it does not know about.

This causes us to have to generate code for lists, dictionaries and messages.

This PR makes it so that if there is a reader and writer anywhere in the
code for type X, then the writer can be invoked like this:

```cs
X x = ...;
writer.Write<X>(x);
```

and the reader can be invoked like this:
```cs
X x = reader.Read<X>();
```
2020-10-01 17:13:30 -05:00
vis2k
efb9b21aa4 Revert xml 2020-09-30 12:11:08 +02:00
vis2k
ae95b0625d revert 2020-09-30 11:09:12 +02:00
vis2k
7fa8345b85 wtf 2020-09-30 11:02:27 +02:00
Paul Pacheco
16864f9ff0 It is fine to serialize empty struct 2020-09-29 21:26:53 -05:00
Paul Pacheco
0267dbe1f2 feat: support Jagged arrays
simplify the code for checking for multidimentional arrays
and lift the restriction on jagged arrays
2020-09-29 21:21:16 -05:00
Paul Pacheco
5e2d87685b Generated class does not need constructor 2020-09-29 15:22:21 -05:00
Paul Pacheco
c720055bce remove empty blocks 2020-09-29 12:26:24 -05:00
Paul Pacheco
7ca08924b5 Remove unused meta 2020-09-29 12:16:21 -05:00
Paul Pacheco
0132697513 Simplify obj initialization 2020-09-29 12:15:26 -05:00
Paul Pacheco
88ece20e68 Simplify IsDerivedFrom 2020-09-29 12:01:49 -05:00
Paul Pacheco
9889ed4f9c Remove unnecesary lists from WeaverLists 2020-09-29 11:22:46 -05:00
Paul Pacheco
8dbf46720e
fix: generic arguments resolution (#2300)
* fix: generic arguments lookup

The weaver was not able to figure out the synclist type in code like this:

```cs
    public class SomeList<G, T> : SyncList<T> { }
    public class SomeListInt : SomeList<string, int> { }
```

This code fixes that problem, and greatly reduces the complexity
of argument lookup.

* linting
2020-09-29 09:39:17 -05:00
vis2k
720a06ea70 MessagePacker.Pack<T> to byte[] moved out of MessagePacker and into MessagePackerTest to simplify code. It's only used in tests anyway. 2020-09-29 11:54:07 +02:00
vis2k
c947bc03e6 MessagePacker.GetId<T> reuses GetId(Type) 2020-09-29 10:55:02 +02:00
Cooper Saye
aba69ca4d0
fix: typos (#2297) 2020-09-29 09:16:30 +02:00
Paul Pacheco
bdb6ca07d2 linting 2020-09-28 23:11:50 -05:00
Paul Pacheco
3103266b44 space linting 2020-09-28 22:49:36 -05:00
Paul Pacheco
3e2c3f8ccc
Refactor reading array segment (#2296)
* Refactor reading array segment

Just deserialize the array and transform to array segment

* Fix comment

* Fix invalid IL
2020-09-28 22:43:44 -05:00
Paul Pacheco
59bc83f997 Fix more comments 2020-09-28 22:42:34 -05:00
Paul Pacheco
fe1064ce0b Remove redundant InitLocals 2020-09-28 22:37:25 -05:00
Paul Pacheco
53452cc003 Fix comments 2020-09-28 22:37:25 -05:00
Paul Pacheco
5c4d8a27cc Refactor writer for loops (#2294)
* Refactor writer for loops

* Remove unused variable
2020-09-28 22:37:25 -05:00
Paul Pacheco
fe2adc8d59 Deduplicate null check (#2295) 2020-09-28 22:37:25 -05:00
Paul Pacheco
0aea48cf06 Linting 2020-09-28 22:14:54 -05:00
Paul Pacheco
b9550cf6d3 Linting 2020-09-28 22:14:09 -05:00
Paul Pacheco
4ec84df494
Reuse checking for null (#2293) 2020-09-28 21:32:43 -05:00
Paul Pacheco
66be588512
reuse ReadLength (#2292) 2020-09-28 21:32:16 -05:00
Paul Pacheco
7c2a6595eb
refactor reader for loops (#2291)
* Fix comments

* refactor for loops

* Cleanup a bit
2020-09-28 21:29:52 -05:00
Paul Pacheco
69161144a0 Fix comments 2020-09-28 21:02:53 -05:00
Paul Pacheco
4a710b2eea Add some comments 2020-09-28 20:44:18 -05:00
Paul Pacheco
86df5954ac Add some comments 2020-09-28 20:32:38 -05:00
Paul Pacheco
3ccb7d9da4
feat: Support recursive data types (#2288)
Remove all the recursionCount nonsense.
This was added to prevent infinite recursion with types that reference themselves.

No need to check anymore, the weaver can generate readers and writers for types that reference themselves such as:

```cs
class Tree {
    Tree child1;
    Tree child2;
}
```

This works by the weaver doing it the way the compiler does: Create a function first, memoize it, then write the body. If the body needs the function, it will get itself and issue a call to itself.
2020-09-28 20:18:56 -05:00
Paul Pacheco
513a0f9945
feat: support null when serializing classes (#2290) 2020-09-28 19:55:29 -05:00
Paul Pacheco
fe641adae8
Refactor writer function generation (#2289) 2020-09-28 17:07:16 -05:00
Paul Pacheco
6fc5a4effc remove TODO comment 2020-09-28 16:43:48 -05:00
Paul Pacheco
7aa47f14be Simplify reader registration 2020-09-28 15:52:36 -05:00
Paul Pacheco
2dc280d292 Refactor reader function generation 2020-09-28 15:50:40 -05:00
Paul Pacheco
fe061ac792 Simplify generated writer name 2020-09-28 15:32:06 -05:00
Paul Pacheco
5e78e27c8f Simplify generated reader name 2020-09-28 15:09:19 -05:00
Paul Pacheco
664d5f7f99
Generate reader and writer functions for enums (#2283)
Currently,  whenever we want to serialize an enum,
we simply serialize the underlying type (byte, short, int)

This works fine,  but in order to get the reader and writer
at runtime I need a function for each type.

With this PR, we generate a reader and writer function for enums too,
the function body simply calls the underlying reader and writer.
2020-09-28 14:51:13 -05:00
James Frowen
fa059b59bf
Squashed (#2187)
* throwing Exception instead of returning null
* re-adding null check until later PR
* removing error from test
* removing extra error
* adding comment
* replacing error with throw for abstact
2020-09-28 21:29:10 +02:00
James Frowen
796aa3baf8
moving WeaverLists functions to WeaverLists (#2285)
The plan is to remove WeaverLists at some point so moving the functions
out of weaver to here for now and then move them closer to where they
are actaully used when we start to remove WeaverLists.
2020-09-28 21:21:30 +02:00
Paul Pacheco
694de7255b Cannot use generics as declared reader and writers 2020-09-28 09:17:33 -05:00
Paul Pacheco
f9ecc64468 Simplify type check 2020-09-28 09:13:25 -05:00
Paul Pacheco
b0d1d9aac0 Rename method for clarity 2020-09-28 08:52:15 -05:00
Paul Pacheco
59566588b1 Simplify type check 2020-09-28 07:39:03 -05:00
Paul Pacheco
54f96309da Simplify type check 2020-09-28 07:38:24 -05:00
vis2k
9077cc7fd7 Add comments 2020-09-27 18:51:23 +02:00
James Frowen
8b3e509c3b
Update Transport.cs 2020-09-23 16:52:11 +01:00
James Frowen
bdd81e33ba
fix: fixing new import
see https://github.com/vis2k/Mirror/pull/2259
2020-09-23 16:30:32 +01:00
Paul Pacheco
a0aecf11fb Linting 2020-09-22 13:07:03 -05:00
Paul Pacheco
25b2fa9af8 KISS 2020-09-22 13:03:33 -05:00
Paul Pacheco
c868561822 Remove passthrough method 2020-09-22 12:49:38 -05:00
Paul Pacheco
3fec9ec880 Remove static weaver state 2020-09-22 12:33:48 -05:00
Paul Pacheco
116336fbf1 Remmove passthrough method 2020-09-22 12:33:18 -05:00
Paul Pacheco
3d331b4c61 Simplify set initialization 2020-09-22 12:21:58 -05:00
Paul Pacheco
34fa002099 Remove comment that does not apply 2020-09-22 12:20:37 -05:00
Paul Pacheco
a126bfd4dd Simplify method signature 2020-09-22 11:56:54 -05:00
Paul Pacheco
fdc21582db simplify module weaving 2020-09-22 11:45:31 -05:00
Paul Pacheco
e79ffeaa8e Use string interpolation 2020-09-22 11:40:13 -05:00
Paul Pacheco
b113fd4ecf KISS 2020-09-22 11:23:24 -05:00
Paul Pacheco
6c7e578d5a Remove redundant validations 2020-09-22 11:22:36 -05:00
Paul Pacheco
3e8870f791 we only weave one assembly at a time, no need for array 2020-09-22 10:11:07 -05:00
Paul Pacheco
eaf6ac66f0 output directory is always null, no need to pass it around 2020-09-22 10:06:13 -05:00
Paul Pacheco
eadb029393 Rename methods for clarity 2020-09-22 09:53:23 -05:00
Paul Pacheco
9d7c9069d7 Simplify namespace 2020-09-22 08:17:06 -05:00
Paul Pacheco
0fbcefe8df Follow naming convention 2020-09-22 08:16:04 -05:00
Paul Pacheco
85d26ebce6 type safe type comparison 2020-09-21 23:00:30 -05:00
Paul Pacheco
541b516d60 Remove unused parameter 2020-09-21 17:09:13 -05:00
Paul Pacheco
030dc86ea9 Namespace simplifications 2020-09-21 17:08:46 -05:00
Paul Pacheco
12debf1c8c Simplify namespace 2020-09-21 17:05:20 -05:00
Paul Pacheco
f77186e1d1 Simplify namespace 2020-09-21 17:00:57 -05:00
Paul Pacheco
d123e03915 Simplify namespace 2020-09-21 17:00:10 -05:00
Paul Pacheco
8fcbba50c4 Remove unused parameter 2020-09-21 16:59:05 -05:00
Paul Pacheco
7347e5700d Remove unused parameter 2020-09-21 16:58:33 -05:00
Paul Pacheco
76ce3796eb Simplify attribute namespace 2020-09-21 16:58:08 -05:00
Paul Pacheco
ca418457e8 Simplify guard check 2020-09-21 16:57:22 -05:00
Paul Pacheco
65f6e42b53 Simplify namespaces 2020-09-21 16:53:01 -05:00
James Frowen
94419ba003
Update ApiConnector.cs
adding null check for when listserver fails to be created
2020-09-20 00:44:13 +01:00
James Frowen
44401ab3bf
Update NetworkHeadlessLogger.cs 2020-09-19 11:30:41 +01:00
vis2k
d559bcfea7 Icon updated to half M 2020-09-19 10:01:10 +02:00
Paul Pacheco
07d290fd8c
Enhance code readability by using extension method (#2260)
# Before

This is hard to read:
```
if (ca.AttributeType.FullName == typeof(Mirror.CommandAttribute).FullName) {
...
}
```

# After

```
if (ca.AttributeType.Is<Mirror.CommandAttribute>()) {
...
}
```
2020-09-18 14:54:51 -05:00
James Frowen
7919942110
Splitting up test function
* Update NetworkServerTest.cs

splitting up test

* Update NetworkServer.cs

using string interpolation
2020-09-18 20:47:54 +01:00
Paul Pacheco
e50ea6318f
perf(weaver): No need to manually load mirror and unity assemblies (#2261) 2020-09-18 14:32:14 -05:00
James Frowen
a573bccc79
Update ApiUpdater.cs 2020-09-18 20:14:10 +01:00
Paul Pacheco
0b5989f87d Move overloads together 2020-09-18 13:06:34 -05:00
Paul Pacheco
6cfdd6469a
Simplify type lookup in weaver (#2258)
# Before
WeaverTypes declared a static variable like this:
```cs
public static TypeReference int32Type;
```
Weavertypes then loaded the variable in SetupTargetTypes like this:
```cs
int32Type = ImportSystemModuleType(currentAssembly, systemModule, "System.Int32");
```
Note we lookup the type with a string,  any typo there won't be detected until the code is executed.  It will also not be found by the IDE when you click "find references",  or when you refactor.

Then we use it like this:
```cs
var intType = WeaverTypes.int32Type;
```
This is a DRY violation: I have to modify 3 different code sections just to say that I want the int32 type.

# After
Get rid of all the duplication, and use the type instead of a string:
```cs
var intType = WeaverTypes.Import<int>();
```
No need for static variable,  or to add it in SetupTargetTypes.
2020-09-18 13:05:16 -05:00
James Frowen
8dac53ce3c
making InvokeUserCode use correct type in argument (#2259) 2020-09-17 22:41:37 +01:00
James Frowen
c69d8cca0b
flip equals to return early (#2245)
* flip equals to return early

* flip equals to return early

* removing un-needed comment
2020-09-16 12:05:43 +01:00
James Frowen
23bd9559d3
pref: increasing performance when Send is called on no observers (#2244)
* pref increasing performance when sending to no observers

* pref increasing performance when sending to no observers
2020-09-16 10:32:16 +02:00
James Frowen
5eb5ff6601
fix: fixing NullReferenceException when loading scene (#2240)
* fixing null ref error when local player is destroyed

* removing null objects

* fixing InvalidOperationException

* moving code to its own function

* Update Assets/Mirror/Runtime/ClientScene.cs
2020-09-16 10:30:10 +02:00
James Frowen
7580e9a6f5
Update ClientScene.cs (#2250)
* Update ClientScene.cs

Improving logging
- making sure sceneId is always hex
- only logging "Client spawn for ..." if it was successful

* Update ClientSceneTests_OnSpawn.cs
2020-09-14 22:35:41 +01:00
James Frowen
833c329ab2
Update ApiUpdater.cs
- Adding handlers in Awake instead of Start to make sure they are added before start on headless
- using GetComponent for NetworkManagerListServer
- Adding asserts to make sure values are set
2020-09-14 21:58:33 +01:00
James Frowen
b4fea1bfa3
Update NetworkServer.cs (#2247) 2020-09-13 19:07:59 +01:00
James Frowen
aec9b8a2ec
Update NetworkIdentity.cs
fixing block not being in remarks
2020-09-13 15:44:25 +01:00
James Frowen
d5c2387d1d
Update SyncObject.cs 2020-09-13 14:33:32 +01:00
James Frowen
ae9d2e35a9
docs: adding debug notes on list server (#2246) 2020-09-13 02:47:57 +01:00
James Frowen
844904dae5
adding doc comment (#2243) 2020-09-13 01:54:23 +01:00