class Worldgen::PlateMap::Plate
A class representing a single plate. TODO: using Ruby for this is kinda slow, maybe port a good chunk of this stuff to C
Attributes
Attributes:
-
seed - the initial point within the map for this plate
-
map - the map that this plate is in
-
id - the ID number of this plate (how this plate identifies itself)
-
type - the type of plate (continental vs. ocean)
Attributes:
-
seed - the initial point within the map for this plate
-
map - the map that this plate is in
-
id - the ID number of this plate (how this plate identifies itself)
-
type - the type of plate (continental vs. ocean)
Attributes:
-
seed - the initial point within the map for this plate
-
map - the map that this plate is in
-
id - the ID number of this plate (how this plate identifies itself)
-
type - the type of plate (continental vs. ocean)
Attributes:
-
seed - the initial point within the map for this plate
-
map - the map that this plate is in
-
id - the ID number of this plate (how this plate identifies itself)
-
type - the type of plate (continental vs. ocean)
Public Instance Methods
Absorb a single empty point along the frontier
# File lib/worldgen/platemap.rb, line 32 def absorb_frontier! # Shuffle the frontier so that we end up grabbing a random point @frontier.shuffle! value = nil # It's possible another plate has absorbed part of our frontier since # the last time we set our frontier, so shift until we find an empty # spot while value == nil and @frontier.length > 0 value = @frontier.shift value = nil unless at(*value) < 0 end if value # move it into me @map[value[0]][value[1]] = @id # add new points onto my frontier @frontier += empty_neighbours(value) end value end
Get the empty neighbours around `point`
# File lib/worldgen/platemap.rb, line 57 def empty_neighbours point neighbours(point).select do |(x, y)| at(x, y) < 0 end end
Get the length of this plate's frontier
# File lib/worldgen/platemap.rb, line 27 def frontier_length @frontier ? @frontier.length : 0 end
See if this plate has a frontier or not
# File lib/worldgen/platemap.rb, line 22 def has_frontier? @frontier and @frontier.length > 0 end
Get the neighbours of `point` - directly adjacent only, no diagonals
# File lib/worldgen/platemap.rb, line 64 def neighbours point [ [-1, 0], [1, 0], [0, 1], [0, -1] ].map do |(dx, dy)| [ (point[0] + dx + @map.length) % @map.length, (point[1] + dy + @map.length) % @map.length ] end end
Set the seed for this plate. Construct the frontier.
# File lib/worldgen/platemap.rb, line 16 def seed= seed @seed = seed @frontier = empty_neighbours(@seed) end
Private Instance Methods
Get the point at x, y
# File lib/worldgen/platemap.rb, line 80 def at x, y @map[x][y] end