~sircmpwn/cells

99dbe4f3e816932f7cb2b93d0b64f0e802e9bb0a — Drew DeVault a month ago 4b4743b master
Refactor chunk coords into separate func
2 files changed, 13 insertions(+), 6 deletions(-)

M conn.go
M map.go
M conn.go => conn.go +6 -4
@@ 19,10 19,8 @@ type Connection struct {
	Conn     *websocket.Conn
	Player   Player
	outgoing chan interface{}
}

func (c *Connection) Send(msg interface{}) {
	c.outgoing <-msg
	chunks   map[Coordinates]interface{}
	location Coordinates
}

func (c *Connection) Run() {


@@ 115,6 113,10 @@ func (c *Connection) Run() {
	conns.Delete(c)
}

func (c *Connection) Send(msg interface{}) {
	c.outgoing <-msg
}

func SendToEveryone(msg interface{}) {
	conns.Range(func(key interface{}, _ interface{}) bool {
		conn, _ := key.(*Connection)

M map.go => map.go +7 -2
@@ 6,8 6,7 @@ func init() {
	Map = make(map[Coordinates]*[CHUNK_SIZE*CHUNK_SIZE]Color)
}

func SetCell(coords Coordinates, c Color) {
	// TODO: Lock mutex
func ChunkAt(coords Coordinates) Coordinates {
	loc := Coordinates{
		X: coords.X / CHUNK_SIZE,
		Y: coords.Y / CHUNK_SIZE,


@@ 18,6 17,12 @@ func SetCell(coords Coordinates, c Color) {
	if coords.Y < 0 {
		loc.Y--
	}
	return loc
}

func SetCell(coords Coordinates, c Color) {
	// TODO: Lock mutex
	loc := ChunkAt(coords)
	chunk, ok := Map[loc]
	if !ok {
		var blank [CHUNK_SIZE*CHUNK_SIZE]Color