world

package
v0.0.0-...-9f892bc Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2014 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

world document

world project world.go

Index

Constants

View Source
const (
	CA_INSANE_LENGTH = CreatureActorError(iota)
	CA_INSANE_BIJECTION
	CA_CREATURE_ALREADY_IN
	CA_ACTOR_ALREADY_IN
)
View Source
const (
	CL_NOOP = CreatureLocationError(iota)
	CL_INSANE_LENGTH
	CL_INSANE_BIJECTION
	CL_CREATURE_ALREADY_IN
	CL_LOCATION_ALREADY_IN
	CL_NOT_FOUND
	CL_OCCUPIED
)

Variables

This section is empty.

Functions

func BACK

func BACK() relativeDirection

func EAST

func EAST() absoluteDirection

Absolute directions.

func FRONT

func FRONT() relativeDirection

Relative directions.

func LEFT

func LEFT() relativeDirection

func NORTH

func NORTH() absoluteDirection
func RIGHT() relativeDirection

func SOUTH

func SOUTH() absoluteDirection

func WEST

func WEST() absoluteDirection

Types

type AbsoluteDirection

type AbsoluteDirection interface {

	// Returns 0, 1, 2 or 3 for EAST, NORTH, WEST and SOUTH.
	Value() int
	// Apply a relative direction to an absolute direction to get another absolute
	// direction.  For example, LEFT of WEST is SOUTH.
	Add(b RelativeDirection) AbsoluteDirection
	// Returns the X and Y increments corresponding to the current direction.
	// For example, `EAST.DxDy()` returns `1, 0`.  Because moving east increments
	// your x and leaves y alone.  `SOUTH.DxDy()` returns `0, -1`, because south
	// points toward negative y.
	DxDy() (Coord, Coord)
	// contains filtered or unexported methods
}

Relative directions can be applied to absolute directions to get a new absolute direction.

type Actor

type Actor struct{}

An Actor is anything that can be at the origin of an Action (see the IA package for Actions). It can be a creature, a trap, a mechanism, etc. An Actor is not aware of its unique identifier, you have to keep track of it yourself.

func MakeActor

func MakeActor() Actor

MakeActor creates, initializes and returns an Actor.

type ActorID

type ActorID uint64

ActorID is used as a unique identifier for an Actor.

type ActorSchedule

type ActorSchedule struct {
	Actor_times          []ActorTime
	Next_stability_index uint64 // To ensure stable sorting.
}

func MakeActorSchedule

func MakeActorSchedule() ActorSchedule

func (ActorSchedule) Add

func (self ActorSchedule) Add(actor_id ActorID, time uint64) ActorSchedule

func (ActorSchedule) Copy

func (self ActorSchedule) Copy() ActorSchedule

func (ActorSchedule) Len

func (self ActorSchedule) Len() int

Implement sort.Interface.

func (ActorSchedule) Less

func (self ActorSchedule) Less(i, j int) bool

func (ActorSchedule) Next

func (self ActorSchedule) Next(time uint64) (ActorTime, bool)

Find an actor that should be acting at the provided time. Brute force search that does ot assume that the actors are sorted by time.

func (ActorSchedule) Pos

func (self ActorSchedule) Pos(actor_time ActorTime) int

func (ActorSchedule) PosActorID

func (self ActorSchedule) PosActorID(actor_id ActorID) int

func (ActorSchedule) Remove

func (self ActorSchedule) Remove(actor_time ActorTime) (ActorSchedule, bool)

func (ActorSchedule) Swap

func (self ActorSchedule) Swap(i, j int)

type ActorTime

type ActorTime struct {
	Time            uint64
	Actor_id        ActorID
	Stability_index uint64 // To ensure stable sorting.
}

type Actors

type Actors struct {
	// NextIDprivate is exported only so that it can be encoded by gob.
	// Do not use.
	// It starts at 0 and increases each time the Add method is called.
	NextIDprivate ActorID
	// ContentPrivate is exported only so that it can be encoded by gob.
	// Do not use.  Use the Actors.Content() method instead.
	ContentPrivate map[ActorID]Actor
}

An Actors object holds a collection of Actor objects s identified by an ActorID. It contains a map of Actors indexed by their unique identifier. It also manages unique identifiers. Use the Add method to get a new unique identifier for an Actor.

func MakeActors

func MakeActors() Actors

MakeActors creates and returns an empty collection of Actors.

func (Actors) Add

func (actors Actors) Add(actor Actor) (Actors, ActorID)

Add returns a new Actors object to which the given Actor actor is added. The method also returns the ActorID that was given to actor.

func (Actors) Content

func (actors Actors) Content() map[ActorID]Actor

Content returns a copy of the private map[ActorID]Actor.

func (Actors) Copy

func (actors Actors) Copy() Actors

Copy returns a deep-copy of the Actors receiver.

func (Actors) Delete

func (actors Actors) Delete(actorID ActorID) Actors

Delete returns a new Actors object from which the entry corresponding to the provided actorID is deleted. If actorID does not exist, this method panics.

