Entitas-Go is a fast Entity Component System Framework (ECS) Go 1.17 port of Entitas v1.13.0 for C# and Unity.

Entitas-Go

Entitas-GO is a fast Entity Component System Framework (ECS) Go 1.17 port of Entitas v1.13.0 for C# and Unity.

Code Generator

  1. Install the library in your project
go get github.com/Falldot/Entitas-Go
  1. Create context file, with components.
//Important! The file should contain this line
//go:generate go run github.com/Falldot/Entitas-Go

Game.go

package main

//go:generate go run github.com/Falldot/Entitas-Go

type Position struct {
	X, Y float64
}

type Direction struct {
	X, Y float64
}

type Speed int

type Health int

type Sprite struct {
	tag  string
	W, H int
}
  1. Use
go generate
  1. A folder 'Entitas' will be created in your project, please do not edit it

  2. Edit the context file, add methods and components, and then use again go generate

Examples

Entity

// main.go file
package main

import (
	ecs "myProject/Entitas"
)

func main() {
	contexts := ecs.CreateContexts()
    game := contexts.Game()

    // System registration
    systems := ecs.CreateSystemPool()
    systems.Add(&Translate{})
    systems.Add(&ReactiveTranslate{})

    // Create entity
    player := game.CreateEntity()

    // Add component
	player.AddPosition(10, 30)
	player.AddDirection(0, 0)
	player.AddSpeed(5)

    // Remove component
    player.RemoveSpeed()

    // Replace component
    player.ReplacePosition(30, 10)

    // On or Off component
    player.OffDirection()
    player.OnDirection()

    // Destroy entity
    player.Destroy()

    // GameLoop
    systems.Init(contexts)
    for true {
        systems.Execute()
        systems.Clean()
    }
    systems.Exit(contexts)
}

System

type Translate struct {
    group ecs.Group
}

func (s *Translate) Initer(contexts ecs.Contexts) {
	game := contexts.Game()
    s.group = game.Group(ecs.NewMatcher().AllOf(ecs.Position))
}

func (s *Translate) Executer() {
	for _, e := range s.group.GetEntities() {
        pos := e.GetPosition()
		e.ReplacePosition(pos.X + 10, pos.X + 10)
	}
}

Reactive system

type ReactiveTranslate struct {
}

func (s *ReactiveTranslate) Trigger(contexts ecs.Contexts) ecs.Collector {
	game := contexts.Game()
	return game.Collector(ecs.NewMatcher().AllOf(ecs.Position)).OnUpdate().OnAdd()
}

func (s *ReactiveTranslate) Filter(entity *ecs.Entity) bool {
	return entity.Has(ecs.Position)
}

func (s *ReactiveTranslate) Executer(entities []*ecs.Entity) {
	for _, e := range entities {
		pos := e.GetPosition()
		e.ReplacePosition(pos.X+10, pos.X+10)
	}
}

The MIT License (MIT)

Copyright © 2021 Vladislav Fedotov (Falldot)

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
Vladislav Fedotov
JS/TS, SASS/SCSS, Vue, Veux Nuxt, React, Redux, Recoil, Jest, Mocha, Next Electron, Node, Go, Docker, MongoDB, PostgreSQL, MySQL, C/C++, SDL2, EASTL
Vladislav Fedotov
Similar Resources

Minecraft Port Knock With Golang

Minecraft Port Knock A simple program that performs two duties: Monitor a Minecraft server and stop it after it has been empty for some amount of time

Jan 11, 2022

A simple tool to send binary data over a serial port. Designed for use with my retro computer systems.

Colin's Transfer Tool This is a really basic tool to transfer firmware files to my retro computer systems over a serial port. This removes the need fo

Dec 21, 2021

:chart_with_upwards_trend: Monitors Go MemStats + System stats such as Memory, Swap and CPU and sends via UDP anywhere you want for logging etc...

Package stats Package stats allows for gathering of statistics regarding your Go application and system it is running on and sent them via UDP to a se

Nov 10, 2022

Fast and secure initramfs generator

Fast and secure initramfs generator

Booster - fast and secure initramfs generator Initramfs is a specially crafted small root filesystem that mounted at the early stages of Linux OS boot

