pgen

package
v0.0.0-...-f68e2cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWalk

func AddWalk(dag *RoomDag, roomPos map[string]tile.TilePosition, rng *rand.Rand, startPos tile.Position, walkLength int, walkNorthOnly bool)

func AnyEdgesIntersect

func AnyEdgesIntersect(dag *RoomDag, rects map[string]RoomPlacement) bool

func AxisAligned

func AxisAligned(tol int, a, b tile.Rect) bool

func CalculateRoomDepths

func CalculateRoomDepths(dag *RoomDag, placements map[string]RoomPlacement, start string)

func FindNodeNeighborAveragePosition

func FindNodeNeighborAveragePosition(dag *RoomDag, place map[string]RoomPlacement, label string) tile.TilePosition

func GetList

func GetList[T any](list []T) (T, bool)

Pick a random item out of a list

func HasAnyRectIntersections

func HasAnyRectIntersections(rects map[string]RoomPlacement) bool

func HasEdgeIntersections

func HasEdgeIntersections(dag *RoomDag, rects map[string]RoomPlacement, label1, label2 string) bool

func HasRectIntersections

func HasRectIntersections(rects map[string]RoomPlacement, label string) bool

func ListItem

func ListItem[T any](rng *rand.Rand, list []T) (T, bool)

func NodeHasEdgeIntersections

func NodeHasEdgeIntersections(dag *RoomDag, rects map[string]RoomPlacement, label string) bool

func NodeHasEdgeIntersectionsWithMoreShallowEdge

func NodeHasEdgeIntersectionsWithMoreShallowEdge(dag *RoomDag, placements map[string]RoomPlacement, label string) bool

func PSLD

func PSLD(rng *rand.Rand, dag *RoomDag, place map[string]RoomPlacement)

func PSLDStep

func PSLDStep(rng *rand.Rand, dag *RoomDag, place map[string]RoomPlacement) bool

Returns true if there were no intersections

func Path

func Path(start, end vec2.T, n int, variation float64) []vec2.T

func PlaceBreadthFirst

func PlaceBreadthFirst(rng *rand.Rand, dag *RoomDag, rooms map[string]RoomPlacement, start string, distance float64)

func PlaceDepthFirst

func PlaceDepthFirst(rng *rand.Rand, dag *RoomDag, rooms map[string]RoomPlacement, start string, distance float64)

func RandomPositionInRect

func RandomPositionInRect(r glm.Rect) glm.Vec2

func Untangle

func Untangle(dag *RoomDag, rooms map[string]RoomPlacement, repelMultiplier, gravityConstant float64, iterations int)

func Wiggle

func Wiggle(dag *RoomDag, rooms map[string]RoomPlacement, repelMultiplier, gravityConstant float64, iterations int) bool

Types

type BreadthFirstLayout

type BreadthFirstLayout struct {
	// contains filtered or unexported fields
}

func NewBreadthFirstLayout

func NewBreadthFirstLayout(rng *rand.Rand, dag *RoomDag, place map[string]RoomPlacement, start string, distance float64) *BreadthFirstLayout

func (*BreadthFirstLayout) Iterate

func (d *BreadthFirstLayout) Iterate() bool

Returns true to indicate it hasn't finished

func (*BreadthFirstLayout) Reset

func (d *BreadthFirstLayout) Reset()

type DepthFirstLayout

type DepthFirstLayout struct {
	// contains filtered or unexported fields
}

func NewDepthFirstLayout

func NewDepthFirstLayout(rng *rand.Rand, dag *RoomDag, place map[string]RoomPlacement, start string, distance float64) *DepthFirstLayout

func (*DepthFirstLayout) Cut

func (d *DepthFirstLayout) Cut(label string)

func (*DepthFirstLayout) CutBelow

func (d *DepthFirstLayout) CutBelow(label string)

func (*DepthFirstLayout) CutCrossed

func (d *DepthFirstLayout) CutCrossed() bool

func (*DepthFirstLayout) Iterate

func (d *DepthFirstLayout) Iterate() bool

Returns true to indicate it hasn't finished

func (*DepthFirstLayout) Reset

func (d *DepthFirstLayout) Reset()

type ForceBasedRelaxer

type ForceBasedRelaxer struct {
	// contains filtered or unexported fields
}

func NewForceBasedRelaxer

func NewForceBasedRelaxer(rng *rand.Rand, dag *RoomDag, placements map[string]RoomPlacement, startingRepel float64, startingGrav float64) *ForceBasedRelaxer

func (*ForceBasedRelaxer) Iterate

func (r *ForceBasedRelaxer) Iterate()

type GridLayout

type GridLayout struct {
	// contains filtered or unexported fields
}

func NewGridLayout

func NewGridLayout(rng *rand.Rand, dag *RoomDag, place map[string]RoomPlacement, start string, tolerance int) *GridLayout

func (*GridLayout) AllEdgesAxisAligned

func (l *GridLayout) AllEdgesAxisAligned(tolerance int) bool

TODO: tolerance?

func (*GridLayout) Expand

func (l *GridLayout) Expand() bool

func (*GridLayout) Iterate

func (l *GridLayout) Iterate() bool

func (*GridLayout) IterateGravity

func (l *GridLayout) IterateGravity() bool

func (*GridLayout) IterateTowardsParent

func (l *GridLayout) IterateTowardsParent() bool

func (*GridLayout) LayoutGrid

func (l *GridLayout) LayoutGrid(roomPos map[string]tile.TilePosition)

func (*GridLayout) MoveTowards

func (l *GridLayout) MoveTowards(rect tile.Rect, pos tile.TilePosition, dist int) tile.Rect

type Item

type Item[T any] struct {
	Weight int
	Item   T
}

func NewItem

func NewItem[T any](weight int, item T) Item[T]

type NoiseMap

type NoiseMap struct {
	// contains filtered or unexported fields
}

func NewNoiseMap

func NewNoiseMap(seed int64, octaves []Octave, exponent float64) *NoiseMap

func (*NoiseMap) Get

func (n *NoiseMap) Get(x, y int) float64

type Octave

type Octave struct {
	Freq, Scale float64
}

type Range

type Range[T castable] struct {
	Min, Max T
}

func (Range[T]) Get

func (r Range[T]) Get() T

func (Range[T]) SeededGet

func (r Range[T]) SeededGet(rng *rand.Rand) T

type RoomDag

type RoomDag struct {
	Nodes   []string            // Holds the nodes in the order that they were added
	NodeMap map[string]int      // holds the rank of the node (to prevent cycles)
	Edges   map[string][]string // This is the dag
	// contains filtered or unexported fields
}

TODO: Dump string labels and use int labels?

func BlankWalkDag

func BlankWalkDag() (*RoomDag, map[string]tile.TilePosition)

func GenerateRandomGridWalkDag2

func GenerateRandomGridWalkDag2(rng *rand.Rand, numRooms int, numWalks int) (*RoomDag, map[string]tile.TilePosition)

func GenerateRandomGridWalkDagNoOverlap

func GenerateRandomGridWalkDagNoOverlap(rng *rand.Rand, numRooms int, numWalks int) (*RoomDag, map[string]tile.TilePosition)

func NewRoomDag

func NewRoomDag() *RoomDag

func (*RoomDag) AddEdge

func (d *RoomDag) AddEdge(from, to string)

func (*RoomDag) AddNode

func (d *RoomDag) AddNode(label string) bool

func (*RoomDag) Distance

func (d *RoomDag) Distance(from, to string) int

Counts and returns the number of edges needed to traverse to get from one node to another

func (*RoomDag) GetLeafNodes

func (d *RoomDag) GetLeafNodes() []string

Returns true if the node is a leaf node (ie has no outward facing edges)

func (*RoomDag) HasEdge

func (d *RoomDag) HasEdge(from, to string) bool

func (*RoomDag) HasEdgeEitherDirection

func (d *RoomDag) HasEdgeEitherDirection(from, to string) bool

func (*RoomDag) IsLeafNode

func (d *RoomDag) IsLeafNode(label string) bool

Returns true if the node is a leaf node (ie has no outward facing edges)

func (*RoomDag) RandomLabel

func (d *RoomDag) RandomLabel(rng *rand.Rand) string

func (*RoomDag) RandomSortedLabel

func (d *RoomDag) RandomSortedLabel(startLabel string, rng *rand.Rand, topoAfter, topoBeforeEnd int) string

func (*RoomDag) TopologicalSort

func (d *RoomDag) TopologicalSort(start string) []string

returns the node labels in topological order

type RoomPlacement

type RoomPlacement struct {
	// MapDef *MapDefinition // TODO: generic
	Rect    tile.Rect
	GoalGap float64
	Static  bool
	Repel   float64
	Attract float64
	Depth   int
	Mass    float64
	Placed  bool
}

type Table

type Table[T any] struct {
	Total int
	Items []Item[T]
}

func NewTable

func NewTable[T any](items ...Item[T]) *Table[T]

func (*Table[T]) Get

func (t *Table[T]) Get() T

Returns the item rolled

func (*Table[T]) GetUnique

func (t *Table[T]) GetUnique(count int) []T

Returns returns count unique items, if there are less items in the loot table, only returns what is available to satisfy the uniqueness

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL