Changed the `Component` class to an interface `IComponentData` to support a data-oriented design. Changed the `Transform` class from a class to a struct, implementing `IComponentData` and updating properties. Changed the `GameObject` class to use a dictionary for components and added properties for state management. Changed the `PlayerLoopService` class to `GameLoopService` and updated methods to integrate with the new `SceneManager`. Changed the `World` class to manage multiple worlds and enhance entity management with new querying methods. Added the `Scene` class to manage root game objects and their lifecycle. Added new utility classes like `ComponentMask`, `Box<T>`, and `TypeHandle<T>` for better component management. Added the `ScriptComponent` class to allow for modular scriptable components attached to entities. Added the `QueryEnumerable` class to facilitate flexible querying of entities with specific components. Updated the `Test` class in `Program.cs` to demonstrate the new entity and component management system. Updated project files to include new references and settings supporting the changes made in the codebase.
128 lines
3.3 KiB
Plaintext
128 lines
3.3 KiB
Plaintext
<#@ import namespace="System.Text" #>
|
|
<#@ import namespace="System.Collections.Generic" #>
|
|
<#+
|
|
|
|
public int Amount = 8;
|
|
public int ExtensionAmount = 3;
|
|
|
|
public string Indent(StringBuilder sb, int spaces)
|
|
{
|
|
var indent = new string(' ', spaces);
|
|
return sb.ToString().Replace("\n", "\n" + indent);
|
|
}
|
|
|
|
string AppendGenerics(int amount, string template)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var i = 0; i < amount; i++)
|
|
{
|
|
if (i > 0) sb.Append(", ");
|
|
sb.Append($"{template}{i}");
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
string AppendGenerics(int amount)
|
|
{
|
|
return AppendGenerics(amount, "T");
|
|
}
|
|
|
|
public StringBuilder AppendGenericRefParameters(int amount)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 0; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"ref T{localIndex} t{localIndex}Component,");
|
|
}
|
|
|
|
sb.Length--;
|
|
return sb;
|
|
}
|
|
|
|
public StringBuilder AppendRefParameters(int amount)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 0; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"ref component{localIndex},");
|
|
}
|
|
|
|
sb.Length--;
|
|
return sb;
|
|
}
|
|
|
|
public StringBuilder AppendGenericRestrictions(int amount, string Ttemplate, string template)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 0; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"where {Ttemplate}{localIndex} : {template}");
|
|
if (localIndex < amount - 1)
|
|
{
|
|
sb.Append(' ');
|
|
}
|
|
}
|
|
return sb;
|
|
}
|
|
|
|
public StringBuilder AppendGenericRestrictions(int amount, string template)
|
|
{
|
|
return AppendGenericRestrictions(amount, "T", template);
|
|
}
|
|
|
|
public StringBuilder TryGetComponentPools(int amount)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 0; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"_componentStorage.TryGetPool<T{localIndex}>(out var pool{localIndex})");
|
|
if (localIndex < amount - 1)
|
|
{
|
|
sb.Append(" && ");
|
|
}
|
|
}
|
|
return sb;
|
|
}
|
|
|
|
public StringBuilder HasEntity(int amount)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 1; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"pool{localIndex}.Has(entity)");
|
|
if (localIndex < amount - 1)
|
|
{
|
|
sb.Append(" && ");
|
|
}
|
|
}
|
|
return sb;
|
|
}
|
|
|
|
public StringBuilder GetComponent(int amount)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 0; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"pool{localIndex}.GetRef(entity)");
|
|
if (localIndex < amount - 1)
|
|
{
|
|
sb.Append(", ");
|
|
}
|
|
}
|
|
return sb;
|
|
}
|
|
|
|
public StringBuilder GetComponentRef(int amount)
|
|
{
|
|
var sb = new StringBuilder();
|
|
for (var localIndex = 0; localIndex < amount; localIndex++)
|
|
{
|
|
sb.Append($"ref pool{localIndex}.GetRef(entity)");
|
|
if (localIndex < amount - 1)
|
|
{
|
|
sb.Append(", ");
|
|
}
|
|
}
|
|
return sb;
|
|
}
|
|
#> |