Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Codegen Split: GameObject Creation #1196

Merged
merged 5 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Reactive components have been removed completely. [#1195](https://github.com/spatialos/gdk-for-unity/pull/1195)
- If you are using reactive components, please see our documentation on the [ECS workflow](https://docs.improbable.io/unity/alpha/workflows/overview#ecs-centric-workflow).
- Codegen for the GameObjectCreation package has been moved into the package. If the package is not used, readers and writers will no longer be generated. [#1196](https://github.com/spatialos/gdk-for-unity/pull/1196)

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
using Improbable.Gdk.CodeGeneration.FileHandling;
using Improbable.Gdk.CodeGeneration.Jobs;
using Improbable.Gdk.CodeGeneration.Model.Details;
using Improbable.Gdk.CodeGeneration.Utils;

namespace Improbable.Gdk.CodeGenerator
namespace Improbable.Gdk.CodeGenerator.Core
{
public class SingleGenerationJob : CodegenJob
public class CoreCodegenJob : CodegenJob
{
private readonly List<GenerationTarget<UnityComponentDetails>> componentsToGenerate;

Expand All @@ -18,7 +17,7 @@ public class SingleGenerationJob : CodegenJob

private const string FileExtension = ".cs";

public SingleGenerationJob(string outputDir, IFileSystem fileSystem, DetailsStore store) : base(
public CoreCodegenJob(string outputDir, IFileSystem fileSystem, DetailsStore store) : base(
outputDir, fileSystem, store)
{
InputFiles = store.SchemaFiles.ToList();
Expand Down Expand Up @@ -61,8 +60,6 @@ public SingleGenerationJob(string outputDir, IFileSystem fileSystem, DetailsStor
Path.ChangeExtension($"{componentName}CommandPayloads", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}CommandComponents", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}CommandSenderReceiver", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}CommandDiffDeserializer", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Expand All @@ -87,8 +84,6 @@ public SingleGenerationJob(string outputDir, IFileSystem fileSystem, DetailsStor
Path.ChangeExtension($"{componentName}ComponentDiffDeserializer", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}Providers", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}ComponentReaderWriter", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}ViewStorage", FileExtension)));
OutputFiles.Add(Path.Combine(relativeOutputPath, Path.ChangeExtension($"{componentName}Metaclass", FileExtension)));
Expand All @@ -111,8 +106,6 @@ protected override void RunImpl()
var componentSenderGenerator = new UnityComponentSenderGenerator();
var ecsViewManagerGenerator = new UnityEcsViewManagerGenerator();
var referenceTypeProviderGenerator = new UnityReferenceTypeProviderGenerator();
var componentReaderWriterGenerator = new UnityComponentReaderWriterGenerator();
var commandSenderReceiverGenerator = new UnityCommandSenderReceiverGenerator();
var componentDiffStorageGenerator = new ComponentDiffStorageGenerator();
var componentDiffDeserializerGenerator = new ComponentDiffDeserializerGenerator();
var commandDiffDeserializerGenerator = new CommandDiffDeserializerGenerator();
Expand Down Expand Up @@ -153,15 +146,6 @@ protected override void RunImpl()
commandPayloadGenerator.Generate(componentTarget.Content, package);
Content.Add(Path.Combine(relativeOutputPath, commandPayloadsFileName), commandPayloadCode);

var commandComponentsFileName =
Path.ChangeExtension($"{componentName}CommandComponents", FileExtension);

var commandSenderReceiverFileName =
Path.ChangeExtension($"{componentName}CommandSenderReceiver", FileExtension);
var commandSenderReceiverCode =
commandSenderReceiverGenerator.Generate(componentTarget.Content, package);
Content.Add(Path.Combine(relativeOutputPath, commandSenderReceiverFileName), commandSenderReceiverCode);

var commandDiffDeserializerFileName =
Path.ChangeExtension($"{componentName}CommandDiffDeserializer", FileExtension);
var commandDiffDeserializerCode =
Expand Down Expand Up @@ -216,12 +200,6 @@ protected override void RunImpl()
referenceProviderTranslationCode);
}

var componentReaderWriterFileName =
Path.ChangeExtension($"{componentName}ComponentReaderWriter", FileExtension);
var componentReaderWriterCode =
componentReaderWriterGenerator.Generate(componentTarget.Content, package);
Content.Add(Path.Combine(relativeOutputPath, componentReaderWriterFileName), componentReaderWriterCode);

var viewStorageFileName = Path.ChangeExtension($"{componentName}ViewStorage", FileExtension);
var viewStorageCode = viewStorageGenerator.Generate(componentTarget.Content, package);
Content.Add(Path.Combine(relativeOutputPath, viewStorageFileName), viewStorageCode);
Expand All @@ -231,19 +209,5 @@ protected override void RunImpl()
Content.Add(Path.Combine(relativeOutputPath, metaclassFileName), metaclassCode);
}
}

private struct GenerationTarget<T>
{
public readonly T Content;
public readonly string Package;
public readonly string OutputPath;

public GenerationTarget(T content, string package)
{
Content = content;
Package = Formatting.CapitaliseQualifiedNameParts(package);
OutputPath = Formatting.GetNamespacePath(package);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Improbable.Gdk.CodeGeneration.FileHandling;
using Improbable.Gdk.CodeGeneration.Jobs;
using Improbable.Gdk.CodeGeneration.Model.Details;

namespace Improbable.Gdk.CodeGenerator.GameObjectCreation
{
public class GameObjectCodegenJob : CodegenJob
{
private readonly List<GenerationTarget<UnityComponentDetails>> componentsToGenerate;

private const string FileExtension = ".cs";

public GameObjectCodegenJob(string outputDir, IFileSystem fileSystem, DetailsStore store) : base(
outputDir, fileSystem, store)
{
InputFiles = store.SchemaFiles.ToList();
OutputFiles = new List<string>();

componentsToGenerate = store.Components
.Select(kv => new GenerationTarget<UnityComponentDetails>(kv.Value, kv.Value.Package))
.ToList();

foreach (var componentTarget in componentsToGenerate)
{
var relativeOutputPath = componentTarget.OutputPath;
var componentName = componentTarget.Content.ComponentName;

if (componentTarget.Content.CommandDetails.Count > 0)
{
OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}CommandSenderReceiver", FileExtension)));
}

OutputFiles.Add(Path.Combine(relativeOutputPath,
Path.ChangeExtension($"{componentName}ComponentReaderWriter", FileExtension)));
}
}

protected override void RunImpl()
{
var componentReaderWriterGenerator = new UnityComponentReaderWriterGenerator();
var commandSenderReceiverGenerator = new UnityCommandSenderReceiverGenerator();

foreach (var componentTarget in componentsToGenerate)
{
var relativeOutputPath = componentTarget.OutputPath;
var componentName = componentTarget.Content.ComponentName;
var package = componentTarget.Package;

if (componentTarget.Content.CommandDetails.Count > 0)
{
var commandSenderReceiverFileName =
Path.ChangeExtension($"{componentName}CommandSenderReceiver", FileExtension);
var commandSenderReceiverCode =
commandSenderReceiverGenerator.Generate(componentTarget.Content, package);
Content.Add(Path.Combine(relativeOutputPath, commandSenderReceiverFileName), commandSenderReceiverCode);
}

var componentReaderWriterFileName =
Path.ChangeExtension($"{componentName}ComponentReaderWriter", FileExtension);
var componentReaderWriterCode =
componentReaderWriterGenerator.Generate(componentTarget.Content, package);
Content.Add(Path.Combine(relativeOutputPath, componentReaderWriterFileName), componentReaderWriterCode);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Improbable.Gdk.CodeGeneration.FileHandling;
using Improbable.Gdk.CodeGeneration.Model.Details;
using Improbable.Gdk.CodeGeneration.Utils;

namespace Improbable.Gdk.CodeGeneration.Jobs
{
Expand Down Expand Up @@ -114,5 +115,19 @@ public void MarkAsDirty()

protected abstract void RunImpl();
private bool isDirtyOverride;

protected struct GenerationTarget<T>
{
public readonly T Content;
public readonly string Package;
public readonly string OutputPath;

public GenerationTarget(T content, string package)
{
Content = content;
Package = Formatting.CapitaliseQualifiedNameParts(package);
OutputPath = Formatting.GetNamespacePath(package);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "Improbable Worlds Ltd",
"description": "SpatialOS GDK Transform Synchronization Module.",
"dependencies": {
"io.improbable.gdk.core": "0.2.10"
"io.improbable.gdk.core": "0.2.10",
"io.improbable.gdk.gameobjectcreation": "0.2.10"
}
}