62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
/*
|
|
Package gohan provides an Entity Component System framework for Ebiten.
|
|
|
|
An example game is available at /examples/twinstick, which may be built by
|
|
executing the following command (in /examples/twinstick):
|
|
|
|
go build -tags example .
|
|
|
|
Entity
|
|
|
|
A general-purpose object, which consists of a unique ID, starting with 1.
|
|
|
|
Component
|
|
|
|
The raw data for one aspect of an object, and how it interacts with the world.
|
|
Each component is assigned a unique ID, starting with 1.
|
|
|
|
type ExampleComponent struct {
|
|
X, Y float64
|
|
}
|
|
|
|
System
|
|
|
|
Each system runs continuously, performing actions on every Entity that fits
|
|
each systems' set of required matching components.
|
|
|
|
type ExampleSystem struct {
|
|
Position *component.PositionComponent // Required component.
|
|
Velocity *component.VelocityComponent // Required component.
|
|
Sprite *component.SpriteComponent `gohan:"?"` // Optional component.
|
|
Enabled bool `gohan:"-"` // Not a component.
|
|
}
|
|
|
|
Component Design Guidelines
|
|
|
|
Components are located in a separate package, typically named component. They
|
|
should be public (start with an uppercase letter) and may be of any type.
|
|
Using only struct types (with zero or more public fields) and accessing the
|
|
structs via pointer is recommended. Components should not have any logic (i.e. game code)
|
|
within them, as all logic should be implemented within a system.
|
|
|
|
System Design Guidelines
|
|
|
|
Systems are located in a separate package, typically named system. They should
|
|
be private (start with a lowercase letter) and offer an instantiation function
|
|
named as follows: NewSystemNameHere(). Data should be stored within components
|
|
attached to one or more entities, rather than within the systems themselves.
|
|
References to components must not be maintained outside each Update and Draw
|
|
call, or else the application will encounter race conditions.
|
|
|
|
Environment Variables
|
|
|
|
Running an application with the environment variable GOHAN_DEBUG set to 1
|
|
enables verification of systems' access to components. This verification is
|
|
disabled by default for performance reasons. While verification is enabled,
|
|
if a system attempts to access a component which is not included in the
|
|
system's Needs or Uses, the application will panic and print information about
|
|
the illegal component access. Setting GOHAN_DEBUG to 1 will also enable
|
|
printing system registration events and statistics.
|
|
*/
|
|
package gohan
|