Exemple #1
0
func TestActionsDone(t *testing.T) {
	tick := message.Tick(42)

	action1 := message.NewAction()
	action1.Id = 25
	action1.Initiator = 65

	actions := []*message.Action{action1}
	// TODO: more actions tests, with action params

	testMessage(t, message.Types["actions_done"], func(w io.Writer) error {
		return builder.SendActionsDone(w, tick, actions)
	}, func(conn *message.Conn, t *testing.T) {
		rt, ractions := handler.ReadActionsDone(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}

		if len(actions) != len(ractions) {
			t.Fatal("Sent", len(actions), "actions but received", len(ractions))
		}
		for i, action := range actions {
			raction := ractions[i]
			if !action.Equals(raction) {
				t.Fatal("Sent action", action, "but received", raction)
			}
		}
	})
}
Exemple #2
0
func (e *Engine) broadcastChanges() {
	if e.ctx.Entity.IsDirty() {
		log.Println("Entity diff dirty, broadcasting to clients...")
		err := e.srv.Write(func(w io.Writer) error {
			return builder.SendEntitiesDiffToClients(w, e.ctx.Entity.Flush())
		})
		if err != nil {
			log.Println("Cannot broadcast entities diff:", err)
		}
	}
	if e.ctx.Action.IsDirty() {
		log.Println("Actions diff dirty, broadcasting to clients...")
		err := e.srv.Write(func(w io.Writer) error {
			return builder.SendActionsDone(w, e.clock.GetRelativeTick(), e.ctx.Action.Flush())
		})
		if err != nil {
			log.Println("Cannot broadcast actions:", err)
		}
	}
}