Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
68b1cd8d
Commit
68b1cd8d
authored
8 years ago
by
kwolekr
Browse files
Options
Downloads
Patches
Plain Diff
Cavegen: Merge instances of repetitive surface level-finding code
parent
a605d690
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cavegen.cpp
+42
-55
42 additions, 55 deletions
src/cavegen.cpp
src/cavegen.h
+5
-0
5 additions, 0 deletions
src/cavegen.h
with
47 additions
and
55 deletions
src/cavegen.cpp
+
42
−
55
View file @
68b1cd8d
...
...
@@ -147,31 +147,10 @@ void CavesRandomWalk::makeTunnel(bool dirswitch)
// Do not make caves that are above ground.
// It is only necessary to check the startpoint and endpoint.
v3s16
orpi
(
orp
.
X
,
orp
.
Y
,
orp
.
Z
);
v3s16
veci
(
vec
.
X
,
vec
.
Y
,
vec
.
Z
);
v3s16
p
;
p
=
orpi
+
veci
+
of
+
rs
/
2
;
if
(
p
.
Z
>=
node_min
.
Z
&&
p
.
Z
<=
node_max
.
Z
&&
p
.
X
>=
node_min
.
X
&&
p
.
X
<=
node_max
.
X
)
{
u32
index
=
(
p
.
Z
-
node_min
.
Z
)
*
ystride
+
(
p
.
X
-
node_min
.
X
);
s16
h
=
mg
->
heightmap
[
index
];
if
(
h
<
p
.
Y
)
return
;
}
else
if
(
p
.
Y
>
water_level
)
{
return
;
// If it's not in our heightmap, use a simple heuristic
}
p
=
orpi
+
of
+
rs
/
2
;
if
(
p
.
Z
>=
node_min
.
Z
&&
p
.
Z
<=
node_max
.
Z
&&
p
.
X
>=
node_min
.
X
&&
p
.
X
<=
node_max
.
X
)
{
u32
index
=
(
p
.
Z
-
node_min
.
Z
)
*
ystride
+
(
p
.
X
-
node_min
.
X
);
s16
h
=
mg
->
heightmap
[
index
];
if
(
h
<
p
.
Y
)
return
;
}
else
if
(
p
.
Y
>
water_level
)
{
v3s16
p1
=
v3s16
(
orp
.
X
,
orp
.
Y
,
orp
.
Z
)
+
of
+
rs
/
2
;
v3s16
p2
=
v3s16
(
vec
.
X
,
vec
.
Y
,
vec
.
Z
)
+
p1
;
if
(
isPosAboveSurface
(
p1
)
||
isPosAboveSurface
(
p2
))
return
;
}
vec
+=
main_direction
;
...
...
@@ -274,6 +253,22 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz)
}
inline
bool
CavesRandomWalk
::
isPosAboveSurface
(
v3s16
p
)
{
if
(
heightmap
!=
NULL
&&
p
.
Z
>=
node_min
.
Z
&&
p
.
Z
<=
node_max
.
Z
&&
p
.
X
>=
node_min
.
X
&&
p
.
X
<=
node_max
.
X
)
{
u32
index
=
(
p
.
Z
-
node_min
.
Z
)
*
ystride
+
(
p
.
X
-
node_min
.
X
);
if
(
heightmap
[
index
]
<
p
.
Y
)
return
true
;
}
else
if
(
p
.
Y
>
water_level
)
{
return
true
;
}
return
false
;
}
////
//// CavesV6
////
...
...
@@ -448,39 +443,18 @@ void CavesV6::makeTunnel(bool dirswitch)
);
}
// Do not make caves that are entirely above ground, to fix
//
shadow bugs
caused by overgenerated large caves.
// Do not make caves that are entirely above ground, to fix
shadow bugs
// caused by overgenerated large caves.
// It is only necessary to check the startpoint and endpoint.
v3s16
orpi
(
orp
.
X
,
orp
.
Y
,
orp
.
Z
);
v3s16
veci
(
vec
.
X
,
vec
.
Y
,
vec
.
Z
);
s16
h1
;
s16
h2
;
v3s16
p1
=
orpi
+
veci
+
of
+
rs
/
2
;
if
(
p1
.
Z
>=
node_min
.
Z
&&
p1
.
Z
<=
node_max
.
Z
&&
p1
.
X
>=
node_min
.
X
&&
p1
.
X
<=
node_max
.
X
)
{
u32
index1
=
(
p1
.
Z
-
node_min
.
Z
)
*
ystride
+
(
p1
.
X
-
node_min
.
X
);
h1
=
heightmap
[
index1
];
}
else
{
h1
=
water_level
;
// If not in heightmap
}
v3s16
p2
=
orpi
+
of
+
rs
/
2
;
if
(
p2
.
Z
>=
node_min
.
Z
&&
p2
.
Z
<=
node_max
.
Z
&&
p2
.
X
>=
node_min
.
X
&&
p2
.
X
<=
node_max
.
X
)
{
u32
index2
=
(
p2
.
Z
-
node_min
.
Z
)
*
ystride
+
(
p2
.
X
-
node_min
.
X
);
h2
=
heightmap
[
index2
];
}
else
{
h2
=
water_level
;
}
v3s16
p1
=
v3s16
(
orp
.
X
,
orp
.
Y
,
orp
.
Z
)
+
of
+
rs
/
2
;
v3s16
p2
=
v3s16
(
vec
.
X
,
vec
.
Y
,
vec
.
Z
)
+
p1
;
// If startpoint and endpoint are above ground,
// disable placing of nodes in carveRoute while
// still running all pseudorandom calls to ensure
// caves consistent with existing worlds.
bool
tunnel_above_ground
=
p1
.
Y
>
h1
&&
p2
.
Y
>
h2
;
// If startpoint and endpoint are above ground, disable placement of nodes
// in carveRoute while still running all PseudoRandom calls to ensure caves
// are consistent with existing worlds.
bool
tunnel_above_ground
=
p1
.
Y
>
getSurfaceFromHeightmap
(
p1
)
&&
p2
.
Y
>
getSurfaceFromHeightmap
(
p2
);
vec
+=
main_direction
;
...
...
@@ -588,3 +562,16 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz,
}
}
}
inline
s16
CavesV6
::
getSurfaceFromHeightmap
(
v3s16
p
)
{
if
(
heightmap
!=
NULL
&&
p
.
Z
>=
node_min
.
Z
&&
p
.
Z
<=
node_max
.
Z
&&
p
.
X
>=
node_min
.
X
&&
p
.
X
<=
node_max
.
X
)
{
u32
index
=
(
p
.
Z
-
node_min
.
Z
)
*
ystride
+
(
p
.
X
-
node_min
.
X
);
return
heightmap
[
index
];
}
else
{
return
water_level
;
}
}
This diff is collapsed.
Click to expand it.
src/cavegen.h
+
5
−
0
View file @
68b1cd8d
...
...
@@ -71,6 +71,9 @@ class CavesRandomWalk {
void
makeCave
(
v3s16
nmin
,
v3s16
nmax
,
int
max_stone_height
);
void
makeTunnel
(
bool
dirswitch
);
void
carveRoute
(
v3f
vec
,
float
f
,
bool
randomize_xz
);
private:
inline
bool
isPosAboveSurface
(
v3s16
p
);
};
/*
...
...
@@ -140,6 +143,8 @@ class CavesV6 {
private:
void
makeTunnel
(
bool
dirswitch
);
void
carveRoute
(
v3f
vec
,
float
f
,
bool
randomize_xz
,
bool
tunnel_above_ground
);
inline
s16
getSurfaceFromHeightmap
(
v3s16
p
);
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment