This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Serialize component updates in jobs * Fix early job schedule due to combined dependencies Filter on changed components to avoid scheduling jobs for unchanged chunks Don't reuse queue, dispose and re-create * Remove UnityComponentSenderGenerator and the ComponentSendSystem Hack MessagesToSend to store pre-serialized component updates * Add more profile markers * Dispose Native collections in right places Fixes unit tests * For performance tests by changing profiling marks Add DisableAutoCreate to ReplicationSystems * Fix code smells * Changelog * Fix netstats for component updates Rename AddComponentUpdate to AddComponentEvent * Better profile markers
- Loading branch information
1 parent
f219927
commit ae4c5fc
Showing
19 changed files
with
209 additions
and
292 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
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
98 changes: 98 additions & 0 deletions
98
...able.gdk.core/.codegen/Source/Generators/Core/UnityComponentReplicationSystemGenerator.cs
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,98 @@ | ||
using Improbable.Gdk.CodeGeneration.CodeWriter; | ||
using Improbable.Gdk.CodeGeneration.Model.Details; | ||
using NLog; | ||
|
||
namespace Improbable.Gdk.CodeGenerator | ||
{ | ||
public static class UnityComponentReplicationSystemGenerator | ||
{ | ||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); | ||
|
||
public static CodeWriter Generate(UnityComponentDetails componentDetails) | ||
{ | ||
var componentNamespace = $"global::{componentDetails.Namespace}.{componentDetails.Name}"; | ||
|
||
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}.ReplicationSystem internal class."); | ||
|
||
return CodeWriter.Populate(cgw => | ||
{ | ||
cgw.UsingDirectives( | ||
"Improbable.Gdk.Core", | ||
"Improbable.Worker.CInterop", | ||
"Unity.Collections", | ||
"Unity.Entities", | ||
"Unity.Profiling" | ||
); | ||
|
||
cgw.Namespace(componentDetails.Namespace, ns => | ||
{ | ||
ns.Type($"public partial class {componentDetails.Name}", partial => | ||
{ | ||
partial.Annotate("DisableAutoCreation, UpdateInGroup(typeof(SpatialOSSendGroup)), UpdateBefore(typeof(SpatialOSSendGroup.InternalSpatialOSSendGroup))") | ||
.Type("internal class ReplicationSystem : SystemBase", system => | ||
{ | ||
system.Line($@" | ||
private NativeQueue<SerializedMessagesToSend.UpdateToSend> dirtyComponents; | ||
private SpatialOSSendSystem spatialOsSendSystem; | ||
private ProfilerMarker foreachMarker = new ProfilerMarker(""{componentDetails.Name}SerializationJob""); | ||
protected override void OnCreate() | ||
{{ | ||
spatialOsSendSystem = World.GetExistingSystem<SpatialOSSendSystem>(); | ||
}} | ||
"); | ||
system.Method("protected override void OnUpdate()", m => | ||
{ | ||
m.Line(new[] | ||
{ | ||
"dirtyComponents = new NativeQueue<SerializedMessagesToSend.UpdateToSend>(Allocator.TempJob);", | ||
"var dirtyComponentsWriter = dirtyComponents.AsParallelWriter();", | ||
"var marker = foreachMarker;", | ||
}); | ||
|
||
m.Line($@" | ||
Dependency = Entities.WithName(""{componentDetails.Name}Replication"")"); | ||
if (!componentDetails.IsBlittable) | ||
{ | ||
m.Line(@" | ||
.WithoutBurst()"); | ||
} | ||
|
||
m.Line(@" | ||
.WithAll<HasAuthority>() | ||
.WithChangeFilter<Component>() | ||
.ForEach((ref Component component, in SpatialEntityId entity) => | ||
{ | ||
marker.Begin(); | ||
if (!component.IsDataDirty()) | ||
{ | ||
marker.End(); | ||
return; | ||
} | ||
// Serialize component | ||
var schemaUpdate = SchemaComponentUpdate.Create(); | ||
Serialization.SerializeUpdate(component, schemaUpdate); | ||
component.MarkDataClean(); | ||
// Schedule update | ||
var componentUpdate = new ComponentUpdate(ComponentId, schemaUpdate); | ||
var update = new SerializedMessagesToSend.UpdateToSend(componentUpdate, entity.EntityId.Id); | ||
dirtyComponentsWriter.Enqueue(update); | ||
marker.End(); | ||
}) | ||
.ScheduleParallel(Dependency); | ||
spatialOsSendSystem.AddReplicationJobProducer(Dependency, dirtyComponents); | ||
dirtyComponents = default; | ||
"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
105 changes: 0 additions & 105 deletions
105
...s/io.improbable.gdk.core/.codegen/Source/Generators/Core/UnityComponentSenderGenerator.cs
This file was deleted.
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
Oops, something went wrong.