world

package
Version: v0.0.0-...-9e256ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeathTypeBorder    = "border"    // Never Player or Entity
	DeathTypeTerrain   = "terrain"   // Never Player or Entity
	DeathTypeCollision = "collision" // requires Player or Entity
	DeathTypeRamming   = "ramming"   // requires Player
	DeathTypeSinking   = "sinking"   // requires Player and Entity
)
View Source
const (
	EntityKindInvalid    = EntityKind(invalidEnumChoice)
	EntitySubKindInvalid = EntitySubKind(invalidEnumChoice)
	EntityTypeInvalid    = EntityType(invalidEnumChoice)
)
View Source
const (
	PlayerIDInvalid     = PlayerID(0)
	PlayerNameLengthMin = 3
	PlayerNameLengthMax = 12
)
View Source
const (
	TeamCodeBase    = 36
	TeamCodeInvalid = TeamCode(0)
	TeamIDInvalid   = TeamID(0)
	TeamIDLengthMin = 1
	TeamIDLengthMax = 6
	TeamMembersMax  = 6
)

No team

View Source
const (
	TickPeriod     = time.Second / 10
	TicksPerSecond = Ticks(time.Second / TickPeriod)
	TicksPerDamage = 60 * TicksPerSecond // i.e. one damage takes one minute to regen
	TicksMax       = Ticks(math32.MaxUint16)
)
View Source
const (
	// MeterPerSecond is 1 m/s
	MeterPerSecond Velocity = 1 << 5
	VelocityMax             = math32.MaxInt16 / float32(MeterPerSecond)
	VelocityMin             = math32.MinInt16 / float32(MeterPerSecond)
)
View Source
const (
	MinRadius = 500

	// Worlds grow this much larger than requested radius
	// Entities outside this * radius die instantly, to protect the world
	RadiusClearance = 1.1

	// PlayerSpace Target space (square meters) per each
	PlayerSpace   = 350000
	CrateSpace    = 30000
	ObstacleSpace = 1000000
)
View Source
const AltitudeCollisionThreshold = 0.25

Entities within this of eachother's altitudes can collide

View Source
const EntityIDInvalid = EntityID(0)
View Source
const Pi = 32768

Variables

View Source
var (
	BoatLevelMax           uint8
	EntityRadiusMax        float32
	EntityTypeCount        int
	BoatEntityTypesByLevel [][]EntityType
)
View Source
var (
	EntityKindAircraft    EntityKind
	EntityKindBoat        EntityKind
	EntityKindCollectible EntityKind
	EntityKindDecoy       EntityKind
	EntityKindObstacle    EntityKind
	EntityKindWeapon      EntityKind

	EntitySubKindBattleship  EntitySubKind
	EntitySubKindDepositor   EntitySubKind
	EntitySubKindDepthCharge EntitySubKind
	EntitySubKindDredger     EntitySubKind
	EntitySubKindHeli        EntitySubKind
	EntitySubKindHovercraft  EntitySubKind
	EntitySubKindPirate      EntitySubKind
	EntitySubKindMine        EntitySubKind
	EntitySubKindMissile     EntitySubKind
	EntitySubKindPlane       EntitySubKind
	EntitySubKindRam         EntitySubKind
	EntitySubKindRocket      EntitySubKind
	EntitySubKindSAM         EntitySubKind
	EntitySubKindShell       EntitySubKind
	EntitySubKindSonar       EntitySubKind
	EntitySubKindSubmarine   EntitySubKind
	EntitySubKindTanker      EntitySubKind
	EntitySubKindTorpedo     EntitySubKind

	EntityTypeBarrel      EntityType
	EntityTypeCoin        EntityType
	EntityTypeCrate       EntityType
	EntityTypeHQ          EntityType
	EntityTypeMark18      EntityType
	EntityTypeOilPlatform EntityType
	EntityTypeScrap       EntityType
)

Functions

func AreaOf

func AreaOf(playerCount int) float32

func Bench

func Bench(b *testing.B, create func(radius int) World, end int)

func CrateCountOf

func CrateCountOf(playerCount int) int

func Lerp

func Lerp(a, b, factor float32) float32

func LevelToScore

func LevelToScore(level uint8) int

levelToScore converts a boat level to a score required to upgrade score = (level^2 - 1) * 10 js must have same function

func ObstacleCountOf

func ObstacleCountOf(playerCount int) int

func RadiusOf

func RadiusOf(playerCount int) float32

func RandString

func RandString(n int) string

Returns random alphanumeric string of length n

func Test

func Test(t *testing.T, create func(radius int) World)

Types

type AABB

type AABB struct {
	Vec2f
	Width  float32 `json:"width"`
	Height float32 `json:"height"`
}

func AABBFrom

func AABBFrom(x, y, width, height float32) AABB

func (AABB) Contains

func (a AABB) Contains(b AABB) bool

Contains a fully contains b

func (AABB) CornerCoordinates

func (a AABB) CornerCoordinates() AABB

CornerCoordinates Center coords to corner coords

func (AABB) Intersects

func (a AABB) Intersects(b AABB) bool

Intersects a and b are intersecting

func (AABB) Quadrant

func (a AABB) Quadrant(quadrant int) AABB

Quadrant of a by index

func (AABB) Quadrants

func (a AABB) Quadrants() [4]AABB

Quadrants All quadrants of a

type Angle

type Angle uint16

Angle is a 2 byte fixed-point representation of an angle. To convert a float in radians to an Angle use ToAngle.

func RandomAngle

func RandomAngle() Angle

Returns a random angle (all possible angles are equally likely)

func ToAngle

func ToAngle(x float32) Angle

ToAngle converts a float in the range of an [MinInt32, MaxInt32] to an angle.

func (Angle) Abs

func (angle Angle) Abs() float32

func (Angle) ClampMagnitude

func (angle Angle) ClampMagnitude(m Angle) Angle

func (Angle) Diff

func (angle Angle) Diff(otherAngle Angle) (difference Angle)

func (Angle) Float

func (angle Angle) Float() float32

Float returns angle in range [-π, π)

func (Angle) Inv

func (angle Angle) Inv() Angle

func (Angle) Lerp

func (angle Angle) Lerp(otherAngle Angle, factor float32) Angle

func (Angle) MarshalJSON

func (angle Angle) MarshalJSON() ([]byte, error)

func (Angle) String

func (angle Angle) String() string

func (*Angle) UnmarshalJSON

func (angle *Angle) UnmarshalJSON(b []byte) error

func (Angle) Vec2f

func (angle Angle) Vec2f() Vec2f

type Armament

type Armament struct {
	Type            EntityType `json:"type"`
	Vertical        bool       `json:"vertical"`
	Length          float32    `json:"length"`
	Width           float32    `json:"width"`
	PositionForward float32    `json:"positionForward"`
	PositionSide    float32    `json:"positionSide"`
	Angle           Angle      `json:"angle"`
	Turret          *int       `json:"turret,omitempty"` // If non-nil, index of turret
}

Armament is the description of an armament in an EntityData. Armaments are not only weapons but also countermeasures.

func (*Armament) Reload

func (armament *Armament) Reload() Ticks

Reload returns the time it takes to reload an Armament in seconds.

func (*Armament) Similar

func (armament *Armament) Similar(other *Armament) bool

Similar returns if the Armament is on the same turret and the same type as other.

func (*Armament) TurretIndex

func (armament *Armament) TurretIndex() int

TurretIndex returns the index of the turret if it exists else -1.

type DeathReason

type DeathReason struct {
	Type   string     `json:"message,omitempty"`
	Player string     `json:"player,omitempty"`
	Entity EntityType `json:"entity,omitempty"`
}

Has a custom (but regular) jsoniter marshaler

func (*DeathReason) FromPlayer

func (reason *DeathReason) FromPlayer() bool

Returns whether the death was a result of player actions

type Entity

type Entity struct {
	Transform
	Guidance
	Owner *Player
	EntityType
	Ticks    Ticks
	EntityID EntityID
}

Entity is an object in the world such as a boat, torpedo, crate or oil platform. Its size is 32 bytes for optimal efficiency. Cannot modify EntityType directly. Entity.Ticks is either damage or lifespan depending on the entity's type. Cannot modify EntityID except in World.

func (*Entity) Active

