diff options
Diffstat (limited to 'src/mapgen/mapgen_v6.h')
0 files changed, 0 insertions, 0 deletions
![]() |
index : minetest.git | |
modified minetest for gpcfs purposes | gpcf |
aboutsummaryrefslogtreecommitdiff |
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "irrlichttypes_extrabloated.h"
#include "mapnode.h"
#include "porting.h"
#include "nodedef.h"
#include "map.h"
#include "content_mapnode.h" // For mapnode_translate_*_internal
#include "serialization.h" // For ser_ver_supported
#include "util/serialize.h"
#include "log.h"
#include "util/directiontables.h"
#include "util/numeric.h"
#include <string>
#include <sstream>
static const Rotation wallmounted_to_rot[] = {
ROTATE_0, ROTATE_180, ROTATE_90, ROTATE_270
};
static const u8 rot_to_wallmounted[] = {
2, 4, 3, 5
};
/*
MapNode
*/
void MapNode::getColor(const ContentFeatures &f, video::SColor *color) const
{
if (f.palette) {
*color = (*f.palette)[param2];
return;
}
*color = f.color;
}
void MapNode::setLight(LightBank bank, u8 a_light, const ContentFeatures &f) noexcept
{
// If node doesn't contain light data, ignore this
if(f.param_type != CPT_LIGHT)
return;
if(bank == LIGHTBANK_DAY)
{
param1 &= 0xf0;
param1 |= a_light & 0x0f;
}
else if(bank == LIGHTBANK_NIGHT)
{
param1 &= 0x0f;
param1 |= (a_light & 0x0f)<<4;
}
else
assert("Invalid light bank" == NULL);
}
void MapNode::setLight(LightBank bank, u8 a_light, const NodeDefManager *nodemgr)
{
setLight(bank, a_light, nodemgr->get(*this));
}
bool MapNode::isLightDayNightEq(const NodeDefManager *nodemgr) const
{
const ContentFeatures &f = nodemgr->get(*this);
bool isEqual;
if (f.param_type == CPT_LIGHT) {
u8 day = MYMAX(f.light_source, param1 & 0x0f);
u8 night = MYMAX(f.light_source, (param1 >> 4) & 0x0f);
isEqual = day == night;
} else {
isEqual = true;
}
return isEqual;
}
u8 MapNode::getLight(LightBank bank, const NodeDefManager *nodemgr) const
{
// Select the brightest of [light source, propagated light]
const ContentFeatures &f = nodemgr->get(*this);
u8 light;
if(f.param_type == CPT_LIGHT)
light = bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f;
else
light = 0;
return MYMAX(f.light_source, light);
}
u8 MapNode::getLightRaw(LightBank bank, const ContentFeatures &f) const noexcept
{
if(f.param_type == CPT_LIGHT)
return bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f;
return 0;
}
u8 MapNode::getLightNoChecks(LightBank bank, const ContentFeatures *f) const noexcept
{
return MYMAX(f->light_source,
bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f);
}
bool MapNode::getLightBanks(u8 &lightday, u8 &lightnight,
const NodeDefManager *nodemgr) const
{
// Select the brightest of [light source, propagated light]
const ContentFeatures &f = nodemgr->get(*this);
if(f.param_type == CPT_LIGHT)
{
lightday = param1 & 0x0f;
lightnight = (param1>>4)&0x0f;
}
else
{
lightday = 0;
lightnight = 0;
}
if(f.light_source > lightday)
lightday = f.light_source;
if(f.light_source > lightnight)
lightnight = f.light_source;
return f.param_type == CPT_LIGHT || f.light_source != 0;
}
u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
bool allow_wallmounted) const
{
const ContentFeatures &f = nodemgr->get(*this);
if (f.param_type_2 == CPT2_FACEDIR ||
f.param_type_2 == CPT2_COLORED_FACEDIR)
return (getParam2() & 0x1F) % 24;
if (allow_wallmounted && (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED))
return wallmounted_to_facedir[getParam2() & 0x07];
return 0;
}
u8 MapNode::getWallMounted(const NodeDefManager *nodemgr) const
{
const ContentFeatures &f = nodemgr->get(*this);
if (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
return getParam2() & 0x07;
} else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE) {
return 1;
}
return 0;
}
v3s16 MapNode::getWallMountedDir(const NodeDefManager *nodemgr) const
{
switch(getWallMounted(nodemgr))
{
case 0: default: return v3s16(0,1,0);
case 1: return v3s16(0,-1,0);
case 2: return v3s16(1,0,0);
case 3: return v3s16(-1,0,0);
case 4: return v3s16(0,0,1);
case 5: return v3s16(0,0,-1);
}
}
u8 MapNode::getDegRotate(const NodeDefManager *nodemgr) const
{
const ContentFeatures &f = nodemgr->get(*this);
if (f.param_type_2 == CPT2_DEGROTATE)
return getParam2() % 240;
if (f.param_type_2 == CPT2_COLORED_DEGROTATE)
return 10 * ((getParam2() & 0x1F) % 24);
return 0;
}
void MapNode::rotateAlongYAxis(const NodeDefManager *nodemgr, Rotation rot)
{
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
if (cpt2 == CPT2_FACEDIR || cpt2 == CPT2_COLORED_FACEDIR) {
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)
0, 1, 2, 3, // Initial facedir 0 to 3
1, 2, 3, 0,
2, 3, 0, 1,
3, 0, 1, 2,
4, 13, 10, 19, // 4 to 7
5, 14, 11, 16,
6, 15, 8, 17,
7, 12, 9, 18,
8, 17, 6, 15, // 8 to 11
9, 18, 7, 12,
10, 19, 4, 13,
11, 16, 5, 14,
12, 9, 18, 7, // 12 to 15
13, 10, 19, 4,
14, 11, 16, 5,
15, 8, 17, 6,
16, 5, 14, 11, // 16 to 19
17, 6, 15, 8,
18, 7, 12, 9,
19, 4, 13, 10,
20, 23, 22, 21, // 20 to 23
21, 20, 23, 22,
22, 21, 20, 23,
23, 22, 21, 20
};
u8 facedir = (param2 & 31) % 24;
u8 index = facedir * 4 + rot;
param2 &= ~31;
param2 |= rotate_facedir[index];
} else if (cpt2 == CPT2_WALLMOUNTED ||
cpt2 == CPT2_COLORED_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];
} else if (cpt2 == CPT2_DEGROTATE) {
int angle = param2; // in 1.5°
angle += 60 * rot; // don’t do that on u8
angle %= 240;
param2 = angle;
} else if (cpt2 == CPT2_COLORED_DEGROTATE) {
int angle = param2 & 0x1F; // in 15°
int color = param2 & 0xE0;
angle += 6 * rot;
angle %= 24;
param2 = color | angle;
}
}
void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
const NodeDefManager *nodemgr, std::vector<aabb3f> *p_boxes,
u8 neighbors = 0)
{
std::vector<aabb3f> &boxes = *p_boxes;
if (nodebox.type == NODEBOX_FIXED || nodebox.type == NODEBOX_LEVELED) {
const std::vector<aabb3f> &fixed = nodebox.fixed;
int facedir = n.getFaceDir(nodemgr, true);
u8 axisdir = facedir>>2;
facedir&=0x03;
for (aabb3f box : fixed) {
if (nodebox.type == NODEBOX_LEVELED)
box.MaxEdge.Y = (-0.5f + n.getLevel(nodemgr) / 64.0f) * BS;
switch (axisdir) {
case 0:
if(facedir == 1)
{
box.MinEdge.rotateXZBy(-90);
box.MaxEdge.rotateXZBy(-90);
}
else if(facedir == 2)
{
box.MinEdge.rotateXZBy(180);
box.MaxEdge.rotateXZBy(180);
}
else if(facedir == 3)
{
box.MinEdge.rotateXZBy(90);
box.MaxEdge.rotateXZBy(90);
}
break;
case 1: // z+
box.MinEdge.rotateYZBy(90);
box.MaxEdge.rotateYZBy(90);
if(facedir == 1)
{
box.MinEdge.rotateXYBy(90);
box.MaxEdge.rotateXYBy(90);
}
else if(facedir == 2)
{
box.MinEdge.rotateXYBy(180);
box.MaxEdge.rotateXYBy(180);
}
else if(facedir == 3)
{
box.MinEdge.rotateXYBy(-90);
box.MaxEdge.rotateXYBy(-90);
}
break;
case 2: //z-
box.MinEdge.rotateYZBy(-90);
box.MaxEdge.rotateYZBy(-90);
if(facedir == 1)
{
box.MinEdge.rotateXYBy(-90);
box.MaxEdge.rotateXYBy(-90);
}
else if(facedir == 2)
{
box.MinEdge.rotateXYBy(180);
box.MaxEdge.rotateXYBy(180);
}
else if(facedir == 3)
{
box.MinEdge.rotateXYBy(90);
box.MaxEdge.rotateXYBy(90);
}
break;
case 3: //x+
box.MinEdge.rotateXYBy(-90);
box.MaxEdge.rotateXYBy(-90);
if(facedir == 1)
{
box.MinEdge.rotateYZBy(90);
box.MaxEdge.rotateYZBy(90);
}
else if(facedir == 2)
{
box.MinEdge.rotateYZBy(180);
box.MaxEdge.rotateYZBy(180);
}
else if(facedir == 3)
{
box.MinEdge.rotateYZBy(-90);
box.MaxEdge.rotateYZBy(-90);
}
break;
case 4: //x-
box.MinEdge.rotateXYBy(90);
box.MaxEdge.rotateXYBy(90);
if(facedir == 1)
{
box.MinEdge.rotateYZBy(-90);
box.MaxEdge.rotateYZBy(-90);
}
else if(facedir == 2)
{
box.MinEdge.rotateYZBy(180);
box.MaxEdge.rotateYZBy(180);
}
else if(facedir == 3)
{
box.MinEdge.rotateYZBy(90);
box.MaxEdge.rotateYZBy(90);
}
break;
case 5:
box.MinEdge.rotateXYBy(-180);
box.MaxEdge.rotateXYBy(-180);
if(facedir == 1)
{
box.MinEdge.rotateXZBy(90);
box.MaxEdge.rotateXZBy(90);
}