Giter Site home page Giter Site logo

Comments (22)

ebkalderon avatar ebkalderon commented on July 22, 2024

@ebkalderon replied: 2016-02-04 @ 12:25PM EST

Uh oh! Good catch. I think we need to have the create() method pop the first element from the vector, not the last.

from amethyst.

ebkalderon avatar ebkalderon commented on July 22, 2024

@boguszaur replied: 2016-02-04 @ 12:25PM EST

do we need to have vec of alive entities in the Entities struct? we can just have next_id and vec of dead entities.. so if we need to add new entity we either pop from dead entities, or return next_id and increment it. To determine if the entity is alive we make sure that its less than next_id and its not in dead vec. num_alive function just returns next_id - length of dead vec

from amethyst.

ebkalderon avatar ebkalderon commented on July 22, 2024

@ebkalderon replied: 2016-02-04 @ 12:27PM EST

@boguszaur I was thinking of something similar, yes. Please watch the ecs branch; it will undergo some minor code churn in a few moments.

from amethyst.

ebkalderon avatar ebkalderon commented on July 22, 2024

@ebkalderon replied: 2016-02-04 @ 4:20PM EST

@Oflor @boguszaur Thanks to you both for the feedback! I've tweaked the Entities struct and it seems to work better now. Let me know if you have any other main suggestions or complaints.

from amethyst.

boguszaur avatar boguszaur commented on July 22, 2024

But is it really important to get entities from the dead vec in the order they were put there? whats wrong with pushing to the end and popping the last added? Our destroy method right now uses self.dead.insert(0, entity); so it shifts all elements to the right every time..not the best for performance.

from amethyst.

lschmierer avatar lschmierer commented on July 22, 2024

Yes, it should not matter in which order we are getting the dead entities. Performance is more important imo.

from amethyst.

lschmierer avatar lschmierer commented on July 22, 2024

Or use VecDeque.

from amethyst.

palodequeso avatar palodequeso commented on July 22, 2024

What about just using uuid4s?

from amethyst.

ebkalderon avatar ebkalderon commented on July 22, 2024

@lschmierer That sounds like a good idea. I presume it's based on the standard Vec, so performance should be similar?

@palodequeso That certainly could work, but it's unnecessary computational overhead in my mind, since simple unsigned integers can do the job just as well. However, UUIDs could be useful for resource management, though. What library did you have in mind?

from amethyst.

palodequeso avatar palodequeso commented on July 22, 2024

@ebkalderon: Yea, the up front generation overhead can be cumbersome, especially if you're tracking say, particles for physics simulation in mass, and you are constantly creating and destroying them by the thousands. Also, I'm not sure what library to use, I just know I've used UUIDs in a lot of places instead of iterative unsigned integers.

from amethyst.

ebkalderon avatar ebkalderon commented on July 22, 2024

Looks like VecDeque lacks a contains() method, so I guess I'll revert to the original .iter().filter(|&e| *e == entity).count() == 1 approach again.

from amethyst.

lschmierer avatar lschmierer commented on July 22, 2024

Or just don't care about the order dead entities are returned.

When using normal Vec we can use binary_seach instead of contains which might be faster. However the vector then needs to be sorted.
We can use binary_search as well for inserting. If element is not found binary_search resturn position to insert.

from amethyst.

shawnscode avatar shawnscode commented on July 22, 2024

Actually, id recycles might not be a good idea in real game development. For example, if we have two logical system A, B handle Entity(0) at same time.

  1. System A Disposed Entity(0);
  2. System A Created a new Entity, and will get Entity(0) as identifier again;
  3. System B now may treats the newer Entity as old Entity, even if they might have different components and meanings.

Its a common case in my game based on ECS.

from amethyst.

lschmierer avatar lschmierer commented on July 22, 2024

Iny understanding, Systems should probably handle the entities based on the components. So System B would not work on Entity(0).

from amethyst.

shawnscode avatar shawnscode commented on July 22, 2024

its common to reference some entity identifier manually cross multi-system. Every time before performing real things based on it, i could do checks by calling is_alive to make sure its available. So if the identifier could be recycled, is_alive might returns confused result about the Entity(0) i used to reference.

from amethyst.

White-Oak avatar White-Oak commented on July 22, 2024

Another problem may be networking - the common way to send updates/states is to send them by id, which may lead to corruption or confusion with recycling ids.

from amethyst.

Aceeri avatar Aceeri commented on July 22, 2024

Probably best to not recycle ids, given the problems it could cause. Either way a u64 (I believe that is the type you are using that for the Entity Ids?) goes up to the incredible amount of 18 quintillion, so it is incredibly unlikely that a game will ever create that many entities.

from amethyst.

White-Oak avatar White-Oak commented on July 22, 2024

@Aceeri +1

from amethyst.

Oflor avatar Oflor commented on July 22, 2024

I've already removed id recycling, @ebkalderon will just have to review it now.

from amethyst.

kvark avatar kvark commented on July 22, 2024

Posting here what I mentioned a while ago on Gitter:

there is an old general solution to this problem with ID recycling - adding the generation count to the ID. When an ID gets recycled, it's generation count increases, so that the (ID,generation) pair is never equal to the (ID,previous_generation)

Was this approach ever considered? I imagine that without ID recycling you'd lose the ability to directly index your component arrays by the IDs, which imposes a significant performance hit. That, of course, only applies to array storage of the components. Did you rule out the arrays completely?

from amethyst.

Aceeri avatar Aceeri commented on July 22, 2024

@kvark I'm thinking we might have something similar to the (id, generation) pair you suggested if we just make the entity unique and the components recycle. We could use the entities unique id for things like networking and such, but not risk duplication ids that would give an entity unwanted components.

(I would also suggest changing the dead list to a set of alive entities. Otherwise that could lead to a memory leak.)

from amethyst.

 avatar commented on July 22, 2024

This is resolved by the migration to specs which does this internally.

from amethyst.

Related Issues (20)

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.