Giter VIP home page Giter VIP logo

ecs's Introduction

ECS - Entity Component System

GoDoc Go Report Card

Build your own Game-Engine based on the Entity Component System concept in Golang

The architectural pattern of an ECS is mostly used in game development, to provide long-term maintainability and extendability of large, dynamic systems.

Overview

An Entity is basically a composition of different components and has an ID.
A Component contains only the state or data of one specific aspect like health, position, velocity etc.
A System handles the behaviour or logic of the components. A movement system uses the position and velocity to implement an entities movement.

Goals

  • Provide an easy-to-use framework to build a game engine from scratch.
  • No dependencies to other modules or specific game libraries - Feel free to use what fits your needs.
  • Minimum overhead - use only what is really needed.
  • Plugins to offer unlimited room for improvements.

Installation

From Source

go get -u github.com/andygeiss/ecs

Steps to start

The first step is to be clear about what we want our game engine to do. The main task is to make sure that we have combined all the essential components that are responsible for the technical and logical aspects.

An Entity Component System (ECS) helps us to do this because the logical components (data) such as entities and their components can be separated from the actual logic. Among other things, this has the advantage that we can implement and test the game mechanics independently from the rest.

So let's start...

We decide to use 2D and define the three most important components:

In the next step, the three most important systems implement:

I want more than 64 Components !

Yes! You can do that by adding a Name() function to your component and using FilterByNames instead of FilterByMask. However if you want the fastest possible solution you need to know that FilterByNames is 40 times slower than FilterByMask. This will maybe not impact your Game if there are only a few thousands of entities. ;-)

bench

ecs's People

Contributors

andygeiss avatar ethanmdavidson avatar imgbotapp avatar setanarut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ecs's Issues

Refactor system_manager.go

I've selected system_manager.go for refactoring, which is a module of 17 lines of code that couples the top-level components tightly. Addressing this will make our codebase more maintainable and improve Better Code Hub's Couple Architecture Components Loosely guideline rating! ๐Ÿ‘

Here's the gist of this guideline:

  • Definition ๐Ÿ“–
    Minimize the amount of interface code; that is, code in modules that are both called from and call modules of other components ("throughput"), and code in modules that are called from modules of other components ("incoming").
  • Whyโ“
    Having loose coupling between top-level components makes it easier to maintain them in isolation.
  • How ๐Ÿ”ง
    You can hide a component's implementation details through various means, e.g. using the "abstract factory" design pattern.

You can find more info about this guideline in Building Maintainable Software. ๐Ÿ“–


โ„น๏ธ To know how many other refactoring candidates need addressing to get a guideline compliant, select some by clicking on the ๐Ÿ”ฒ next to them. The risk profile below the candidates signals (โœ…) when it's enough! ๐Ÿ


Good luck and happy coding! :shipit: โœจ ๐Ÿ’ฏ

Refactor entity.go

I've selected entity.go for refactoring, which is a module of 65 lines of code that couples the top-level components tightly. Addressing this will make our codebase more maintainable and improve Better Code Hub's Couple Architecture Components Loosely guideline rating! ๐Ÿ‘

Here's the gist of this guideline:

  • Definition ๐Ÿ“–
    Minimize the amount of interface code; that is, code in modules that are both called from and call modules of other components ("throughput"), and code in modules that are called from modules of other components ("incoming").
  • Whyโ“
    Having loose coupling between top-level components makes it easier to maintain them in isolation.
  • How ๐Ÿ”ง
    You can hide a component's implementation details through various means, e.g. using the "abstract factory" design pattern.

You can find more info about this guideline in Building Maintainable Software. ๐Ÿ“–


โ„น๏ธ To know how many other refactoring candidates need addressing to get a guideline compliant, select some by clicking on the ๐Ÿ”ฒ next to them. The risk profile below the candidates signals (โœ…) when it's enough! ๐Ÿ


Good luck and happy coding! :shipit: โœจ ๐Ÿ’ฏ

missing interface fields doc comments

Can you explain what their purpose Run(), Setup(), Teardown(), Tick(), Setup(), Process(), Teardown() for beginners?

