Cleaner and more efficient generation loop. Add second noise. Add smoothing of junction corners

This commit is contained in:
paramat 2020-06-04 01:38:45 +01:00
parent b567dfe559
commit 9828a843b6
5 changed files with 150 additions and 47 deletions

View File

@ -1,9 +1,44 @@
driftgame 0.1.0 by paramat. driftgame 0.1.1 by paramat
A game for Minetest Engine 5.2.0 and later. A game for Minetest Engine 5.2.0 and later
See each mod for mod-specific credits and licenses. Built on the 'minipeli' game by paramat
Authors of media Authors of media
---------------- ----------------
paramat (CC BY-SA 3.0): paramat (CC BY-SA 3.0):
header.png header.png
icon.png icon.png
Using this game
---------------
Due to client->server->client control delay it is recommended that this game is used in singleplayer or in local multiplayer.
Generation of new areas of world may slightly affect the control response of the vehicle, the best control response will occur in previously generated areas.
Left arrow and right arrow blocks are given to a new player to mark out a race track.
Third-person camera mode is recommended when driving for a better view.
How to start playing this game
------------------------------
Decoration placement must be disabled, this can be done in the 'All Settings' menu (Settings tab -> All Settings -> Mapgen -> Mapgen flags) or by adding the line below to your minetet.conf file:
mg_flags = caves,dungeons,light,nodecorations,biomes
Start a new world, the game will only allow 'Mapgen Flat' to be selected.
When you enter the world, if the screen is black you are probably inside a tree, walk in various directions to exit the tree.
Type '/grantme all' to obtain all privileges.
Press 'K' to enable fly mode, and 'J' to enable fast mode.
Fly fast to find some track, it might take a minute or more to find it.
Place the car on the track, enter it. Press 'F7' to use third-person camera mode.
Car controls
------------
Left mouse button = Place car in inventory when pointing at car.
Right mouse button = Place car in world. Enter or exit car when pointing at car.
Forward = Speed up.
Slow down when moving backwards.
Backward = Slow down.
Speed up when moving backwards.
Left = Rotate anticlockwise.
Right = Rotate clockwise.

View File

