aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen
diff options
context:
space:
mode:
authorJozef Behran <jozuejozef@gmail.com>2019-04-07 12:08:27 -0500
committerSmallJoker <SmallJoker@users.noreply.github.com>2019-04-07 19:08:27 +0200
commit0c90ab4f6c8f0e4ddb1e674736bec5165278327d (patch)
treeb2ef3976fc9430142e6f69942e2d8133af8d1505 /src/mapgen
parent25f231a0e023b0ace5604f167b5189529bd2598f (diff)
downloadminetest-0c90ab4f6c8f0e4ddb1e674736bec5165278327d.tar.gz
minetest-0c90ab4f6c8f0e4ddb1e674736bec5165278327d.tar.bz2
minetest-0c90ab4f6c8f0e4ddb1e674736bec5165278327d.zip
Optimize random turns in dungeongen (#8129)
It turns out there is no need to return the new value and preserve the old one in random_turn, the procedure can be made to modify the value in-place. This saves quite a bunch of parameter and return value copying.
Diffstat (limited to 'src/mapgen')
-rw-r--r--src/mapgen/dungeongen.cpp21
-rw-r--r--src/mapgen/dungeongen.h2
2 files changed, 11 insertions, 12 deletions
diff --git a/src/mapgen/dungeongen.cpp b/src/mapgen/dungeongen.cpp
index 3acd22877..1aa3317cf 100644
--- a/src/mapgen/dungeongen.cpp
+++ b/src/mapgen/dungeongen.cpp
@@ -494,7 +494,7 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir,
if (partcount >= partlength) {
partcount = 0;
- dir = random_turn(random, dir);
+ random_turn(random, dir);
partlength = random.range(1, length);
@@ -655,20 +655,19 @@ v3s16 turn_xz(v3s16 olddir, int t)
}
-v3s16 random_turn(PseudoRandom &random, v3s16 olddir)
+void random_turn(PseudoRandom &random, v3s16 &dir)
{
int turn = random.range(0, 2);
- v3s16 dir;
- if (turn == 0)
- // Go straight
- dir = olddir;
- else if (turn == 1)
+ if (turn == 0) {
+ // Go straight: nothing to do
+ return;
+ } else if (turn == 1) {
// Turn right
- dir = turn_xz(olddir, 0);
- else
+ dir = turn_xz(dir, 0);
+ } else {
// Turn left
- dir = turn_xz(olddir, 1);
- return dir;
+ dir = turn_xz(dir, 1);
+ }
}
diff --git a/src/mapgen/dungeongen.h b/src/mapgen/dungeongen.h
index 2748524c5..7d04a6254 100644
--- a/src/mapgen/dungeongen.h
+++ b/src/mapgen/dungeongen.h
@@ -34,7 +34,7 @@ class NodeDefManager;
v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs);
v3s16 turn_xz(v3s16 olddir, int t);
-v3s16 random_turn(PseudoRandom &random, v3s16 olddir);
+void random_turn(PseudoRandom &random, v3s16 &dir);
int dir_to_facedir(v3s16 d);