func (entity *Entity) Active() bool

func (*Entity) AimTarget

func (entity *Entity) AimTarget() Vec2f

func (*Entity) Altitude

func (entity *Entity) Altitude() float32

-1 = deep, 0 = surface, 1 = high in the air

func (*Entity) AltitudeOverlap

func (entity *Entity) AltitudeOverlap(other *Entity) bool

Returns if entities have sufficiently similar altitudes to collide

func (*Entity) ArmamentConsumption

func (entity *Entity) ArmamentConsumption() []Ticks

func (*Entity) ArmamentTransform

func (entity *Entity) ArmamentTransform(index int) Transform

ArmamentTransform Returns world transform

func (*Entity) BelowKeel

func (entity *Entity) BelowKeel(terrain Terrain) float32

BelowKeel returns meters below keel.

func (*Entity) Camera

func (entity *Entity) Camera() (position Vec2f, visual, radar, sonar float32)

Camera is the combined Sensor view of an Entity.

func (*Entity) CanLand

func (entity *Entity) CanLand(parent *Entity) bool

func (*Entity) ClearSpawnProtection

func (entity *Entity) ClearSpawnProtection()

func (*Entity) Close

func (entity *Entity) Close()

Close is called when an Entity is removed from a World.

func (*Entity) Collides

func (entity *Entity) Collides(otherEntity *Entity, seconds float32) bool

Collides does a rectangle to rectangle collision with another Entity. Does not take into account altitude

func (*Entity) ConsumeArmament

func (entity *Entity) ConsumeArmament(index int)

func (*Entity) Damage

func (entity *Entity) Damage(damage Ticks) bool

Damage damages an entity and returns if it died.

func (*Entity) DamagePercent

func (entity *Entity) DamagePercent() float32

DamagePercent returns an Entity's damage in the range [0, 1.0].

func (*Entity) Hash

func (entity *Entity) Hash() float32

Hash returns a float in range [0, 1) based on the entity's id.

func (*Entity) HealthPercent

func (entity *Entity) HealthPercent() float32

HealthPercent returns an Entity's health in the range [0, 1.0].

func (*Entity) Initialize

func (entity *Entity) Initialize(entityType EntityType)

Initialize is called whenever a boat's type is set/changed.

func (*Entity) KillIn

func (entity *Entity) KillIn(ticks, killTime Ticks) bool

KillIn damages an entity enough to kill it in killTime Ticks.

func (*Entity) OwnerBoatAimTarget

func (entity *Entity) OwnerBoatAimTarget() Vec2f

When a weapon wants the turret target of the owner's ship

func (*Entity) Repair

func (entity *Entity) Repair(ticks Ticks)

Repair regenerates the Entity's health by an amount of Ticks.

func (*Entity) Replenish

func (entity *Entity) Replenish(amount Ticks)

Replenish replenishes the Entity's armaments by an amount. It starts with the ones that have the least time left. O(n^2) worst case if amount is very high.

func (*Entity) SetActive

func (entity *Entity) SetActive(val bool)

func (*Entity) SetAimTarget

func (entity *Entity) SetAimTarget(target Vec2f)

func (*Entity) SetAltitudeTarget

func (entity *Entity) SetAltitudeTarget(altitudeTarget float32)

func (*Entity) SpawnProtection

func (entity *Entity) SpawnProtection() float32

Returns value in the range [0,1] where 0 is full protection and 1 is no protection Intended to be multiplied by, for example, damage, to decrease damage taken while having been spawned recently

func (*Entity) TurretAngles

func (entity *Entity) TurretAngles() []Angle

func (*Entity) Update

func (entity *Entity) Update(ticks Ticks, worldRadius float32, terrain Terrain) (die bool)

Update updates all the variables of an Entity such as Position, Direction, ArmamentConsumption etc. by an amount of time. It only modifies itself so each one can be processed by a different goroutine. seconds cannot be > 1.0.

func (*Entity) UpdateSensor

func (entity *Entity) UpdateSensor(otherEntity *Entity)

UpdateSensor runs a simple AI for homing torpedoes/missiles.

type EntityID

type EntityID uint32

func AllocateEntityID

func AllocateEntityID(used func(id EntityID) bool) (uniqueID EntityID)

