Compare commits
19 Commits
2813d9d5fe
...
mapgen-opt
| Author | SHA1 | Date | |
|---|---|---|---|
| ceb35639b8 | |||
| 79df8f2f52 | |||
| e986a4c538 | |||
| 93bda75727 | |||
| 1531abc3e2 | |||
| a34822ed54 | |||
| 145f65d4af | |||
| e359c4be09 | |||
| c009493484 | |||
| fab86c0486 | |||
| cb15f25d60 | |||
| 867238e11b | |||
| df247108ef | |||
| e34fd29a4b | |||
| 41cf4710da | |||
| c6573ae308 | |||
| 4ef2476771 | |||
| 2c13e1697f | |||
| 7b4839e63b |
@@ -32,7 +32,8 @@
|
|||||||
"vector",
|
"vector",
|
||||||
"Ensure",
|
"Ensure",
|
||||||
"string",
|
"string",
|
||||||
"string_utf8"
|
"string_utf8",
|
||||||
|
"Profiler"
|
||||||
],
|
],
|
||||||
"globalsRegex": []
|
"globalsRegex": []
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
Source code licensing:
|
# Source code licensing
|
||||||
|
|
||||||
The MIT License (MIT)
|
**The MIT License (MIT)**
|
||||||
Copyright (c) 2025 Apancore.Studio, Doloment
|
|
||||||
|
Copyright (c) 2025 Apancore.Studio, Van (varttist), Doloment
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
@@ -11,9 +12,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
Sprites licensing:
|
# Sprites licensing
|
||||||
|
|
||||||
CC BY 4.0
|
**CC BY 4.0**
|
||||||
Copyright (c) 2025 Apancore.Studio, Doloment and others (see list below)
|
|
||||||
|
Copyright (c) 2025 Apancore.Studio, Van (varttist) and others (see list below)
|
||||||
|
|
||||||
|
All textures except those listed here are copyrighted by Van (varttist) and are distributed under the CC BY 4.0.
|
||||||
|
|
||||||
List of all textures and authors:
|
List of all textures and authors:
|
||||||
|
- ...
|
||||||
@@ -43,7 +43,7 @@ local Item = {
|
|||||||
_title = '',
|
_title = '',
|
||||||
_description = '',
|
_description = '',
|
||||||
_title_color = '#FFFFFF',
|
_title_color = '#FFFFFF',
|
||||||
_description_color = '#C0C0C0',
|
_description_color = '#838383',
|
||||||
_rarity = 'common',
|
_rarity = 'common',
|
||||||
_add_mod_name = true,
|
_add_mod_name = true,
|
||||||
stack_max = 128,
|
stack_max = 128,
|
||||||
@@ -98,11 +98,9 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||||
end
|
end
|
||||||
|
|
||||||
local titleTranslate, descriptionTranslate = S(title), S(description)
|
|
||||||
|
|
||||||
if s._title_color ~= nil and s._description_color ~= nil then
|
if s._title_color ~= nil and s._description_color ~= nil then
|
||||||
titleTranslate = colorize(s._title_color , titleTranslate)
|
title = colorize(s._title_color , S(title))
|
||||||
descriptionTranslate = colorize(s._description_color, descriptionTranslate)
|
description = colorize(s._description_color, S(description))
|
||||||
else
|
else
|
||||||
error('Item description color parameters cannot be empty.')
|
error('Item description color parameters cannot be empty.')
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,45 +1,50 @@
|
|||||||
local mathAbs, mathRound, mathMin, mathMax, id
|
local mathRound, mathRandom, mathClamp, tableInsert
|
||||||
= math.abs, math.round, math.min, math.max, core.get_content_id
|
= math.round, math.random, math.clamp, table.insert
|
||||||
|
|
||||||
|
local posToString, getUsTime = core.pos_to_string, core.get_us_time
|
||||||
|
|
||||||
|
local pairs, ipairs, assert = pairs, ipairs, assert
|
||||||
|
|
||||||
|
local v = vector.new
|
||||||
|
local id = core.get_content_id
|
||||||
|
local AIR_ID = core.CONTENT_AIR
|
||||||
|
|
||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
|
local LOG_PROFILE = true
|
||||||
|
local PROFILE_CHUNK = true
|
||||||
|
|
||||||
|
local function mglog(text, ...)
|
||||||
|
core.log((text):format(...))
|
||||||
|
end
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---Numeric values defining the surface height and climate for the node.
|
||||||
---@alias MapGen.factors {height:number, temp:number, humidity:number}
|
---@alias MapGen.factors {height:number, temp:number, humidity:number}
|
||||||
|
|
||||||
---@alias MapGen.PastCalcNoiseValue {triangle:MapGen.Triangle?, x:integer?, z:integer?, noiseValue:number?}
|
---Table of all past generation factor calculations for nodes.
|
||||||
|
---
|
||||||
|
---Contains generation factors by layer name and coordinate.
|
||||||
|
---@type table<string, table<string, MapGen.factors>>
|
||||||
|
local pastNoiseValues = {}
|
||||||
|
|
||||||
---@type table<MapGen.Layer.Category, MapGen.PastCalcNoiseValue>
|
---The triangle in which generation occurred for the previous node.
|
||||||
local pastNoise2DCalc = {
|
---@type MapGen.Triangle?
|
||||||
landscape = {},
|
local pastTriangle
|
||||||
temp = {},
|
|
||||||
humidity = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
---@type MapGen.Layer
|
---@type MapGen.Layer
|
||||||
local Layer = require('MapGen.Layer')
|
local Layer = require('MapGen.Layer')
|
||||||
|
|
||||||
---@type MapGen.StaticLayer
|
---@type MapGen.StaticLayer
|
||||||
local StaticLayer = require('MapGen.StaticLayer')
|
local StaticLayer = require('MapGen.StaticLayer')
|
||||||
|
|
||||||
---@type MapGen.Peak
|
|
||||||
local Peak = require('MapGen.Peak')
|
|
||||||
|
|
||||||
---@type MapGen.Biome
|
---@type MapGen.Biome
|
||||||
local Biome = require('MapGen.Biome')
|
local Biome = require('MapGen.Biome')
|
||||||
|
|
||||||
---@type MapGen.Triangulation
|
|
||||||
local Triangulation = require('MapGen.Triangulation')
|
|
||||||
|
|
||||||
---@type MapGen.Cavern
|
---@type MapGen.Cavern
|
||||||
local Cavern = require('MapGen.Cavern')
|
local Cavern = require('MapGen.Cavern')
|
||||||
|
|
||||||
---@type MapGen.Region
|
---@type MapGen.Region
|
||||||
local Region = require('MapGen.Region')
|
local Region = require('MapGen.Region')
|
||||||
|
|
||||||
local ff2luat = require('MapGen.ff2luat')
|
|
||||||
|
|
||||||
---@class MapGen
|
---@class MapGen
|
||||||
---@field layersByName table<string, MapGen.Layer>
|
---@field layersByName table<string, MapGen.Layer>
|
||||||
---@field layersList MapGen.Layer[]
|
---@field layersList MapGen.Layer[]
|
||||||
@@ -48,6 +53,7 @@ local ff2luat = require('MapGen.ff2luat')
|
|||||||
---@field isLayersNoisesInitialized boolean Is the fractal noise of the layer initialized? This is necessary for a one-time noise initialization.
|
---@field isLayersNoisesInitialized boolean Is the fractal noise of the layer initialized? This is necessary for a one-time noise initialization.
|
||||||
---@field isCavernsNoiseInitialized boolean Is the fractal noise of the caverns initialized? This is necessary for a one-time noise initialization.
|
---@field isCavernsNoiseInitialized boolean Is the fractal noise of the caverns initialized? This is necessary for a one-time noise initialization.
|
||||||
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
|
||||||
|
---@field nodes table<string, string>
|
||||||
---@field nodeIDs table<string, number>
|
---@field nodeIDs table<string, number>
|
||||||
local MapGen = {
|
local MapGen = {
|
||||||
layersByName = {},
|
layersByName = {},
|
||||||
@@ -74,11 +80,9 @@ function MapGen:new(def)
|
|||||||
nodesIDs[k] = id(v)
|
nodesIDs[k] = id(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type MapGen
|
local instance = getInstance(self, {})
|
||||||
local instance = getInstance(self, {
|
instance.nodes = def.nodes
|
||||||
nodes = def.nodes,
|
instance.nodeIDs = nodesIDs
|
||||||
nodeIDs = nodesIDs,
|
|
||||||
})
|
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -95,18 +99,16 @@ function MapGen:getLayerByName(layerName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Determines which layer a node belongs to based on its height coordinate.
|
---Determines which layer a node belongs to based on its height coordinate.
|
||||||
---@param yPos number
|
---@param y number
|
||||||
---@return MapGen.Layer?
|
---@return MapGen.Layer?
|
||||||
function MapGen:getLayerByHeight(yPos)
|
function MapGen:getLayerByHeight(y)
|
||||||
--- TODO: возможно здесь получится сделать более оптимизированный алгоритм
|
--- TODO: возможно здесь получится сделать более оптимизированный алгоритм
|
||||||
--- учитывая тот факт, что эта функция вызывается для каждой ноды в on_generated
|
|
||||||
--- и может быть даже не один раз
|
|
||||||
--- Можно подумать над тем, чтобы использовать сортированный список
|
--- Можно подумать над тем, чтобы использовать сортированный список
|
||||||
|
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
for _, layer in ipairs(self.layersList) do
|
for _, layer in ipairs(self.layersList) do
|
||||||
|
|
||||||
if yPos >= layer.minY and yPos <= layer.maxY then
|
if y >= layer.minY and y <= layer.maxY then
|
||||||
return layer
|
return layer
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -114,9 +116,9 @@ function MapGen:getLayerByHeight(yPos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Determines which statics layer a node belongs to based on its height coordinate.
|
---Determines which statics layer a node belongs to based on its height coordinate.
|
||||||
---@param yPos number
|
---@param y number
|
||||||
---@return MapGen.StaticLayer?
|
---@return MapGen.StaticLayer?
|
||||||
function MapGen:getStaticByHeight(yPos)
|
function MapGen:getStaticByHeight(y)
|
||||||
--- TODO: возможно здесь получится сделать более оптимизированный алгоритм
|
--- TODO: возможно здесь получится сделать более оптимизированный алгоритм
|
||||||
--- учитывая тот факт, что эта функция вызывается для каждой ноды в on_generated
|
--- учитывая тот факт, что эта функция вызывается для каждой ноды в on_generated
|
||||||
--- и может быть даже не один раз
|
--- и может быть даже не один раз
|
||||||
@@ -125,7 +127,7 @@ function MapGen:getStaticByHeight(yPos)
|
|||||||
---@param static MapGen.StaticLayer
|
---@param static MapGen.StaticLayer
|
||||||
for _, static in ipairs(self.staticsList) do
|
for _, static in ipairs(self.staticsList) do
|
||||||
|
|
||||||
if yPos >= static.minY and yPos <= static.maxY then
|
if y >= static.minY and y <= static.maxY then
|
||||||
return static
|
return static
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -134,67 +136,84 @@ end
|
|||||||
|
|
||||||
---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns `nil`.
|
---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns `nil`.
|
||||||
---@param layer string|MapGen.Layer The layer or name of the layer in which the peak is located.
|
---@param layer string|MapGen.Layer The layer or name of the layer in which the peak is located.
|
||||||
---@param category MapGen.Layer.Category The category in which the peak is located.
|
|
||||||
---@param pos MapPosition Coordinate of the desired peak.
|
---@param pos MapPosition Coordinate of the desired peak.
|
||||||
---@return MapGen.Peak?
|
---@return MapGen.Peak?
|
||||||
function MapGen:getPeakByPos(layer, category, pos)
|
function MapGen:getPeakByPos(layer, pos)
|
||||||
if type(layer) == 'string' then
|
if type(layer) == 'string' then
|
||||||
local layerName = layer
|
local layerName = layer
|
||||||
layer = self:getLayerByName(layerName)
|
layer = self:getLayerByName(layerName)
|
||||||
end
|
end
|
||||||
|
|
||||||
return layer:getPeakByPos(category, pos)
|
return layer:getPeakByPos(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns `true` if the point is within the triangle's region.
|
---Checks if a point is inside a triangle using the vector product method.
|
||||||
---The barycentric coordinate method is used.
|
|
||||||
---@param px integer
|
|
||||||
---@param pz integer
|
|
||||||
---@param triangle MapGen.Triangle
|
|
||||||
local function pointInTriangle2D(px, pz, triangle)
|
|
||||||
local posP = vector.new(px, 0, pz)
|
|
||||||
local pos1 = triangle.p1.getPeakPos()
|
|
||||||
local pos2 = triangle.p2.getPeakPos()
|
|
||||||
local pos3 = triangle.p3.getPeakPos()
|
|
||||||
|
|
||||||
local v0 = pos3 - pos1
|
|
||||||
local v1 = pos2 - pos1
|
|
||||||
local v2 = posP - pos1
|
|
||||||
|
|
||||||
local dot00 = vector.dot(v0, v0)
|
|
||||||
local dot01 = vector.dot(v0, v1)
|
|
||||||
local dot02 = vector.dot(v0, v2)
|
|
||||||
local dot11 = vector.dot(v1, v1)
|
|
||||||
local dot12 = vector.dot(v1, v2)
|
|
||||||
|
|
||||||
local invDenom = 1 / (dot00 * dot11 - dot01 * dot01)
|
|
||||||
local u = (dot11 * dot02 - dot01 * dot12) * invDenom
|
|
||||||
local v = (dot00 * dot12 - dot01 * dot02) * invDenom
|
|
||||||
|
|
||||||
return (u >= 0) and (v >= 0) and (u + v <= 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Returns the `MapGen.Triangle` at the coordinates. If there is no triangle at these coordinates, it returns `nil`.
|
|
||||||
---
|
---
|
||||||
---**Important:** works only in the XZ plane.
|
---If the point is inside the triangle, it will return the triangle itself;
|
||||||
---@param layer string|MapGen.Layer The layer or name of the layer the triangle is in.
|
---if it is outside, its neighbor in the direction of the point will be returned.
|
||||||
---@param category MapGen.Layer.Category The category in which the triangle is in.
|
---
|
||||||
---@param pos MapPosition Coordinate of the desired peak.
|
---**Note**: works only with coordinates X-Z.
|
||||||
---@return MapGen.Triangle?
|
---@param triangle MapGen.Triangle
|
||||||
function MapGen:getTriangleByPos2D(layer, category, pos)
|
---@param pointPos IntegerVector
|
||||||
if type(layer) == 'string' then
|
---@return boolean, MapGen.Triangle?
|
||||||
local layerName = layer
|
function MapGen:isPointInTriangle(triangle, pointPos)
|
||||||
layer = self:getLayerByName(layerName)
|
local e1, e2, e3 = triangle.e1, triangle.e2, triangle.e3
|
||||||
|
|
||||||
|
local y1 = e1.vec:cross(pointPos - e1.p1.pos).y
|
||||||
|
if y1 > 0 then
|
||||||
|
return false, triangle.neighbours[3]
|
||||||
|
end
|
||||||
|
|
||||||
|
local y2 = e2.vec:cross(pointPos - e2.p1.pos).y
|
||||||
|
if y2 > 0 then
|
||||||
|
return false, triangle.neighbours[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
local y3 = e3.vec:cross(pointPos - e3.p1.pos).y
|
||||||
|
if y3 > 0 then
|
||||||
|
return false, triangle.neighbours[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
return true, triangle
|
||||||
|
end
|
||||||
|
|
||||||
|
---Finds the triangle containing the point specified by coordinates X & Z.
|
||||||
|
---@param layer MapGen.Layer The layer of the layer the triangle is in.
|
||||||
|
---@param x integer
|
||||||
|
---@param z integer
|
||||||
|
---@param triangle MapGen.Triangle? The triangle from which to begin the search.
|
||||||
|
--- If not specified, the search will be performed
|
||||||
|
--- from the triangle at `id = 1`
|
||||||
|
---@return MapGen.Triangle?
|
||||||
|
function MapGen:findTriangle(layer, x, z, triangle)
|
||||||
|
if triangle == nil then
|
||||||
|
triangle = layer.trianglesList[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Limit the number of iterations to prevent the loop from going into infinity.
|
||||||
|
local iterationCount = 1000000
|
||||||
|
|
||||||
|
local isFound = false
|
||||||
|
while not isFound do
|
||||||
|
if iterationCount < 0 then
|
||||||
|
error('The number of triangle search iterations'..
|
||||||
|
'has significantly exceeded the number of triangles'..
|
||||||
|
'in the list. Most likely, the loop has become infinite')
|
||||||
|
end
|
||||||
|
iterationCount = iterationCount - 1
|
||||||
|
|
||||||
|
if triangle == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
isFound, triangle = self:isPointInTriangle(triangle, v(x, 0, z))
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, triangle in ipairs(layer.trianglesList[category]) do
|
|
||||||
if pointInTriangle2D(pos.x, pos.z, triangle) then
|
|
||||||
return triangle
|
return triangle
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Checks if a point is inside a region.
|
---Checks if a point is inside a region.
|
||||||
|
---
|
||||||
---If the point is inside the region, it will also return the distance to the nearest border.
|
---If the point is inside the region, it will also return the distance to the nearest border.
|
||||||
---@param layer MapGen.Layer The name of the layer in which the region is located.
|
---@param layer MapGen.Layer The name of the layer in which the region is located.
|
||||||
---@param regionName string The name of the region in which the location of the point is checked.
|
---@param regionName string The name of the region in which the location of the point is checked.
|
||||||
@@ -203,7 +222,7 @@ end
|
|||||||
function MapGen:pointInRegion2D(layer, regionName, point)
|
function MapGen:pointInRegion2D(layer, regionName, point)
|
||||||
local region = layer.regionsByName[regionName]
|
local region = layer.regionsByName[regionName]
|
||||||
|
|
||||||
assert(layer ~= nil, ('There is no region named `%s` registered.'):format(regionName))
|
assert(region ~= nil, ('There is no region named `%s` registered.'):format(regionName))
|
||||||
|
|
||||||
return region:pointInRegion(point)
|
return region:pointInRegion(point)
|
||||||
end
|
end
|
||||||
@@ -238,13 +257,13 @@ end
|
|||||||
---@param peak MapGen.Peak
|
---@param peak MapGen.Peak
|
||||||
---@return string
|
---@return string
|
||||||
local function vertexKey(peak)
|
local function vertexKey(peak)
|
||||||
local pos = peak:getPeakPos()
|
local pos = peak.pos
|
||||||
|
|
||||||
return string.format("%.6f,%.6f", pos.x, pos.z)
|
return string.format("%.6f,%.6f", pos.x, pos.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Creates a canonical (sorted) key for an edge.
|
---Creates a canonical (sorted) key for an edge.
|
||||||
---@param edge MapGen.Triangulation.Edge
|
---@param edge MapGen.Edge
|
||||||
---@return string
|
---@return string
|
||||||
local function edgeKey(edge)
|
local function edgeKey(edge)
|
||||||
local k1 = vertexKey(edge.p1)
|
local k1 = vertexKey(edge.p1)
|
||||||
@@ -264,7 +283,7 @@ end
|
|||||||
function MapGen:getTriangulateBoundaryVertices(triangles)
|
function MapGen:getTriangulateBoundaryVertices(triangles)
|
||||||
-- Count how many triangles share each edge
|
-- Count how many triangles share each edge
|
||||||
local edgeCount = {}
|
local edgeCount = {}
|
||||||
---@type table<string, MapGen.Triangulation.Edge>
|
---@type table<string, MapGen.Edge>
|
||||||
local edgeData = {}
|
local edgeData = {}
|
||||||
|
|
||||||
for _, triangle in ipairs(triangles) do
|
for _, triangle in ipairs(triangles) do
|
||||||
@@ -283,12 +302,12 @@ function MapGen:getTriangulateBoundaryVertices(triangles)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Boundary edges belong to exactly ONE triangle
|
-- Boundary edges belong to exactly ONE triangle
|
||||||
---@type MapGen.Triangulation.Edge[]
|
---@type MapGen.Edge[]
|
||||||
local boundaryEdges = {}
|
local boundaryEdges = {}
|
||||||
|
|
||||||
for key, count in pairs(edgeCount) do
|
for key, count in pairs(edgeCount) do
|
||||||
if count == 1 then
|
if count == 1 then
|
||||||
table.insert(boundaryEdges, edgeData[key])
|
tableInsert(boundaryEdges, edgeData[key])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -312,8 +331,8 @@ function MapGen:getTriangulateBoundaryVertices(triangles)
|
|||||||
adjacency[k1] = adjacency[k1] or {}
|
adjacency[k1] = adjacency[k1] or {}
|
||||||
adjacency[k2] = adjacency[k2] or {}
|
adjacency[k2] = adjacency[k2] or {}
|
||||||
|
|
||||||
table.insert(adjacency[k1], k2)
|
tableInsert(adjacency[k1], k2)
|
||||||
table.insert(adjacency[k2], k1)
|
tableInsert(adjacency[k2], k1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Walk along boundary edges to create ordered vertex list
|
-- Walk along boundary edges to create ordered vertex list
|
||||||
@@ -331,9 +350,9 @@ function MapGen:getTriangulateBoundaryVertices(triangles)
|
|||||||
|
|
||||||
while currentKey and not visited[currentKey] do
|
while currentKey and not visited[currentKey] do
|
||||||
visited[currentKey] = true
|
visited[currentKey] = true
|
||||||
local pos = vertexData[currentKey]:getPeakPos()
|
local pos = vertexData[currentKey].pos
|
||||||
|
|
||||||
table.insert(boundary, {
|
tableInsert(boundary, {
|
||||||
x = pos.x,
|
x = pos.x,
|
||||||
y = 0,
|
y = 0,
|
||||||
z = pos.z
|
z = pos.z
|
||||||
@@ -375,7 +394,9 @@ function MapGen:registerLayer(name, def)
|
|||||||
local layer = Layer:new(name, def)
|
local layer = Layer:new(name, def)
|
||||||
|
|
||||||
self.layersByName[name] = layer
|
self.layersByName[name] = layer
|
||||||
table.insert(self.layersList, layer)
|
tableInsert(self.layersList, layer)
|
||||||
|
|
||||||
|
pastNoiseValues[name] = {}
|
||||||
|
|
||||||
-- Sort layers by maxY descending for processing priority.
|
-- Sort layers by maxY descending for processing priority.
|
||||||
table.sort(self.layersList, function(a, b)
|
table.sort(self.layersList, function(a, b)
|
||||||
@@ -410,7 +431,7 @@ function MapGen:registerStaticLayer(name, def)
|
|||||||
local static = StaticLayer:new(name, def)
|
local static = StaticLayer:new(name, def)
|
||||||
|
|
||||||
self.staticsByName[name] = static
|
self.staticsByName[name] = static
|
||||||
table.insert(self.staticsList, static)
|
tableInsert(self.staticsList, static)
|
||||||
|
|
||||||
-- Sort srtatics by maxY descending for processing priority.
|
-- Sort srtatics by maxY descending for processing priority.
|
||||||
table.sort(self.staticsList, function(a, b)
|
table.sort(self.staticsList, function(a, b)
|
||||||
@@ -418,121 +439,6 @@ function MapGen:registerStaticLayer(name, def)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
|
|
||||||
---
|
|
||||||
---Note: The peaks shouldn't overlap.
|
|
||||||
---@param layerName string The name of the layer in which the new peak will be included.
|
|
||||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
|
|
||||||
---@param def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
|
|
||||||
function MapGen:registerPeak(layerName, category, def)
|
|
||||||
local layer = self:getLayerByName(layerName)
|
|
||||||
|
|
||||||
--assert(self:getPeakByPos(layer, category, def.pos) == nil,
|
|
||||||
--('In the `%s` layer in the `%s` category there is already a peak with coordinates: %s, %s, %s.'):format(
|
|
||||||
-- layerName, category, def.pos.x, def.pos.y, def.pos.z))
|
|
||||||
|
|
||||||
---@type MapGen.Peak
|
|
||||||
local peak = Peak:new(def)
|
|
||||||
|
|
||||||
layer:addPeak(category, peak)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Mark a world point as `MapGen.Peak` and assign it a specific color that will affect the generation.
|
|
||||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
|
||||||
---
|
|
||||||
---Note: The peaks shouldn't overlap.
|
|
||||||
---@param layerName string The name of the layer in which the new peak will be included.
|
|
||||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
|
|
||||||
---@param def MapGen.PeakDef Peak description table, see details `MapGen.PeakDef`.
|
|
||||||
function MapGen:register2DPeak(layerName, category, def)
|
|
||||||
def = table.copy_with_metatables(def)
|
|
||||||
|
|
||||||
def.pos.y = 0
|
|
||||||
|
|
||||||
if def.groups == nil then
|
|
||||||
def.groups = {is2d = 1}
|
|
||||||
else
|
|
||||||
def.groups.is2d = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
self:registerPeak(layerName, category, def)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Mark the world points as `MapGen.Peak` and assign them all a specific noise that will affect generation.
|
|
||||||
---The Y coordinate will be forced to zero, and the `is2d` group will be added to the groups field.
|
|
||||||
---
|
|
||||||
---Note: The peaks shouldn't overlap.
|
|
||||||
---@param layerName string The name of the layer in which the new peaks will be included.
|
|
||||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
|
|
||||||
---@param defs MapGen.PeakDef[] Peaks description table, see details `MapGen.PeakDef`.
|
|
||||||
function MapGen:register2DPeaks(layerName,category, defs)
|
|
||||||
for _, def in ipairs(defs) do
|
|
||||||
self:register2DPeak(layerName, category, def)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Extract the `MapGen.Peak` from the image and assign them all a specific color that will affect the generation.
|
|
||||||
---@param layerName string The name of the layer in which the new peaks will be included.
|
|
||||||
---@param map string The name of the image from which the peaks will be extracted. It should be located in the `<mod_name>/textures/maps` folder and have the following format `<image_name>.ff`
|
|
||||||
---@param scale number Multiplier of how many blocks (nodes) will be between image pixels. It is not recommended to set the value below 50 for performance reasons.
|
|
||||||
---@param zeroPos IntegerPosition2d The position in pixels where the zero world coordinate will be in the image.
|
|
||||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peaks.
|
|
||||||
---@param groups? table<string, number> Groups that will be added to all peaks.
|
|
||||||
function MapGen:register2DPeaksFromFile(layerName, map, scale,zeroPos, category, groups)
|
|
||||||
if scale < 2 then
|
|
||||||
error('The map scale should not be less than 2.')
|
|
||||||
end
|
|
||||||
|
|
||||||
local modPath = core.get_modpath(core.get_current_modname())
|
|
||||||
local peaks = ff2luat(modPath .. '/textures/maps/' .. map)
|
|
||||||
|
|
||||||
---@type {h:integer, w:integer}
|
|
||||||
local mapSize = peaks.size
|
|
||||||
peaks.size = nil
|
|
||||||
|
|
||||||
zeroPos.x = zeroPos.x + mathRound(mapSize.w/2)
|
|
||||||
zeroPos.y = zeroPos.y + mathRound(mapSize.h/2)
|
|
||||||
|
|
||||||
local x, z
|
|
||||||
|
|
||||||
for color, peaksPos in pairs(peaks) do
|
|
||||||
for _, peakPos in ipairs(peaksPos) do
|
|
||||||
---@type integer, integer
|
|
||||||
x, z = (peakPos.x - zeroPos.x - 1) * scale, (peakPos.y - zeroPos.y - 1) * -scale
|
|
||||||
|
|
||||||
-- Converting a rectangular grid into an isometric-like one.
|
|
||||||
if peakPos.y % 2 == 1 then
|
|
||||||
x = mathRound(x + (scale/2))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type MapGen.PeakDef
|
|
||||||
local def = {
|
|
||||||
pos = {x=x, y=0, z=z},
|
|
||||||
color = color,
|
|
||||||
groups = groups,
|
|
||||||
}
|
|
||||||
|
|
||||||
self:register2DPeak(layerName, category, def)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Adds groups to the already registered groups in the peak by coordinate.
|
|
||||||
---If the peak does not exist, an error will be raised.
|
|
||||||
---@param layerName string The name of the layer in which the new peak will be included.
|
|
||||||
---@param category MapGen.Layer.Category Category indicating what will be generated by peak.
|
|
||||||
---@param pos MapPosition The position of the peak to which the group should be added.
|
|
||||||
---@param groups table<string, number> Groups to be added.
|
|
||||||
function MapGen:addGroupsToPeakByPos(layerName, category, pos, groups)
|
|
||||||
local layer = self:getLayerByName(layerName)
|
|
||||||
|
|
||||||
local peak = self:getPeakByPos(layer, category, pos)
|
|
||||||
assert( peak ~= nil, ('In the `%s` layer in the `%s` category there is no peak with coordinates: %s, %s, %s.'):format(
|
|
||||||
layerName, category, pos.x, pos.y, pos.z))
|
|
||||||
|
|
||||||
peak:addGroups(groups)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Mark a point on the biomes diagram and constrain the world area by height to mark it as `MapGen.Biome`.
|
---Mark a point on the biomes diagram and constrain the world area by height to mark it as `MapGen.Biome`.
|
||||||
---@param layerName string The name of the layer in which the new biome will be included.
|
---@param layerName string The name of the layer in which the new biome will be included.
|
||||||
---@param biomeName string The name to be assigned to the biome. The name must be unique for each biome.
|
---@param biomeName string The name to be assigned to the biome. The name must be unique for each biome.
|
||||||
@@ -588,31 +494,24 @@ end
|
|||||||
|
|
||||||
-- --- INITIALIZATION METHODS ---
|
-- --- INITIALIZATION METHODS ---
|
||||||
|
|
||||||
---Initialize the boundary region for a triangulated area.
|
---Initialize the boundary region for a layer and category.
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
---@param category MapGen.Layer.Category
|
function MapGen:initTriangultaionBoundaryRegion(layer)
|
||||||
---@param triangles MapGen.Triangle[]
|
local triangles = layer.trianglesList
|
||||||
function MapGen:initTriangultaionBoundaryRegion(layer, category, triangles)
|
|
||||||
local regionVertices = self:getTriangulateBoundaryVertices(triangles)
|
local regionVertices = self:getTriangulateBoundaryVertices(triangles)
|
||||||
|
|
||||||
local regionName = category..'_boundary'
|
local regionName = 'triangles_boundary'
|
||||||
|
|
||||||
local region = Region:new(regionName, {vertices = regionVertices})
|
local region = Region:new(regionName, {vertices = regionVertices})
|
||||||
|
|
||||||
layer:addRegion(regionName, region)
|
layer:addRegion(regionName, region)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Divide all layers into triangles whose vertices are the `Mapgen.Peak` belonging to these layers.
|
---Initialize border regions for all layers and all categories.
|
||||||
function MapGen:initLayersTriangultaion()
|
function MapGen:initLayersBoundaryRegion()
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
for _, layer in ipairs(self.layersList) do
|
for _, layer in ipairs(self.layersList) do
|
||||||
for category, peaks in pairs(layer.peaksList) do
|
self:initTriangultaionBoundaryRegion(layer)
|
||||||
local triangles = Triangulation.triangulate(peaks)
|
|
||||||
|
|
||||||
layer.trianglesList[category] = triangles
|
|
||||||
self:initTriangultaionBoundaryRegion(layer, category, triangles)
|
|
||||||
-- layer.tetrahedronsList = Triangulation.tetrahedralize(layer.peaksList) -- 3D not supported
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -695,6 +594,7 @@ end
|
|||||||
---@param y integer
|
---@param y integer
|
||||||
---@param z integer
|
---@param z integer
|
||||||
local function generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
local function generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
||||||
|
|
||||||
local ids = mapGenerator.nodeIDs
|
local ids = mapGenerator.nodeIDs
|
||||||
local waterLevel = layer.waterLevel
|
local waterLevel = layer.waterLevel
|
||||||
local height, temp, humidity = factors.height, factors.temp, factors.humidity
|
local height, temp, humidity = factors.height, factors.temp, factors.humidity
|
||||||
@@ -708,17 +608,17 @@ local function generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
|||||||
local scattHeight = y
|
local scattHeight = y
|
||||||
|
|
||||||
if scatteringGorizontal ~= 0 then
|
if scatteringGorizontal ~= 0 then
|
||||||
scattTemp = scattTemp + math.random(scatteringGorizontal * -1, scatteringGorizontal)
|
scattTemp = scattTemp + mathRandom(scatteringGorizontal * -1, scatteringGorizontal)
|
||||||
scattHumidity = scattHumidity + math.random(scatteringGorizontal * -1, scatteringGorizontal)
|
scattHumidity = scattHumidity + mathRandom(scatteringGorizontal * -1, scatteringGorizontal)
|
||||||
end
|
end
|
||||||
|
|
||||||
if scatteringVertical ~= 0 then
|
if scatteringVertical ~= 0 then
|
||||||
scattHeight = scattHeight + math.random(scatteringVertical * -1, scatteringVertical)
|
scattHeight = scattHeight + mathRandom(scatteringVertical * -1, scatteringVertical)
|
||||||
end
|
end
|
||||||
|
|
||||||
scattTemp = math.clamp(scattTemp, layer.minTemp, layer.maxTemp)
|
scattTemp = mathClamp(scattTemp, layer.minTemp, layer.maxTemp)
|
||||||
scattHumidity = math.clamp(scattHumidity, layer.minHumidity, layer.maxHumidity)
|
scattHumidity = mathClamp(scattHumidity, layer.minHumidity, layer.maxHumidity)
|
||||||
scattHeight = math.clamp(scattHeight, layer.minY, layer.maxY)
|
scattHeight = mathClamp(scattHeight, layer.minY, layer.maxY)
|
||||||
|
|
||||||
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
scattHeight, scattTemp, scattHumidity = mathRound(scattHeight), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
height, temp, humidity = mathRound(height), mathRound(scattTemp), mathRound(scattHumidity)
|
||||||
@@ -788,15 +688,15 @@ end
|
|||||||
---Calculates a weight for a coordinate using the projection onto
|
---Calculates a weight for a coordinate using the projection onto
|
||||||
---the triangle's height and specifying the distance to the peak
|
---the triangle's height and specifying the distance to the peak
|
||||||
---for which the weight is calculated.
|
---for which the weight is calculated.
|
||||||
---@param height MapGen.Triangulation.Edge
|
---@param height MapGen.Edge
|
||||||
---@param x integer
|
---@param x integer
|
||||||
---@param y integer
|
---@param y integer
|
||||||
---@param z integer
|
---@param z integer
|
||||||
---@return number
|
---@return number
|
||||||
local function calcWeight(height, x, y, z)
|
local function calcWeight(height, x, y, z)
|
||||||
local pos1 = vector.new(x, y, z)
|
local pos1 = v(x, y, z)
|
||||||
local pos2 = height.p1:getPeakPos()
|
local pos2 = height.p1.pos
|
||||||
local pos3 = height.p2:getPeakPos()
|
local pos3 = height.p2.pos
|
||||||
|
|
||||||
local v = pos3 - pos2
|
local v = pos3 - pos2
|
||||||
---@type vector
|
---@type vector
|
||||||
@@ -808,7 +708,7 @@ local function calcWeight(height, x, y, z)
|
|||||||
|
|
||||||
local posP = pos2 + v * t
|
local posP = pos2 + v * t
|
||||||
|
|
||||||
return 1 - vector.distance(pos2, posP) / height:length()
|
return 1 - pos2:distance(posP) / height:length()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns the weighted values of 2d noise.
|
---Returns the weighted values of 2d noise.
|
||||||
@@ -832,9 +732,9 @@ local function calcNoise2dValue(category, layer, triangle, x, y, z)
|
|||||||
local peak2 = triangle.p2
|
local peak2 = triangle.p2
|
||||||
local peak3 = triangle.p3
|
local peak3 = triangle.p3
|
||||||
|
|
||||||
local noise1 = layer:getNoiseByColor(category, peak1:getColor())
|
local noise1 = layer:getNoiseByColor(category, peak1.color)
|
||||||
local noise2 = layer:getNoiseByColor(category, peak2:getColor())
|
local noise2 = layer:getNoiseByColor(category, peak2.color)
|
||||||
local noise3 = layer:getNoiseByColor(category, peak3:getColor())
|
local noise3 = layer:getNoiseByColor(category, peak3.color)
|
||||||
|
|
||||||
local noiseValue = 0.0
|
local noiseValue = 0.0
|
||||||
|
|
||||||
@@ -861,166 +761,78 @@ end
|
|||||||
---Calculates a smoothed 2D noise value based on a preliminary space partitioning.
|
---Calculates a smoothed 2D noise value based on a preliminary space partitioning.
|
||||||
---
|
---
|
||||||
---Returns `nil` if the point is not included in any triangle.
|
---Returns `nil` if the point is not included in any triangle.
|
||||||
---@param category MapGen.Layer.Category
|
|
||||||
---@param layer MapGen.Layer
|
---@param layer MapGen.Layer
|
||||||
---@param x integer
|
---@param x integer
|
||||||
---@param y integer
|
---@param y integer
|
||||||
---@param z integer
|
---@param z integer
|
||||||
---@return number?
|
---@return number?, number?, number?
|
||||||
function MapGen:getNoises2dValue(category, layer, x, y, z)
|
function MapGen:getFactors(layer, x, y, z)
|
||||||
---@type MapGen.PastCalcNoiseValue
|
local posString = posToString({x=x,y=0,z=z})
|
||||||
local pastCalc = pastNoise2DCalc[category]
|
|
||||||
|
|
||||||
if (pastCalc.x ~= nil and pastCalc.z ~= nil) and (x == pastCalc.x and z == pastCalc.z) then
|
local factors = pastNoiseValues[layer.name][posString]
|
||||||
return pastCalc.noiseValue
|
if factors ~= nil then
|
||||||
|
return factors.height, factors.temp, factors.humidity
|
||||||
end
|
end
|
||||||
|
|
||||||
if pastCalc.triangle ~= nil then
|
-- TODO: это сильно тормозит обычные чанки, но ускоряет те, что находятся за границей
|
||||||
---@type number?
|
if not self:pointInRegion2D(layer, 'triangles_boundary', {x=x, y=y, z=z}) then
|
||||||
local noiseValue
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if pastTriangle ~= nil then
|
||||||
local triangles = {
|
local triangles = {
|
||||||
pastCalc.triangle,
|
pastTriangle,
|
||||||
pastCalc.triangle.neighbours.t1,
|
pastTriangle.neighbours[1],
|
||||||
pastCalc.triangle.neighbours.t2,
|
pastTriangle.neighbours[2],
|
||||||
pastCalc.triangle.neighbours.t3,
|
pastTriangle.neighbours[3],
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param t MapGen.Triangle
|
|
||||||
for _, t in ipairs(triangles) do
|
|
||||||
if pointInTriangle2D(x, z, t) then
|
|
||||||
noiseValue = calcNoise2dValue(category, layer, t, x, y, z)
|
|
||||||
|
|
||||||
pastCalc.x = x
|
|
||||||
pastCalc.z = z
|
|
||||||
pastCalc.noiseValue = noiseValue
|
|
||||||
|
|
||||||
return noiseValue
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not self:pointInRegion2D(layer, category..'_boundary', {x=x, y=y, z=z}) then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param triangle MapGen.Triangle
|
---@param triangle MapGen.Triangle
|
||||||
for _, triangle in ipairs(layer.trianglesList[category]) do
|
for _, triangle in ipairs(triangles) do
|
||||||
if pointInTriangle2D(x, z, triangle) then
|
if self:isPointInTriangle(triangle, v(x, 0, z)) then
|
||||||
local noiseValue = calcNoise2dValue(category, layer, triangle, x, y, z)
|
local height = calcNoise2dValue('landscape', layer, triangle, x, y, z)
|
||||||
|
local temp = calcNoise2dValue('temp', layer, triangle, x, y, z)
|
||||||
|
local humidity = calcNoise2dValue('humidity', layer, triangle, x, y, z)
|
||||||
|
|
||||||
pastCalc.triangle = triangle
|
pastNoiseValues[layer.name][posString] = {
|
||||||
pastCalc.x = x
|
height = height,
|
||||||
pastCalc.z = z
|
temp = temp,
|
||||||
pastCalc.noiseValue = noiseValue
|
humidity = humidity
|
||||||
|
}
|
||||||
|
|
||||||
return noiseValue
|
return height, temp, humidity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If the point does not fall within the triangle, it is impossible to calculate the height.
|
local triangle = self:findTriangle(layer, x, z, pastTriangle)
|
||||||
-- For debugging purposes only, may slow down generation:
|
if triangle == nil then
|
||||||
--core.log('warning', string.format('The point %s %s %s does not fall within any triangle, calculating the noise value is impossible.', tostring(x), tostring(y), tostring(z)))
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
local height = calcNoise2dValue('landscape', layer, triangle, x, y, z)
|
||||||
3D noise smoothing is too slow, so it was decided to stop using it.
|
local temp = calcNoise2dValue('temp', layer, triangle, x, y, z)
|
||||||
|
local humidity = calcNoise2dValue('humidity', layer, triangle, x, y, z)
|
||||||
|
|
||||||
---@param P vector
|
pastTriangle = triangle
|
||||||
---@param A vector
|
pastNoiseValues[layer.name][posString] = {
|
||||||
---@param B vector
|
height = height,
|
||||||
---@param C vector
|
temp = temp,
|
||||||
local function pointInTetrahedron(P, A, B, C, D)
|
humidity = humidity
|
||||||
local function det3(a, b, c)
|
}
|
||||||
return a.x * (b.y * c.z - b.z * c.y)
|
|
||||||
- a.y * (b.x * c.z - b.z * c.x)
|
return height, temp, humidity
|
||||||
+ a.z * (b.x * c.y - b.y * c.x)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local v0 = B - A
|
|
||||||
local v1 = C - A
|
|
||||||
local v2 = D - A
|
|
||||||
local v3 = P - A
|
|
||||||
|
|
||||||
local d = det3(v0, v1, v2)
|
|
||||||
|
|
||||||
local u = det3(v3, v1, v2) / d
|
|
||||||
local v = det3(v0, v3, v2) / d
|
|
||||||
local w = det3(v0, v1, v3) / d
|
|
||||||
|
|
||||||
return (u >= 0 and v >= 0 and w >= 0 and (u + v + w) <= 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Calculates a smoothed 3D noise value based on a preliminary space partitioning.
|
|
||||||
---
|
|
||||||
---Returns `nil` if the point is not included in any tetrahedron.
|
|
||||||
---
|
|
||||||
---@param layer MapGen.Layer
|
|
||||||
---@param x number
|
|
||||||
---@param y number
|
|
||||||
---@param z number
|
|
||||||
---@return number?
|
|
||||||
function MapGen:getNoises3dValues(layer, x, y, z)
|
|
||||||
---@param triangle MapGen.Tetrahedron
|
|
||||||
for _, tetrahedron in ipairs(layer.tetrahedronsList) do
|
|
||||||
local peak1 = tetrahedron.p1
|
|
||||||
local peak2 = tetrahedron.p2
|
|
||||||
local peak3 = tetrahedron.p3
|
|
||||||
local peak4 = tetrahedron.p4
|
|
||||||
|
|
||||||
local pos1 = peak1:getPeakPos()
|
|
||||||
local pos2 = peak2:getPeakPos()
|
|
||||||
local pos3 = peak3:getPeakPos()
|
|
||||||
local pos4 = peak4:getPeakPos()
|
|
||||||
|
|
||||||
-- If the point is in the tetrahedron defined by the `MapGen.Peak`...
|
|
||||||
if pointInTetrahedron(
|
|
||||||
vector.new(x, y, z),
|
|
||||||
pos1,
|
|
||||||
pos2,
|
|
||||||
pos3,
|
|
||||||
pos4
|
|
||||||
)
|
|
||||||
then
|
|
||||||
local noiseValue = 0.0
|
|
||||||
|
|
||||||
local totalWeight = 0.0
|
|
||||||
|
|
||||||
-- ... we calculate the height for this point using smoothing.
|
|
||||||
local weight = calcWeight(tetrahedron.h1, x, y, z)
|
|
||||||
noiseValue = noiseValue + peak1:getMultinoise().someNoise:get_3d({x = x, y = y, z = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
|
||||||
|
|
||||||
weight = calcWeight(tetrahedron.h2, x, y, z)
|
|
||||||
noiseValue = noiseValue + peak1:getMultinoise().someNoise:get_3d({x = x, y = y, z = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
|
||||||
|
|
||||||
weight = calcWeight(tetrahedron.h3, x, y, z)
|
|
||||||
noiseValue = noiseValue + peak2:getMultinoise().someNoise:get_3d({x = x, y = y, z = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
|
||||||
|
|
||||||
weight = calcWeight(tetrahedron.h4, x, y, z)
|
|
||||||
noiseValue = noiseValue + peak3:getMultinoise().someNoise:get_2d({x = x, y = y, z = z}) * weight
|
|
||||||
totalWeight = totalWeight + weight
|
|
||||||
|
|
||||||
return mathRound(noiseValue / totalWeight)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- If the point does not fall within the tetrahedron, it is impossible to calculate the height.
|
|
||||||
-- For debugging purposes only, may slow down generation:
|
|
||||||
-- core.log('warning', string.format('The point %s %s %s does not fall within any tetrahedron, calculating the noise value is impossible.', tostring(x), tostring(y), tostring(z)))
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
---Generator handler for specific coordinates.
|
---Generator handler for specific coordinates.
|
||||||
---@param mapGenerator MapGen
|
---@param mapGenerator MapGen
|
||||||
|
---@param layer MapGen.Layer?
|
||||||
---@param data number[]
|
---@param data number[]
|
||||||
---@param index number
|
---@param index number
|
||||||
---@param x integer
|
---@param x integer
|
||||||
---@param y integer
|
---@param y integer
|
||||||
---@param z integer
|
---@param z integer
|
||||||
local function generatorHandler(mapGenerator, data, index, x, y, z)
|
local function generatorHandler(mapGenerator, layer, data, index, x, y, z)
|
||||||
-- If the node belongs to a static layer, then a static node is generated.
|
-- If the node belongs to a static layer, then a static node is generated.
|
||||||
local static = mapGenerator:getStaticByHeight(y)
|
local static = mapGenerator:getStaticByHeight(y)
|
||||||
if static ~= nil then
|
if static ~= nil then
|
||||||
@@ -1030,42 +842,32 @@ local function generatorHandler(mapGenerator, data, index, x, y, z)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- If generation occurs outside the layers, then a void is generated.
|
-- If generation occurs outside the layers, then a void is generated.
|
||||||
local layer = mapGenerator:getLayerByHeight(y)
|
|
||||||
if layer == nil then
|
if layer == nil then
|
||||||
data[index] = mapGenerator.nodeIDs.air
|
data[index] = mapGenerator.nodeIDs.air
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local endGetLayerTime = getUsTime()
|
||||||
|
local startNoiseCalcTime = endGetLayerTime
|
||||||
-- If the value of the noise is `nil`,
|
-- If the value of the noise is `nil`,
|
||||||
-- then the point does not fall within any of the triangles.
|
-- then the point does not fall within any of the triangles.
|
||||||
local noiseHeightValue = mapGenerator:getNoises2dValue('landscape', layer, x, y, z)
|
local height, temp, humidity = mapGenerator:getFactors(layer, x, y, z)
|
||||||
if noiseHeightValue == nil then
|
if height == nil or temp == nil or humidity == nil then
|
||||||
data[index] = core.CONTENT_IGNORE
|
data[index] = core.CONTENT_IGNORE
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local noiseTempValue = mapGenerator:getNoises2dValue('temp', layer, x, y, z)
|
|
||||||
if noiseTempValue == nil then
|
|
||||||
data[index] = core.CONTENT_IGNORE
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local noiseHumidityValue = mapGenerator:getNoises2dValue('humidity', layer, x, y, z)
|
|
||||||
if noiseHumidityValue == nil then
|
|
||||||
data[index] = core.CONTENT_IGNORE
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We recalculate the climate based on altitude.
|
-- We recalculate the climate based on altitude.
|
||||||
noiseTempValue = layer:calcTemp(noiseTempValue, y)
|
temp = layer:calcTemp(temp, y)
|
||||||
noiseHumidityValue = layer:calcHumidity(noiseHumidityValue, y)
|
humidity = layer:calcHumidity(humidity, y)
|
||||||
|
|
||||||
---@type MapGen.factors
|
---@type MapGen.factors
|
||||||
local factors = {
|
local factors = {
|
||||||
height = noiseHeightValue,
|
height = height,
|
||||||
temp = noiseTempValue,
|
temp = temp,
|
||||||
humidity = noiseHumidityValue,
|
humidity = humidity,
|
||||||
}
|
}
|
||||||
|
|
||||||
generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
generateNode(mapGenerator, layer, factors, data, index, x, y, z)
|
||||||
@@ -1077,8 +879,16 @@ end
|
|||||||
---@param maxPos MapPosition
|
---@param maxPos MapPosition
|
||||||
---@param blockseed number
|
---@param blockseed number
|
||||||
function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
||||||
-- We obtain a generation area for further manipulations
|
local minPosStr, maxPosStr = posToString(minPos), posToString(maxPos)
|
||||||
--local voxelManip, eMin, eMax = core.get_mapgen_object('voxelmanip')
|
local startTime, endTime = 0.0, 0.0
|
||||||
|
|
||||||
|
if LOG_PROFILE then
|
||||||
|
mglog('Chunk run:\n'..
|
||||||
|
'min_pos: %s\n'..
|
||||||
|
'max_pos: %s\n',
|
||||||
|
minPosStr, maxPosStr)
|
||||||
|
startTime = getUsTime()
|
||||||
|
end
|
||||||
|
|
||||||
local eMin, eMax = voxelManip:get_emerged_area()
|
local eMin, eMax = voxelManip:get_emerged_area()
|
||||||
|
|
||||||
@@ -1094,6 +904,11 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
-- local param2_data = voxelManip:get_param2_data()
|
-- local param2_data = voxelManip:get_param2_data()
|
||||||
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
||||||
|
|
||||||
|
-- We obtain a layer for the entire chunk at once for optimization purposes.
|
||||||
|
-- Therefore, if the layer boundaries do not coincide with the chunk boundaries,
|
||||||
|
-- the chunk will be entirely contained within the layer containing its center.
|
||||||
|
local layer = self:getLayerByHeight((minPos.y+maxPos.y)/2)
|
||||||
|
|
||||||
local index
|
local index
|
||||||
-- Initial generation: landscape
|
-- Initial generation: landscape
|
||||||
for z = minPos.z, maxPos.z do
|
for z = minPos.z, maxPos.z do
|
||||||
@@ -1101,13 +916,14 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
for y = minPos.y, maxPos.y do
|
for y = minPos.y, maxPos.y do
|
||||||
index = area:index(x, y, z)
|
index = area:index(x, y, z)
|
||||||
|
|
||||||
if data[index] == core.CONTENT_AIR then
|
if data[index] == AIR_ID then
|
||||||
generatorHandler(self, data, index, x, y, z)
|
generatorHandler(self, layer, data, index, x, y, z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Post-proccesing generation
|
-- Post-proccesing generation
|
||||||
for _, ppdata in pairs(postProcessing) do
|
for _, ppdata in pairs(postProcessing) do
|
||||||
if ppdata.biome.postProcessing ~= nil then
|
if ppdata.biome.postProcessing ~= nil then
|
||||||
@@ -1134,7 +950,18 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
|
|||||||
voxelManip:calc_lighting()
|
voxelManip:calc_lighting()
|
||||||
voxelManip:update_liquids()
|
voxelManip:update_liquids()
|
||||||
|
|
||||||
--voxelManip:write_to_map() -- Async edit
|
pastTriangle = nil
|
||||||
|
|
||||||
|
if PROFILE_CHUNK then
|
||||||
|
endTime = getUsTime()
|
||||||
|
mglog('Chunk end:\n'..
|
||||||
|
'min_pos: %s\n'..
|
||||||
|
'max_pos: %s\n'..
|
||||||
|
'time (sec): %.3f\n'..
|
||||||
|
'---------------',
|
||||||
|
minPosStr, maxPosStr,
|
||||||
|
(endTime - startTime)/1000000)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -1157,9 +984,10 @@ function MapGen:run()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
self:initBiomesDiagram()
|
self:initBiomesDiagram()
|
||||||
self:initLayersTriangultaion()
|
self:initLayersBoundaryRegion()
|
||||||
|
|
||||||
MapGen.isRunning = true
|
MapGen.isRunning = true
|
||||||
|
core.log('MapGen run')
|
||||||
end
|
end
|
||||||
|
|
||||||
return MapGen
|
return MapGen
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
---@class MapGen.Triangulation.Edge
|
---@class MapGen.Edge
|
||||||
---@field p1 MapGen.Peak
|
---@field p1 MapGen.Peak
|
||||||
---@field p2 MapGen.Peak
|
---@field p2 MapGen.Peak
|
||||||
|
---@field vec vector
|
||||||
local Edge = {}
|
local Edge = {}
|
||||||
|
|
||||||
---@param p1 MapGen.Peak
|
---@param p1 MapGen.Peak
|
||||||
---@param p2 MapGen.Peak
|
---@param p2 MapGen.Peak
|
||||||
---@return MapGen.Triangulation.Edge
|
---@return MapGen.Edge
|
||||||
function Edge:new( p1, p2 )
|
function Edge:new( p1, p2 )
|
||||||
---@type MapGen.Triangulation.Edge
|
---@type MapGen.Edge
|
||||||
local instance = getInstance(self, {
|
local instance = getInstance(self, {
|
||||||
p1 = p1,
|
p1 = p1,
|
||||||
p2 = p2
|
p2 = p2,
|
||||||
|
vec = p2.pos - p1.pos
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
__tostring = self.toString,
|
__tostring = self.toString,
|
||||||
@@ -29,14 +31,14 @@ function Edge:toString()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Returns true if the edges are equivalent.
|
---Returns true if the edges are equivalent.
|
||||||
---@param other MapGen.Triangulation.Edge
|
---@param other MapGen.Edge
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Edge:eq(other)
|
function Edge:eq(other)
|
||||||
return self.p1 == other.p1 and self.p2 == other.p2
|
return self.p1 == other.p1 and self.p2 == other.p2
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns true if the edges are similar.
|
---Returns true if the edges are similar.
|
||||||
---@param other MapGen.Triangulation.Edge
|
---@param other MapGen.Edge
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Edge:same(other)
|
function Edge:same(other)
|
||||||
return (self.p1 == other.p1 and self.p2 == other.p2)
|
return (self.p1 == other.p1 and self.p2 == other.p2)
|
||||||
@@ -46,14 +48,14 @@ end
|
|||||||
---Returns the length of an edge.
|
---Returns the length of an edge.
|
||||||
---@return number
|
---@return number
|
||||||
function Edge:length()
|
function Edge:length()
|
||||||
return (self.p1.getPeakPos() - self.p2.getPeakPos()):length()
|
return (self.p1.pos - self.p2.pos):length()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Returns the vector of the point located in the middle of the edge.
|
---Returns the vector of the point located in the middle of the edge.
|
||||||
---@return vector
|
---@return vector
|
||||||
function Edge:getMidPoint()
|
function Edge:getMidPoint()
|
||||||
local pos1 = self.p1:getPeakPos()
|
local pos1 = self.p1.pos
|
||||||
local pos2 = self.p2:getPeakPos()
|
local pos2 = self.p2.pos
|
||||||
|
|
||||||
return (pos1 + pos2 )/2
|
return (pos1 + pos2 )/2
|
||||||
end
|
end
|
||||||
@@ -7,7 +7,7 @@ local Peak = require('MapGen.Peak')
|
|||||||
---Allows you to create a `MapGen.Peak` without specifying a noise parameter.
|
---Allows you to create a `MapGen.Peak` without specifying a noise parameter.
|
||||||
---
|
---
|
||||||
---**WARNING: MUST NOT BE PARTICIPATED IN GENERATION**
|
---**WARNING: MUST NOT BE PARTICIPATED IN GENERATION**
|
||||||
---@class MapGen.Triangulation.FakePeak : MapGen.Peak
|
---@class MapGen.FakePeak : MapGen.Peak
|
||||||
---@field id number
|
---@field id number
|
||||||
---@field getPeakPos fun():vector
|
---@field getPeakPos fun():vector
|
||||||
local FakePeak = Class.extend(Peak, {})
|
local FakePeak = Class.extend(Peak, {})
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
local getInstance = Class.getInstance
|
local getInstance = Class.getInstance
|
||||||
|
|
||||||
|
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
---@type MapGen.Peak
|
||||||
|
local Peak = require('MapGen.Peak')
|
||||||
|
---@type MapGen.Triangle
|
||||||
|
local Triangle = require('MapGen.Triangle')
|
||||||
|
|
||||||
---@class MapGen.Layer
|
---@class MapGen.Layer
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field minY integer
|
---@field minY integer
|
||||||
@@ -11,9 +19,10 @@ local getInstance = Class.getInstance
|
|||||||
---@field waterLevel integer
|
---@field waterLevel integer
|
||||||
---@field calcTemp fun(self:MapGen.Layer, value:number, height:number):number
|
---@field calcTemp fun(self:MapGen.Layer, value:number, height:number):number
|
||||||
---@field calcHumidity fun(self:MapGen.Layer, value:number, height:number):number
|
---@field calcHumidity fun(self:MapGen.Layer, value:number, height:number):number
|
||||||
---@field peaksList {['landscape']:MapGen.Peak[],['temp']:MapGen.Peak[],['humidity']:MapGen.Peak[]}
|
---@field peaksList MapGen.Peak[]
|
||||||
---@field noisesByColor {['landscape']:table<ColorString, ValueNoise>,['temp']:table<ColorString, ValueNoise>,['humidity']:table<ColorString, ValueNoise>}
|
---@field peaksByPos table<string, MapGen.Peak>
|
||||||
---@field noisesParamsByColor {['landscape']:table<ColorString, NoiseParams>,['temp']:table<ColorString, NoiseParams>,['humidity']:table<ColorString, NoiseParams>}
|
---@field noisesByColor table<MapGen.Layer.Category, table<ColorString, ValueNoise>>
|
||||||
|
---@field noisesParamsByColor table<MapGen.Layer.Category, table<ColorString, NoiseParams>>
|
||||||
---@field biomesByName table<string, MapGen.Biome>
|
---@field biomesByName table<string, MapGen.Biome>
|
||||||
---@field biomesList MapGen.Biome[]
|
---@field biomesList MapGen.Biome[]
|
||||||
---@field biomesDiagram table
|
---@field biomesDiagram table
|
||||||
@@ -22,14 +31,10 @@ local getInstance = Class.getInstance
|
|||||||
---@field cavernsByName table<string, MapGen.Cavern>
|
---@field cavernsByName table<string, MapGen.Cavern>
|
||||||
---@field cavernsList MapGen.Cavern[]
|
---@field cavernsList MapGen.Cavern[]
|
||||||
---@field regionsByName table<string, MapGen.Region>
|
---@field regionsByName table<string, MapGen.Region>
|
||||||
---@field trianglesList {['landscape']:MapGen.Triangle[],['temp']:MapGen.Triangle[],['humidity']:MapGen.Triangle[]}
|
---@field trianglesList MapGen.Triangle[]
|
||||||
---@field tetrahedronsList MapGen.Tetrahedron[] **Not supported**
|
|
||||||
local Layer = {
|
local Layer = {
|
||||||
peaksList = {
|
peaksList = {},
|
||||||
landscape = {},
|
peaksByPos = {},
|
||||||
temp = {},
|
|
||||||
humidity = {},
|
|
||||||
},
|
|
||||||
noisesByColor = {
|
noisesByColor = {
|
||||||
landscape = {},
|
landscape = {},
|
||||||
temp = {},
|
temp = {},
|
||||||
@@ -46,11 +51,7 @@ local Layer = {
|
|||||||
cavernsByName = {},
|
cavernsByName = {},
|
||||||
cavernsList = {},
|
cavernsList = {},
|
||||||
regionsByName = {},
|
regionsByName = {},
|
||||||
trianglesList = {
|
trianglesList = {},
|
||||||
landscape = {},
|
|
||||||
temp = {},
|
|
||||||
humidity = {},
|
|
||||||
},
|
|
||||||
tetrahedronsList = {},
|
tetrahedronsList = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,17 +59,23 @@ local Layer = {
|
|||||||
---
|
---
|
||||||
---**Only for EmmyLua.**
|
---**Only for EmmyLua.**
|
||||||
---@class MapGen.LayerDef
|
---@class MapGen.LayerDef
|
||||||
---@field minY number
|
---@field minY integer
|
||||||
---@field maxY number
|
---@field maxY integer
|
||||||
---@field minTemp number
|
---@field minTemp integer
|
||||||
---@field maxTemp number
|
---@field maxTemp integer
|
||||||
---@field minHumidity number
|
---@field minHumidity integer
|
||||||
---@field maxHumidity number
|
---@field maxHumidity integer
|
||||||
---@field waterLevel? number
|
---@field waterLevel? integer
|
||||||
---@field calcTemp (fun(self:MapGen.Layer, value:number, height:number):number)?
|
---@field calcTemp (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||||
---@field calcHumidity (fun(self:MapGen.Layer, value:number, height:number):number)?
|
---@field calcHumidity (fun(self:MapGen.Layer, value:number, height:number):number)?
|
||||||
---@field biomesGorizontalScattering number?
|
---@field biomesGorizontalScattering integer?
|
||||||
---@field biomesVerticalScattering number?
|
---@field biomesVerticalScattering integer?
|
||||||
|
---@field triangulationLandscapeFile string
|
||||||
|
---@field triangulationTempFile string
|
||||||
|
---@field triangulationHumidityFile string
|
||||||
|
---@field landscapeMapScale number
|
||||||
|
---@field tempMapScale number
|
||||||
|
---@field humidityMapScale number
|
||||||
|
|
||||||
---@param self MapGen.Layer
|
---@param self MapGen.Layer
|
||||||
---@param value number
|
---@param value number
|
||||||
@@ -78,6 +85,73 @@ local function defaultCalcFunc(self, value, height)
|
|||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Checks `def` for compliance with `MapGen.PeakDef` and creates a new peak
|
||||||
|
---if a peak with such coordinates has not yet been registered or returns an existing one.
|
||||||
|
---
|
||||||
|
---**Note:** If the colors of the new peak and the existing one at the same coordinates
|
||||||
|
---are different, an error will be called.
|
||||||
|
---@param def MapGen.PeakDef
|
||||||
|
---@param scale number
|
||||||
|
---@return MapGen.Peak
|
||||||
|
function Layer:registerPeak(def, scale)
|
||||||
|
assert(def.pos ~= nil)
|
||||||
|
assert(def.pos.x ~= nil)
|
||||||
|
assert(def.pos.z ~= nil)
|
||||||
|
assert(def.color ~= nil)
|
||||||
|
assert(type(def.color) == 'string')
|
||||||
|
|
||||||
|
def.pos.x = def.pos.x * scale
|
||||||
|
def.pos.z = def.pos.z * scale
|
||||||
|
def.pos.y = 0
|
||||||
|
|
||||||
|
local positionStr = core.pos_to_string(def.pos)
|
||||||
|
|
||||||
|
local peak = self.peaksByPos[positionStr]
|
||||||
|
|
||||||
|
if peak == nil then
|
||||||
|
peak = Peak:new(def)
|
||||||
|
self.peaksByPos[positionStr] = peak
|
||||||
|
elseif peak.color ~= def.color then
|
||||||
|
error('There cannot be two peaks with the same coordinates but different colors.')
|
||||||
|
end
|
||||||
|
|
||||||
|
return peak
|
||||||
|
end
|
||||||
|
|
||||||
|
function Layer:initTrianglesNeighbours()
|
||||||
|
local triangles = self.trianglesList
|
||||||
|
|
||||||
|
for _, triangle in pairs(triangles) do
|
||||||
|
for _, id in ipairs(triangle.neighboursIDs) do
|
||||||
|
table.insert(triangle.neighbours, triangles[id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param fileName string
|
||||||
|
---@param category MapGen.Layer.Category
|
||||||
|
---@param scale number
|
||||||
|
function Layer:getTriaglesFromFile(fileName, category, scale)
|
||||||
|
local file = io.open(core.get_modpath(core.get_current_modname())..'/maps/'..fileName, 'r')
|
||||||
|
assert(file ~= nil)
|
||||||
|
|
||||||
|
local json = core.parse_json(file:read('*a')) or {}
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
local triangles = json.triangles
|
||||||
|
assert(triangles ~= nil)
|
||||||
|
|
||||||
|
for _, tr in ipairs(triangles) do
|
||||||
|
local p1 = self:registerPeak( tr.vertices[1], scale)
|
||||||
|
local p2 = self:registerPeak( tr.vertices[2], scale)
|
||||||
|
local p3 = self:registerPeak( tr.vertices[3], scale)
|
||||||
|
|
||||||
|
local triangle = Triangle:new(tr.id,p1, p2, p3, tr.adjacent_triangle_ids)
|
||||||
|
|
||||||
|
self:addTriangle(category, triangle)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param def MapGen.LayerDef
|
---@param def MapGen.LayerDef
|
||||||
---@return MapGen.Layer
|
---@return MapGen.Layer
|
||||||
@@ -93,20 +167,34 @@ function Layer:new(name, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@type MapGen.Layer
|
---@type MapGen.Layer
|
||||||
local instance = getInstance(self, {
|
local instance = getInstance(self, {})
|
||||||
name = name,
|
instance.name = name
|
||||||
minY = def.minY,
|
instance.minY = def.minY
|
||||||
maxY = def.maxY,
|
instance.maxY = def.maxY
|
||||||
minTemp = def.minTemp,
|
instance.minTemp = def.minTemp
|
||||||
maxTemp = def.maxTemp,
|
instance.maxTemp = def.maxTemp
|
||||||
minHumidity = def.minHumidity,
|
instance.minHumidity = def.minHumidity
|
||||||
maxHumidity = def.maxHumidity,
|
instance.maxHumidity = def.maxHumidity
|
||||||
waterLevel = def.waterLevel or 0,
|
instance.waterLevel = def.waterLevel or 0
|
||||||
calcTemp = def.calcTemp,
|
instance.calcTemp = def.calcTemp
|
||||||
calcHumidity = def.calcHumidity,
|
instance.calcHumidity = def.calcHumidity
|
||||||
biomesGorizontalScattering = def.biomesGorizontalScattering or 0,
|
instance.biomesGorizontalScattering = def.biomesGorizontalScattering or 0
|
||||||
biomesVerticalScattering = def.biomesVerticalScattering or 0,
|
instance.biomesVerticalScattering = def.biomesVerticalScattering or 0
|
||||||
})
|
|
||||||
|
instance:getTriaglesFromFile(
|
||||||
|
def.triangulationLandscapeFile,
|
||||||
|
'landscape',
|
||||||
|
def.landscapeMapScale)
|
||||||
|
instance:getTriaglesFromFile(
|
||||||
|
def.triangulationTempFile,
|
||||||
|
'temp',
|
||||||
|
def.tempMapScale)
|
||||||
|
instance:getTriaglesFromFile(
|
||||||
|
def.triangulationHumidityFile,
|
||||||
|
'humidity',
|
||||||
|
def.humidityMapScale)
|
||||||
|
|
||||||
|
instance:initTrianglesNeighbours()
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -114,35 +202,35 @@ end
|
|||||||
---A category of noise that affects specific map generation objects.
|
---A category of noise that affects specific map generation objects.
|
||||||
---@alias MapGen.Layer.Category 'landscape'|'temp'|'humidity'
|
---@alias MapGen.Layer.Category 'landscape'|'temp'|'humidity'
|
||||||
|
|
||||||
---Adds a peak to the `Layer.peaksList`
|
---Adds a triangle to the `Layer.trianglesList`
|
||||||
---@param category MapGen.Layer.Category
|
---@param category MapGen.Layer.Category
|
||||||
---@param peak MapGen.Peak
|
---@param triangle MapGen.Triangle
|
||||||
function Layer:addPeak(category, peak)
|
function Layer:addTriangle(category, triangle)
|
||||||
if category == 'landscape' then
|
local triangles = self.trianglesList
|
||||||
table.insert(self.peaksList.landscape, peak)
|
if triangles ~= nil then
|
||||||
elseif category == 'temp' then
|
triangles[triangle.id] = triangle
|
||||||
table.insert(self.peaksList.temp, peak)
|
|
||||||
elseif category == 'humidity' then
|
|
||||||
table.insert(self.peaksList.humidity, peak)
|
|
||||||
else
|
else
|
||||||
error(('There is no peak category named %s.'):format(category))
|
error(('There is no peak category named %s.'):format(category))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Adds a peak to the `Layer.peaksList`
|
||||||
|
---@param category MapGen.Layer.Category
|
||||||
|
---@param peak MapGen.Peak
|
||||||
|
function Layer:addPeak(category, peak)
|
||||||
|
table.insert(self.peaksList, peak)
|
||||||
|
end
|
||||||
|
|
||||||
---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns `nil`.
|
---Returns the `MapGen.Peak` at the coordinates. If there is no peak at these coordinates, it returns `nil`.
|
||||||
---@param category MapGen.Layer.Category The category in which the peak is located.
|
|
||||||
---@param pos Position Coordinate of the desired peak.
|
---@param pos Position Coordinate of the desired peak.
|
||||||
---@return MapGen.Peak?
|
---@return MapGen.Peak?
|
||||||
function Layer:getPeakByPos(category, pos)
|
function Layer:getPeakByPos(pos)
|
||||||
pos = vector.new(pos)
|
local positionStr = core.pos_to_string(pos)
|
||||||
|
|
||||||
|
local peak = self.peaksByPos[positionStr]
|
||||||
|
|
||||||
---@param peak MapGen.Peak
|
|
||||||
for _, peak in ipairs(self.peaksList[category]) do
|
|
||||||
if peak:getPeakPos() == pos then
|
|
||||||
return peak
|
return peak
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Adds a NoiseParams color to the `Layer.noisesParamsByColor`
|
---Adds a NoiseParams color to the `Layer.noisesParamsByColor`
|
||||||
---@param category MapGen.Layer.Category
|
---@param category MapGen.Layer.Category
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ local getInstance = Class.getInstance
|
|||||||
|
|
||||||
---@class MapGen.Peak
|
---@class MapGen.Peak
|
||||||
---@field id number
|
---@field id number
|
||||||
---@field getPeakPos fun(self):vector
|
---@field pos vector
|
||||||
---@field getColor fun(self):ColorString
|
---@field color ColorString
|
||||||
---@field getGroups fun(self):table<string, number>
|
---@field getGroups fun(self):table<string, number>
|
||||||
---@field addGroups fun(self, groups:table<string, number>)
|
---@field addGroups fun(self, groups:table<string, number>)
|
||||||
local Peak = {
|
local Peak = {
|
||||||
@@ -23,7 +23,6 @@ local Peak = {
|
|||||||
---@param def MapGen.PeakDef
|
---@param def MapGen.PeakDef
|
||||||
---@return MapGen.Peak
|
---@return MapGen.Peak
|
||||||
function Peak:new(def)
|
function Peak:new(def)
|
||||||
local _pos = vector.new(def.pos)
|
|
||||||
local _color = def.color
|
local _color = def.color
|
||||||
local _groups
|
local _groups
|
||||||
|
|
||||||
@@ -39,14 +38,8 @@ function Peak:new(def)
|
|||||||
__tostring = self.toString,
|
__tostring = self.toString,
|
||||||
__eq = self.eq
|
__eq = self.eq
|
||||||
})
|
})
|
||||||
|
instance.pos = vector.new(def.pos)
|
||||||
function instance:getPeakPos()
|
instance.color = def.color
|
||||||
return _pos:copy()
|
|
||||||
end
|
|
||||||
|
|
||||||
function instance:getColor()
|
|
||||||
return _color
|
|
||||||
end
|
|
||||||
|
|
||||||
function instance:getGroups()
|
function instance:getGroups()
|
||||||
return table.copy_with_metatables(_groups)
|
return table.copy_with_metatables(_groups)
|
||||||
@@ -66,7 +59,7 @@ end
|
|||||||
---Returns a string describing the object in a readable form.
|
---Returns a string describing the object in a readable form.
|
||||||
---@return string
|
---@return string
|
||||||
function Peak:toString()
|
function Peak:toString()
|
||||||
local pos = self:getPeakPos()
|
local pos = self.pos
|
||||||
return ('Peak (%s) x: %.2f y: %.2f z: %.2f'):format( self.id, pos.x, pos.y, pos.z)
|
return ('Peak (%s) x: %.2f y: %.2f z: %.2f'):format( self.id, pos.x, pos.y, pos.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -74,8 +67,8 @@ end
|
|||||||
---@param other MapGen.Peak
|
---@param other MapGen.Peak
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Peak:eq(other)
|
function Peak:eq(other)
|
||||||
local pos1 = self:getPeakPos()
|
local pos1 = self.pos
|
||||||
local pos2 = other:getPeakPos()
|
local pos2 = other.pos
|
||||||
|
|
||||||
return pos1.x == pos2.x and pos1.z == pos2.z
|
return pos1.x == pos2.x and pos1.z == pos2.z
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,155 +0,0 @@
|
|||||||
---@diagnostic disable: param-type-not-match
|
|
||||||
local mathAbs = math.abs
|
|
||||||
|
|
||||||
local getInstance = Class.getInstance
|
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
|
||||||
local require = modInfo.require
|
|
||||||
|
|
||||||
---@type MapGen.Triangle
|
|
||||||
local Triangle = require('MapGen.Triangle')
|
|
||||||
---@type MapGen.Triangulation.Edge
|
|
||||||
local Edge = require('MapGen.Triangulation.Edge')
|
|
||||||
---@type MapGen.Triangulation.FakePeak
|
|
||||||
local FakePeak = require('MapGen.Triangulation.FakePeak')
|
|
||||||
|
|
||||||
---@class MapGen.Tetrahedron
|
|
||||||
---@field p1 MapGen.Peak
|
|
||||||
---@field p2 MapGen.Peak
|
|
||||||
---@field p3 MapGen.Peak
|
|
||||||
---@field p4 MapGen.Peak
|
|
||||||
---@field h1 MapGen.Triangulation.Edge
|
|
||||||
---@field h2 MapGen.Triangulation.Edge
|
|
||||||
---@field h3 MapGen.Triangulation.Edge
|
|
||||||
---@field h4 MapGen.Triangulation.Edge
|
|
||||||
---@field f1 MapGen.Triangle
|
|
||||||
---@field f2 MapGen.Triangle
|
|
||||||
---@field f3 MapGen.Triangle
|
|
||||||
---@field f4 MapGen.Triangle
|
|
||||||
local Tetrahedron = {}
|
|
||||||
|
|
||||||
---@param p1 MapGen.Peak
|
|
||||||
---@param p2 MapGen.Peak
|
|
||||||
---@param p3 MapGen.Peak
|
|
||||||
---@param p4 MapGen.Peak
|
|
||||||
---@return MapGen.Tetrahedron
|
|
||||||
function Tetrahedron:new(p1, p2, p3, p4)
|
|
||||||
local instance = getInstance(self, {
|
|
||||||
p1 = p1,
|
|
||||||
p2 = p2,
|
|
||||||
p3 = p3,
|
|
||||||
p4 = p4,
|
|
||||||
h1 = self:getHeight(p1, p2, p3, p4),
|
|
||||||
h2 = self:getHeight(p2, p3, p4, p1),
|
|
||||||
h3 = self:getHeight(p3, p4, p1, p2),
|
|
||||||
h4 = self:getHeight(p4, p1, p2, p3),
|
|
||||||
f1 = Triangle:new(p1, p2, p3),
|
|
||||||
f2 = Triangle:new(p1, p2, p4),
|
|
||||||
f3 = Triangle:new(p1, p3, p4),
|
|
||||||
f4 = Triangle:new(p2, p3, p4),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
__tostring = self.toString
|
|
||||||
})
|
|
||||||
|
|
||||||
return instance
|
|
||||||
end
|
|
||||||
|
|
||||||
---Returns a string describing the object in a readable form.
|
|
||||||
---@return string
|
|
||||||
function Tetrahedron:toString()
|
|
||||||
return ('Tetrahedron: \n %s\n %s\n %s\n %s'):format(
|
|
||||||
tostring(self.p1.getPeakPos()),
|
|
||||||
tostring(self.p2.getPeakPos()),
|
|
||||||
tostring(self.p3.getPeakPos()),
|
|
||||||
tostring(self.p4.getPeakPos())
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param p1 MapGen.Peak
|
|
||||||
---@param p2 MapGen.Peak
|
|
||||||
---@param p3 MapGen.Peak
|
|
||||||
---@param p4 MapGen.Peak
|
|
||||||
function Tetrahedron:getHeight(p1, p2, p3, p4)
|
|
||||||
local pos1 = p1:getPeakPos()
|
|
||||||
local pos2 = p2:getPeakPos()
|
|
||||||
local pos3 = p3:getPeakPos()
|
|
||||||
local pos4 = p4:getPeakPos()
|
|
||||||
|
|
||||||
-- Векторы, лежащие в плоскости
|
|
||||||
local AB = pos3 - pos2
|
|
||||||
local AC = pos4 - pos2
|
|
||||||
|
|
||||||
-- Нормаль к плоскости
|
|
||||||
local normal = AB:cross(AC)
|
|
||||||
local normal_length = normal:length()
|
|
||||||
|
|
||||||
-- Если плоскость вырождена (точки на одной прямой)
|
|
||||||
if normal_length < 1e-10 then
|
|
||||||
return nil -- или другая обработка ошибки
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Вектор от точки на плоскости к нашей точке
|
|
||||||
local AP = pos1 - pos2
|
|
||||||
|
|
||||||
-- Расстояние от точки до плоскости
|
|
||||||
local distance = AP:dot(normal) / normal_length
|
|
||||||
|
|
||||||
-- Проекция точки на плоскость (вектор!)
|
|
||||||
local projection = pos1 - (normal * (distance / normal_length))
|
|
||||||
|
|
||||||
return Edge:new(p1, FakePeak:new(projection))
|
|
||||||
end
|
|
||||||
|
|
||||||
---Returns the center of the circumscribed sphere.
|
|
||||||
---@return vector
|
|
||||||
function Tetrahedron:getCircumSphereCenter()
|
|
||||||
local pos1 = self.p1.getPeakPos()
|
|
||||||
local pos2 = self.p2.getPeakPos()
|
|
||||||
local pos3 = self.p3.getPeakPos()
|
|
||||||
local pos4 = self.p4.getPeakPos()
|
|
||||||
|
|
||||||
local a = pos2 - pos1
|
|
||||||
local b = pos3 - pos1
|
|
||||||
local c = pos4 - pos1
|
|
||||||
|
|
||||||
local a2 = a:dot(a)
|
|
||||||
local b2 = b:dot(b)
|
|
||||||
local c2 = c:dot(c)
|
|
||||||
|
|
||||||
local cross_bc = b:cross(c)
|
|
||||||
local cross_ca = c:cross(a)
|
|
||||||
local cross_ab = a:cross(b)
|
|
||||||
|
|
||||||
local det = a:dot(b:cross(c)) * 2
|
|
||||||
|
|
||||||
if mathAbs(det) < 0 then
|
|
||||||
return (pos1 + pos2 + pos3 + pos4) / 4
|
|
||||||
end
|
|
||||||
|
|
||||||
local center = pos1 + (cross_bc * a2 + cross_ca * b2 + cross_ab * c2) / det
|
|
||||||
|
|
||||||
return center
|
|
||||||
end
|
|
||||||
|
|
||||||
---Returns the radius of the circumscribed sphere.
|
|
||||||
---@return number
|
|
||||||
function Tetrahedron:getCircumSphereRadius()
|
|
||||||
local center = self:getCircumSphereCenter()
|
|
||||||
local pos1 = self.p1.getPeakPos()
|
|
||||||
return (pos1 - center):length()
|
|
||||||
end
|
|
||||||
|
|
||||||
---Checks whether a given point lies within the circumscribed sphere of a tetrahedron.
|
|
||||||
---@param p MapGen.Peak
|
|
||||||
function Tetrahedron:inCircumSphere(p)
|
|
||||||
local pos = p.getPeakPos()
|
|
||||||
local c = self:getCircumSphereCenter()
|
|
||||||
local r = self:getCircumSphereRadius()
|
|
||||||
|
|
||||||
local distance = (pos - c):length()
|
|
||||||
|
|
||||||
return distance <= r
|
|
||||||
end
|
|
||||||
|
|
||||||
return Tetrahedron
|
|
||||||
@@ -6,10 +6,10 @@ local getInstance = Class.getInstance
|
|||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
local modInfo = Mod.getInfo('smc__core__map_gen')
|
||||||
local require = modInfo.require
|
local require = modInfo.require
|
||||||
|
|
||||||
---@type MapGen.Triangulation.Edge
|
---@type MapGen.Edge
|
||||||
local Edge = require('MapGen.Triangulation.Edge')
|
local Edge = require('MapGen.Edge')
|
||||||
---@type MapGen.Triangulation.FakePeak
|
---@type MapGen.FakePeak
|
||||||
local FakePeak = require('MapGen.Triangulation.FakePeak')
|
local FakePeak = require('MapGen.FakePeak')
|
||||||
|
|
||||||
-- --- Helpers functions ---
|
-- --- Helpers functions ---
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ end
|
|||||||
---@param p3 MapGen.Peak
|
---@param p3 MapGen.Peak
|
||||||
---@return boolean
|
---@return boolean
|
||||||
local function isFlatAngle(p1, p2, p3)
|
local function isFlatAngle(p1, p2, p3)
|
||||||
local pos1 = p1:getPeakPos()
|
local pos1 = p1.pos
|
||||||
local pos2 = p2:getPeakPos()
|
local pos2 = p2.pos
|
||||||
local pos3 = p3:getPeakPos()
|
local pos3 = p3.pos
|
||||||
|
|
||||||
local vec1 = pos1 - pos2 -- Vector from p2 to p1
|
local vec1 = pos1 - pos2 -- Vector from p2 to p1
|
||||||
local vec2 = pos3 - pos2 -- Vector from p2 to p3
|
local vec2 = pos3 - pos2 -- Vector from p2 to p3
|
||||||
@@ -63,16 +63,18 @@ end
|
|||||||
---@alias MapGen.Triangle.Neighbours {t1:MapGen.Triangle?,t2:MapGen.Triangle?,t3:MapGen.Triangle?}
|
---@alias MapGen.Triangle.Neighbours {t1:MapGen.Triangle?,t2:MapGen.Triangle?,t3:MapGen.Triangle?}
|
||||||
|
|
||||||
---@class MapGen.Triangle
|
---@class MapGen.Triangle
|
||||||
|
---@field id integer
|
||||||
---@field p1 MapGen.Peak
|
---@field p1 MapGen.Peak
|
||||||
---@field p2 MapGen.Peak
|
---@field p2 MapGen.Peak
|
||||||
---@field p3 MapGen.Peak
|
---@field p3 MapGen.Peak
|
||||||
---@field e1 MapGen.Triangulation.Edge
|
---@field e1 MapGen.Edge
|
||||||
---@field e2 MapGen.Triangulation.Edge
|
---@field e2 MapGen.Edge
|
||||||
---@field e3 MapGen.Triangulation.Edge
|
---@field e3 MapGen.Edge
|
||||||
---@field h1 MapGen.Triangulation.Edge
|
---@field h1 MapGen.Edge
|
||||||
---@field h2 MapGen.Triangulation.Edge
|
---@field h2 MapGen.Edge
|
||||||
---@field h3 MapGen.Triangulation.Edge
|
---@field h3 MapGen.Edge
|
||||||
---@field neighbours MapGen.Triangle.Neighbours
|
---@field neighboursIDs integer[]
|
||||||
|
---@field neighbours MapGen.Triangle[]
|
||||||
---@field color ColorString?
|
---@field color ColorString?
|
||||||
local Triangle = {
|
local Triangle = {
|
||||||
neighbours = {}
|
neighbours = {}
|
||||||
@@ -82,20 +84,21 @@ local Triangle = {
|
|||||||
---@param p2 MapGen.Peak
|
---@param p2 MapGen.Peak
|
||||||
---@param p3 MapGen.Peak
|
---@param p3 MapGen.Peak
|
||||||
---@return MapGen.Triangle
|
---@return MapGen.Triangle
|
||||||
function Triangle:new(p1, p2, p3)
|
function Triangle:new(id, p1, p2, p3, neighboursIDs)
|
||||||
assert(not isFlatAngle(p1, p2, p3), ("angle (p1, p2, p3) is flat:\n %s\n %s\n %s")
|
assert(not isFlatAngle(p1, p2, p3), ("angle (p1, p2, p3) is flat:\n %s\n %s\n %s")
|
||||||
:format(tostring(p1), tostring(p2), tostring(p3)))
|
:format(tostring(p1), tostring(p2), tostring(p3)))
|
||||||
|
|
||||||
---@type ColorString?
|
---@type ColorString?
|
||||||
local color = nil
|
local color = nil
|
||||||
|
|
||||||
local c1, c2, c3 = p1.getColor(), p2.getColor(), p3.getColor()
|
local c1, c2, c3 = p1.color, p2.color, p3.color
|
||||||
|
|
||||||
if c1 == c2 and c2 == c3 and c3 == c1 then
|
if c1 == c2 and c2 == c3 and c3 == c1 then
|
||||||
color = c1
|
color = c1
|
||||||
end
|
end
|
||||||
|
|
||||||
local instance = getInstance(self, {
|
local instance = getInstance(self, {
|
||||||
|
id = id,
|
||||||
p1 = p1,
|
p1 = p1,
|
||||||
p2 = p2,
|
p2 = p2,
|
||||||
p3 = p3,
|
p3 = p3,
|
||||||
@@ -105,7 +108,8 @@ function Triangle:new(p1, p2, p3)
|
|||||||
e1 = Edge:new(p1, p2),
|
e1 = Edge:new(p1, p2),
|
||||||
e2 = Edge:new(p2, p3),
|
e2 = Edge:new(p2, p3),
|
||||||
e3 = Edge:new(p3, p1),
|
e3 = Edge:new(p3, p1),
|
||||||
color = color
|
neighboursIDs = neighboursIDs,
|
||||||
|
color = color,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
__tostring = self.toString,
|
__tostring = self.toString,
|
||||||
@@ -119,9 +123,9 @@ end
|
|||||||
---@return string
|
---@return string
|
||||||
function Triangle:toString()
|
function Triangle:toString()
|
||||||
return ('Triangle: \n %s\n %s\n %s'):format(
|
return ('Triangle: \n %s\n %s\n %s'):format(
|
||||||
tostring(self.p1.getPeakPos()),
|
tostring(self.p1.pos),
|
||||||
tostring(self.p2.getPeakPos()),
|
tostring(self.p2.pos),
|
||||||
tostring(self.p3.getPeakPos())
|
tostring(self.p3.pos)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -144,9 +148,9 @@ end
|
|||||||
---Returns the coordinates of the triangle's center.
|
---Returns the coordinates of the triangle's center.
|
||||||
---@return vector
|
---@return vector
|
||||||
function Triangle:getCenter()
|
function Triangle:getCenter()
|
||||||
local pos1 = self.p1:getPeakPos()
|
local pos1 = self.p1.pos
|
||||||
local pos2 = self.p2:getPeakPos()
|
local pos2 = self.p2.pos
|
||||||
local pos3 = self.p3:getPeakPos()
|
local pos3 = self.p3.pos
|
||||||
|
|
||||||
return (pos1 + pos2 + pos3) / 3
|
return (pos1 + pos2 + pos3) / 3
|
||||||
end
|
end
|
||||||
@@ -163,11 +167,11 @@ end
|
|||||||
---@param p1 MapGen.Peak
|
---@param p1 MapGen.Peak
|
||||||
---@param p2 MapGen.Peak
|
---@param p2 MapGen.Peak
|
||||||
---@param p3 MapGen.Peak
|
---@param p3 MapGen.Peak
|
||||||
---@return MapGen.Triangulation.Edge
|
---@return MapGen.Edge
|
||||||
function Triangle:getHeight(p1, p2, p3)
|
function Triangle:getHeight(p1, p2, p3)
|
||||||
local pos1 = p1:getPeakPos()
|
local pos1 = p1.pos
|
||||||
local pos2 = p2:getPeakPos()
|
local pos2 = p2.pos
|
||||||
local pos3 = p3:getPeakPos()
|
local pos3 = p3.pos
|
||||||
|
|
||||||
local v = pos3 - pos2
|
local v = pos3 - pos2
|
||||||
---@type vector
|
---@type vector
|
||||||
@@ -189,11 +193,11 @@ end
|
|||||||
---@param p1 MapGen.Peak
|
---@param p1 MapGen.Peak
|
||||||
---@param p2 MapGen.Peak
|
---@param p2 MapGen.Peak
|
||||||
---@param p3 MapGen.Peak
|
---@param p3 MapGen.Peak
|
||||||
---@return MapGen.Triangulation.Edge
|
---@return MapGen.Edge
|
||||||
function Triangle:getHeight2D(p1, p2, p3)
|
function Triangle:getHeight2D(p1, p2, p3)
|
||||||
local pos1 = p1:getPeakPos()
|
local pos1 = p1.pos
|
||||||
local pos2 = p2:getPeakPos()
|
local pos2 = p2.pos
|
||||||
local pos3 = p3:getPeakPos()
|
local pos3 = p3.pos
|
||||||
|
|
||||||
pos1.y = 0
|
pos1.y = 0
|
||||||
pos2.y = 0
|
pos2.y = 0
|
||||||
@@ -224,9 +228,9 @@ end
|
|||||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||||
---@return number, number, number
|
---@return number, number, number
|
||||||
function Triangle:getSidesLength2D()
|
function Triangle:getSidesLength2D()
|
||||||
local pos1 = self.p1:getPeakPos()
|
local pos1 = self.p1.pos
|
||||||
local pos2 = self.p2:getPeakPos()
|
local pos2 = self.p2.pos
|
||||||
local pos3 = self.p3:getPeakPos()
|
local pos3 = self.p3.pos
|
||||||
|
|
||||||
pos1.y = 0
|
pos1.y = 0
|
||||||
pos2.y = 0
|
pos2.y = 0
|
||||||
@@ -241,9 +245,9 @@ end
|
|||||||
---that is, the calculation is performed on the projection of the triangle XZ.
|
---that is, the calculation is performed on the projection of the triangle XZ.
|
||||||
---@return vector
|
---@return vector
|
||||||
function Triangle:getCircumCenter2D()
|
function Triangle:getCircumCenter2D()
|
||||||
local pos1 = self.p1:getPeakPos()
|
local pos1 = self.p1.pos
|
||||||
local pos2 = self.p2:getPeakPos()
|
local pos2 = self.p2.pos
|
||||||
local pos3 = self.p3:getPeakPos()
|
local pos3 = self.p3.pos
|
||||||
|
|
||||||
local D = ( pos1.x * (pos2.z - pos3.z) +
|
local D = ( pos1.x * (pos2.z - pos3.z) +
|
||||||
pos2.x * (pos3.z - pos1.z) +
|
pos2.x * (pos3.z - pos1.z) +
|
||||||
@@ -290,7 +294,7 @@ end
|
|||||||
---@param p MapGen.Peak
|
---@param p MapGen.Peak
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Triangle:inCircumCircle2D(p)
|
function Triangle:inCircumCircle2D(p)
|
||||||
local pos = p:getPeakPos()
|
local pos = p.pos
|
||||||
|
|
||||||
local c, r = self:getCircumCircle2D()
|
local c, r = self:getCircumCircle2D()
|
||||||
|
|
||||||
|
|||||||
@@ -1,327 +0,0 @@
|
|||||||
---@diagnostic disable: param-type-not-match
|
|
||||||
-- Tringulation lib
|
|
||||||
-- Original code: https://github.com/iskolbin/Triangulation/blob/master/Triangulation.lua
|
|
||||||
-- Date of copying: 07.11.2025
|
|
||||||
-- Commit: e8d26241767cd6af377b5eda0c1e27122b6afe8a
|
|
||||||
|
|
||||||
-- Main changes:
|
|
||||||
-- * refactoring code to our standard;
|
|
||||||
-- * splitting code into different files (classes);
|
|
||||||
-- * Adapting the code to the mapgen concept;
|
|
||||||
-- * Adding tetrahedralization;
|
|
||||||
-- * Fixed non-determinism by sorting vertices before processing;
|
|
||||||
|
|
||||||
local assert, mathMax, tableRemove, tableSort
|
|
||||||
= assert, math.max, table.remove, table.sort
|
|
||||||
|
|
||||||
local modInfo = Mod.getInfo('smc__core__map_gen')
|
|
||||||
local require = modInfo.require
|
|
||||||
|
|
||||||
---@type MapGen.Triangle
|
|
||||||
local Triangle = require('MapGen.Triangle')
|
|
||||||
---@type MapGen.Tetrahedron
|
|
||||||
local Tetrahedron = require('MapGen.Tetrahedron')
|
|
||||||
---@type MapGen.Triangulation.FakePeak
|
|
||||||
local FakePeak = require('MapGen.Triangulation.FakePeak')
|
|
||||||
|
|
||||||
---@class MapGen.Triangulation
|
|
||||||
---@field convexMultiplier number
|
|
||||||
local Triangulation = {
|
|
||||||
convexMultiplier = 1e3,
|
|
||||||
}
|
|
||||||
|
|
||||||
---Finds and writes adjacent triangles into triangles.
|
|
||||||
---@param triangles MapGen.Triangle[]
|
|
||||||
local function findTrianglesNeighbours(triangles)
|
|
||||||
for _, triangle in ipairs(triangles) do
|
|
||||||
for _, t in ipairs(triangles) do
|
|
||||||
if triangle.e1 == t.e1 and triangle.p3 ~= t.p3 then
|
|
||||||
triangle.neighbours.t1 = t
|
|
||||||
elseif triangle.e2 == t.e2 and triangle.p3 ~= t.p1 then
|
|
||||||
triangle.neighbours.t2 = t
|
|
||||||
elseif triangle.e3 == t.e3 and triangle.p3 ~= t.p2 then
|
|
||||||
triangle.neighbours.t3 = t
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---Filter vertices by group and return a new table
|
|
||||||
---@param vertices table<integer, MapGen.Peak>
|
|
||||||
---@param groupKey string
|
|
||||||
---@return table<integer, MapGen.Peak>
|
|
||||||
local function filterVerticesByGroup(vertices, groupKey)
|
|
||||||
local result = {}
|
|
||||||
for i = 1, #vertices do
|
|
||||||
local vertex = vertices[i]
|
|
||||||
if vertex:getGroups()[groupKey] ~= nil then
|
|
||||||
result[#result + 1] = vertex
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
---Sort vertices deterministically by position to ensure consistent triangulation
|
|
||||||
---@param vertices table<integer, MapGen.Peak>
|
|
||||||
local function sortVerticesDeterministically(vertices)
|
|
||||||
tableSort(vertices, function(a, b)
|
|
||||||
local posA = a:getPeakPos()
|
|
||||||
local posB = b:getPeakPos()
|
|
||||||
|
|
||||||
-- Sort by X first
|
|
||||||
if posA.x ~= posB.x then
|
|
||||||
return posA.x < posB.x
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Then by Z
|
|
||||||
if posA.z ~= posB.z then
|
|
||||||
return posA.z < posB.z
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Then by Y
|
|
||||||
if posA.y ~= posB.y then
|
|
||||||
return posA.y < posB.y
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Fallback to unique identifier if positions are identical
|
|
||||||
-- This handles potential duplicate positions
|
|
||||||
local nameA = a.getName and a:getName() or ""
|
|
||||||
local nameB = b.getName and b:getName() or ""
|
|
||||||
return nameA < nameB
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
---The Delaunay method divides a plane into triangles based on a list of their vertices.
|
|
||||||
---
|
|
||||||
---Doesn't take into account the Y coordinate of the vertices.
|
|
||||||
---That is, all triangles that don't lie in the XZ plane will be projected onto it.
|
|
||||||
---
|
|
||||||
---Vertices that do not have a `is2d` group will not participate in the triangulation.
|
|
||||||
---@param vertices table<integer, MapGen.Peak>
|
|
||||||
function Triangulation.triangulate(vertices)
|
|
||||||
-- Filter vertices with is2d group (creates a new table)
|
|
||||||
vertices = filterVerticesByGroup(vertices, "is2d")
|
|
||||||
|
|
||||||
-- Sort deterministically to ensure consistent results across sessions
|
|
||||||
sortVerticesDeterministically(vertices)
|
|
||||||
|
|
||||||
local nvertices = #vertices
|
|
||||||
|
|
||||||
assert(nvertices > 2, "Cannot triangulate, needs more than 3 vertices")
|
|
||||||
|
|
||||||
if nvertices == 3 then
|
|
||||||
return {Triangle:new(vertices[1], vertices[2], vertices[3])}
|
|
||||||
end
|
|
||||||
|
|
||||||
local minPos = vertices[1]:getPeakPos()
|
|
||||||
local minX, minY = minPos.x, minPos.z
|
|
||||||
local maxX, maxY = minX, minY
|
|
||||||
|
|
||||||
for i = 1, nvertices do
|
|
||||||
local vertex = vertices[i]
|
|
||||||
local vertexPos = vertex:getPeakPos()
|
|
||||||
vertex.id = i
|
|
||||||
|
|
||||||
if vertexPos.x < minX then
|
|
||||||
minX = vertexPos.x
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.z < minY then
|
|
||||||
minY = vertexPos.z
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.x > maxX then
|
|
||||||
maxX = vertexPos.x
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.z > maxY then
|
|
||||||
maxY = vertexPos.z
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Finding the vertices of a supertriangle
|
|
||||||
local convex_mult = Triangulation.convexMultiplier
|
|
||||||
local dx, dy = (maxX - minX) * convex_mult, (maxY - minY) * convex_mult
|
|
||||||
local deltaMax = mathMax(dx, dy)
|
|
||||||
local midx, midy = (minX + maxX) * 0.5, (minY + maxY) * 0.5
|
|
||||||
|
|
||||||
local p1 = FakePeak:new(vector.new(midx - 2 * deltaMax, 0, midy - deltaMax))
|
|
||||||
local p2 = FakePeak:new(vector.new(midx, 0, midy + 2 * deltaMax))
|
|
||||||
local p3 = FakePeak:new(vector.new(midx + 2 * deltaMax, 0, midy - deltaMax))
|
|
||||||
|
|
||||||
p1.id, p2.id, p3.id = nvertices + 1, nvertices + 2, nvertices + 3
|
|
||||||
vertices[p1.id], vertices[p2.id], vertices[p3.id] = p1, p2, p3
|
|
||||||
|
|
||||||
---@type MapGen.Triangle[]
|
|
||||||
local triangles = {Triangle:new(vertices[nvertices + 1], vertices[nvertices + 2], vertices[nvertices + 3])}
|
|
||||||
|
|
||||||
for i = 1, nvertices do
|
|
||||||
---@type MapGen.Triangulation.Edge[]
|
|
||||||
local edges = {}
|
|
||||||
|
|
||||||
-- Finding bad triangles.
|
|
||||||
for j = #triangles, 1, -1 do
|
|
||||||
local curTriangle = triangles[j]
|
|
||||||
|
|
||||||
if curTriangle:inCircumCircle2D(vertices[i]) then
|
|
||||||
edges[#edges + 1] = curTriangle.e1
|
|
||||||
edges[#edges + 1] = curTriangle.e2
|
|
||||||
edges[#edges + 1] = curTriangle.e3
|
|
||||||
tableRemove(triangles, j)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removing duplicate edges.
|
|
||||||
for j = #edges - 1, 1, -1 do
|
|
||||||
for k = #edges, j + 1, -1 do
|
|
||||||
if edges[j] and edges[k] and edges[j]:same(edges[k]) then
|
|
||||||
tableRemove(edges, j)
|
|
||||||
tableRemove(edges, k - 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Create new triangles.
|
|
||||||
for j = 1, #edges do
|
|
||||||
triangles[#triangles + 1] = Triangle:new(edges[j].p1, edges[j].p2, vertices[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Remove triangles associated with the vertices of a supertriangle.
|
|
||||||
for i = #triangles, 1, -1 do
|
|
||||||
local triangle = triangles[i]
|
|
||||||
if triangle.p1.id > nvertices or triangle.p2.id > nvertices or triangle.p3.id > nvertices then
|
|
||||||
tableRemove(triangles, i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removing the vertices of a supertriangle.
|
|
||||||
for _ = 1, 3 do
|
|
||||||
tableRemove(vertices)
|
|
||||||
end
|
|
||||||
|
|
||||||
findTrianglesNeighbours(triangles)
|
|
||||||
|
|
||||||
return triangles
|
|
||||||
end
|
|
||||||
|
|
||||||
---The Delaunay method divides space into tetrahedra based on a list of their vertices.
|
|
||||||
---
|
|
||||||
---Vertices that do not have a `is3d` group will not participate in the triangulation.
|
|
||||||
---@param vertices table<integer, MapGen.Peak>
|
|
||||||
function Triangulation.tetrahedralize(vertices)
|
|
||||||
-- Filter vertices with is3d group (creates a new table)
|
|
||||||
vertices = filterVerticesByGroup(vertices, "is3d")
|
|
||||||
|
|
||||||
-- Sort deterministically to ensure consistent results across sessions
|
|
||||||
sortVerticesDeterministically(vertices)
|
|
||||||
|
|
||||||
local nvertices = #vertices
|
|
||||||
|
|
||||||
assert(nvertices > 3, "Cannot tetrahedralize, needs more than 4 vertices")
|
|
||||||
|
|
||||||
if nvertices == 4 then
|
|
||||||
return {Tetrahedron:new(vertices[1], vertices[2], vertices[3], vertices[4])}
|
|
||||||
end
|
|
||||||
|
|
||||||
local minPos = vertices[1]:getPeakPos()
|
|
||||||
local minX, minY, minZ = minPos.x, minPos.y, minPos.z
|
|
||||||
local maxX, maxY, maxZ = minX, minY, minZ
|
|
||||||
|
|
||||||
for i = 1, nvertices do
|
|
||||||
local vertex = vertices[i]
|
|
||||||
local vertexPos = vertex:getPeakPos()
|
|
||||||
vertex.id = i
|
|
||||||
|
|
||||||
if vertexPos.x < minX then
|
|
||||||
minX = vertexPos.x
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.y < minY then
|
|
||||||
minY = vertexPos.y
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.z < minZ then
|
|
||||||
minZ = vertexPos.z
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.x > maxX then
|
|
||||||
maxX = vertexPos.x
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.y > maxY then
|
|
||||||
maxY = vertexPos.y
|
|
||||||
end
|
|
||||||
|
|
||||||
if vertexPos.z > maxZ then
|
|
||||||
maxZ = vertexPos.z
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Finding the vertices of a supertetrahedron
|
|
||||||
local convex_mult = Triangulation.convexMultiplier
|
|
||||||
local dx, dy, dz = (maxX - minX) * convex_mult, (maxY - minY) * convex_mult, (maxZ - minZ) * convex_mult
|
|
||||||
local deltaMax = mathMax(dx, dy, dz)
|
|
||||||
local midx, midy, midz = (minX + maxX) * 0.5, (minY + maxY) * 0.5, (minZ + maxZ) * 0.5
|
|
||||||
|
|
||||||
local p1 = FakePeak:new(vector.new(midx - 2 * deltaMax, midy - deltaMax, midz - deltaMax))
|
|
||||||
local p2 = FakePeak:new(vector.new(midx + 2 * deltaMax, midy - deltaMax, midz - deltaMax))
|
|
||||||
local p3 = FakePeak:new(vector.new(midx, midy + 2 * deltaMax, midz - deltaMax))
|
|
||||||
local p4 = FakePeak:new(vector.new(midx, midy, midz + 2 * deltaMax))
|
|
||||||
|
|
||||||
p1.id, p2.id, p3.id, p4.id = nvertices + 1, nvertices + 2, nvertices + 3, nvertices + 4
|
|
||||||
vertices[p1.id], vertices[p2.id], vertices[p3.id], vertices[p4.id] = p1, p2, p3, p4
|
|
||||||
|
|
||||||
---@type MapGen.Tetrahedron[]
|
|
||||||
local tetrahedrons = {Tetrahedron:new(p1, p2, p3, p4)}
|
|
||||||
|
|
||||||
for i = 1, nvertices do
|
|
||||||
---@type MapGen.Triangle[]
|
|
||||||
local faces = {}
|
|
||||||
|
|
||||||
-- Finding bad tetrahedrons.
|
|
||||||
for j = #tetrahedrons, 1, -1 do
|
|
||||||
local curTetrahedron = tetrahedrons[j]
|
|
||||||
|
|
||||||
if curTetrahedron:inCircumSphere(vertices[i]) then
|
|
||||||
faces[#faces + 1] = curTetrahedron.f1
|
|
||||||
faces[#faces + 1] = curTetrahedron.f2
|
|
||||||
faces[#faces + 1] = curTetrahedron.f3
|
|
||||||
faces[#faces + 1] = curTetrahedron.f4
|
|
||||||
tableRemove(tetrahedrons, j)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removing duplicate faces.
|
|
||||||
for j = #faces - 1, 1, -1 do
|
|
||||||
for k = #faces, j + 1, -1 do
|
|
||||||
if faces[j] and faces[k] and faces[j]:same(faces[k]) then
|
|
||||||
tableRemove(faces, j)
|
|
||||||
tableRemove(faces, k - 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Create new tetrahedrons.
|
|
||||||
for j = 1, #faces do
|
|
||||||
tetrahedrons[#tetrahedrons + 1] = Tetrahedron:new(faces[j].p1, faces[j].p2, faces[j].p3, vertices[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Remove tetrahedra associated with the vertices of a supertetrahedron.
|
|
||||||
for i = #tetrahedrons, 1, -1 do
|
|
||||||
local tetrahedron = tetrahedrons[i]
|
|
||||||
if tetrahedron.p1.id > nvertices or tetrahedron.p2.id > nvertices or tetrahedron.p3.id > nvertices or tetrahedron.p4.id > nvertices then
|
|
||||||
tableRemove(tetrahedrons, i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Removing the vertices of a supertetrahedron.
|
|
||||||
for _ = 1, 4 do
|
|
||||||
tableRemove(vertices)
|
|
||||||
end
|
|
||||||
|
|
||||||
return tetrahedrons
|
|
||||||
end
|
|
||||||
|
|
||||||
return Triangulation
|
|
||||||
@@ -1,4 +1,23 @@
|
|||||||
---@class Player
|
---@class Player
|
||||||
local Player = {}
|
local Player = {}
|
||||||
|
|
||||||
|
---@type PlayerInventoryUI
|
||||||
|
local PlayerInventoryUI = Mod.getInfo('smc__ui__player_inventory').require('PlayerInventoryUI')
|
||||||
|
|
||||||
|
core.register_on_joinplayer(function(player)
|
||||||
|
player:set_inventory_formspec(PlayerInventoryUI:getFormSpecString(player:get_player_name()))
|
||||||
|
player:hud_set_hotbar_itemcount(9)
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
inv:set_size('main', 18)
|
||||||
|
end)
|
||||||
|
|
||||||
|
core.register_chatcommand('show_inv',
|
||||||
|
{
|
||||||
|
func = function(name, param)
|
||||||
|
PlayerInventoryUI:showForm(name)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return Player
|
return Player
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
-- World generation occurs in a separate thread (MapGen Environment).
|
-- World generation occurs in a separate thread (MapGen Environment).
|
||||||
-- But for the main thread, the mapgenerator object is also initialized.
|
-- But for the main thread, the mapgenerator object is also initialized.
|
||||||
|
|
||||||
|
--core.set_mapgen_setting('chunksize', '{x=2,y=10,z=2}', true)
|
||||||
|
|
||||||
local mapGeneneratorRequire = Mod.getInfo('smc__core__map_generator').require
|
local mapGeneneratorRequire = Mod.getInfo('smc__core__map_generator').require
|
||||||
|
|
||||||
-- Main env init
|
-- Main env init
|
||||||
|
|||||||
10171
mods/ENVIRONMENT/mapGenerator/maps/tarion.json
Normal file
10171
mods/ENVIRONMENT/mapGenerator/maps/tarion.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,9 @@ dofile(core.get_modpath('smc__system__logger')..'/init.lua')
|
|||||||
-- Math
|
-- Math
|
||||||
dofile(core.get_modpath('smc__system__math')..'/init.lua')
|
dofile(core.get_modpath('smc__system__math')..'/init.lua')
|
||||||
|
|
||||||
|
-- Profile
|
||||||
|
dofile(core.get_modpath('smc__system__profiler')..'/init.lua')
|
||||||
|
|
||||||
-- Require
|
-- Require
|
||||||
dofile(core.get_modpath('smc__system__require')..'/init.lua')
|
dofile(core.get_modpath('smc__system__require')..'/init.lua')
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,396 @@ mapGenerator:registerLayer('midgard', {
|
|||||||
calcTemp = calcTemp,
|
calcTemp = calcTemp,
|
||||||
calcHumidity = calcHumidity,
|
calcHumidity = calcHumidity,
|
||||||
biomesVerticalScattering = 5,
|
biomesVerticalScattering = 5,
|
||||||
biomesGorizontalScattering = 5
|
biomesGorizontalScattering = 5,
|
||||||
|
triangulationLandscapeFile = 'tarion.json',
|
||||||
|
triangulationTempFile = 'tarion.json',
|
||||||
|
triangulationHumidityFile = 'tarion.json',
|
||||||
|
landscapeMapScale = 100,
|
||||||
|
tempMapScale = 100,
|
||||||
|
humidityMapScale = 100,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- TODO: Config should be imported from .json file in the world's folder
|
||||||
|
local ocean = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = -10,
|
||||||
|
scale = 3,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 420,
|
||||||
|
octaves = 2,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = -10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = -10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local common_lands = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 0,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 88005553535,
|
||||||
|
octaves = 2,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = -10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = -10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 10, y = 10, z = 10},
|
||||||
|
seed = 47,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local foresty_lands = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 5,
|
||||||
|
scale = 8,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 12345,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 20,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 48,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 60,
|
||||||
|
scale = 15,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 49,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local hilly_lands = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 15,
|
||||||
|
scale = 12,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 54321,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 15,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 25, y = 25, z = 25},
|
||||||
|
seed = 50,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 40,
|
||||||
|
scale = 15,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 51,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local low_mountains = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 30,
|
||||||
|
scale = 20,
|
||||||
|
spread = {x = 25, y = 25, z = 25},
|
||||||
|
seed = 11111,
|
||||||
|
octaves = 4,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 5,
|
||||||
|
scale = 15,
|
||||||
|
spread = {x = 30, y = 30, z = 30},
|
||||||
|
seed = 52,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 30,
|
||||||
|
scale = 15,
|
||||||
|
spread = {x = 25, y = 25, z = 25},
|
||||||
|
seed = 53,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local high_mountains = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 60,
|
||||||
|
scale = 35,
|
||||||
|
spread = {x = 30, y = 30, z = 30},
|
||||||
|
seed = 22222,
|
||||||
|
octaves = 4,
|
||||||
|
persistence = 0.55,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = -10,
|
||||||
|
scale = 15,
|
||||||
|
spread = {x = 35, y = 35, z = 35},
|
||||||
|
seed = 54,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 20,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 30, y = 30, z = 30},
|
||||||
|
seed = 55,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local highest_peaks = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 100,
|
||||||
|
scale = 50,
|
||||||
|
spread = {x = 40, y = 40, z = 40},
|
||||||
|
seed = 33333,
|
||||||
|
octaves = 5,
|
||||||
|
persistence = 0.6,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = -30,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 50, y = 50, z = 50},
|
||||||
|
seed = 56,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 10,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 40, y = 40, z = 40},
|
||||||
|
seed = 57,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local rivers = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = -5,
|
||||||
|
scale = 2,
|
||||||
|
spread = {x = 5, y = 5, z = 100},
|
||||||
|
seed = 44444,
|
||||||
|
octaves = 2,
|
||||||
|
persistence = 0.3,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 50, y = 50, z = 50},
|
||||||
|
seed = 58,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 80,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 59,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local lakes = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = -8,
|
||||||
|
scale = 2,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 55555,
|
||||||
|
octaves = 2,
|
||||||
|
persistence = 0.3,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 10,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 30, y = 30, z = 30},
|
||||||
|
seed = 60,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 90,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 61,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local rocky_shores = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 2,
|
||||||
|
scale = 4,
|
||||||
|
spread = {x = 8, y = 8, z = 8},
|
||||||
|
seed = 66666,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 15,
|
||||||
|
scale = 8,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 62,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 70,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 63,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local rocky_islands = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 8,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 12, y = 12, z = 12},
|
||||||
|
seed = 77777,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.5,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 20,
|
||||||
|
scale = 8,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 64,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 60,
|
||||||
|
scale = 15,
|
||||||
|
spread = {x = 20, y = 20, z = 20},
|
||||||
|
seed = 65,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local swamp_land = {
|
||||||
|
['landscape'] = {
|
||||||
|
offset = 1,
|
||||||
|
scale = 2,
|
||||||
|
spread = {x = 12, y = 12, z = 12},
|
||||||
|
seed = 88888,
|
||||||
|
octaves = 2,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['temp'] = {
|
||||||
|
offset = 25,
|
||||||
|
scale = 5,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 66,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
['humidity'] = {
|
||||||
|
offset = 85,
|
||||||
|
scale = 10,
|
||||||
|
spread = {x = 15, y = 15, z = 15},
|
||||||
|
seed = 67,
|
||||||
|
octaves = 3,
|
||||||
|
persistence = 0.4,
|
||||||
|
lacunarity = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local v = vector.new
|
||||||
|
|
||||||
|
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#4978c6', ocean[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#81c948', common_lands[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#187726', foresty_lands[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#357a60', hilly_lands[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#5a7269', low_mountains[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#773b18', high_mountains[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#a3a3a3', highest_peaks[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#182077', rivers[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#06f5ff', lakes[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#677a48', rocky_shores[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#e4dc36', rocky_islands[c])
|
||||||
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#3b7718', swamp_land[c])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
local land1 = {
|
local land1 = {
|
||||||
offset = -10,
|
offset = -10,
|
||||||
scale = 5,
|
scale = 5,
|
||||||
@@ -145,7 +532,7 @@ mapGenerator:register2DPeaks('midgard',
|
|||||||
v(200, 0, 100),
|
v(200, 0, 100),
|
||||||
v(-300, 0, -200),
|
v(-300, 0, -200),
|
||||||
})--]]
|
})--]]
|
||||||
|
--[[
|
||||||
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
||||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#4978c6', land1)
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#4978c6', land1)
|
||||||
mapGenerator:registerLayerNoiseColor('midgard', c, '#77ea72', land2)
|
mapGenerator:registerLayerNoiseColor('midgard', c, '#77ea72', land2)
|
||||||
@@ -168,13 +555,9 @@ for _, c in ipairs({'landscape', 'temp', 'humidity'}) do
|
|||||||
color = '#4978c6',
|
color = '#4978c6',
|
||||||
pos = vector.new(-512, 0, 512)
|
pos = vector.new(-512, 0, 512)
|
||||||
},
|
},
|
||||||
})--]]
|
})
|
||||||
end
|
end
|
||||||
|
--]]
|
||||||
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 100,{x=0, y=0}, 'landscape')
|
|
||||||
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 150,{x=0, y=0}, 'temp')
|
|
||||||
mapGenerator:register2DPeaksFromFile('midgard', 'map.ff', 200,{x=0, y=0}, 'humidity')
|
|
||||||
|
|
||||||
-- [[
|
-- [[
|
||||||
mapGenerator:registerCavern('midgard', 'cavern1', {
|
mapGenerator:registerCavern('midgard', 'cavern1', {
|
||||||
minY = -48,
|
minY = -48,
|
||||||
|
|||||||
BIN
mods/ENVIRONMENT/mapGenerator/textures/maps/map.png
Normal file
BIN
mods/ENVIRONMENT/mapGenerator/textures/maps/map.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -60,12 +60,24 @@ end
|
|||||||
|
|
||||||
local t = logTileSheet
|
local t = logTileSheet
|
||||||
|
|
||||||
local function registerWood(name, x)
|
|
||||||
|
---@class WoodDef
|
||||||
|
---@field rarity Item.Rarity?
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param x number
|
||||||
|
---@param def WoodDef?
|
||||||
|
local function registerWood(name, x, def)
|
||||||
|
if def == nil then
|
||||||
|
def = {}
|
||||||
|
end
|
||||||
|
|
||||||
defaultLog:new({
|
defaultLog:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = name..'_log',
|
name = name..'_log',
|
||||||
tiles = getLogTiles(x, 2),
|
tiles = getLogTiles(x, 2),
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
callbacks = {
|
callbacks = {
|
||||||
on_place = core.rotate_node
|
on_place = core.rotate_node
|
||||||
@@ -77,6 +89,7 @@ local function registerWood(name, x)
|
|||||||
name = name..'_log_stripped',
|
name = name..'_log_stripped',
|
||||||
tiles = getLogTiles(x, 4),
|
tiles = getLogTiles(x, 4),
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
|
_rarity = def.rarity
|
||||||
},
|
},
|
||||||
callbacks = {
|
callbacks = {
|
||||||
on_place = core.rotate_node
|
on_place = core.rotate_node
|
||||||
@@ -90,6 +103,7 @@ local function registerWood(name, x)
|
|||||||
logTileSheet:t(x, 7), logTileSheet:t(x, 7),
|
logTileSheet:t(x, 7), logTileSheet:t(x, 7),
|
||||||
logTileSheet:t(x, 8), logTileSheet:t(x, 8),},
|
logTileSheet:t(x, 8), logTileSheet:t(x, 8),},
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
callbacks = {
|
callbacks = {
|
||||||
on_place = core.rotate_node
|
on_place = core.rotate_node
|
||||||
@@ -103,6 +117,7 @@ local function registerWood(name, x)
|
|||||||
inventory_overlay = 'wood_trunk_overlay.png',
|
inventory_overlay = 'wood_trunk_overlay.png',
|
||||||
drop = 'wood:'..name..'_log',
|
drop = 'wood:'..name..'_log',
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
callbacks = {
|
callbacks = {
|
||||||
on_place = core.rotate_node
|
on_place = core.rotate_node
|
||||||
@@ -116,6 +131,7 @@ local function registerWood(name, x)
|
|||||||
inventory_overlay = 'wood_trunk_overlay.png',
|
inventory_overlay = 'wood_trunk_overlay.png',
|
||||||
drop = 'wood:'..name..'_log',
|
drop = 'wood:'..name..'_log',
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
callbacks = {
|
callbacks = {
|
||||||
on_place = core.rotate_node
|
on_place = core.rotate_node
|
||||||
@@ -140,7 +156,8 @@ local function registerWood(name, x)
|
|||||||
connect_back = {-.25,-.25,-.25, .25,.25,.5},
|
connect_back = {-.25,-.25,-.25, .25,.25,.5},
|
||||||
connect_right = {-.25,-.25,-.25, .5,.25,.25},
|
connect_right = {-.25,-.25,-.25, .5,.25,.25},
|
||||||
},
|
},
|
||||||
connects_to = {'group:wood', 'group:soil'}
|
connects_to = {'group:wood', 'group:soil'},
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -158,7 +175,8 @@ local function registerWood(name, x)
|
|||||||
connect_top = {-.25,-.25,-.25, .25,.5,.25},
|
connect_top = {-.25,-.25,-.25, .25,.5,.25},
|
||||||
connect_bottom = {-.25,-.5,-.25, .25,.25,.25},
|
connect_bottom = {-.25,-.5,-.25, .25,.25,.25},
|
||||||
},
|
},
|
||||||
connects_to = {'group:wood', 'group:soil'}
|
connects_to = {'group:wood', 'group:soil'},
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -166,6 +184,7 @@ local function registerWood(name, x)
|
|||||||
settings = {
|
settings = {
|
||||||
name = name..'_planks',
|
name = name..'_planks',
|
||||||
tiles = { logTileSheet:t(x, 6) },
|
tiles = { logTileSheet:t(x, 6) },
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -173,6 +192,7 @@ local function registerWood(name, x)
|
|||||||
settings = {
|
settings = {
|
||||||
name = name..'_leafs',
|
name = name..'_leafs',
|
||||||
tiles = { logTileSheet:t(x, 1) },
|
tiles = { logTileSheet:t(x, 1) },
|
||||||
|
_rarity = def.rarity,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -181,6 +201,6 @@ registerWood('marentine', 0)
|
|||||||
registerWood('allwhere', 1)
|
registerWood('allwhere', 1)
|
||||||
registerWood('fis', 2)
|
registerWood('fis', 2)
|
||||||
registerWood('tammoy', 3)
|
registerWood('tammoy', 3)
|
||||||
registerWood('gi', 4)
|
registerWood('gi', 4, {rarity = 'uncommon'})
|
||||||
registerWood('dallalia', 5)
|
registerWood('dallalia', 5)
|
||||||
registerWood('zuph', 6)
|
registerWood('zuph', 6, {rarity = 'uncommon'})
|
||||||
|
|||||||
133
mods/GAME/ITEMS/wood/locale/wood.ru.tr
Normal file
133
mods/GAME/ITEMS/wood/locale/wood.ru.tr
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
# textdomain: wood
|
||||||
|
marentine_log-title=Бревно марентина
|
||||||
|
marentine_log-desc=Темная древесина, отдающая синевой.@n Часто встречается вблизи крупных водоёмов.
|
||||||
|
marentine_log_stripped-title=Обтёсанное бревно марентина
|
||||||
|
marentine_log_stripped-desc=Освобождённое от тёмно-синей коры@n более светлая древесная сердцевина.
|
||||||
|
marentine_timber-title=
|
||||||
|
marentine_timber-desc=
|
||||||
|
marentine_trunk-title=
|
||||||
|
marentine_trunk-desc=
|
||||||
|
marentine_trunk_vertical-title=
|
||||||
|
marentine_trunk_vertical-desc=
|
||||||
|
marentine_trunk_branch-title=
|
||||||
|
marentine_trunk_branch-desc=
|
||||||
|
marentine_trunk_branch_vertical-title=
|
||||||
|
marentine_trunk_branch_vertical-desc=
|
||||||
|
marentine_planks-title=Марентиновые доски
|
||||||
|
marentine_planks-desc=Темные плотно скрепленные между собой@n доски из марентиновой древесины.
|
||||||
|
marentine_leafs-title=
|
||||||
|
marentine_leafs-desc=
|
||||||
|
|
||||||
|
allwhere_log-title=Бревно всемира
|
||||||
|
allwhere_log-desc=Распростроенный древесный материал,@n встречающийся почти во всех местах Тариона.@n Эта древесина не обладает особыми свойствами,@n но за счёт своей распространённости широко@n применяется во многих базовых изделиях.
|
||||||
|
allwhere_log_stripped-title=Обтёсанное бревно всемира.
|
||||||
|
allwhere_log_stripped-desc=Светлая мягкая сердцевина,@n лишённая своей коры.
|
||||||
|
allwhere_timber-title=
|
||||||
|
allwhere_timber-desc=
|
||||||
|
allwhere_trunk-title=
|
||||||
|
allwhere_trunk-desc=
|
||||||
|
allwhere_trunk_vertical-title=
|
||||||
|
allwhere_trunk_vertical-desc=
|
||||||
|
allwhere_trunk_branch-title=
|
||||||
|
allwhere_trunk_branch-desc=
|
||||||
|
allwhere_trunk_branch_vertical-title=
|
||||||
|
allwhere_trunk_branch_vertical-desc=
|
||||||
|
allwhere_planks-title=Всемировые доски
|
||||||
|
allwhere_planks-desc=Светлые доски, плотно@n состыкованные между собой.
|
||||||
|
allwhere_leafs-title=
|
||||||
|
allwhere_leafs-desc=
|
||||||
|
|
||||||
|
fis_log-title=Бревно фиса
|
||||||
|
fis_log-desc=Необычное бревно с кроваво-красной@n сердцевиной и коры цвета белой кости.
|
||||||
|
fis_log_stripped-title=Обтёсанное бревно фиса
|
||||||
|
fis_log_stripped-desc=Кроваво-красная сердцевина,@n лишенная оболочки из светлой коры.
|
||||||
|
fis_timber-title=
|
||||||
|
fis_timber-desc=
|
||||||
|
fis_trunk-title=
|
||||||
|
fis_trunk-desc=
|
||||||
|
fis_trunk_vertical-title=
|
||||||
|
fis_trunk_vertical-desc=
|
||||||
|
fis_trunk_branch-title=
|
||||||
|
fis_trunk_branch-desc=
|
||||||
|
fis_trunk_branch_vertical-title=
|
||||||
|
fis_trunk_branch_vertical-desc=
|
||||||
|
fis_planks-title=Фисовые доски
|
||||||
|
fis_planks-desc=Красные подогнанные друг к другу и@n доски из фисовой древесины.
|
||||||
|
fis_leafs-title=
|
||||||
|
fis_leafs-desc=
|
||||||
|
|
||||||
|
tammoy_log-title=Бревно таммоя
|
||||||
|
tammoy_log-desc=Светлая хвойная древесина, покрытая@n легкоотдираемой чешуйчатой корой.
|
||||||
|
tammoy_log_stripped-title=Обтёсанное бревно таммоя
|
||||||
|
tammoy_log_stripped-desc=Светлая хвойная древесина,@n сочащаяся смолой взамен удалённой коры.
|
||||||
|
tammoy_timber-title=
|
||||||
|
tammoy_timber-desc=
|
||||||
|
tammoy_trunk-title=
|
||||||
|
tammoy_trunk-desc=
|
||||||
|
tammoy_trunk_vertical-title=
|
||||||
|
tammoy_trunk_vertical-desc=
|
||||||
|
tammoy_trunk_branch-title=
|
||||||
|
tammoy_trunk_branch-desc=
|
||||||
|
tammoy_trunk_branch_vertical-title=
|
||||||
|
tammoy_trunk_branch_vertical-desc=
|
||||||
|
tammoy_planks-title=Таммоевые доски
|
||||||
|
tammoy_planks-desc=Смолянистые плотно прилегающие друг к другу светлые доски.
|
||||||
|
tammoy_leafs-title=
|
||||||
|
tammoy_leafs-desc=
|
||||||
|
|
||||||
|
gi_log-title=Бревно ги
|
||||||
|
gi_log-desc=Благодорно-тёмная хвойная древесина,@n относящаяся к высококачественным древесным породам.@n Эта древесина особенно славится своими прочностными@n свойствами и фактурой волокон.
|
||||||
|
gi_log_stripped-title=Обтёсанное бревно ги
|
||||||
|
gi_log_stripped-desc=Плотная хвойная сердцевина, являющаяся идеальным@n материалом для изготовления различных предметов.@n В руках умелого мастера фактура этого дерева@n приобретает особенно красивый узор.
|
||||||
|
gi_timber-title=
|
||||||
|
gi_timber-desc=
|
||||||
|
gi_trunk-title=
|
||||||
|
gi_trunk-desc=
|
||||||
|
gi_trunk_vertical-title=
|
||||||
|
gi_trunk_vertical-desc=
|
||||||
|
gi_trunk_branch-title=
|
||||||
|
gi_trunk_branch-desc=
|
||||||
|
gi_trunk_branch_vertical-title=
|
||||||
|
gi_trunk_branch_vertical-desc=
|
||||||
|
gi_planks-title=Гиевые доски
|
||||||
|
gi_planks-desc=Прочные хорошо сложенные@n доски из благодорного дерева ги.
|
||||||
|
gi_leafs-title=
|
||||||
|
gi_leafs-desc=
|
||||||
|
|
||||||
|
dallalia_log-title=Бревно даллалии
|
||||||
|
dallalia_log-desc=Сладко-жёлтоватая древесина, покрытая пепельно-серой корой.@n Плотность и прочность этого вида дерева@n позволяет дереву устремляться в небо на несколько десятков метров.
|
||||||
|
dallalia_log_stripped-title=Обтёсанное бревно даллалии
|
||||||
|
dallalia_log_stripped-desc=Освобожденная от своей бледной коры жёлтовая древесина,@n сочащаяся сладким соком.
|
||||||
|
dallalia_timber-title=
|
||||||
|
dallalia_timber-desc=
|
||||||
|
dallalia_trunk-title=
|
||||||
|
dallalia_trunk-desc=
|
||||||
|
dallalia_trunk_vertical-title=
|
||||||
|
dallalia_trunk_vertical-desc=
|
||||||
|
dallalia_trunk_branch-title=
|
||||||
|
dallalia_trunk_branch-desc=
|
||||||
|
dallalia_trunk_branch_vertical-title=
|
||||||
|
dallalia_trunk_branch_vertical-desc=
|
||||||
|
dallalia_planks-title=Даллалиевые доски
|
||||||
|
dallalia_planks-desc=Жёлтые плотно сложенные доски,@n покрытие застывшим соком дерева.
|
||||||
|
dallalia_leafs-title=
|
||||||
|
dallalia_leafs-desc=
|
||||||
|
|
||||||
|
zuph_log-title=Бревно зуфа
|
||||||
|
zuph_log-desc=Светлая древесина с корой из мелких волокон.@n Из-за толстой плотной оболочки плохо поддается рубке.
|
||||||
|
zuph_log_stripped-title=Обтёсанное бревно зуфа
|
||||||
|
zuph_log_stripped-desc=Жёлтая древесина,@n лишённая трудноразрубаемой коры.
|
||||||
|
zuph_timber-title=
|
||||||
|
zuph_timber-desc=
|
||||||
|
zuph_trunk-title=
|
||||||
|
zuph_trunk-desc=
|
||||||
|
zuph_trunk_vertical-title=
|
||||||
|
zuph_trunk_vertical-desc=
|
||||||
|
zuph_trunk_branch-title=
|
||||||
|
zuph_trunk_branch-desc=
|
||||||
|
zuph_trunk_branch_vertical-title=
|
||||||
|
zuph_trunk_branch_vertical-desc=
|
||||||
|
zuph_planks-title=Зуфовые доски
|
||||||
|
zuph_planks-desc=Хорошо скрепленные между собой жёлтые древестные изделия.
|
||||||
|
zuph_leafs-title=
|
||||||
|
zuph_leafs-desc=
|
||||||
@@ -65,6 +65,7 @@ core.register_on_joinplayer(function(player, last_login)
|
|||||||
},
|
},
|
||||||
saturation = 1.0,
|
saturation = 1.0,
|
||||||
})
|
})
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Keys indicating the languages for which localization presence is checked.
|
-- Keys indicating the languages for which localization presence is checked.
|
||||||
|
|||||||
60
mods/SYSTEM/Profiler/init.lua
Normal file
60
mods/SYSTEM/Profiler/init.lua
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
local getUsTime = core.get_us_time
|
||||||
|
|
||||||
|
---@alias Profiler.TimeUnits 'sec'|'us'
|
||||||
|
|
||||||
|
---@class Profiler
|
||||||
|
---@field name string
|
||||||
|
---@field startTime number
|
||||||
|
---@field endTime number
|
||||||
|
---@field deltaTime number
|
||||||
|
Profiler = {
|
||||||
|
timers = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param name string?
|
||||||
|
---@return Profiler
|
||||||
|
function Profiler:new(name)
|
||||||
|
local instance = getInstance(self, {})
|
||||||
|
instance.name = name or 'NoName'
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---Marks the time when the timer starts.
|
||||||
|
function Profiler:startTimer()
|
||||||
|
self.startTime = getUsTime()
|
||||||
|
self.deltaTime = nil
|
||||||
|
self.endTime = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---Marks the end time of the timer.
|
||||||
|
function Profiler:stopTimer()
|
||||||
|
self.endTime = getUsTime()
|
||||||
|
|
||||||
|
self.deltaTime = self.endTime - self.startTime
|
||||||
|
end
|
||||||
|
|
||||||
|
---Returns the time difference between the start and stop of the timer in seconds (`sec`) or microseconds (`us`).
|
||||||
|
---@param units Profiler.TimeUnits? Units of time measurement. Default 'us'.
|
||||||
|
function Profiler:getDeltaTime(units)
|
||||||
|
if units == nil then
|
||||||
|
units = 'us'
|
||||||
|
end
|
||||||
|
|
||||||
|
if units == 'us' then
|
||||||
|
return self.deltaTime
|
||||||
|
elseif units == 'sec' then
|
||||||
|
return self.deltaTime/1000000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Displays the time difference in the chat using `core.log`.
|
||||||
|
---@param min number?
|
||||||
|
function Profiler:logDeltaTime(min)
|
||||||
|
local delta = self:getDeltaTime()
|
||||||
|
|
||||||
|
if delta >= (min or 0) then
|
||||||
|
core.log(('DeltaTime[%s]: %.3f'):format(self.name, delta))
|
||||||
|
end
|
||||||
|
end
|
||||||
2
mods/SYSTEM/Profiler/mod.conf
Normal file
2
mods/SYSTEM/Profiler/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__system__profiler
|
||||||
|
depends = smc__system__class, smc__system__table
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
name = smc__system__system_loader
|
name = smc__system__system_loader
|
||||||
description = Include this mod in your `depends` to ensure all necessary Libs are loaded for your mod
|
description = Include this mod in your `depends` to ensure all necessary Libs are loaded for your mod
|
||||||
depends = smc__system__ensure, smc__system__math, smc__system__mod, smc__system__require, smc__system__table, smc__system__string, smc__system__utf8, smc__system__class, smc__system__helper_lib
|
depends = smc__system__ensure, smc__system__math, smc__system__mod, smc__system__require, smc__system__table, smc__system__string, smc__system__utf8, smc__system__class, smc__system__helper_lib, smc__system__profiler
|
||||||
|
|||||||
4
mods/UI/PlayerInventoryUI/init.lua
Normal file
4
mods/UI/PlayerInventoryUI/init.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
local modInfo = Mod.getInfo('smc__ui__player_inventory')
|
||||||
|
local require = modInfo.require
|
||||||
|
|
||||||
|
return require('PlayerInventoryUI')
|
||||||
2
mods/UI/PlayerInventoryUI/mod.conf
Normal file
2
mods/UI/PlayerInventoryUI/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__ui__player_inventory
|
||||||
|
depends = smc__core__formspec
|
||||||
40
mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua
Normal file
40
mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec()
|
||||||
|
|
||||||
|
---@param self BaseUI
|
||||||
|
---@param playerName string
|
||||||
|
---@return string
|
||||||
|
local function getFormSpecString(self, playerName)
|
||||||
|
local InventoryForm = Formspec:new({
|
||||||
|
size = {x=24, y=8.5},
|
||||||
|
position = {x=0.5, y=0.6},
|
||||||
|
})
|
||||||
|
|
||||||
|
InventoryForm:
|
||||||
|
list('current_player', 'main', 12,0.5, 9,2)
|
||||||
|
|
||||||
|
return InventoryForm:toString()
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class PlayerInventoryUI : BaseUI
|
||||||
|
---@field getFormSpecString fun(self:BaseUI,playerName:string):string
|
||||||
|
---@field showForm fun(self:BaseUI,playerName:string):string
|
||||||
|
local PlayerInventoryUI = BaseUI:new('', getFormSpecString, false)
|
||||||
|
|
||||||
|
--[[
|
||||||
|
---Shows the player their inventory.
|
||||||
|
---@param playerName string
|
||||||
|
function PlayerInventoryUI:showForm(playerName)
|
||||||
|
local player = core.get_player_by_name(playerName)
|
||||||
|
assert(player ~= nil)
|
||||||
|
|
||||||
|
player:set_inventory_formspec(self:getFormSpecString(playerName))
|
||||||
|
core.show_formspec(playerName, '', '')
|
||||||
|
end
|
||||||
|
|
||||||
|
---Closes the player's inventory.
|
||||||
|
---@param playerName string
|
||||||
|
function PlayerInventoryUI:closeForm(playerName)
|
||||||
|
core.close_formspec(playerName, '')
|
||||||
|
end--]]
|
||||||
|
|
||||||
|
return PlayerInventoryUI
|
||||||
Reference in New Issue
Block a user