Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating flecs ecs for Simulation application #21

Open
guerro323 opened this issue Jul 13, 2020 · 4 comments
Open

Integrating flecs ecs for Simulation application #21

guerro323 opened this issue Jul 13, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@guerro323
Copy link
Owner

Adding flecs (https://github.com/SanderMertens/flecs) to the Simulation application would be a good addition. I don't want to use the current DefaultEcs package for simulation since the architecture isn't suited for my games (lots of entity update, serialization, need to have continuous data, ...).
DefaultEcs is still used for other parts of the application tho (since it does support managed data well and its architecture is perfect for the software/framework part)

flecs is extremely performant, but there need to be new bindings based on the V2 (I'm currently working on it, which should also come under a nugget package)

@guerro323 guerro323 added the enhancement New feature or request label Jul 13, 2020
@guerro323 guerro323 self-assigned this Jul 13, 2020
@guerro323
Copy link
Owner Author

i made it run, but i need to experiment a bit more before officialy integrating it in GameHost

@guerro323
Copy link
Owner Author

did not crash, and work perfectly with this small code sample, so i guess it's i n t e g r a t i o n t i m e

var world = flecs.ecs_init();

var components = new Dictionary<Type, SWIGTYPE_p_ecs_vector_t>();

SWIGTYPE_p_ecs_vector_t ECS_COMPONENT<T>()
{
	if (!components.TryGetValue(typeof(T), out var typeId))
	{
		var entityId = flecs.ecs_new_component(world, typeof(T).Name, (uint) Unsafe.SizeOf<T>());
		typeId = flecs.ecs_type_from_entity(world, entityId);
	}

	return typeId;
}

ulong Set<T>(ulong entity, T value)
{
	return flecs._ecs_set_ptr(world, entity, flecs.ecs_type_to_entity(world, ECS_COMPONENT<T>()), (uint) Unsafe.SizeOf<T>(), Unsafe.AsPointer(ref value));
}

T Get<T>(ulong entity)
{
	return Unsafe.AsRef<T>(flecs._ecs_get_ptr(world, entity, ECS_COMPONENT<T>()));
}

var e1 = flecs._ecs_new(world, null);
var e2 = flecs._ecs_new(world, null);

Console.WriteLine($"{e1} {e2}");

Set(e1, new Vector3(1, 2, 3));
Console.WriteLine(Get<Vector3>(e1));

@guerro323
Copy link
Owner Author

This issue will be closed once it will be fully integrated to GameHost

@guerro323
Copy link
Owner Author

finally, i don't know if it will be integrated, most of the bindings generator are kinda broken with flecs, and I don't want to spend time making the bindings by myself (way too much try-&-fail when implement bindings, not worth it)

so instead i'm making an ECS that somewhat look like flecs, but not really (table based instead of traditional chunk based)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant