Skip to content

Commit

Permalink
Testing v0.3 release.
Browse files Browse the repository at this point in the history
Differentiated texture.
Made it impossible to place start positions before the texture is loaded.
Made maps bumpier on average and a little less watery.
Moved mexes inwards from the map edge.
  • Loading branch information
GoogleFrog committed Sep 8, 2019
1 parent 34e7784 commit 1323ad4
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 93 deletions.
110 changes: 63 additions & 47 deletions luarules/gadgets/map_terrain_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ local function GetTerrainWaveFunction()
waveRotationsMin = 1,
waveRotationsMax = 8,
spreadScaleMin = 0.2,
spreadScaleMax = 0.3,
spreadScaleMax = 0.4,
}

local params = {
Expand Down Expand Up @@ -1078,7 +1078,7 @@ end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Process Edges
-- Process the terrain squares around edges

local function GetSlopeWidth(startWidth, endWidth, startDist, endDist, dist)
local propDist = startDist + dist*(endDist - startDist)
Expand Down Expand Up @@ -1314,6 +1314,53 @@ local function ProcessEdges(cells, edges)
return tierFlood, heightMod
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Generate edge and cell structures

local function GenerateCellTiers(cells, waveFunc)
local averageheight = 0
for i = 1, #cells do
local height = waveFunc(cells[i].site[1], cells[i].site[2])
averageheight = averageheight + height
end
averageheight = averageheight/#cells

local std = 0
for i = 1, #cells do
local height = waveFunc(cells[i].site[1], cells[i].site[2])
std = std + (height - averageheight)^2
end
std = sqrt(std/#cells)

local waterFator = 0.2 + 0.8*random()

local bucketWidth = 65 + std*0.55
local tierHeight = 120
local tierConst = tierHeight + 45
local tierMin, tierMax = 1000, -1000

local heightOffset = -0.8*averageheight

for i = 1, #cells do
local cell = cells[i]
local height = waveFunc(cell.site[1], cell.site[2])
local tier = math.floor((height + heightOffset + bucketWidth*waterFator)/bucketWidth)

cell.tier = tier
cell.height = tier*tierHeight + tierConst
if cell.mirror then
cell.mirror.tier = cell.tier
cell.mirror.height = cell.height
end

tierMin = min(tier, tierMin)
tierMax = max(tier, tierMax)
end

return tierConst, tierHeight, tierMin, tierMax
end

local function MirrorEdgePassability(edge)
local mirror = edge.mirror
if not mirror then
Expand Down Expand Up @@ -1403,6 +1450,10 @@ local function GenerateEdgePassability(edgesSorted)
end
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Heightmap application

local function GetHeightMod(tierMin, tierMax, posTier, posChange, x, z)
if not posChange then
return 0
Expand Down Expand Up @@ -1475,48 +1526,7 @@ end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Voronoi heights

local function GenerateCellTiers(cells, waveFunc)
local averageheight = 0
for i = 1, #cells do
local height = waveFunc(cells[i].site[1], cells[i].site[2])
averageheight = averageheight + height
end
averageheight = averageheight/#cells

local std = 0
for i = 1, #cells do
local height = waveFunc(cells[i].site[1], cells[i].site[2])
std = std + (height - averageheight)^2
end
std = sqrt(std/#cells)

local waterFator = random()

local bucketWidth = 80 + std/2
local tierHeight = 120
local tierConst = tierHeight + 45
local tierMin, tierMax = 1000, -1000

for i = 1, #cells do
local cell = cells[i]
local height = waveFunc(cell.site[1], cell.site[2])
local tier = math.floor((height - averageheight + bucketWidth*waterFator)/bucketWidth)

cell.tier = tier
cell.height = tier*tierHeight + tierConst
if cell.mirror then
cell.mirror.tier = cell.tier
cell.mirror.height = cell.height
end

tierMin = min(tier, tierMin)
tierMax = max(tier, tierMax)
end

return tierConst, tierHeight, tierMin, tierMax
end
-- Start positions

local function EstimateHeightDiff(mid, checkRadius, heights)
local sampleCount = 25
Expand Down Expand Up @@ -1643,7 +1653,7 @@ local function GetRandomMexPos(mexes, edges, pos, megaMex, placeRadius, maxRadiu

local randomPoint
while tries < 50 do
randomPoint = GetRandomPointInCircle(pos, placeRadius, 100)
randomPoint = GetRandomPointInCircle(pos, placeRadius, 180)
local _, lineDistSq = GetClosestLine(randomPoint, edges, HasTierDiff)
if (not lineDistSq) or (lineAvoid^2 < lineDistSq) then
local _, pointDist = GetClosestPoint(randomPoint, mexes)
Expand Down Expand Up @@ -1787,7 +1797,7 @@ local function GetMetalValues(cells, edges, startCells)
end
end

local mexSpots = 5 + floor(random()*6)
local mexSpots = 6 + floor(random()*6)
while mexSpots > 0 do
local mexCell = cells[random(1, #cells)]
local randAllocateSum = random()*totalMexAlloc
Expand Down Expand Up @@ -1842,7 +1852,7 @@ end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Coordination
-- Large logical chunks

local function GetSeed()
local mapOpts = Spring.GetMapOptions()
Expand All @@ -1858,6 +1868,12 @@ local function GetSeed()
return random(1, 100000)
end

local function TerrainStructureTestRun()
local waveFunc = GetTerrainWaveFunction()
local cells, edges = GetVoronoi(18, 400, 500)
local tierConst, tierHeight, tierMin, tierMax = GenerateCellTiers(cells, waveFunc)
end

local function GetTerrainStructure()
local waveFunc = GetTerrainWaveFunction()
--TerraformByFunc(waveFunc)
Expand Down
88 changes: 43 additions & 45 deletions luarules/gadgets/randommapgen_texture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ local GL_RGBA32F = 0x8814
local floor = math.floor
local random = math.random


local SPLAT_DETAIL_TEX_POOL = {
{0.7,0.0,0.0,1.0}, --R
{0.0,0.9,0.0,1.0}, --G
{0.0,0.0,1.0,1.0}, --B
{0.0,0.0,0.0,1.0}, --A
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local initialized, mapfullyprocessed = false, false

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand All @@ -90,12 +93,16 @@ local function StartScript(fn)
end

local function UpdateCoroutines()
if activeCoroutine and coroutine.status(activeCoroutine) ~= "dead" then
assert(coroutine.resume(activeCoroutine))
if activeCoroutine then
if coroutine.status(activeCoroutine) ~= "dead" then
assert(coroutine.resume(activeCoroutine))
else
activeCoroutine = nil
end
end
end

local RATE_LIMIT = 10000
local RATE_LIMIT = 12000

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -184,7 +191,7 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
if texX then
glTexture(texturePool[i].texture)
for j = 1, #texX do
local heightMult = 0.12*(mapHeight[texX[j]][texZ[j]]/350) + 0.88
local heightMult = 0.15*(mapHeight[texX[j]][texZ[j]]/400) + 0.85
glColor(1, 1, 1, heightMult)
glRenderToTexture(fulltex, DrawTexBlock, texX[j], texZ[j])
loopCount = RateCheck(loopCount, texturePool[i].texture)
Expand Down Expand Up @@ -221,6 +228,26 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
local cur = Spring.GetTimer()
Spring.Echo("TopTex rendered in: "..(Spring.DiffTimers(cur, ago, true)))

if USE_SHADING_TEXTURE then
local ago2 = Spring.GetTimer()
for i = 1, #SPLAT_DETAIL_TEX_POOL do
local texX = splatTexX[i]
local texZ = splatTexZ[i]
if texX then
glColor(SPLAT_DETAIL_TEX_POOL[i])
for j = 1, #texX do
glRenderToTexture(splattex, DrawColorBlock, texX[j], texZ[j])
Spring.ClearWatchDogTimer()
loopCount = RateCheck(loopCount, false, SPLAT_DETAIL_TEX_POOL[i])
end
end
Sleep()
end
cur = Spring.GetTimer()
Spring.Echo("Splattex rendered in: "..(Spring.DiffTimers(cur, ago2, true)))
glColor(1, 1, 1, 1)
end

local texOut = fulltex
Spring.Echo("Starting to render SquareTextures")

Expand Down Expand Up @@ -279,26 +306,6 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
end
cur = Spring.GetTimer()
Spring.Echo("All squaretex rendered and applied in: "..(Spring.DiffTimers(cur, ago3, true)))

if USE_SHADING_TEXTURE then
local ago2 = Spring.GetTimer()
for i = 1, #SPLAT_DETAIL_TEX_POOL do
local texX = splatTexX[i]
local texZ = splatTexZ[i]
if texX then
glColor(SPLAT_DETAIL_TEX_POOL[i])
for j = 1, #texX do
glRenderToTexture(splattex, DrawColorBlock, texX[j], texZ[j])
Spring.ClearWatchDogTimer()
loopCount = RateCheck(loopCount, false, SPLAT_DETAIL_TEX_POOL[i])
end
end
Sleep()
end
cur = Spring.GetTimer()
Spring.Echo("Splattex rendered in: "..(Spring.DiffTimers(cur, ago2, true)))
glColor(1, 1, 1, 1)
end

if USE_SHADING_TEXTURE then
Spring.SetMapShadingTexture("$grass", texOut)
Expand Down Expand Up @@ -335,10 +342,9 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
local DrawEnd = Spring.GetTimer()
Spring.Echo("map fully processed in: "..(Spring.DiffTimers(DrawEnd, DrawStart, true)))

mapfullyprocessed = nil
mapfullyprocessed = true
end


StartScript(DrawLoop)
end

Expand Down Expand Up @@ -370,12 +376,12 @@ local function GetMainTex(height, vehiclePass, botPass, inWater)
end
return 19
end
local heightPower = (height + 50)/200
local heightPower = 1.5^((height - 180)*0.02)
if vehiclePass then
return 1 + floor((random()^heightPower)*5)
end
if botPass then
return 6 + floor((random()^heightPower)*5)
return 6 + floor(random()*5)
end
return random(11, 15)
end
Expand Down Expand Up @@ -587,13 +593,12 @@ end
local texturePool
local mapTexX, mapTexZ, topTexX, topTexZ, topTexAlpha, splatTexX, splatTexZ, mapHeight

local initialized, mapfullyprocessed = false, false

function gadget:DrawGenesis()
if initialized ~= true then
if not initialized then
return
end
if mapfullyprocessed == true then
if mapfullyprocessed then
gadgetHandler:RemoveGadget()
return
end

Expand All @@ -604,27 +609,20 @@ function gadget:DrawGenesis()
end
end

function gadget:MousePress(x, y, button)
return (button == 1) and (not mapfullyprocessed)
end

local function MakeMapTexture()
if (not gl.RenderToTexture) then --super bad graphic driver
mapfullyprocessed = true
return
end
texturePool = GetTextureSet(Spring.GetGameRulesParam("typemap"))
mapTexX, mapTexZ, topTexX, topTexZ, topTexAlpha, splatTexX, splatTexZ, mapHeight = InitializeTextures(USE_SHADING_TEXTURE, Spring.GetGameRulesParam("typemap"))
initialized = true
end

local function RemakeMapTexture()
if not Spring.IsCheatingEnabled() then
return
end
mapfullyprocessed = false
MakeMapTexture()
end

function gadget:Initialize()
gadgetHandler:AddChatAction("maptex", RemakeMapTexture, "Remakes Map Texture.")
end

local updateCount = 0
function gadget:Update(n)
if not updateCount then
Expand Down
2 changes: 1 addition & 1 deletion mapinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local mapinfo = {
shortname = "RCrags",
description = "A sometimes-craggy, sometimes flat random map (12x12)",
author = "GoogleFrog",
version = "v0.2",
version = "v0.3",
modtype = 3, --// 1=primary, 0=hidden, 3=map

maphardness = 140,
Expand Down

0 comments on commit 1323ad4

Please sign in to comment.