@ -1,16 +1,16 @@
-- Parameters -- Parameters
local MAXGRIP = 7 -- Maximum linear and lateral acceleration, in nodes/s^2 local GRIP = 8 -- On road maximum linear and lateral acceleration, in nodes/s^2
-- Halved on 'crumbly' nodes. local ORGRIP = 5 -- Off road maximum linear and lateral acceleration, in nodes/s^2
local SZTORQ = 22 -- Car speed where motor torque drops to zero, in nodes/s local SZTORQ = 22 -- Car speed where motor torque drops to zero, in nodes/s
local DRAG = 0.04 -- Air drag local DRAG = 0.04 -- Air drag
local ROLRES = 0.6 -- Rolling resistence TODO increase in crumbly local ROLRES = 0.6 -- Rolling resistence, in nodes/s^2
local ORROLRES = 1.8 -- Off road Rolling resistence, in nodes/s^2
local GRAV = 9.81 -- Acceleration of gravity, in nodes/s^2 local GRAV = 9.81 -- Acceleration of gravity, in nodes/s^2
-- Turn parameters, in radians/s or radians/s^2 local TINIT = 0.36 -- Initial turn speed on first control input, in radians/s
local TINIT = 0.36 -- Initial turn speed on first control input local TACC = 0.12 -- Turn acceleration on control input, in radians/s^2
local TACC = 0.12 -- Turn acceleration on control input local TMAX = 1.6 -- Maximum turn speed, in radians/s
local TMAX = 1.6 -- Maximum turn speed (Smart fortwo turning circle 7 nodes) local TDEC = 0.24 -- Turn deceleration on no control input, in radians/s^2
local TDEC = 0.24 -- Turn deceleration on no control input
-- End of parameters -- End of parameters
@ -220,10 +220,13 @@ function car.on_step(self, dtime)
local node_under = minetest.get_node(under_pos) local node_under = minetest.get_node(under_pos)
local nodedef_under = minetest.registered_nodes[node_under.name] local nodedef_under = minetest.registered_nodes[node_under.name]
local touch = nodedef_under.walkable local touch = nodedef_under.walkable
-- On road bool
local onroad = true
-- Modify grip according to 'crumbly' group -- Modify grip according to 'crumbly' group
local grip = MAXGRIP local grip = GRIP
if nodedef_under.groups.crumbly then if nodedef_under.groups.crumbly then
grip = MAXGRIP / 2 grip = ORGRIP
onroad = false
end end
-- Torque acceleration applied linear to car -- Torque acceleration applied linear to car
@ -306,9 +309,17 @@ function car.on_step(self, dtime)
local rraccmag = 0 local rraccmag = 0
if touch then if touch then
if linvel > 0 then if linvel > 0 then
if onroad then
rraccmag = -ROLRES rraccmag = -ROLRES
else
rraccmag = -ORROLRES
end
elseif linvel < 0 then elseif linvel < 0 then
if onroad then
rraccmag = ROLRES rraccmag = ROLRES
else
rraccmag = ORROLRES
end
end end
end end
--local rracc = get_veccomp(rraccmag, self.object:getyaw(), 0) --local rracc = get_veccomp(rraccmag, self.object:getyaw(), 0)
@ -328,7 +339,7 @@ function car.on_step(self, dtime)
tlfacc = get_veccomp(tlfaccmag, self.object:getyaw() + math.pi / 2, 0) tlfacc = get_veccomp(tlfaccmag, self.object:getyaw() + math.pi / 2, 0)
-- Tire smoke -- Tire smoke
if self.driver and math.random() < -0.05 + math.abs(latvel) / 30 then if self.driver and onroad and math.random() < -0.05 + math.abs(latvel) / 30 then
local opos = self.object:getpos() local opos = self.object:getpos()
opos.y = opos.y - 0.5 opos.y = opos.y - 0.5
local yaw = self.object:getyaw() local yaw = self.object:getyaw()

View File

@ -5,9 +5,18 @@ local pathy = 8
local np_patha = { local np_patha = {
offset = 0, offset = 0,
scale = 1, scale = 1,
spread = {x = 1024, y = 1024, z = 1024}, spread = {x = 256, y = 256, z = 256},
seed = 11711, seed = 11711,
octaves = 5, octaves = 3,
persist = 0.5
}
local np_pathb = {
offset = 0,
scale = 1,
spread = {x = 256, y = 256, z = 256},
seed = 303,
octaves = 3,
persist = 0.5 persist = 0.5
} }
@ -30,6 +39,37 @@ minetest.register_node("track:road_white", {
groups = {cracky = 3}, groups = {cracky = 3},
}) })
minetest.register_node("track:arrow_left", {
description = "Arrow Block Left",
tiles = {"track_red.png", "track_red.png",
"track_red.png", "track_red.png",
"track_red.png", "track_arrow_left.png"},
paramtype = "light",
light_source = 14,
paramtype2 = "facedir",
groups = {dig_immediate = 2},
})
minetest.register_node("track:arrow_right", {
description = "Arrow Block Right",
tiles = {"track_red.png", "track_red.png",
"track_red.png", "track_red.png",
"track_red.png", "track_arrow_left.png^[transformFX"},
paramtype = "light",
light_source = 14,
paramtype2 = "facedir",
groups = {dig_immediate = 2},
})
-- Give initial items
minetest.register_on_newplayer(function(player)
local inv = player:get_inventory()
inv:add_item("main", "track:arrow_left 512")
inv:add_item("main", "track:arrow_right 512")
end)
-- Constants -- Constants
@ -40,7 +80,9 @@ local c_roadwhite = minetest.get_content_id("track:road_white")
-- Initialise noise object, noise table, voxelmanip table -- Initialise noise object, noise table, voxelmanip table
local nobj_patha = nil local nobj_patha = nil
local nobj_pathb = nil
local nvals_patha = {} local nvals_patha = {}
local nvals_pathb = {}
local data = {} local data = {}
@ -60,33 +102,48 @@ minetest.register_on_generated(function(minp, maxp, seed)
local y0 = minp.y local y0 = minp.y
local z0 = minp.z local z0 = minp.z
local sidelen = x1 - x0 + 1 -- Noise map extends from x0/z0 - 5 to x1/z1 + 4, one node larger than the track brush
local emerlen = sidelen + 32 -- centre generation area, to allow sign change of noise to be detected along minimum
local overlen = sidelen + 9 -- edges of track brush centre generation area.
local pmapdims = {x = overlen, y = overlen, z = 1} local mchudim = x1 - x0 + 1
local pmapdim = mchudim + 9
local pmapdims = {x = pmapdim, y = pmapdim, z = 1}
local pmapminp = {x = x0 - 5, y = z0 - 5} local pmapminp = {x = x0 - 5, y = z0 - 5}
nobj_patha = nobj_patha or minetest.get_perlin_map(np_patha, pmapdims) nobj_patha = nobj_patha or minetest.get_perlin_map(np_patha, pmapdims)
nobj_pathb = nobj_pathb or minetest.get_perlin_map(np_pathb, pmapdims)
nobj_patha:get2dMap_flat(pmapminp, nvals_patha) nobj_patha:get2dMap_flat(pmapminp, nvals_patha)
nobj_pathb:get2dMap_flat(pmapminp, nvals_pathb)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax} local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
vm:get_data(data) vm:get_data(data)
local ni = 1 -- Track brush centre generation area extends from x0/z0 - 4 to x1/z1 + 4
for z = z0 - 5, z1 + 4 do for z = z0 - 4, z1 + 4 do
local n_xprepatha = false -- Initial noise index at x0 - 4 for this z
-- x0 - 5, z0 - 5 is to setup initial values of 'xprepath_', 'zprepath_' local ni = 1 + (z - (z0 - 5)) * pmapdim + 1
for x = x0 - 5, x1 + 4 do local n_xprepatha = nvals_patha[(ni - 1)]
local n_xprepathb = nvals_pathb[(ni - 1)]
for x = x0 - 4, x1 + 4 do
local n_patha = nvals_patha[ni] local n_patha = nvals_patha[ni]
local n_zprepatha = nvals_patha[(ni - overlen)] local n_pathb = nvals_pathb[ni]
local n_zprepatha = nvals_patha[(ni - pmapdim)]
if x >= x0 - 4 and z >= z0 - 4 then local n_zprepathb = nvals_pathb[(ni - pmapdim)]
if (n_patha >= 0 and n_xprepatha < 0) -- detect sign change of noise -- Detect sign change of noise
if (n_patha >= 0 and n_xprepatha < 0)
or (n_patha < 0 and n_xprepatha >= 0) or (n_patha < 0 and n_xprepatha >= 0)
or (n_patha >= 0 and n_zprepatha < 0) or (n_patha >= 0 and n_zprepatha < 0)
or (n_patha < 0 and n_zprepatha >= 0) then or (n_patha < 0 and n_zprepatha >= 0)
-- place path node brush
or (n_pathb >= 0 and n_xprepathb < 0)
or (n_pathb < 0 and n_xprepathb >= 0)
or (n_pathb >= 0 and n_zprepathb < 0)
or (n_pathb < 0 and n_zprepathb >= 0)-- then
-- Smooth corners of junctions
or math.pow(math.abs(n_patha), 0.1) *
math.pow(math.abs(n_pathb), 0.1) < 0.5 then
-- Place track brush of radius 4
for k = -4, 4 do for k = -4, 4 do
local vi = area:index(x - 4, pathy, z + k) local vi = area:index(x - 4, pathy, z + k)
for i = -4, 4 do for i = -4, 4 do
@ -103,10 +160,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
end end
end
n_xprepatha = n_patha
ni = ni + 1 ni = ni + 1
n_xprepatha = n_patha
n_xprepathb = n_pathb
end end
end end

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B