make context great again
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
package mapgens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util/appctx"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util/delaunay"
|
||||
)
|
||||
|
||||
func DelaunayMstGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
|
||||
func DelaunayMstGen(ctx context.Context, l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
|
||||
|
||||
rng := util.NewRNG()
|
||||
|
||||
@ -33,7 +33,7 @@ func DelaunayMstGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level, []g
|
||||
for _, room := range rooms {
|
||||
centers = append(centers, room.Center)
|
||||
}
|
||||
edges := delaunay.GetMst(centers, l.W, l.H)
|
||||
edges := delaunay.GetMst(centers, l.W, l.H, 0)
|
||||
for _, edge := range edges {
|
||||
MedianStraight(rng, l, rooms, centers, edge)
|
||||
}
|
||||
@ -41,27 +41,5 @@ func DelaunayMstGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level, []g
|
||||
return l, rooms
|
||||
}
|
||||
|
||||
func MedianStraight(rng *util.RNG, l *gamemap.Level, rooms []gamemap.Room, centers []types.Coords, edge types.Edge) {
|
||||
//find connected rooms
|
||||
var fromRoom, toRoom gamemap.Room
|
||||
for _, room := range rooms {
|
||||
if room.Center == edge.From {
|
||||
fromRoom = room
|
||||
continue
|
||||
}
|
||||
if room.Center == edge.To {
|
||||
toRoom = room
|
||||
continue
|
||||
}
|
||||
if len(fromRoom.Connectors) > 0 && len(toRoom.Connectors) > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
midpoint := edge.Midpoint()
|
||||
fromConnector := FindNearestConnector(midpoint, fromRoom)
|
||||
toConnector := FindNearestConnector(midpoint, toRoom)
|
||||
ConnectStraight(rng, l, fromConnector, toConnector, midpoint)
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user