more cleanup

This commit is contained in:
thefish 2023-08-02 00:09:54 +03:00
parent 4c0117b6a7
commit 5613744d6e
3 changed files with 17 additions and 18 deletions

View File

@ -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)

View File

@ -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,12 +130,13 @@ 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.
@ -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
}

View File

@ -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
}