diff --git a/engine/ecs/systems/level_render_system.go b/engine/ecs/systems/level_render_system.go index 3bccb88..c3d258a 100644 --- a/engine/ecs/systems/level_render_system.go +++ b/engine/ecs/systems/level_render_system.go @@ -46,7 +46,7 @@ func NewLevelRenderSystem( return trs } -//fixme add to screens/game Exit() +// fixme add to screens/game Exit() func (trs LevelRenderSystem) Close() { trs.animateTiles.Stop() trs.animateTiles = nil //zero pointer to ticker @@ -93,7 +93,7 @@ func (trs LevelRenderSystem) Process() { //terrain for y := 0; y < trs.Viewport.H; y++ { for x := 0; x < trs.Viewport.W; x++ { - mapCoords := types.Coords{trs.Viewport.CameraCoords.X + x, trs.Viewport.CameraCoords.Y + y} + mapCoords := types.Coords{X: trs.Viewport.CameraCoords.X + x, Y: trs.Viewport.CameraCoords.Y + y} if trs.state.Level.InBounds(mapCoords) { tile := trs.state.Level.GetTile(mapCoords) diff --git a/util/delaunay/delaunay.go b/util/delaunay/delaunay.go index 58ac466..0bb9bd4 100644 --- a/util/delaunay/delaunay.go +++ b/util/delaunay/delaunay.go @@ -6,6 +6,7 @@ import "lab.zaar.be/thefish/alchemyst-go/engine/types" var nodeId = 0 var nodeList = make(map[types.Coords]Node, 0) + // Node defines a struct having as components the node X and Y coordinate position. type Node struct { Id int @@ -129,17 +130,18 @@ func (d *Delaunay) Init(width, height int) *Delaunay { } var supertriangle1, supertriangle2 Triangle + // clear method clears the delaunay triangles slice. func (d *Delaunay) clear() { - p0 := newNode(types.Coords{0,0}) - p1 := newNode(types.Coords{d.width, 0}) - p2 := newNode(types.Coords{d.width, d.height}) - p3 := newNode(types.Coords{0, d.height}) + p0 := newNode(types.Coords{X: 0, Y: 0}) + p1 := newNode(types.Coords{X: d.width, Y: 0}) + p2 := newNode(types.Coords{X: d.width, Y: d.height}) + p3 := newNode(types.Coords{X: 0, Y: d.height}) // Create the supertriangle, an artificial triangle which encompasses all the points. // At the end of the triangulation process any triangles which share Edges with the supertriangle are deleted from the triangle list. - supertriangle1 = t.newTriangle(p0,p1,p2) - supertriangle2 = t.newTriangle(p0,p2,p3) + supertriangle1 = t.newTriangle(p0, p1, p2) + supertriangle2 = t.newTriangle(p0, p2, p3) d.triangles = []Triangle{supertriangle1, supertriangle2} } @@ -199,7 +201,7 @@ func (d *Delaunay) Insert(points []types.Coords) *Delaunay { } for i = 0; i < len(polygon); i++ { edge := polygon[i] - temps = append(temps, t.newTriangle(edge.Nodes[0], edge.Nodes[1], newNode(types.Coords{x, y}))) + temps = append(temps, t.newTriangle(edge.Nodes[0], edge.Nodes[1], newNode(types.Coords{X: x, Y: y}))) } d.triangles = temps } @@ -247,10 +249,7 @@ func (d *Delaunay) GetTriangles() []Triangle { func (d *Delaunay) GetEdges() []Edge { edges := make([]Edge, 0) for _, trs := range d.triangles { - for _, e := range trs.Edges { - edges = append(edges, e) - } - + edges = append(edges, trs.Edges...) } return edges } diff --git a/util/delaunay/mst.go b/util/delaunay/mst.go index aeb3551..72bc8ca 100644 --- a/util/delaunay/mst.go +++ b/util/delaunay/mst.go @@ -11,7 +11,7 @@ func GetTriangles(coords []types.Coords, w, h int) []types.Edge { edges := d.Init(100, 100).Insert(coords).GetEdges() output := make([]types.Edge, 0) for _, e := range edges{ - output = append(output, types.Edge{e.Nodes[0].Coords, e.Nodes[1].Coords}) + output = append(output, types.Edge{From: e.Nodes[0].Coords, To: e.Nodes[1].Coords}) } return output } @@ -46,16 +46,16 @@ func GetMst(coords []types.Coords, w, h, negativeWeight int) []types.Edge { graph = append( graph, kruskals.SimpleWeightedEdge{ - nodeMap[e.Nodes[0].Id], - nodeMap[e.Nodes[1].Id], - negativeWeight - int(e.Nodes[0].Coords.DistanceTo(e.Nodes[1].Coords))}, + F: nodeMap[e.Nodes[0].Id], + T: nodeMap[e.Nodes[1].Id], + W: negativeWeight - int(e.Nodes[0].Coords.DistanceTo(e.Nodes[1].Coords))}, ) } result := kruskals.MinimumSpanningTree(graph) output := make([]types.Edge, 0) for _, we := range result{ - output = append(output, types.Edge{nodeList[we.From()].Coords, nodeList[we.To()].Coords}) + output = append(output, types.Edge{From: nodeList[we.From()].Coords, To: nodeList[we.To()].Coords}) } return output }