Ento is an Entity Component System written in Go.

About

Ento is an Entity Component System written in Go.

Getting Started

See examples folder.

From hello.go:

package main

type Component1 struct{ value int }
type Component2 struct{ value int }
type Component3 struct{ value int }

type System struct {
	// Always use pointer to base component type (!)
	// Add `ento:"bind"` tag to automatically bind components
	Component1 *Component1 `ento:"bind"`

	// Components are bound by type, not name
	Renamed *Component2 `ento:"bind"`

	// Systems can have non-component-bound fields
	calls int
}

// Update implements ento.System
// It will be called only for entities that have both tagged components
func (s *System) Update(entity *ento.Entity) {
	// Access automatically bound components from currently passed entity
	s.Component1.value += s.Renamed.value

	// Get components from entity manually (somewhat slower than automatic binding)
	// Can be used for "optional" components
	var c3 *Component3
	entity.Get(&c3)

	// If entity does not have the component, the pointer value will be set to nil
	if c3 != nil {
		s.Component1.value += c3.value
	}

	s.calls++
}

func (s *System) reportCalls() {
	println(s.calls)
	s.calls = 0
}

func main() {
	// Create the world and register components
	world := ento.NewWorldBuilder().
		// Use "zero-values" as values are ignored when registering
		WithSparseComponents(Component1{}, Component2{}, Component3{}).
		// Pre-allocate space for 256 entities (world can grow beyond that automatically)
		Build(256)

	// Add systems
	system := &System{}
	world.AddSystems(system)

	// Create entities (they are added to the world immediately)
	world.NewEntity(Component1{1}, Component2{2}, Component3{3})

	// Use Set to add or update their components
	entity := world.NewEntity()
	entity.Set(Component1{0}) // Will not be handled by System

	// Update the world
	world.Update()
	system.reportCalls() // Prints: 1

	// Update the entity (add Component2)
	entity.Set(Component2{5})

	world.Update()
	system.reportCalls() // Prints: 2

	// Update the entity (remove Component2)
	entity.Rem(Component2{})

	world.Update()
	system.reportCalls() // Prints: 1
}

License

Ento is distributed under MIT license.

MIT License

Copyright (c) 2021 Wojciech Franczyk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Owner
Similar Resources

A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃

go-hashlru A simple thread-safe, fixed size LRU written in Go. Based on dominictarr's Hashlru Algorithm. 🔃 Uses map[interface{}]interface{} to allow

Dec 5, 2022

Elf binary infector written in Golang

Elf binary infector written in Golang. It can be used for infecting executables of type ET_DYN and ET_EXEC with a payload of your creation. Utilizing the classic elf text segment padding algorithm by Silvio Cesar, your payload (parasite) will run before native functionality of the binary effectively backooring the binary.

Dec 30, 2022

Nintendo 64 ROM utility written in Go.

Nintendo 64 ROM utility written in Go.

Nintendo 64 ROM utility written in Go. Commands ls - List information about all ROMs in a directory info - Show information about a single ROM convert

Dec 7, 2022

Galvanity is Algorand vanity address generator written in Go

Galvanity Galvanity is Algorand vanity address generator written in Go Usage galvanity [search-type] pattern search-type is matching function to sea

Nov 14, 2022

Geographic coordinates and distances library written in Go.

Geographic coordinates and distances library written in Go.

Apr 5, 2022

A concurrent Download Manager written in Go

golang-download-manager A concurrent Download Manager written in Go Changes In main.go file paste the file url in fileUrl variable paste the path for

Aug 16, 2022

CookieStealer written in Go

CookieStealer written in Go

Nov 25, 2022

Julia Set Generator Written In Golang

 Julia Set Generator Written In Golang

Julia Set Generator Written In Golang This is a simple (naive) Julia Set generator written in Golang. The project utilizes concurrent workers to speed

Nov 5, 2021

Sentiment Analysis Pipeline + API written in Golang (currently processing Twitter tweets).

Go Sentiment Analysis Components Config: config module based in JSON (enter twitter credentials for use) Controllers: handle the API db call/logic for

Mar 22, 2022
A fully Go userland with Linux bootloaders! u-root can create a one-binary root file system (initramfs) containing a busybox-like set of tools written in Go.

u-root Description u-root embodies four different projects. Go versions of many standard Linux tools, such as ls, cp, or shutdown. See cmds/core for m

Dec 29, 2022
go-sysinfo is a library for collecting system information.

go-sysinfo go-sysinfo is a library for collecting system information. This includes information about the host machine and processes running on the ho

Dec 26, 2022
ptypes is a pointer-based box typing system for golang.

ptypes bypass go's type system through unsafe pointers the paradigm is to created a "boxed" type with .From and then use whatever types we want by ass

Aug 26, 2021
System software of computers

SSoC System software of computers BSUIR labs Project structure Client client client/components client/components/client client/components/command clie

Jan 5, 2022
A utility library to do files/io/bytes processing/parsing in file-system or network.

goreader A utility library to do files/io/bytes processing/parsing in file-system or network. These features are really common to be implemented for a

Nov 1, 2021
Provides simple, semantic manipulation of the operating system's signal processing.
Provides simple, semantic manipulation of the operating system's signal processing.

Provides simple, semantic manipulation of the operating system's signal processing.

Dec 15, 2021
Flock is a project which provides a Go solution for system level file locks for all platforms Golang supports.

Flock is a project which provides a Go solution for system level file locks for all platforms Golang supports.

Feb 8, 2022
This is a simple HTTP application that returns system info

sysinfo This is a simple HTTP application that returns system info. Trace Support There is also simple OpenTelemetry tracing support via the -t flag.

Dec 25, 2022
bebop is a bebop parser written in Go, for generating Go code.

bebop is a bebop parser written in Go, for generating Go code. bebop can read .bop files and output .go files representing them: package main i

Dec 24, 2022
Minict is a minimal container runtime written in Go.

Minict Minict is a minimal container runtime written in Go. It was made mainly for learning purposes and is intended to be as simple as possible.

Oct 31, 2022