func (Actors) Replace

func (actors Actors) Replace(actorID ActorID, actor Actor) Actors

Replace returns a new Actors object in which the Actor actor is given the ActorID actorID. There must be an existing Actor with this ID. If not, this method panics.

type BaseBuilding

type BaseBuilding struct {
	// Underscore means that this field is public but should not be used.
	// Please use the Model() function to read it, and do NOT change it.
	// It is public only because Gob requires it.  I may spend time writing
	// a GobEncoder later to hide this field again, but I do not want to
	// spend time maintaining code that is still so likely to change.
	Model_ ModelId
}

func MakeBaseBuilding

func MakeBaseBuilding(model ModelId) BaseBuilding

func (BaseBuilding) Model

func (self BaseBuilding) Model() ModelId

type Building

type Building interface {
	Model() ModelId
}

type Buildings

type Buildings map[Location]Building

func MakeBuildings

func MakeBuildings() Buildings

func (Buildings) Copy

func (src Buildings) Copy() Buildings

Making copies is required to produce updated version of maps.

func (Buildings) Delete

func (src Buildings) Delete(x, y Coord) Buildings

func (Buildings) Get

func (src Buildings) Get(x, y Coord) (Building, bool)

func (Buildings) Set

func (src Buildings) Set(x, y Coord, value Building) Buildings

type Coord

type Coord int

Used to represent either an absolute position, or a relative position. Kind of messy compared with the rotations. However, the x and y coordinates are easy to get right, as their algebra is not modulo 4, so I do not need a safety net in the form of type checking here.

type Creature

type Creature struct {
	F AbsoluteDirection
}

func MakeCreature

func MakeCreature() Creature

func (Creature) Facing

func (self Creature) Facing() AbsoluteDirection

Implement Facer interface.

type CreatureActor

type CreatureActor struct {
	// Upper case for debugging and for Gob, not so that you use it.
	Ca map[CreatureId]ActorID
	Ac map[ActorID]CreatureId
}

func MakeCreatureActor

func MakeCreatureActor() CreatureActor

func (CreatureActor) Add

func (self CreatureActor) Add(creature_id CreatureId, actor_id ActorID) (CreatureActor, error)

func (CreatureActor) Copy

func (self CreatureActor) Copy() CreatureActor

func (CreatureActor) GetActor

func (self CreatureActor) GetActor(creature_id CreatureId) (ActorID, bool)

func (CreatureActor) GetCreature

func (self CreatureActor) GetCreature(actor_id ActorID) (CreatureId, bool)

func (CreatureActor) IsSane

func (self CreatureActor) IsSane() error

func (CreatureActor) RemoveActor

func (self CreatureActor) RemoveActor(actor_id ActorID) (CreatureActor, bool)

func (CreatureActor) RemoveCreature

func (self CreatureActor) RemoveCreature(creature_id CreatureId) (CreatureActor, bool)

type CreatureActorError

type CreatureActorError int

func (CreatureActorError) Error

func (self CreatureActorError) Error() string

type CreatureId

type CreatureId uint64

Each creature in the world is identified with a unique ID. A creature does not know its own ID. This is to avoid inconsistencies. Indeed, creatures are contained in a map[CreatureId]Creature.

type CreatureLocation

type CreatureLocation struct {
	Cl map[CreatureId]Location
	Lc map[Location]CreatureId
}

func MakeCreatureLocation

func MakeCreatureLocation() CreatureLocation

func (CreatureLocation) Add

func (self CreatureLocation) Add(creature_id CreatureId, location Location) (CreatureLocation, error)

func (CreatureLocation) Copy

func (self CreatureLocation) Copy() CreatureLocation

func (CreatureLocation) GetCreature

func (self CreatureLocation) GetCreature(loc Location) (CreatureId, bool)

func (CreatureLocation) GetLocation

func (self CreatureLocation) GetLocation(creature_id CreatureId) (Location, bool)

func (CreatureLocation) IsSane

func (self CreatureLocation) IsSane() error

func (CreatureLocation) Move

func (self CreatureLocation) Move(creature_id CreatureId, location Location) (CreatureLocation, error)

func (CreatureLocation) RemoveCreature

func (self CreatureLocation) RemoveCreature(creature_id CreatureId) (CreatureLocation, bool)

func (CreatureLocation) RemoveLocation

func (self CreatureLocation) RemoveLocation(location Location) (CreatureLocation, bool)

type CreatureLocationError

type CreatureLocationError int

func (CreatureLocationError) Error

func (self CreatureLocationError) Error() string

type Creatures

type Creatures struct {
	Next_id CreatureId
	Content map[CreatureId]Creature
}

func MakeCreatures

func MakeCreatures() Creatures

func (Creatures) Add

func (self Creatures) Add(creature Creature) (Creatures, CreatureId)

func (Creatures) Copy

func (self Creatures) Copy() Creatures

func (Creatures) Get

func (self Creatures) Get(creature_id CreatureId) (Creature, bool)

