Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Compile fixes and V3 update adjustments #34

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
Binary file added .vs/flecs/v17/.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions src/cs/examples/Flecs.Examples.HelloWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ internal static class Program
// components they have, and each group has its own set of component arrays.
private static void Move(Iterator iterator)
{
var p = iterator.Term<Position>(1);
var v = iterator.Term<Velocity>(2);
var p = iterator.Field<Position>(1);
var v = iterator.Field<Velocity>(2);

// Print the set of components for the iterated over entities
var tableString = iterator.Table().String();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int Main(string[] args)
var it = world.EntityIterator<Position>();
while (it.HasNext())
{
var p = it.Term<Position>(1);
var p = it.Field<Position>(1);
for (var i = 0; i < it.Count; i ++)
{
var entity = it.Entity(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static void IterateComponents(Entity entity)
var pair = identifier.AsPair();
var relationName = pair.First.Name();
var objectName = pair.Second.Name();
Console.Write("Relation: " + relationName + ", Object: " + objectName);
Console.Write("First: " + relationName + ", Second: " + objectName);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/cs/production/Flecs/EntityIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public bool HasNext()
}
}

public Span<T> Term<T>(int index)
public Span<T> Field<T>(int index)
{
fixed (EntityIterator* @this = &this)
{
var handlePointer = &@this->Handle;
var structSize = Marshal.SizeOf<T>();
var pointer = ecs_term_w_size(handlePointer, (ulong) structSize, index);
var pointer = ecs_field_w_size(handlePointer, (ulong) structSize, index);
return new Span<T>(pointer, Handle.count);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/cs/production/Flecs/Flecs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<EnableAnalyzersStyleCop>true</EnableAnalyzersStyleCop>
<StyleCopSettingsFilePath>$(MSBuildThisFileDirectory)/Properties/StyleCop.json</StyleCopSettingsFilePath>
</PropertyGroup>
<ItemGroup>
<Content Remove="flecs.cs" />
</ItemGroup>

<!-- NuGet package references -->
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/cs/production/Flecs/Iterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ internal Iterator(World world, ecs_iter_t* it)
Handle = it;
}

public Span<T> Term<T>(int index)
public Span<T> Field<T>(int index)
{
var structSize = Marshal.SizeOf<T>();
var pointer = ecs_term_w_size(Handle, (ulong) structSize, index);
var pointer = ecs_field_w_size(Handle, (ulong) structSize, index);
return new Span<T>(pointer, Handle->count);
}

Expand Down
31 changes: 16 additions & 15 deletions src/cs/production/Flecs/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ public void RegisterComponent<TComponent>(ComponentHooks? hooks = null)
var structSize = Unsafe.SizeOf<TComponent>();
var structAlignment = structLayoutAttribute!.Pack;

var id = default(ecs_entity_t);
var id = CreateEntityRaw(componentName);
ecs_component_desc_t desc;
desc.entity.entity = id;
desc.entity.name = componentNameC;
desc.entity.symbol = componentNameC;
desc.entity = id;
desc.type.size = structSize;
desc.type.alignment = structAlignment;
id = ecs_component_init(Handle, &desc);
_componentIdentifiersByType[typeof(TComponent)] = id.Data.Data;

SetHooks(hooks, id);
}

Expand Down Expand Up @@ -97,26 +94,24 @@ public void RegisterSystem<TComponent1, TComponent2>(
CallbackIterator callback, string? name = null)
{
ecs_system_desc_t desc = default;
desc.entity.name = name ?? callback.Method.Name;
desc.query.filter.name = name ?? callback.Method.Name;
var phase = EcsOnUpdate;
desc.entity.add[0] = phase.Data != 0 ? ecs_pair(EcsDependsOn, phase) : default;
desc.entity.add[1] = phase;
desc.callback.Data.Pointer = &SystemCallback;
desc.binding_ctx = (void*)CallbacksHelper.CreateSystemCallbackContext(this, callback);
FillSystemDescriptorCommon(ref desc, callback, phase, name);

var componentName1 = GetFlecsTypeName<TComponent1>();
var componentName2 = GetFlecsTypeName<TComponent2>();
desc.query.filter.expr = componentName1 + ", " + componentName2;

ecs_system_init(Handle, &desc);
}

private void FillSystemDescriptorCommon(
ref ecs_system_desc_t desc, CallbackIterator callback, ecs_entity_t phase, string? name)
{
desc.entity.name = name ?? callback.Method.Name;
desc.entity.add[0] = phase.Data != 0 ? ecs_pair(EcsDependsOn, phase) : default;
desc.entity.add[1] = phase;
ecs_entity_desc_t edesc = default;
edesc.name = name ?? callback.Method.Name;
edesc.add[0] = phase.Data != 0 ? ecs_pair(EcsDependsOn, phase) : default;
edesc.add[1] = phase;
desc.entity = ecs_entity_init(Handle, &edesc);
desc.callback.Data.Pointer = &SystemCallback;
desc.binding_ctx = (void*)CallbacksHelper.CreateSystemCallbackContext(this, callback);
}
Expand All @@ -130,12 +125,18 @@ private static void SystemCallback(ecs_iter_t* it)
data.Callback(iterator);
}

public Entity CreateEntity(string name)
private ecs_entity_t CreateEntityRaw(string name)
{
var desc = default(ecs_entity_desc_t);
desc.name = name;

var entity = ecs_entity_init(Handle, &desc);
return entity;
}

public Entity CreateEntity(string name)
{
var entity = CreateEntityRaw(name);
var result = new Entity(this, entity);
return result;
}
Expand Down
Loading