type Engine interface {
        // ???
	Run() 
        // ???
	Setup()
        // ???
	Teardown()
        // ???
	Tick()
}
type System interface {
        // ???
	Setup()
        // ???
        Process(entityManager EntityManager) (state int)
        // ???
	Teardown()
}

Refactor run.go

I've selected run.go for refactoring, which is a module of 33 lines of code that couples the top-level components tightly. Addressing this will make our codebase more maintainable and improve Better Code Hub's Couple Architecture Components Loosely guideline rating! ๐Ÿ‘

Here's the gist of this guideline:

  • Definition ๐Ÿ“–
    Minimize the amount of interface code; that is, code in modules that are both called from and call modules of other components ("throughput"), and code in modules that are called from modules of other components ("incoming").
  • Whyโ“
    Having loose coupling between top-level components makes it easier to maintain them in isolation.
  • How ๐Ÿ”ง
    You can hide a component's implementation details through various means, e.g. using the "abstract factory" design pattern.

You can find more info about this guideline in Building Maintainable Software. ๐Ÿ“–


โ„น๏ธ To know how many other refactoring candidates need addressing to get a guideline compliant, select some by clicking on the ๐Ÿ”ฒ next to them. The risk profile below the candidates signals (โœ…) when it's enough! ๐Ÿ


Good luck and happy coding! :shipit: โœจ ๐Ÿ’ฏ

Any Chance for some documentation?

This looks like its a pretty comprehensive ECS, but I'm kinda struggling to make heads and tails of it (I'm fairly new to Go).

Any chance for some documentation for this little guy?

Cheers.

Refactor entity_manager.go

I've selected entity_manager.go for refactoring, which is a module of 67 lines of code that couples the top-level components tightly. Addressing this will make our codebase more maintainable and improve Better Code Hub's Couple Architecture Components Loosely guideline rating! ๐Ÿ‘

Here's the gist of this guideline:

  • Definition ๐Ÿ“–
    Minimize the amount of interface code; that is, code in modules that are both called from and call modules of other components ("throughput"), and code in modules that are called from modules of other components ("incoming").
  • Whyโ“
    Having loose coupling between top-level components makes it easier to maintain them in isolation.
  • How ๐Ÿ”ง
    You can hide a component's implementation details through various means, e.g. using the "abstract factory" design pattern.

You can find more info about this guideline in Building Maintainable Software. ๐Ÿ“–


โ„น๏ธ To know how many other refactoring candidates need addressing to get a guideline compliant, select some by clicking on the ๐Ÿ”ฒ next to them. The risk profile below the candidates signals (โœ…) when it's enough! ๐Ÿ


Good luck and happy coding! :shipit: โœจ ๐Ÿ’ฏ

Has method?

Hello! Along time ago I forked this library to work on it with some added changes, I stopped work on it. I noticed that there is no longer a entity.Has(componentType) method? What's the preferred way of doing this? For example:

	for _, entity := range entityManager.FilterByNames("StaticModelComponent", "TransformComponent", "PositionComponent") {
		model := entity.Get(components.MaskStaticModel).(*components.StaticModelComponent)
		transform := entity.Get(components.MaskTransform).(*components.TransformComponent)
		position := entity.Get(components.MaskPosition).(*components.PositionComponent)

		translation := raylib.NewMatrixTranslate(transform.Position.X, transform.Position.Y, transform.Position.Z)
		model.Model.Model.Transform = model.Model.Model.Transform.Multiply(translation)
		if entity.Has(MaskBoundingBox) {
			bb := entity.Get(MaskBoundingBox).(*components.BoundingBoxComponent)
			bb.BoundingBox.Min = bb.BoundingBox.Min.Add(transform.Position)
			bb.BoundingBox.Max = bb.BoundingBox.Max.Add(transform.Position)
		}
		position.Vector3 = transform.Position.Add(position.Vector3)
		entity.Remove(MaskTransform)
	}

Would something like this be added? Or would it be better to have another system that filters based on all four of them instead of having an if for one case?

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.