예제 #1
0
func TestChunkUpdate(t *testing.T) {
	tick := message.Tick(42)
	blk := message.NewBlock()
	for i := 0; i < 10; i++ {
		blk.Points[10][5+i] = 1
	}
	for i := 0; i < 7; i++ {
		blk.Points[20+i][10] = 2
	}

	testMessage(t, message.Types["chunk_update"], func(w io.Writer) error {
		return builder.SendChunkUpdate(w, tick, blk)
	}, func(conn *message.Conn, t *testing.T) {
		rt, rblk := handler.ReadChunkUpdate(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}

		for i := range blk.Points {
			for j := range blk.Points[i] {
				pt := blk.Points[i][j]
				rpt := rblk.Points[i][j]
				if rpt != pt {
					t.Fatal("Sent point", pt, " at ", i, j, "but received", rpt)
				}
			}
		}
	})
}
예제 #2
0
파일: server.go 프로젝트: emersion/miko
	},
	message.Types["terrain_request"]: func(ctx *message.Context, conn *message.Conn) error {
		var size uint8
		Read(conn, &size)

		for i := 0; i < int(size); i++ {
			var x, y message.BlockCoord
			Read(conn, &x, &y)

			blk, err := ctx.Terrain.GetBlockAt(x, y)
			if err != nil {
				return err
			}

			err = conn.Write(func(w io.Writer) error {
				return builder.SendChunkUpdate(w, ctx.Clock.GetRelativeTick(), blk)
			})
			if err != nil {
				return err
			}
		}

		return nil
	},
	message.Types["entity_update"]: func(ctx *message.Context, conn *message.Conn) error {
		// TODO: add update initiator as parameter to ctx.Entity.Update()

		t := ctx.Clock.ToAbsoluteTick(readTick(conn))

		entity, diff := ReadEntity(conn)
		log.Printf("Received entity update: tick=%v entity=%+v position=%+v speed=%+v\n", t, entity, entity.Position, entity.Speed)