game

package
v0.0.0-...-de431f0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const RespDisconnect = "disconnected"

Variables

This section is empty.

Functions

func ActorCullBounds

func ActorCullBounds(center coord.Cell) coord.Bounds

func LoginAndConnectActor

func LoginAndConnectActor(loginConn PreLoginConn, actorConnector ActorConnector) error

func NewActor

func NewActor(id entity.Id, dsactor datastore.Actor, stateWriter InitialStateWriter) *actor

func NewSimShard

func NewSimShard(c ShardConfig) (*http.Server, error)

func NewSimulation

func NewSimulation(actorIndex *ActorIndexLocker, sim rpg2d.RunningSimulation) rpg2d.RunningSimulation

Types

type ActorEntityState

type ActorEntityState struct {
	Id entity.Id `json:"id"`

	Name string `json:"name"`

	// Movement and position
	Facing coord.Direction `json:"facing"`
	Cell   coord.Cell      `json:"cell"`

	PathAction *coord.PathActionState `json:"pathAction"`

	// Health and Mana
	Hp    int `json:"hp"`
	HpMax int `json:"hpMax"`
	Mp    int `json:"mp"`
	MpMax int `json:"mpMax"`
	// contains filtered or unexported fields
}

func (ActorEntityState) Bounds

func (e ActorEntityState) Bounds() coord.Bounds

func (ActorEntityState) EntityId

func (e ActorEntityState) EntityId() entity.Id

func (ActorEntityState) IsDifferentFrom

func (e ActorEntityState) IsDifferentFrom(other entity.State) (different bool)

type ActorIndex

type ActorIndex map[rpg2d.ActorId]*actor

Store actor's indexed by id

type ActorIndexLocker

type ActorIndexLocker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A wrapper for actorIndex that provides safety for concurrent access.

func NewActorIndexLocker

func NewActorIndexLocker(around ActorIndex) *ActorIndexLocker

func (*ActorIndexLocker) Lock

func (m *ActorIndexLocker) Lock() ActorIndex

func (*ActorIndexLocker) RLock

func (m *ActorIndexLocker) RLock() ActorIndex

func (*ActorIndexLocker) Unlock

func (m *ActorIndexLocker) Unlock(index ActorIndex)

type AssailEntityState

type AssailEntityState struct {
	Type string `json:"type"`

	Id entity.Id `json:"id"`

	SpawnedBy entity.Id  `json:"spawnedBy"`
	SpawnedAt stime.Time `json:"spawnedAt"`

	Cell coord.Cell `json:"cell"`
}

func (AssailEntityState) Bounds

func (e AssailEntityState) Bounds() coord.Bounds

func (AssailEntityState) EntityId

func (e AssailEntityState) EntityId() entity.Id

func (AssailEntityState) IsDifferentFrom

func (e AssailEntityState) IsDifferentFrom(entity.State) bool

type ChatRequest

type ChatRequest struct {
	ChatRequestType
	stime.Time
	Msg string
}

type ChatRequestType

type ChatRequestType int
const (
	CR_ERROR ChatRequestType = iota
	CR_SAY
	CR_SIZE
)

func (ChatRequestType) String

func (i ChatRequestType) String() string

type ClientSettings

type ClientSettings struct {
	JsMain       string
	WebsocketURL string
	Simulation   SimulationSettings
}

A set of data that the index page template will have access to when it is executed.

type Conn

type Conn interface {
	EncodeAndSend(EncodedType, interface{}) error
	ReadNextType() (EncodedType, error)
	Decode(interface{}) error
}

func NewGobConn

func NewGobConn(rw io.ReadWriter) Conn

type ConnectedActorConn

type ConnectedActorConn interface {
	HandleIO() error
}

type DiffWriter

type DiffWriter interface {
	WriteWorldStateDiff(rpg2d.WorldStateDiff)
}

type EncodedType

type EncodedType int

Used to determine the next type that's in the buffer so we can decode it into a real value. We'll decode an encoded type and switch on its value so we'll have the correct value to decode into.

const (
	ET_ERROR EncodedType = iota
	ET_DISCONNECT

	ET_REQ_LOGIN
	ET_REQ_CREATE

	ET_RESP_ACTOR_ALREADY_CONNECTED
	ET_RESP_AUTH_FAILED
	ET_RESP_ACTOR_EXISTS
	ET_RESP_ACTOR_DOESNT_EXIST

	ET_RESP_LOGIN_SUCCESS
	ET_RESP_CREATE_SUCCESS

	ET_REQ_CONNECT
	ET_CONNECTED

	ET_WORLD_STATE
	ET_WORLD_STATE_DIFF

	ET_REQ_MOVE
	ET_REQ_USE
	ET_REQ_CHAT
)

