Documentation ¶
Index ¶
- Constants
- Variables
- func Buf(width, height int) tcell.CellBuffer
- func BufRune(buf tcell.CellBuffer, rune rune, style tcell.Style, pos Vec) tcell.CellBuffer
- func BufText(buf tcell.CellBuffer, text string, style tcell.Style, pos Vec) tcell.CellBuffer
- func CLog(data ...interface{})
- func CLogErr(err error)
- func CloseLogs()
- func Connect()
- func FillBufRune(rune rune, style tcell.Style) tcell.CellBuffer
- func Host()
- func InitLogs()
- func Run()
- func SLog(data ...interface{})
- func SLogErr(err error)
- func Singleplayer()
- type AttackComponent
- type Callback
- type Cell
- type CellDatComp
- type ClickEvent
- type Client
- type ClientCommandEvent
- type Closer
- type Component
- type DestroyWinEvent
- type ECS
- func (ECS *ECS) AddCell(cell *Cell)
- func (ECS *ECS) AddEmpire(name string, pos Vec, dirty bool)
- func (ECS *ECS) AddEntity(Entity *Entity, components ...Component)
- func (ECS *ECS) AddPlayer(name string) uint32
- func (ECS *ECS) AddSettlement(settlement *Settlement) uint32
- func (ECS *ECS) AddState(state *State) uint32
- func (ECS *ECS) AddUnit(unit *Unit) uint32
- func (ECS *ECS) Close()
- func (ECS *ECS) CreateCell(pos Vec, cellType uint32, dirty bool) *Cell
- func (ECS *ECS) CreateSettlement(name string, pos Vec, dirty bool) *Settlement
- func (ECS *ECS) CreateState(id string, dirty bool) *State
- func (ECS *ECS) CreateUnit(pos Vec, dirty bool) *Unit
- func (ECS *ECS) Event(Event Event)
- func (ECS *ECS) GetEntity(id uint32) *Entity
- func (ECS *ECS) GetEntityComponents(id uint32) []Component
- func (ECS *ECS) Init()
- func (ECS *ECS) NewEntity(tag string) *Entity
- func (ECS *ECS) RegisterEntity(tag string, t reflect.Type, components reflect.Value)
- func (ECS *ECS) RegisterSystem(System System)
- func (ECS *ECS) SerializeEntity(id uint32) string
- func (ECS *ECS) Sys() []System
- func (ECS *ECS) Update()
- type Empire
- type EmpireStatsComp
- type EmpireStatsEvent
- type EmpireSys
- type Entity
- type Event
- type EventBase
- type GameInterface
- type HealthComponent
- type Initialiser
- type InputData
- type MovementComp
- type MovementSys
- type NetworkSys
- func (N *NetworkSys) AddEntity(Entity *Entity, SyncComp *SyncComp)
- func (N *NetworkSys) Broadcast(command ServerCommandEvent)
- func (N *NetworkSys) Close()
- func (N *NetworkSys) Direct(clientID int, command ServerCommandEvent)
- func (N *NetworkSys) Dispatch(command ServerCommandEvent)
- func (N *NetworkSys) Init()
- func (N *NetworkSys) ListenClientCommandEvent(command ClientCommandEvent)
- func (N *NetworkSys) ListenServerCommandEvent(command ServerCommandEvent)
- func (N *NetworkSys) PollClientCommands()
- func (N *NetworkSys) PollClientConnections()
- func (N *NetworkSys) PollServerCommands()
- func (N *NetworkSys) Priority() int
- func (N *NetworkSys) Remove()
- func (N *NetworkSys) Update()
- type NewWinEvent
- type NextTurnEvent
- type Player
- type PlayerStatsComp
- type PlayerSys
- type PosComp
- type Prioritiser
- type RenderComp
- type RendererSys
- type Screen
- func (Screen *Screen) CalculateMouseDepth() int
- func (Screen *Screen) Char(r rune, pos Vec, style tcell.Style, view uint8, depth int)
- func (Screen *Screen) Close()
- func (Screen *Screen) Draw()
- func (Screen *Screen) Init()
- func (Screen *Screen) Poll()
- func (Screen *Screen) Rect(r rune, pos Vec, width, height int, style tcell.Style, fill bool, view uint8, ...)
- func (Screen *Screen) Resize()
- func (Screen *Screen) ScreenToWorld(v Vec) Vec
- func (Screen *Screen) Text(text string, pos Vec, style tcell.Style, view uint8, depth int)
- func (Screen *Screen) WorldToScreen(v Vec) Vec
- type Server
- type ServerCommandEvent
- type Settlement
- type SettlementStatsComp
- type SettlementSys
- type State
- type StateComp
- type StateSys
- func (S *StateSys) AddEntity(Entity *Entity, SyncComp *SyncComp, StateComp *StateComp)
- func (S *StateSys) Init()
- func (S *StateSys) ListenClientCommandEvent(event ClientCommandEvent)
- func (S *StateSys) ListenServerCommandEvent(event ServerCommandEvent)
- func (S *StateSys) Remove()
- func (S *StateSys) Update()
- type SyncAction
- type SyncComp
- type SyncComponentContainer
- type SyncEntityContainer
- type System
- type SystemBase
- type Text
- type Transform
- type UI
- type UIManager
- func (UIManager *UIManager) AddUI(id string, ui UI)
- func (UIManager *UIManager) Draw()
- func (UIManager *UIManager) GetText(id string) *Text
- func (UIManager *UIManager) NewText(id, text string, enabled bool, pos Vec, view uint8, style tcell.Style, ...) *Text
- func (UIManager *UIManager) NewWin(id string, enabled bool, pos Vec) *Window
- func (U *UIManager) Remove(id string)
- func (UIManager *UIManager) SetText(id, text string)
- func (UIManager *UIManager) SetWinText(winID, id, text string)
- func (UIManager *UIManager) WinRemoveText(id string, textIDs ...string)
- type UISys
- type UITemplate
- type Unit
- type UnitSys
- type Vec
- type Window
- func (Window *Window) Draw()
- func (Window *Window) NewText(id string, text interface{}, style tcell.Style, callback Callback)
- func (Window *Window) RemoveText(textIDs ...string)
- func (Window *Window) UpdateSize()
- func (Window *Window) UpdateTextPos()
- func (Window *Window) WinGetElem(id string) *Text
- type WorldSys
Constants ¶
const ( CELL_WATER uint32 = 0x0 CELL_PLAINS uint32 = 0x1 CELL_BEACH uint32 = 0x2 )
const ( CLogPath = "./clogs.txt" SLogPath = "./slogs.txt" )
const ( CLIENT = 0x1 << 1 SERVER = 0x1 << 2 PORT = ":7777" // used by the client to indicate it wants to go to the next turn CLIENT_CMD_NEXT_TURN = 0x1 // used by the client to tell the server it is moving a unit CLIENT_CMD_MOVE_UNIT = 0x2 // used to broadcast to all clients BROADCAST = 0x0 // directed to one client DIRECT = 0x1 // used when the server tells the clients it is the next turn SERVER_CMD_NEXT_TURN = 0x98 // used by the server to indicate clients should sync SERVER_CMD_SYNC = 0x99 // used by the server to tell a client they are being initialised SERVER_CMD_CLIENT_INIT = 0xA0 )
const ( PRESS = 0x0 HELD = 0x1 CAM_SPEED = 0x3 CELL_DEPTH = 0x0 STRUCTURES_DEPTH = 0x1 UNITS_DEPTH = 0x2 UI_DEPTH = 0x3 )
const ( DEFAULT_WIDTH = 200 DEFAULT_HEIGHT = 100 WORLD_VIEW = 0x0 SCREEN_VIEW = 0x1 Z_DEPTH = 0x4 )
Variables ¶
var ( Running = true WaitGroup sync.WaitGroup )
var ( ScreenMutex = sync.Mutex{} InputBuffer = InputData{} )
Functions ¶
func Buf ¶
func Buf(width, height int) tcell.CellBuffer
func BufRune ¶
func BufRune(buf tcell.CellBuffer, rune rune, style tcell.Style, pos Vec) tcell.CellBuffer
fill a cell buffer with text
func BufText ¶
func BufText(buf tcell.CellBuffer, text string, style tcell.Style, pos Vec) tcell.CellBuffer
fill a cell buffer with text
func FillBufRune ¶
func FillBufRune(rune rune, style tcell.Style) tcell.CellBuffer
fill a cell buffer with text
func Singleplayer ¶
func Singleplayer()
Types ¶
type AttackComponent ¶
type AttackComponent struct {
Damage float64
}
func (*AttackComponent) Test ¶
func (A *AttackComponent) Test()
type Cell ¶
type Cell struct { *Entity *SyncComp *PosComp *RenderComp *CellDatComp }
type CellDatComp ¶
type ClickEvent ¶
type ClientCommandEvent ¶
type ClientCommandEvent struct { EventBase // whether the command is on the server or client side Side uint8 Type uint32 Data string }
used by clients to send commands to the server
type ECS ¶
type ECS struct { // number of entities Size int // store a map of each priority level containing systems Systems [][]System // store a reference to each entity Entities map[uint32]*Entity // we store a type registry to store the type of a component EntityNameTypeRegistry map[string]reflect.Type // we store a type registry to store the type of a component EntityComponentTypeRegistry map[string][]reflect.Type // store a reference to the components attached to the entity (linearly added) Components []Component // used as an index lookup to find the position of the first component of the particular entity EntityComponentLookup map[uint32]uint32 // whether the ECS is a server or client HostMode uint8 // this is used for the goroutines that poll client/server commands // to dispatch events into the ECS in a thread-safe manner EventChannel chan Event }
func (*ECS) AddEntity ¶
add an entity to the system. this is useful for querying components this is likely only used to know which components an entity has
func (*ECS) AddSettlement ¶
func (ECS *ECS) AddSettlement(settlement *Settlement) uint32
func (*ECS) CreateSettlement ¶
func (ECS *ECS) CreateSettlement(name string, pos Vec, dirty bool) *Settlement
func (*ECS) GetEntityComponents ¶
get all the components attached to a particular entity this is likely only used for serialization and de-serialization as the only accessable data this will return is the ability to call Serialize() and Deserialize()
func (*ECS) RegisterEntity ¶
register an entity by adding its type, and components to the ECS
func (*ECS) RegisterSystem ¶
func (*ECS) SerializeEntity ¶
serialize an entity by serializing each component TODO make this better, as its gonna be hard to unmarshal the bytes...
type EmpireStatsComp ¶
component for storing empire statistics
func (*EmpireStatsComp) Deserialize ¶
func (E *EmpireStatsComp) Deserialize(data interface{})
type EmpireStatsEvent ¶
triggered when something should change the stats of an empire
type EmpireSys ¶
type EmpireSys struct { *SystemBase PosComps []*PosComp EmpireStatsComps []*EmpireStatsComp }
empire system
func (*EmpireSys) AddEntity ¶
func (E *EmpireSys) AddEntity(Entity *Entity, PosComp *PosComp, EmpireStatsComp *EmpireStatsComp)
func (*EmpireSys) Listen ¶
func (E *EmpireSys) Listen(Event EmpireStatsEvent)
listen out for when something modifies the empires stats
type GameInterface ¶
var ( Game *GameInterface Username = "default" )
func (*GameInterface) ProcessClient ¶
func (G *GameInterface) ProcessClient()
func (*GameInterface) ProcessServer ¶
func (G *GameInterface) ProcessServer()
type HealthComponent ¶
type HealthComponent struct {
Health float64
}
used for anything that has health e.g. units, settlements etc
func (*HealthComponent) Test ¶
func (H *HealthComponent) Test()
type Initialiser ¶
type Initialiser interface {
Init()
}
type MovementComp ¶
func (*MovementComp) Test ¶
func (M *MovementComp) Test()
type MovementSys ¶
type MovementSys struct { *SystemBase // store all the position & movement components components PosComps []*PosComp MovementComps []*MovementComp }
func (*MovementSys) Add ¶
func (MovementSys *MovementSys) Add(Entity *Entity, PosComp *PosComp, MovementComp *MovementComp)
func (*MovementSys) Remove ¶
func (MovementSys *MovementSys) Remove(ECS *ECS)
func (*MovementSys) Update ¶
func (MovementSys *MovementSys) Update()
TODO fix this, we only want to apply the movement on a next turn event
type NetworkSys ¶
type NetworkSys struct { *SystemBase SyncComps []*SyncComp // connection to the server (used if we are a client) ServerConnection net.Conn // connections to clients (used if we are a server) Listener net.Listener ClientConnections map[int]net.Conn NumConnections int // address of the server to connect to ServerAddress string }
this system handles everything network related. it can be in 1 of 2 modes, CLIENT or SERVER. the mode determines the behaviour and will send and listen for the relevant events. the system stores all the sync components. these components are sent across the network
func (*NetworkSys) AddEntity ¶
func (N *NetworkSys) AddEntity(Entity *Entity, SyncComp *SyncComp)
func (*NetworkSys) Broadcast ¶
func (N *NetworkSys) Broadcast(command ServerCommandEvent)
func (*NetworkSys) Close ¶
func (N *NetworkSys) Close()
func (*NetworkSys) Direct ¶
func (N *NetworkSys) Direct(clientID int, command ServerCommandEvent)
func (*NetworkSys) Dispatch ¶
func (N *NetworkSys) Dispatch(command ServerCommandEvent)
func (*NetworkSys) Init ¶
func (N *NetworkSys) Init()
func (*NetworkSys) ListenClientCommandEvent ¶
func (N *NetworkSys) ListenClientCommandEvent(command ClientCommandEvent)
TODO CLIENT listen for systems to send commands to the server receive the command, and send it over the connection to the server
func (*NetworkSys) ListenServerCommandEvent ¶
func (N *NetworkSys) ListenServerCommandEvent(command ServerCommandEvent)
TODO CLIENT & SERVER TODO make this code better jesus listen for when the server has done processing and is ready to sync
func (*NetworkSys) PollClientCommands ¶
func (N *NetworkSys) PollClientCommands()
TODO SERVER server listens for commands from clients
func (*NetworkSys) PollClientConnections ¶
func (N *NetworkSys) PollClientConnections()
TODO SERVER listen for client connections. this runs throughout the lifetime of the application
func (*NetworkSys) PollServerCommands ¶
func (N *NetworkSys) PollServerCommands()
TODO CLIENT listen for sync messages from the server connection, once we receive a sync over the network dispatch the sync locally
func (*NetworkSys) Priority ¶
func (N *NetworkSys) Priority() int
the network code must be ran AFTER every other system has updated their state. this allows the server to queue up the changes, and then send them across the network
func (*NetworkSys) Remove ¶
func (N *NetworkSys) Remove()
func (*NetworkSys) Update ¶
func (N *NetworkSys) Update()
type NewWinEvent ¶
event to create a new window
type NextTurnEvent ¶
type PlayerStatsComp ¶
type PlayerStatsComp struct { // name of the player Name string }
component for storing player info
func (*PlayerStatsComp) Test ¶
func (P *PlayerStatsComp) Test()
type PlayerSys ¶
type PlayerSys struct { *SystemBase SyncComps []*SyncComp PlayerStatsComps []*PlayerStatsComp // the current turn we are on Turn int TurnBuffer int Done bool }
player system
func (*PlayerSys) AddEntity ¶
func (P *PlayerSys) AddEntity(Entity *Entity, PlayerStatsComp *PlayerStatsComp, SyncComp *SyncComp)
func (*PlayerSys) ListenServerCommandEvent ¶
func (P *PlayerSys) ListenServerCommandEvent(event ServerCommandEvent)
TODO CLIENT listen for sync event to update our state
type Prioritiser ¶
type Prioritiser interface {
Priority() int
}
type RenderComp ¶
type RenderComp struct { Depth int Offset Vec Buffer tcell.CellBuffer }
func (*RenderComp) Test ¶
func (R *RenderComp) Test()
type RendererSys ¶
type RendererSys struct { *SystemBase PosComps []*PosComp RenderComps []*RenderComp Screen *Screen Clicked tcell.ButtonMask }
renderer is a system
func (*RendererSys) AddEntity ¶
func (R *RendererSys) AddEntity(Entity *Entity, RenderComp *RenderComp, PosComp *PosComp)
func (*RendererSys) Close ¶
func (R *RendererSys) Close()
func (*RendererSys) Init ¶
func (R *RendererSys) Init()
func (*RendererSys) Remove ¶
func (R *RendererSys) Remove()
func (*RendererSys) Update ¶
func (R *RendererSys) Update()
type Screen ¶
type Screen struct { Screen tcell.Screen Cam Vec Width, Height int ZBuffer []tcell.CellBuffer PrevZBuffer []tcell.CellBuffer }
func (*Screen) CalculateMouseDepth ¶
TODO the screen seems to be able to only recognise clicks on depth 0, every other z-layer is just blank
func (*Screen) ScreenToWorld ¶
func (*Screen) WorldToScreen ¶
type ServerCommandEvent ¶
type ServerCommandEvent struct { EventBase // whether the command is on the server or client side Side uint8 Type uint32 Data []byte TargetMode uint8 Target int }
used by clients to send commands to the server
type Settlement ¶
type Settlement struct { *Entity *SyncComp *PosComp *SettlementStatsComp *RenderComp }
empire entity
type SettlementStatsComp ¶
component for storing empire statistics
func (*SettlementStatsComp) Test ¶
func (S *SettlementStatsComp) Test()
type SettlementSys ¶
type SettlementSys struct { *SystemBase PosComps []*PosComp SettlementStatsComps []*SettlementStatsComp SelectedCity uint32 }
settlement system
func (*SettlementSys) AddEntity ¶
func (S *SettlementSys) AddEntity(Entity *Entity, PosComp *PosComp, SettlementStatsComp *SettlementStatsComp)
func (*SettlementSys) Close ¶
func (S *SettlementSys) Close()
func (*SettlementSys) Init ¶
func (S *SettlementSys) Init()
func (*SettlementSys) ListenClickEvent ¶
func (S *SettlementSys) ListenClickEvent(event ClickEvent)
func (*SettlementSys) Remove ¶
func (S *SettlementSys) Remove()
func (*SettlementSys) Update ¶
func (S *SettlementSys) Update()
type StateSys ¶
type StateSys struct { *SystemBase SyncComps []*SyncComp // TODO in theory this should only be a single StateComp StateComps []*StateComp // the id of the entity that represents us OurStateID uint32 }
represents the state of the game it keeps track of the turn etc
func (*StateSys) ListenClientCommandEvent ¶
func (S *StateSys) ListenClientCommandEvent(event ClientCommandEvent)
TODO SERVER server listens for commands
func (*StateSys) ListenServerCommandEvent ¶
func (S *StateSys) ListenServerCommandEvent(event ServerCommandEvent)
type SyncAction ¶
type SyncAction struct{}
type SyncComp ¶
type SyncComp struct { // this is true if the entity is new or has been modified Dirty bool // TODO for now we don't need this as the component can simply choose not to deserialize itself // names of the components that we DON't want to sync with the server, these will be ignored when syncing. // this is particularly useful for ignoring client side components e.g. RenderComps etc Hidden map[string]struct{} }
a sync component is attached to any entity that needs to be synchronized on the network
type SyncComponentContainer ¶
type SyncEntityContainer ¶
type SyncEntityContainer struct { Id float64 Tag string Components []SyncComponentContainer }
type SystemBase ¶
func NewSysBase ¶
func NewSysBase(ECS *ECS) *SystemBase
type Text ¶
type Text struct { UITemplate // the text is an interface so it can be updated on the fly T interface{} // if T is a pointer to a value Ptr bool Pos Vec Callback Callback }
type UIManager ¶
type UIManager struct { Screen *Screen // TODO optimise this by using a uint32 id UI map[string]UI }
func NewUIManager ¶
func (*UIManager) SetWinText ¶
set the T value of a text UI element
func (*UIManager) WinRemoveText ¶
set the T value of a text UI element
type UISys ¶
type UISys struct { *SystemBase UIManager *UIManager }
TODO this is to test a UI system
func (*UISys) ListenDestroyWinEvent ¶
func (U *UISys) ListenDestroyWinEvent()
func (*UISys) ListenNewWinEvent ¶
func (U *UISys) ListenNewWinEvent(event NewWinEvent)
func (*UISys) ListenNextTurnEvent ¶
func (U *UISys) ListenNextTurnEvent(event NextTurnEvent)
type UITemplate ¶
func (*UITemplate) Enable ¶
func (UITemplate *UITemplate) Enable(enabled bool)
type Unit ¶
type Unit struct { *Entity *SyncComp *PosComp *MovementComp *HealthComponent *AttackComponent *RenderComp }
type UnitSys ¶
type UnitSys struct { *SystemBase SyncComps []*SyncComp PosComps []*PosComp MovementComps []*MovementComp HealthComps []*HealthComponent AttackComps []*AttackComponent SelectedUnit uint32 }
func (*UnitSys) AddEntity ¶
func (U *UnitSys) AddEntity(Entity *Entity, SyncComp *SyncComp, PosComp *PosComp, MovementComp *MovementComp, HealthComp *HealthComponent, AttackComp *AttackComponent)
func (*UnitSys) ListenClickEvent ¶
func (U *UnitSys) ListenClickEvent(event ClickEvent)
func (*UnitSys) ListenClientCommandEvent ¶
func (U *UnitSys) ListenClientCommandEvent(event ClientCommandEvent)
TODO SERVER listen for when the player wants to move a unit
type Window ¶
type Window struct { UITemplate Title string Pos, Size Vec Text []*Text Dragging bool DragOffset Vec }
func (*Window) NewText ¶
the reason the text is an interface, is becuase it can be any value and thus be updated on the fly
func (*Window) RemoveText ¶
func (*Window) UpdateSize ¶
func (Window *Window) UpdateSize()
update the size of the window based on the text contents
func (*Window) UpdateTextPos ¶
func (Window *Window) UpdateTextPos()
func (*Window) WinGetElem ¶
type WorldSys ¶
type WorldSys struct { *SystemBase CellDatComps []*CellDatComp // position of cells PosComps []*PosComp Width, Height int }
func (*WorldSys) AddEntity ¶
func (W *WorldSys) AddEntity(Entity *Entity, CellDatComp *CellDatComp, PosComp *PosComp)
func (*WorldSys) ListenClickEvent ¶
func (W *WorldSys) ListenClickEvent(event ClickEvent)