func (EntityID) AppendText

func (entityID EntityID) AppendText(buf []byte) []byte

func (EntityID) MarshalText

func (entityID EntityID) MarshalText() ([]byte, error)

func (EntityID) String

func (entityID EntityID) String() string

func (*EntityID) UnmarshalText

func (entityID *EntityID) UnmarshalText(text []byte) error

type EntityKind

type EntityKind enumChoice

EntityKind is the kind of an entity one of: boat, collectible, obstacle, and weapon.

func ParseEntityKind

func ParseEntityKind(s string) EntityKind

func (EntityKind) AppendText

func (entityKind EntityKind) AppendText(buf []byte) []byte

func (EntityKind) MarshalText

func (entityKind EntityKind) MarshalText() ([]byte, error)

func (EntityKind) String

func (entityKind EntityKind) String() string

func (*EntityKind) UnmarshalText

func (entityKind *EntityKind) UnmarshalText(text []byte) (err error)

type EntitySubKind

type EntitySubKind enumChoice

EntitySubKind is the sub-kind of an entity such as: depth charge, missile, MTB, score, shell, submarine, torpedo, etc.

func ParseEntitySubKind

func ParseEntitySubKind(s string) EntitySubKind

func (EntitySubKind) AppendText

func (entitySubKind EntitySubKind) AppendText(buf []byte) []byte

func (EntitySubKind) MarshalText

func (entitySubKind EntitySubKind) MarshalText() ([]byte, error)

func (EntitySubKind) String

func (entitySubKind EntitySubKind) String() string

func (*EntitySubKind) UnmarshalText

func (entitySubKind *EntitySubKind) UnmarshalText(text []byte) (err error)

type EntityType

type EntityType enumChoice

EntityType is the type of an entity such as: crate, fairmileD, etc.

func ParseEntityType

func ParseEntityType(s string) EntityType

func (EntityType) AppendText

func (entityType EntityType) AppendText(buf []byte) []byte

func (EntityType) Data

func (entityType EntityType) Data() *EntityTypeData

func (EntityType) MarshalText

func (entityType EntityType) MarshalText() ([]byte, error)

func (EntityType) MaxHealth

func (entityType EntityType) MaxHealth() Ticks

MaxHealth is the maximum health of an EntityType as Ticks.

func (EntityType) ReducedLifespan

func (entityType EntityType) ReducedLifespan(desiredLifespan Ticks) Ticks

Returns a lifespan to start an entity's life at, so as to make it expire in desiredLifespan ticks

func (EntityType) String

func (entityType EntityType) String() string

func (*EntityType) UnmarshalText

func (entityType *EntityType) UnmarshalText(text []byte) (err error)

func (EntityType) UpgradePaths

func (entityType EntityType) UpgradePaths(score int) (upgradePaths []EntityType)

func (EntityType) UpgradesTo

func (entityType EntityType) UpgradesTo(nextEntityType EntityType, score int) bool

type EntityTypeData

type EntityTypeData struct {
	// All units are SI (meters, seconds, etc.)
	Kind         EntityKind    `json:"kind"`
	SubKind      EntitySubKind `json:"subkind"`
	Level        uint8         `json:"level"`
	Limited      bool          `json:"limited"`
	NPC          bool          `json:"npc"` // only bots can use
	Lifespan     Ticks         `json:"lifespan"`
	Reload       Ticks         `json:"reload"` // time to reload
	Speed        Velocity      `json:"speed"`
	Length       float32       `json:"length"`
	Width        float32       `json:"width"`
	Draft        float32       `json:"draft"`
	Radius       float32       `json:"-"`
	InvSize      float32       `json:"-"`
	Damage       float32       `json:"damage"`       // health of ship, or damage dealt by weapon
	AntiAircraft float32       `json:"antiAircraft"` // chance aircraft is shot down per second
	Stealth      float32       `json:"stealth"`
	Sensors      Sensors       `json:"sensors"`
	Armaments    []Armament    `json:"armaments"`
	Turrets      []Turret      `json:"turrets"`
	Label        string        `json:"label"`
}

EntityTypeData is the description of an EntityType.

type Guidance

