From 361ab8c8c54160f052ed8b430a493271ce225b64 Mon Sep 17 00:00:00 2001 From: darkrose Date: Tue, 16 Jun 2015 04:58:03 +1000 Subject: [PATCH] optimise grass growth code a bit --- src/plantgrowth.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/plantgrowth.cpp b/src/plantgrowth.cpp index 7735820..9a1252e 100644 --- a/src/plantgrowth.cpp +++ b/src/plantgrowth.cpp @@ -495,18 +495,26 @@ void plantgrowth_grass(ServerEnvironment *env, v3s16 p0) bool add = false; { u8 p = n.param2&0xF0; - MapNode nn = env->getMap().getNodeNoEx(p0+v3s16(0,0,-1)); - if (nn.getContent() == c) - p |= 1<<7; - nn = env->getMap().getNodeNoEx(p0+v3s16(0,0,1)); - if (nn.getContent() == c) - p |= 1<<6; - nn = env->getMap().getNodeNoEx(p0+v3s16(-1,0,0)); - if (nn.getContent() == c) - p |= 1<<5; - nn = env->getMap().getNodeNoEx(p0+v3s16(1,0,0)); - if (nn.getContent() == c) - p |= 1<<4; + if ((p&(1<<7)) == 0) { + MapNode nn = env->getMap().getNodeNoEx(p0+v3s16(0,0,-1)); + if (nn.getContent() == c) + p |= 1<<7; + } + if ((p&(1<<6)) == 0) { + MapNode nn = env->getMap().getNodeNoEx(p0+v3s16(0,0,1)); + if (nn.getContent() == c) + p |= 1<<6; + } + if ((p&(1<<5)) == 0) { + MapNode nn = env->getMap().getNodeNoEx(p0+v3s16(-1,0,0)); + if (nn.getContent() == c) + p |= 1<<5; + } + if ((p&(1<<4)) == 0) { + MapNode nn = env->getMap().getNodeNoEx(p0+v3s16(1,0,0)); + if (nn.getContent() == c) + p |= 1<<4; + } if (!n.param2 && p == 0 && myrand_range(0,20) != 0) return; if (!n.param2 || p != (n.param2&0xF0)) {