Dec 28, 2022

The package manager for macOS you didn’t know you missed. Simple, functional, and fast.

The package manager for macOS you didn’t know you missed. Simple, functional, and fast.

Stew The package manager for macOS you didn’t know you missed. Built with simplicity, functionality, and most importantly, speed in mind. Installation

Mar 30, 2022

a really fast difficulty and pp calculator for osu!mania

gonia | mania star + pp calculator a very fast and accurate star + pp calculator for mania. gonia has low memory usage and very fast calculation times

Mar 10, 2022

Executor - Fast exec task with go and less mem ops

executor fast exec task with go and less mem ops Why we need executor? Go with g

Dec 19, 2022

A fast and easy-to-use gutenberg book downloader

Gutenberg Downloader A brief description of what this project does and who it's for Usage download books Download all english books as epubs with imag

Jan 11, 2022

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system.

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system. Lithia is designed around a few core concepts in mind all language features contribute to.

Dec 24, 2022
Comments
  • Whenever I reuse words the generation gets confused

    Whenever I reuse words the generation gets confused

    If I have a component called Position, then add another called DirtyPosition, when the generation kicks in I end up with DirtyPositionComponentComponent for some reason.

  • Using a component that points to a different package fails

    Using a component that points to a different package fails

    Trying to add a component that holds a reference to a socket:

    type Socket struct {
        Connection *websocket.Conn
    }
    

    This fails, because it produces code that tries to use *websocket.conn when calling .addSocket(). Also the import statement in the generated game.go is messed up.

  • Wrong type return value in Getters for basic type components

    Wrong type return value in Getters for basic type components

    The type of the return for Getters when they are basic types, and not structs, is wrong.

    e.g.: On your example, the component Speed, when generate code the GetSpeed() method returns an Int, and it should return a *SpeedComponent

    Please, keep developing this framework because it looks amazing! Good job guys.

Ecsgo - Cache friendly, Multi threading Entity Component System in Go (with Generic)

ECSGo ECSGo is an Entity Component System(ECS) in Go. This is made with Generic

Oct 19, 2022
A toaster component for hogosuru framework
A toaster component for hogosuru framework

Toaster component for hogosuru Toaster implementation for hogosuru How to use? Create a hogosurutoaster.Toaster or attach it to a hogosuru container a

Mar 24, 2022
A boilerplate showing how to create a Pulumi component provider written in Go

xyz Pulumi Component Provider (Go) This repo is a boilerplate showing how to create a Pulumi component provider written in Go. You can search-replace

Mar 4, 2022
Packer Plugin Vagrant - The Vagrant multi-component plugin can be used with HashiCorp Packer to create custom images

Packer Plugin Vagrant - The Vagrant multi-component plugin can be used with HashiCorp Packer to create custom images

Jul 13, 2022
The Webhooks Listener-Plugin library consists of two component libraries written in GoLang

The Webhooks Listener-Plugin library consists of two component libraries written in GoLang: WebHook Listener Libraries and Plugin (Event Consumer) Libraries.

Feb 3, 2022
Antch, a fast, powerful and extensible web crawling & scraping framework for Go

Antch Antch, inspired by Scrapy. If you're familiar with scrapy, you can quickly get started. Antch is a fast, powerful and extensible web crawling &

Jan 6, 2023
Lima launches Linux virtual machines on macOS, with automatic file sharing, port forwarding, and containerd.

Lima: Linux-on-Mac ("macOS subsystem for Linux", "containerd for Mac")

Jan 8, 2023
A Go package to allow you to read and write from the serial port as a stream of bytes.

Serial A Go package to allow you to read and write from the serial port as a stream of bytes. Details It aims to have the same API on all platforms, i

Jan 6, 2023
Go port of Coda Hale's Metrics library

go-metrics Go port of Coda Hale's Metrics library: https://github.com/dropwizard/metrics. Documentation: http://godoc.org/github.com/rcrowley/go-metri

Dec 30, 2022
Go binding to libserialport for serial port functionality.

Go Serial Package serial provides a binding to libserialport for serial port functionality. Serial ports are commonly used with embedded systems, such

Nov 1, 2022