type Guidance struct {
	DirectionTarget Angle    `json:"directionTarget,omitempty"`
	VelocityTarget  Velocity `json:"velocityTarget,omitempty"`
}

type IDPlayerData

type IDPlayerData struct {
	PlayerData
	PlayerID PlayerID `json:"playerID,omitempty"`
}

type Player

type Player struct {
	PlayerData
	DeathReason     DeathReason
	DeathPos        Vec2f
	DeathTime       int64
	DeathVisual     float32 // if non-zero, in respawn animation
	DeathFromPlayer bool
	EntityID        EntityID
	// contains filtered or unexported fields
}

Player owns entities and has score

func (*Player) Camera

func (player *Player) Camera() (pos Vec2f, visual, radar, sonar float32)

Camera Returns the camera that a player has if their entity doesn't exist

func (Player) CanRespawnWithTeam

func (player Player) CanRespawnWithTeam() bool

Says nothing about whether player is in a team. Only whether they are allowed to respawn with it if it exists.

func (*Player) ClearDeath

func (player *Player) ClearDeath()

Clears all death related fields

func (*Player) ClearRespawn

func (player *Player) ClearRespawn()

ClearRespawn clears after-death camera

func (*Player) Died

func (player *Player) Died(entity *Entity)

func (*Player) Friendly

func (player *Player) Friendly(other *Player) bool

func (*Player) IDPlayerData

func (player *Player) IDPlayerData() IDPlayerData

func (*Player) PlayerID

func (player *Player) PlayerID() PlayerID

func (*Player) Respawning

func (player *Player) Respawning() bool

Respawning returns if player is currently in the respawn animation

type PlayerData

type PlayerData struct {
	Name   string `json:"name,omitempty"`
	Score  int    `json:"score,omitempty"`
	TeamID TeamID `json:"team,omitempty"`
}

func (*PlayerData) ScoreLess

func (data *PlayerData) ScoreLess(other *PlayerData) bool

func (PlayerData) String

func (data PlayerData) String() string

Formats player first as: [team] name (score)

type PlayerID

type PlayerID uintptr

PlayerID is the unique id of a Player

func (PlayerID) AppendText

func (playerID PlayerID) AppendText(buf []byte) []byte

func (PlayerID) MarshalText

func (playerID PlayerID) MarshalText() ([]byte, error)

func (*PlayerID) UnmarshalText

func (playerID *PlayerID) UnmarshalText(text []byte) error

type PlayerSet

type PlayerSet []*Player

PlayerSet Set with order

func (*PlayerSet) Add

func (set *PlayerSet) Add(player *Player)

func (*PlayerSet) AppendData

func (set *PlayerSet) AppendData(buf []IDPlayerData) []IDPlayerData

AppendData converts a PlayerSet to []IDPlayerData Uses append api to reuse old slice

func (*PlayerSet) Contains

func (set *PlayerSet) Contains(player *Player) bool

func (*PlayerSet) GetByID

func (set *PlayerSet) GetByID(playerID PlayerID) *Player

func (*PlayerSet) Len

func (set *PlayerSet) Len() int

func (*PlayerSet) Less

func (set *PlayerSet) Less(i, j int) bool

func (*PlayerSet) Pop

func (set *PlayerSet) Pop() interface{}

func (*PlayerSet) Push

func (set *PlayerSet) Push(x interface{})

func (*PlayerSet) Remove

func (set *PlayerSet) Remove(player *Player)

func (*PlayerSet) Swap

func (set *PlayerSet) Swap(i, j int)

type Sensor

type Sensor struct {
	Range float32 `json:"range"`
}

Sensor the description of a sensor in an EntityType.

type Sensors

type Sensors struct {
	Visual Sensor `json:"visual"`
	Radar  Sensor `json:"radar"`
	Sonar  Sensor `json:"sonar"`
}

func (Sensors) Any

func (sensors Sensors) Any() bool

func (Sensors) MaxRange

func (sensors Sensors) MaxRange() float32

type Team

type Team struct {
	JoinRequests PlayerSet
	Members      PlayerSet // First member is owner
	Code         TeamCode
}

Team A group of players on the same team

func (*Team) Create

func (team *Team) Create(owner *Player)

