summaryrefslogtreecommitdiff
path: root/src/mapnode.cpp
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2015-10-02 01:07:57 +0100
committerparamat <mat.gregory@virginmedia.com>2015-10-02 06:03:36 +0100
commit8aaae7db05917dbbedebbd1b5616db976dfc2e8e (patch)
treebf39d114556ef25e477ab4305cbc4c2bd95039f9 /src/mapnode.cpp
parent0bf1984d2c9fb3a9dc73303551c18906c3c9482b (diff)
downloadminetest-8aaae7db05917dbbedebbd1b5616db976dfc2e8e.tar.gz
minetest-8aaae7db05917dbbedebbd1b5616db976dfc2e8e.tar.bz2
minetest-8aaae7db05917dbbedebbd1b5616db976dfc2e8e.zip
Mapnode: Replace rotateAlongYAxis with improved version
Get facedir by using lowest 5 bits of param2 and limiting to 23 More robust, frees up higher param2 bits for other uses Change lookup table and table index to u8
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r--src/mapnode.cpp30
1 files changed, 5 insertions, 25 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 64c0ea03f..671e949f1 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -164,29 +164,7 @@ void MapNode::rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot)
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
if (cpt2 == CPT2_FACEDIR) {
- if (param2 >= 4)
- return;
-
- u8 newrot = param2 & 3;
- param2 &= ~3;
- param2 |= (newrot + rot) & 3;
- } else if (cpt2 == CPT2_WALLMOUNTED) {
- u8 wmountface = (param2 & 7);
- if (wmountface <= 1)
- return;
-
- Rotation oldrot = wallmounted_to_rot[wmountface - 2];
- param2 &= ~7;
- param2 |= rot_to_wallmounted[(oldrot - rot) & 3];
- }
-}
-
-void MapNode::rotateAlongYAxisFull(INodeDefManager *nodemgr, Rotation rot)
-{
- ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
-
- if (cpt2 == CPT2_FACEDIR) {
- static const u16 rotate_facedir[24 * 4] = {
+ static const u8 rotate_facedir[24 * 4] = {
// Table value = rotated facedir
// Columns: 0, 90, 180, 270 degrees rotation around vertical axis
// Rotation is anticlockwise as seen from above (+Y)
@@ -221,8 +199,10 @@ void MapNode::rotateAlongYAxisFull(INodeDefManager *nodemgr, Rotation rot)
22, 21, 20, 23,
23, 22, 21, 20
};
- u16 index = param2 * 4 + rot;
- param2 = rotate_facedir[index];
+ u8 facedir = (param2 & 31) % 24;
+ u8 index = facedir * 4 + rot;
+ param2 &= ~31;
+ param2 |= rotate_facedir[index];
} else if (cpt2 == CPT2_WALLMOUNTED) {
u8 wmountface = (param2 & 7);
if (wmountface <= 1)