Skip to content

Commit

Permalink
New system syntax, along with a better way to create queries:
Browse files Browse the repository at this point in the history
SYSTEMS:
Cannot create multiple command structs, instead the system introduce the Cmd field, and you can add new commands in it by adding interfaces to the system itself.
To create a query, use RequireQuery(...) or OptionalQuery(...); the generator will automatically replace the method call with an optimized version.
QUERIES:
With<T> was renamed to All<T>
Iterating on a query will not give a tuple anymore; instead you'll be presented with an iteration struct with all components. In the future it will be even more optimized with the generator.
  • Loading branch information
guerro323 committed Jan 29, 2022
1 parent 15568ae commit 92a351b
Show file tree
Hide file tree
Showing 59 changed files with 1,051 additions and 2,603 deletions.
6 changes: 0 additions & 6 deletions nuget.config

This file was deleted.

15 changes: 10 additions & 5 deletions revecs.Generator/CommandGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ void Usings()
{
sb.Append(@"using revecs.Core;
using revecs.Utility;
using revecs.Query;
using revecs.Querying;
using revecs.Systems;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.ComponentModel;
using revtask.Core;
using revtask.Helpers;
Expand Down Expand Up @@ -181,6 +182,8 @@ void BeginCommand()

//var interfaces = source.Header.Select(t => t.GetTypeName());*/
//sb.AppendLine($" partial struct {structName} : {string.Join(",\n ", interfaces)}\n {{");
if (structName.StartsWith("__"))
sb.Append(" [EditorBrowsable(EditorBrowsableState.Never)]");
sb.AppendLine($" partial struct {structName}\n {{");
}

Expand Down Expand Up @@ -235,7 +238,7 @@ void Init()

sb.AppendLine($@" public readonly RevolutionWorld World;
public {source.Name}(RevolutionWorld world)
public {source.StructureName ?? source.Name}(RevolutionWorld world)
{{
World = world;
Expand Down Expand Up @@ -319,7 +322,7 @@ public void AddDependencyReader(IJobRunner runner, JobRequest request)
EndNamespace();

var fileName = $"{(source.Parent == null ? "" : $"{source.Parent.Name}.")}{source.Name}";
Context.AddSource($"{Path.GetFileNameWithoutExtension(source.FilePath)}.{fileName}", "#pragma warning disable\n" + sb.ToString());
Context.AddSource($"COMMAND.{Path.GetFileNameWithoutExtension(source.FilePath)}.{fileName}", "#pragma warning disable\n" + sb.ToString());
}

private void CreateCommands()
Expand All @@ -340,9 +343,11 @@ private void CreateCommands()

var symbol = (INamedTypeSymbol) semanticModel.GetDeclaredSymbol(declaredStruct);

// is query
// is system (cancel if found)
var systemInterface = symbol!.AllInterfaces.FirstOrDefault(i => i.Name == "IRevolutionSystem");
// is command
var commandInterface = symbol!.AllInterfaces.FirstOrDefault(i => i.Name == "IRevolutionCommand");
if (commandInterface != null)
if (systemInterface == null && commandInterface != null)
{
Log(0, "Found Command: " + symbol.GetTypeName() + ", File: " + tree.FilePath);

Expand Down
7 changes: 3 additions & 4 deletions revecs.Generator/ComponentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ public string GetInit(string fieldName, string componentType, string worldName)
.Replace("[componentType]", componentType, StringComparison.InvariantCultureIgnoreCase);
}

public string GetAccess(string valueName, string fieldName, string entityName, string access)
public string GetAccess(string fieldName, string entityName, string access)
{
return Access
.Replace("[value]", valueName, StringComparison.InvariantCultureIgnoreCase)
.Replace("[field]", fieldName, StringComparison.InvariantCultureIgnoreCase)
.Replace("[access]", access, StringComparison.InvariantCultureIgnoreCase)
.Replace("[entity]", entityName, StringComparison.InvariantCultureIgnoreCase);
Expand Down Expand Up @@ -266,7 +265,7 @@ void Usings()
{
sb.Append(@"using revecs.Core;
using revecs.Utility;
using revecs.Query;
using revecs.Querying;
using revecs.Systems;
using System;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -377,7 +376,7 @@ void Body()
var fileName = $"{(source.Parent == null ? "" : $"{source.Parent.Name}.")}{source.Name}";
FinalMap[fileName] = sb.ToString();

Context.AddSource($"{Path.GetFileNameWithoutExtension(source.FilePath)}.{fileName}",
Context.AddSource($"COMPONENT.{Path.GetFileNameWithoutExtension(source.FilePath)}.{fileName}",
"#pragma warning disable\n" + sb.ToString());
}

Expand Down
2 changes: 1 addition & 1 deletion revecs.Generator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Execute(GeneratorExecutionContext context)
// retrieve the populated receiver
if (!(context.SyntaxContextReceiver is SyntaxReceiver receiver))
return;

var sw = new Stopwatch();
void start() => sw.Restart();

Expand Down
Loading

0 comments on commit 92a351b

Please sign in to comment.