EngoEngine / ecs

A Go-implementation of the Entity-Component-System paradigm
MIT License
298 stars 43 forks source link

Add Identifier interface, targeted at BasicEntity #23

Closed yarbelk closed 8 years ago

yarbelk commented 8 years ago

If I want to be able to easily look up an entity by its ID, I would need to easily store purely based on ID; one solution to this is:

        type Identifier interface {
                ID() uint64
        }

        // Registry is an example data structure where this would be useful
        // it could implement the basic Add/Remove functionality that is so common

        type Registry struct {
                entities map[uint64]Identifier
                entitiesRWMutex sync.RWMutex
        }

The benefit of this is I can register something in one system, and the dynamically check to see if whatever that entity was implements a specific interface at run time. this means I don't need to store as many 'half implemented' subsets of the entities, and i will have less duplicated code. The only thing I need to store in the system itself would be the ID, and the information specific to the system.

yarbelk commented 8 years ago

I also think it would be good to implement some of the standard library interfaces on top of this (like sort.Interface). Which I added. Sometimes you want to deal with the O=n log n lookups of a sorted slice rather than the muxer needed for a map, or a plain loop over all elements