func (*Team) Full

func (team *Team) Full() bool

func (*Team) Owner

func (team *Team) Owner() *Player

Owner First member of team is owner

type TeamCode

type TeamCode uint32

TeamCode is a code that allows a Player to join a Team. Used with invite links.

func (TeamCode) AppendText

func (code TeamCode) AppendText(text []byte) []byte

func (TeamCode) MarshalText

func (code TeamCode) MarshalText() ([]byte, error)

func (TeamCode) String

func (code TeamCode) String() string

func (*TeamCode) UnmarshalText

func (code *TeamCode) UnmarshalText(text []byte) error

type TeamID

type TeamID uint64

TeamID is a fixed-length string Team name that needs to be unique Use uint64 for fast comparisons and can store TeamIDLengthMax bytes

func (TeamID) AppendText

func (teamID TeamID) AppendText(text []byte) []byte

func (TeamID) MarshalText

func (teamID TeamID) MarshalText() ([]byte, error)

func (TeamID) String

func (teamID TeamID) String() string

func (*TeamID) UnmarshalText

func (teamID *TeamID) UnmarshalText(text []byte) error

type Terrain

type Terrain interface {
	Collides(entity *Entity, seconds float32) bool
	AltitudeAt(Vec2f) float32
}

Avoid import cycle by not importing terrain directly

type Ticks

type Ticks uint16

Ticks is a time measured in updates. It wraps after 65535 (109.225 minutes or 109 torpedoes worth of damage).

func DamageToTicks

func DamageToTicks(damage float32) Ticks

func ToTicks

func ToTicks(seconds float32) Ticks

func (Ticks) ClampMin

func (ticks Ticks) ClampMin(m Ticks) Ticks

func (Ticks) Damage

func (ticks Ticks) Damage() float32

func (Ticks) Float

func (ticks Ticks) Float() float32

func (*Ticks) MarshalJSON

func (ticks *Ticks) MarshalJSON() ([]byte, error)

func (Ticks) SaturatingSub

func (ticks Ticks) SaturatingSub(t Ticks) Ticks

func (*Ticks) UnmarshalJSON

func (ticks *Ticks) UnmarshalJSON(b []byte) error

type Transform

type Transform struct {
	Position  Vec2f    `json:"position"`
	Velocity  Velocity `json:"velocity"` // TODO omitempty crashes client
	Direction Angle    `json:"direction"`
}

func ArmamentTransform

func ArmamentTransform(entityType EntityType, entityTransform Transform, turretAngles []Angle, index int) Transform

ArmamentTransform returns the world transform of an Armament.

func (Transform) Add

func (transform Transform) Add(otherTransform Transform) Transform

type Turret

type Turret struct {
	PositionForward float32 `json:"positionForward"`
	PositionSide    float32 `json:"positionSide"`
	Angle           Angle   `json:"angle"`
	AzimuthFL       Angle   `json:"azimuthFL"`
	AzimuthFR       Angle   `json:"azimuthFR"`
	AzimuthBL       Angle   `json:"azimuthBL"`
	AzimuthBR       Angle   `json:"azimuthBR"`
}

Turret is the description of a turret's relative transform in an EntityType.

func (*Turret) CheckAzimuth

func (turret *Turret) CheckAzimuth(curr Angle) bool

Returns true only if the parameter is within the turrets valid azimuth ranges

type Vec2f

type Vec2f struct {
	X float32 `json:"x"`
	Y float32 `json:"y"`
}

func (Vec2f) Abs

func (vec Vec2f) Abs() Vec2f

func (Vec2f) Add

func (vec Vec2f) Add(otherVec Vec2f) Vec2f

func (Vec2f) AddScaled

func (vec Vec2f) AddScaled(otherVec Vec2f, factor float32) Vec2f

func (Vec2f) Angle

func (vec Vec2f) Angle() Angle

func (Vec2f) Ceil

func (vec Vec2f) Ceil() Vec2f

func (Vec2f) Distance

func (vec Vec2f) Distance(otherVec Vec2f) float32

func (Vec2f) DistanceSquared

func (vec Vec2f) DistanceSquared(otherVec Vec2f) float32

func (Vec2f) Div