func (Creatures) Set

func (self Creatures) Set(creature_id CreatureId, creature Creature) Creatures

func (Creatures) Spawn

func (self Creatures) Spawn() (Creatures, CreatureId, Creature)

type Dynamic

type Dynamic struct {
	T0 uint64 // Date of birth
}

func (Dynamic) Mesh

func (self Dynamic) Mesh(t uint64) []float64

func (Dynamic) ModelMat

func (self Dynamic) ModelMat(t uint64) glm.Matrix4

type Facer

type Facer interface {
	Facing() AbsoluteDirection
}

type Floor

type Floor struct {
	OrientedBuilding
	MaybePassable
}

func MakeFloor

func MakeFloor(model ModelId, facing AbsoluteDirection, passable bool) Floor

type Level

type Level struct {
	Floors           Buildings
	Ceilings         Buildings
	Walls            [4]Buildings // Sorted by facing.
	Columns          Buildings
	Dynamic          Dynamic
	Actors           Actors
	Creatures        Creatures
	CreatureLocation CreatureLocation
	CreatureActor    CreatureActor
	ActorSchedule    ActorSchedule
}

func MakeLevel

func MakeLevel() Level

func (Level) ActorLocation

func (self Level) ActorLocation(actor_id ActorID) (Location, bool)

func (Level) ActorPosition

func (self Level) ActorPosition(actor_id ActorID) (Position, bool)

func (*Level) IsPassable

func (level *Level) IsPassable(location Location, direction AbsoluteDirection) bool

func (Level) SetActorSchedule

func (self Level) SetActorSchedule(actor_schedule ActorSchedule) Level

type Location

type Location struct {
	X, Y Coord
}

func (Location) MoveAbsolute

func (self Location) MoveAbsolute(absdir AbsoluteDirection, steps int) Location

func (Location) SetX

func (self Location) SetX(x Coord) Location

func (Location) SetY

func (self Location) SetY(y Coord) Location

func (Location) ToPosition

func (self Location) ToPosition(facing AbsoluteDirection) Position

type MaybePassable

type MaybePassable struct {
	Passable_ bool
}

func (MaybePassable) IsPassable

func (self MaybePassable) IsPassable() bool

type ModelId

type ModelId uint16

This should go into a package that knows about models.

type OrientedBuilding

type OrientedBuilding struct {
	BaseBuilding
	F AbsoluteDirection
}

func MakeOrientedBuilding

func MakeOrientedBuilding(model ModelId, facing AbsoluteDirection) OrientedBuilding

func (OrientedBuilding) Facing

func (building OrientedBuilding) Facing() AbsoluteDirection

type Position

type Position struct {
	Location
	F AbsoluteDirection
}

func (Position) Facing

func (self Position) Facing() AbsoluteDirection

func (Position) MoveAbsolute

func (self Position) MoveAbsolute(absdir AbsoluteDirection, steps int) Position

func (Position) MoveBackward

func (self Position) MoveBackward(steps int) Position

func (Position) MoveForward

func (self Position) MoveForward(steps int) Position

func (Position) MoveLeft

func (self Position) MoveLeft(steps int) Position

func (Position) MoveRelative

func (self Position) MoveRelative(reldir RelativeDirection, steps int) Position

func (Position) MoveRight

func (self Position) MoveRight(steps int) Position

func (Position) SetF

func (self Position) SetF(f AbsoluteDirection) Position

func (Position) SetLocation

func (self Position) SetLocation(location Location) Position

func (Position) SetX

func (self Position) SetX(x Coord) Position

func (Position) SetY

func (self Position) SetY(y Coord) Position

func (Position) ToLocation

func (self Position) ToLocation() Location

func (Position) Turn

func (self Position) Turn(rel_dir RelativeDirection, steps int) Position

type RelativeDirection

type RelativeDirection interface {

	// Returns 0, 1, 2 or 3 for FRONT, LEFT, BACK or RIGHT.
	Value() int
	// Returns -1 for LEFT, +1 for RIGHT, 0 for the rest.
	Sign() int
	// Combines two relative directions together.
	Add(rel RelativeDirection) RelativeDirection
	// contains filtered or unexported methods
}

The rotation arithmetics is abstracted behind these two interfaces. You can combine relative directions together. For example, left of left is back. Back of right is left. Note that this is commutative: right of back is left too.

type Wall

type Wall struct {
	BaseBuilding
	MaybePassable
}

func MakeWall

func MakeWall(model ModelId, passable bool) Wall

type World

type World struct {
	Player_id ActorID // Later, there will also be a LevelId too in here.
	Level     Level   // Later, there will be many.
	Time      uint64  // Nanoseconds.
}

func Load

func Load() (*World, error)

func MakeWorld

func MakeWorld() World

func (*World) Save

func (world *World) Save() error

func (World) SetActorSchedule

func (world World) SetActorSchedule(actor_schedule ActorSchedule) World

func (World) SetTime

func (world World) SetTime(time uint64) World

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL