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

@ -46,7 +46,7 @@ func NewLevelRenderSystem(
return trs return trs
} }
//fixme add to screens/game Exit() // fixme add to screens/game Exit()
func (trs LevelRenderSystem) Close() { func (trs LevelRenderSystem) Close() {
trs.animateTiles.Stop() trs.animateTiles.Stop()
trs.animateTiles = nil //zero pointer to ticker trs.animateTiles = nil //zero pointer to ticker
@ -93,7 +93,7 @@ func (trs LevelRenderSystem) Process() {
//terrain //terrain
for y := 0; y < trs.Viewport.H; y++ { for y := 0; y < trs.Viewport.H; y++ {
for x := 0; x < trs.Viewport.W; x++ { 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) { if trs.state.Level.InBounds(mapCoords) {
tile := trs.state.Level.GetTile(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 nodeId = 0
var nodeList = make(map[types.Coords]Node, 0) var nodeList = make(map[types.Coords]Node, 0)
// Node defines a struct having as components the node X and Y coordinate position. // Node defines a struct having as components the node X and Y coordinate position.
type Node struct { type Node struct {
Id int Id int
@ -129,17 +130,18 @@ func (d *Delaunay) Init(width, height int) *Delaunay {
} }
var supertriangle1, supertriangle2 Triangle var supertriangle1, supertriangle2 Triangle
// clear method clears the delaunay triangles slice. // clear method clears the delaunay triangles slice.
func (d *Delaunay) clear() { func (d *Delaunay) clear() {
p0 := newNode(types.Coords{0,0}) p0 := newNode(types.Coords{X: 0, Y: 0})
p1 := newNode(types.Coords{d.width, 0}) p1 := newNode(types.Coords{X: d.width, Y: 0})
p2 := newNode(types.Coords{d.width, d.height}) p2 := newNode(types.Coords{X: d.width, Y: d.height})
p3 := newNode(types.Coords{0, d.height}) p3 := newNode(types.Coords{X: 0, Y: d.height})
// Create the supertriangle, an artificial triangle which encompasses all the points. // 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. // 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) supertriangle1 = t.newTriangle(p0, p1, p2)
supertriangle2 = t.newTriangle(p0,p2,p3) supertriangle2 = t.newTriangle(p0, p2, p3)
d.triangles = []Triangle{supertriangle1, supertriangle2} d.triangles = []Triangle{supertriangle1, supertriangle2}
} }
@ -199,7 +201,7 @@ func (d *Delaunay) Insert(points []types.Coords) *Delaunay {
} }
for i = 0; i < len(polygon); i++ { for i = 0; i < len(polygon); i++ {
edge := 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 d.triangles = temps
} }
@ -247,10 +249,7 @@ func (d *Delaunay) GetTriangles() []Triangle {
func (d *Delaunay) GetEdges() []Edge { func (d *Delaunay) GetEdges() []Edge {
edges := make([]Edge, 0) edges := make([]Edge, 0)
for _, trs := range d.triangles { for _, trs := range d.triangles {
for _, e := range trs.Edges { edges = append(edges, trs.Edges...)
edges = append(edges, e)
}
} }
return 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() edges := d.Init(100, 100).Insert(coords).GetEdges()
output := make([]types.Edge, 0) output := make([]types.Edge, 0)
for _, e := range edges{ 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 return output
} }
@ -46,16 +46,16 @@ func GetMst(coords []types.Coords, w, h, negativeWeight int) []types.Edge {
graph = append( graph = append(
graph, graph,
kruskals.SimpleWeightedEdge{ kruskals.SimpleWeightedEdge{
nodeMap[e.Nodes[0].Id], F: nodeMap[e.Nodes[0].Id],
nodeMap[e.Nodes[1].Id], T: nodeMap[e.Nodes[1].Id],
negativeWeight - int(e.Nodes[0].Coords.DistanceTo(e.Nodes[1].Coords))}, W: negativeWeight - int(e.Nodes[0].Coords.DistanceTo(e.Nodes[1].Coords))},
) )
} }
result := kruskals.MinimumSpanningTree(graph) result := kruskals.MinimumSpanningTree(graph)
output := make([]types.Edge, 0) output := make([]types.Edge, 0)
for _, we := range result{ 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 return output
} }