func (vec Vec2f) Div(divisor float32) Vec2f

func (Vec2f) Dot

func (vec Vec2f) Dot(otherVec Vec2f) float32

func (Vec2f) Floor

func (vec Vec2f) Floor() Vec2f

func (Vec2f) Length

func (vec Vec2f) Length() float32

func (Vec2f) LengthSquared

func (vec Vec2f) LengthSquared() float32

func (Vec2f) Lerp

func (vec Vec2f) Lerp(otherVec Vec2f, factor float32) Vec2f

func (Vec2f) Mul

func (vec Vec2f) Mul(factor float32) Vec2f

func (Vec2f) Norm

func (vec Vec2f) Norm() Vec2f

func (Vec2f) Rot180

func (vec Vec2f) Rot180() Vec2f

Rot180 rotates 180 degrees.

func (Vec2f) Rot90

func (vec Vec2f) Rot90() Vec2f

Rot90 rotates 90 degrees clockwise.

func (Vec2f) RotN90

func (vec Vec2f) RotN90() Vec2f

Rot90 rotates 90 degrees counterclockwise.

func (Vec2f) Round

func (vec Vec2f) Round() Vec2f

func (Vec2f) Sub

func (vec Vec2f) Sub(otherVec Vec2f) Vec2f

type Velocity

type Velocity int16

Velocity is a 11_5 fixed point representing any valid velocity.

func ToVelocity

func ToVelocity(x float32) Velocity

ToVelocity converts a float in m/s to a Velocity.

func (Velocity) AddClamped

func (vel Velocity) AddClamped(amount float32, mag Velocity) Velocity

AddClamped adds a float to a Velocity and clamps it to mag.

func (Velocity) ClampMagnitude

func (vel Velocity) ClampMagnitude(mag Velocity) Velocity

func (Velocity) ClampMin

func (vel Velocity) ClampMin(min Velocity) Velocity

func (Velocity) Float

func (vel Velocity) Float() float32

Float returns the Velocity as a float in m/s.

func (Velocity) MarshalJSON

func (vel Velocity) MarshalJSON() ([]byte, error)

func (Velocity) String

func (vel Velocity) String() string

func (*Velocity) UnmarshalJSON

func (vel *Velocity) UnmarshalJSON(b []byte) error

type World

type World interface {
	// AddEntity Adds a new entity to its sector
	// Cannot hold pointer after call is finished
	AddEntity(entity *Entity)

	// Count returns number of entities in the world
	// Cannot be called concurrently with writes
	Count() int

	// Debug Prints debug output to os.Stdout
	// Cannot be called concurrently with writes
	Debug()

	// EntityByID Gets an entity by its id
	// For reading and writing
	// Cannot hold pointers after call is finished
	EntityByID(entityID EntityID, callback func(entity *Entity) (remove bool))

	// ForEntities Iterates all the entities and returns if stopped early
	// For reading and writing
	// Cannot hold pointer after call is finished
	ForEntities(callback func(entity *Entity) (stop, remove bool)) bool

	// ForEntitiesInRadius Iterates all the entities in a radius and returns if stopped early
	// Only for reading so no adding or modifying entities
	// Cannot hold pointer after call is finished
	ForEntitiesInRadius(position Vec2f, radius float32, callback func(r float32, entity *Entity) (stop bool)) bool

	// ForEntitiesAndOthers Iterates all the entities and other entities in a radius and returns if stopped early
	// For reading and writing
	// Cannot hold pointers after call is finished
	// Cannot modify position of entities
	// If entities are added during iteration may not iterate them
	// Skips radii that are <= 0
	// Radii that are too big cause all sectors to be iterated
	ForEntitiesAndOthers(entityCallback func(entity *Entity) (stop bool, radius float32),
		otherCallback func(entity *Entity, otherEntity *Entity) (stop, remove, removeOther bool)) bool

	// Resize sets the max size of the World.
	// It may or may not reallocate parts of the World depending on the difference in radius.
	Resize(radius float32)

	// SetParallel Marks world as ready only for concurrent reads
	// Cannot remove or add during read only mode
	// Returns if can be read concurrently
	SetParallel(parallel bool) bool
}

World A world holds entities

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL