Git Product home page Git Product logo

hypecs's People

Contributors

byteron avatar discodonut avatar hhyyrylainen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hypecs's Issues

World.GetTargets<T>(Entity entity) purpose unclear

What does this method do? What is its primary use?

I was looking for a way to find all targets of a relation, e.g.:

world.On(frank).Add(new Owes { Amount = 100 }, bob);
world.On(steve).Add(new Owes { Amount = 200 }, alice);

... and would expect ...

var creditors = world.GetTargets<Owes>(Entity.Any);

//creditors contains bob and alice, both targets of the Owes relation, i.e. 

However, the method requires an Identity parameter, which semantically makes no sense to me at this stage. This almost feels like multiple relations would be possible for the same component type.

Also, from looking at the code (I may have misread it), it feels like the target isn't ever stored; only its type fingerprint.

In advance, thank you for offering some clarification :)

Identity "Generation" is unused

Entities have a "generation" associated with them but it is always set to 1 since nothing passes a generation in to the constructor.

HypEcs/src/Identity.cs

Lines 27 to 32 in 2cc54cd

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Identity(int id, ushort generation = 1)
{
Id = id;
Generation = generation;
}

Inside Despawn() we queue up the "unused" id without incrementing the generation

UnusedIds.Enqueue(identity);

and then inside Spawn() we pop that id without incrementing the generation

var identity = UnusedIds.Count > 0 ? UnusedIds.Dequeue() : new Identity(++EntityCount);

Additionally, functions like IsAlive() do not check the generation at all

HypEcs/src/Archetypes.cs

Lines 283 to 287 in 2cc54cd

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool IsAlive(Identity identity)
{
return Meta[identity.Id].Identity != Identity.None;
}

It's easy to reproduce this issue since the despawned ids are used immediately

var entity = world.Spawn().Id();
world.Despawn(entity);
var anotherEntity = world.Spawn().Id();
Assert.IsFalse(entity == anotherEntity); //entity == anotherEntity will return true
Assert.IsTrue(world.IsAlive(anotherEntity));
Assert.IsFalse(world.IsAlive(entity)); // This will of course also be true unexpectedly

The same issue exists in RelEcs Byteron/RelEcs#39

Relationship to RelEcs

Does HypEcs supersede RelEcs? If I was to start tinkering now, which project should I use?

Archetypes.Queries cache with long-term relation use notes

Archetypes.Queries seems to cache every query it comes across.

There appears no mechanism that invalidates entries in this cache.

This appears to mean that, across the runtime of a game, if you frequently query for specific relations (e.g. to partition a game world into several relationships, think units following specific leaders, locking on to specific objectives, etc.), over time, as these target entities are spawned and despawned and respawned, all the old queries from past generations stick around.

I use relations to partition my game world into sub-worlds (so there's a Tenancy relation targeting the simulation's root Entity). Simulations rarely (but not never - maybe one per second) spawn and despawn, but due to each of them holding its own physics, it seemed like it would make sense to work through the physics and coordinate transfers per-world as fast as possible, in parallel threads.

It seems query objects are actually kind of lightweight, but I wonder what the best approach to invalidate one would be.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.