Skip to content

Archetypal ECS implementation#55

Draft
itsBuggingMe wants to merge 8 commits intoEndlessEscapade:devfrom
itsBuggingMe:dev
Draft

Archetypal ECS implementation#55
itsBuggingMe wants to merge 8 commits intoEndlessEscapade:devfrom
itsBuggingMe:dev

Conversation

@itsBuggingMe
Copy link

I'm opening this draft PR for feedback.

Changes

Fixed sparse set implementation, added some collections, and implemented the ECS.
Entity creation, component Add<T>/Remove<T>, Has<T>, Get<T>, TryGet<T>, querying

The current state is pretty agnostic and the System API is unfinished, as I am not sure what kind of API is desired.

Also, would like suggestions on API naming. Currently its whatever popped into my head at the moment.

Notes:

  • currently the API is generics only
  • no entity tags
  • 255 max component count on entity
  • Not sure where to put ThrowHelper
  • Entity name interferes with terraria's entity
  • Probably has bugs (no tests yet)

API sample

World world = new World();

Entity e = world.Entity()
    .Set<int>(69)
    .Set<double>(42)
    .Set<float>(420)
    .Entity;

e.Add<decimal>(4);
e.Remove<decimal>();

_ = e.World;

Query query = world.Query()
    .With<int>()
    .With<double>()
    .Build();

@itsBuggingMe itsBuggingMe marked this pull request as draft March 10, 2025 22:22
@mayli4 mayli4 added the help wanted Extra attention is needed label Mar 10, 2025
@mayli4
Copy link
Member

mayli4 commented Mar 10, 2025

255 component limit is a non-issue. In a terraria context, there will more than likely never be a need for more than maybe ~20 components per entity.

As for the naming interference, id suggest a global using for either terrarias entity class or our own.

global using Terraria_Entity = Terraria.Entity;
global using EE_Entity = EndlessEscapade.Core.ECS.Entity;

@mayli4 mayli4 requested a review from shnakamura March 11, 2025 01:31
@mayli4 mayli4 self-assigned this Mar 11, 2025
@itsBuggingMe
Copy link
Author

itsBuggingMe commented Mar 11, 2025

Another question I have. Some of the APIs aren't really meant to be messed with by the user; e.g. World.Table. Normally I would simply mark it as internal, but that won't have much of an effect here.
How much of a problem would this be?

@shnakamura
Copy link
Collaborator

Looking good apart from minor issues that are mostly syntax/formatting, but obviously easy fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants