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

Add Identifier interface, targeted at BasicEntity #23

Closed
yarbelk opened this issue Jun 26, 2016 · 1 comment
Closed

Add Identifier interface, targeted at BasicEntity #23

yarbelk opened this issue Jun 26, 2016 · 1 comment

Comments

@yarbelk
Copy link
Contributor

yarbelk commented Jun 26, 2016

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 added a commit to yarbelk/ecs that referenced this issue Jun 26, 2016
@yarbelk
Copy link
Contributor Author

yarbelk commented Jun 26, 2016

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

@paked paked closed this as completed in #24 Jun 26, 2016
paked pushed a commit that referenced this issue Jun 26, 2016
* Add Identifier interface

[Fixes #23]

* Implement sort.Interface on IdentifierSlice

 - so you can use it for collections if you need too.
otraore pushed a commit that referenced this issue Jul 7, 2016
* ecs: Update documentation and fix golint issues.

u@x1 ~/g/s/e/ecs> golint .
entity.go:11:2: don't use underscores in Go names; var id_incr should be idIncr
entity_test.go:53:1: receiver name sys should be consistent with previous receiver name m for MySystemOneTwo

* ecs: Update Add example for Systems.

* Use atomic operations in NewBasic, remove overflow check and add benchmarks. (#22)

Fixes #21.

   u@x1 ~/g/s/e/ecs> benchcmp old.txt new.txt
   benchmark               old ns/op     new ns/op     delta
   BenchmarkNewBasic-4     27.3          10.4          -61.90%

Also add benchmarks to find the breakpoint where it starts to make
sense to allocate several basic entities. On this machine, using
NewEntities is faster even for 10 entities as it only uses a single
lock as compared to 10 atomic operations.

BenchmarkNewBasic-4        	100000000	        10.5 ns/op
BenchmarkNewBasics1-4      	30000000	        42.8 ns/op
BenchmarkNewBasic10-4      	20000000	       105 ns/op
BenchmarkNewBasics10-4     	20000000	        70.3 ns/op
BenchmarkNewBasic100-4     	 1000000	      1046 ns/op
BenchmarkNewBasics100-4    	 3000000	       433 ns/op
BenchmarkNewBasic1000-4    	  200000	     10418 ns/op
BenchmarkNewBasics1000-4   	  300000	      3907 ns/op

* Add Identifier interface (#24)

* Add Identifier interface

[Fixes #23]

* Implement sort.Interface on IdentifierSlice

 - so you can use it for collections if you need too.

* Documentation (#18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant