Ejemplo n.º 1
0
func main() {
	params := getArgs()

	nodecnt := params.sheeplecnt + params.tvcnt
	pkt := lib.SimPacket{}
	pkt.Itermax = int(params.itermax) // TODO overflow check
	pkt.Torus.W = params.width
	pkt.Torus.H = params.height
	pkt.Beliefs = strings.Split(params.beliefs, ",")
	pkt.Nodes = make([]lib.UserNode, nodecnt)

	for i := uint(0); i < params.tvcnt; i++ {
		n := ext.NewTvNode(pkt.Torus)
		pkt.Nodes[i] = lib.SimNode2UserNode(n)
	}

	shmax := params.tvcnt + params.sheeplecnt
	for i := params.tvcnt; i < shmax; i++ {
		n := ext.NewSheepleNode(pkt.Torus)
		pkt.Nodes[i] = lib.SimNode2UserNode(n)
	}

	for i, n := range pkt.Nodes {
		n.Id = i
	}

	lib.WriteSimPkt(pkt, os.Stdout)
}
Ejemplo n.º 2
0
func (r *Renderer) userNodes(nodes []*core.SimNode) []core.UserNode {
	out := make([]core.UserNode, len(nodes))
	for i, n := range nodes {
		out[i] = core.SimNode2UserNode(n)
	}
	return out
}
Ejemplo n.º 3
0
func (base BaseExtension) DefaultRender(entity string) {
	boxes := make([]ColorBox, len(base.user))
	for i, sn := range base.nodes {
		mapped := core.MapNode(base.render.torscreen, sn)
		un := core.SimNode2UserNode(mapped)
		boxes[i] = renderNode(un, base.noderad())
	}
	sheepShape := base.render.entshapes[entity]
	fr := base.render.fr
	fr.Shapes[sheepShape] = append(fr.Shapes[sheepShape], boxes...)
}
Ejemplo n.º 4
0
func (gr TvGroup) Render() {
	boxes := make([]ColorBox, len(gr.user))
	fr := gr.render.fr
	for i, un := range gr.user {
		ts := gr.render.torscreen
		mapped := core.MapNode(ts, gr.nodes[i])
		e := mapped.Entity
		tv := e.(*ext.Tv) // A better deserialization mechanism would allow no typecast
		exprad := ts.Scale(tv.R)
		boxes[i] = renderNode(core.SimNode2UserNode(mapped), BaseExtension(gr).noderad())
		expls := make([]Explosion, len(un.Expression))
		for i, b := range un.Expression {
			expls[i] = renderExplosion(core.BlasVec2UserVec(mapped.P), exprad, gr.render.time, b)
		}
		fr.Explosions = append(fr.Explosions, expls...)
	}
	tvShape := gr.render.entshapes["tv"]

	fr.Shapes[tvShape] = append(fr.Shapes[tvShape], boxes...)
}