func (EncodedType) String

func (i EncodedType) String() string

type InitialStateWriter

type InitialStateWriter interface {
	WriteWorldState(rpg2d.WorldState) DiffWriter
}

type InputReceiver

type InputReceiver interface {
	SubmitMoveRequest(MoveRequest)
	SubmitUseRequest(UseRequest)
	SubmitChatRequest(ChatRequest)

	Close()
}

type LoggedInConn

type LoggedInConn interface {
	HandleConnect(ActorConnector) (ConnectedActorConn, error)
}

type MoveRequest

type MoveRequest struct {
	MoveRequestType
	stime.Time
	coord.Direction
}

type MoveRequestType

type MoveRequestType int
const (
	MR_ERROR MoveRequestType = iota
	MR_MOVE
	MR_MOVE_CANCEL
	MR_SIZE
)

func (MoveRequestType) String

func (i MoveRequestType) String() string

type PreLoginConn

type PreLoginConn interface {
	HandleLogin() (LoggedInConn, error)
}

func NewPreLoginConn

func NewPreLoginConn(conn Conn, ds datastore.Datastore) PreLoginConn

type ReqConnect

type ReqConnect struct{ Name string }

type ReqCreate

type ReqCreate struct{ Name, Password string }

type ReqLogin

type ReqLogin struct{ Name, Password string }

type RespActorAlreadyConnected

type RespActorAlreadyConnected struct{ Name string }

type RespActorDoesntExist

type RespActorDoesntExist struct{ Name, Password string }

type RespActorExists

type RespActorExists struct{ Name string }

type RespAuthFailed

type RespAuthFailed struct{ Name string }

type RespCreateSuccess

type RespCreateSuccess struct{ Name string }

type RespLoginSuccess

type RespLoginSuccess struct{ Name string }

type SayEntityState

type SayEntityState struct {
	Type string `json:"type"`

	Id entity.Id `json:"id"`

	SaidBy entity.Id  `json:"saidBy"`
	SaidAt stime.Time `json:"saidAt"`

	Cell coord.Cell `json:"cell"`

	Msg string `json:"msg"`
}

func (SayEntityState) Bounds

func (e SayEntityState) Bounds() coord.Bounds

func (SayEntityState) EntityId

func (e SayEntityState) EntityId() entity.Id

func (SayEntityState) IsDifferentFrom

func (e SayEntityState) IsDifferentFrom(other entity.State) bool

type ShardConfig

type ShardConfig struct {
	// Flag whether the server is running from heroku
	OnHeroku bool

	// FQDN that the server is running at
	Domain,

	Port,

	JsDir,

	JsMain,

	AssetDir,

	CssDir string

	// A template for the index page. The template
	// will be executed with a game.ClientSettings{} struct.
	IndexTmpl *template.Template

	// A mux that http server will use. Is provided so the
	// user can extend the server with additional routes.
	Mux *http.ServeMux

	// A handler that will be used instead of the Mux
	// when setting the Handler field of the *http.Server.
	// If Handler is nil, the Mux will be used instead.
	Handler http.Handler
}

type SimulationSettings

type SimulationSettings struct {
	Width, Height int
}

Part of the ClientSettings that are rpg2d.Simulation specific

type UseRequest

type UseRequest struct {
	UseRequestType
	stime.Time
	Skill string
}

type UseRequestType

type UseRequestType int
const (
	UR_ERROR UseRequestType = iota
	UR_USE
	UR_USE_CANCEL
	UR_SIZE
)

func (UseRequestType) String

func (i UseRequestType) String() string

type WallEntityState

type WallEntityState struct {
	Type string     `json:"type"`
	Id   entity.Id  `json:"id"`
	Cell coord.Cell `jsonZ:"cell"`
}

func (WallEntityState) Bounds

func (w WallEntityState) Bounds() coord.Bounds

func (WallEntityState) EntityId

func (w WallEntityState) EntityId() entity.Id

func (WallEntityState) IsDifferentFrom

func (w WallEntityState) IsDifferentFrom(entity.State) bool

Directories

Path Synopsis
bot

Jump to

Keyboard shortcuts

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