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.
master
Jozef Behran 2019-04-07 12:08:27 -05:00 committed by SmallJoker
parent 25f231a0e0
commit 0c90ab4f6c
2 changed files with 11 additions and 12 deletions

View File

@ -494,7 +494,7 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir,
if (partcount >= partlength) { if (partcount >= partlength) {
partcount = 0; partcount = 0;
dir = random_turn(random, dir); random_turn(random, dir);
partlength = random.range(1, length); 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); int turn = random.range(0, 2);
v3s16 dir; if (turn == 0) {
if (turn == 0) // Go straight: nothing to do
// Go straight return;
dir = olddir; } else if (turn == 1) {
else if (turn == 1)
// Turn right // Turn right
dir = turn_xz(olddir, 0); dir = turn_xz(dir, 0);
else } else {
// Turn left // Turn left
dir = turn_xz(olddir, 1); dir = turn_xz(dir, 1);
return dir; }
} }

View File

@ -34,7 +34,7 @@ class NodeDefManager;
v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs); v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs);
v3s16 turn_xz(v3s16 olddir, int t); 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); int dir_to_facedir(v3s16 d);