aboutsummaryrefslogtreecommitdiff
path: root/src/mapblock_mesh.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2012-01-21 00:11:44 +0100
committerPerttu Ahola <celeron55@gmail.com>2012-01-22 17:24:50 +0200
commit157a4cf18cb9c098f465b8baecd7d2cd5705f2dd (patch)
treea194b86e0452d1dc892aec6b3ac940327ce85e2a /src/mapblock_mesh.cpp
parentf22c73f50169b978f13c0b6511805b9d4a1a6871 (diff)
downloadminetest-157a4cf18cb9c098f465b8baecd7d2cd5705f2dd.tar.gz
minetest-157a4cf18cb9c098f465b8baecd7d2cd5705f2dd.tar.bz2
minetest-157a4cf18cb9c098f465b8baecd7d2cd5705f2dd.zip
Node placement / mineral / serialization / iron freq / node_dig callback
- Node placement code moved to Lua - Mineral system removed (added default:stone_with_coal and default:stone_with_iron). - MapBlock and MapNode serialization updated. - Mapgen: Frequency of iron increased. - node_dig callback and related changes.
Diffstat (limited to 'src/mapblock_mesh.cpp')
-rw-r--r--src/mapblock_mesh.cpp83
1 files changed, 30 insertions, 53 deletions
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index db9057e19..b843448c4 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h"
#include "gamedef.h"
#include "content_mapblock.h"
-#include "mineral.h" // For mineral_block_texture
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{
@@ -282,59 +281,37 @@ static void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p,
dest.push_back(face);
}
-static TileSpec getTile(const MapNode &node, v3s16 dir,
- ITextureSource *tsrc, INodeDefManager *nodemgr)
+static TileSpec getTile(const MapNode &node, v3s16 dir, INodeDefManager *nodemgr)
{
- const ContentFeatures &f = nodemgr->get(node);
+ // Direction must be (1,0,0), (-1,0,0), (0,1,0), (0,-1,0),
+ // (0,0,1), (0,0,-1) or (0,0,0)
+ assert(dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z <= 1);
+
+ // Convert direction to single integer for table lookup
+ // 0 = (0,0,0)
+ // 1 = (1,0,0)
+ // 2 = (0,1,0)
+ // 3 = (0,0,1)
+ // 4 = invalid, treat as (0,0,0)
+ // 5 = (0,0,-1)
+ // 6 = (0,-1,0)
+ // 7 = (-1,0,0)
+ u8 dir_i = (dir.X + 2 * dir.Y + 3 * dir.Z) & 7;
+
+ // Get rotation for things like chests
+ u8 facedir = node.getFaceDir(nodemgr);
+ assert(facedir <= 3);
- if(f.param_type == CPT_FACEDIR_SIMPLE)
- dir = facedir_rotate(node.param1, dir);
-
- TileSpec spec;
-
- s32 dir_i = -1;
-
- if(dir == v3s16(0,0,0))
- dir_i = -1;
- else if(dir == v3s16(0,1,0))
- dir_i = 0;
- else if(dir == v3s16(0,-1,0))
- dir_i = 1;
- else if(dir == v3s16(1,0,0))
- dir_i = 2;
- else if(dir == v3s16(-1,0,0))
- dir_i = 3;
- else if(dir == v3s16(0,0,1))
- dir_i = 4;
- else if(dir == v3s16(0,0,-1))
- dir_i = 5;
-
- if(dir_i == -1)
- // Non-directional
- spec = f.tiles[0];
- else
- spec = f.tiles[dir_i];
-
- /*
- If it contains some mineral, change texture id
- */
- if(f.param_type == CPT_MINERAL && tsrc)
+ static const u8 dir_to_tile[4 * 8] =
{
- u8 mineral = node.getMineral(nodemgr);
- std::string mineral_texture_name = mineral_block_texture(mineral);
- if(mineral_texture_name != "")
- {
- u32 orig_id = spec.texture.id;
- std::string texture_name = tsrc->getTextureName(orig_id);
- //texture_name += "^blit:";
- texture_name += "^";
- texture_name += mineral_texture_name;
- u32 new_id = tsrc->getTextureId(texture_name);
- spec.texture = tsrc->getTexture(new_id);
- }
- }
-
- return spec;
+ // 0 +X +Y +Z 0 -Z -Y -X
+ 0, 2, 0, 4, 0, 5, 1, 3, // facedir = 0
+ 0, 4, 0, 3, 0, 2, 1, 5, // facedir = 1
+ 0, 3, 0, 5, 0, 4, 1, 2, // facedir = 2
+ 0, 5, 0, 2, 0, 3, 1, 4, // facedir = 3
+ };
+
+ return nodemgr->get(node).tiles[dir_to_tile[facedir*8 + dir_i]];
}
/*
@@ -345,7 +322,7 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
NodeModMap *temp_mods, ITextureSource *tsrc, INodeDefManager *ndef)
{
TileSpec spec;
- spec = getTile(mn, face_dir, tsrc, ndef);
+ spec = getTile(mn, face_dir, ndef);
/*
Check temporary modifications on this node
@@ -363,7 +340,7 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
if(mod.type == NODEMOD_CHANGECONTENT)
{
MapNode mn2(mod.param);
- spec = getTile(mn2, face_dir, tsrc, ndef);
+ spec = getTile(mn2, face_dir, ndef);
}
#endif
if(mod.type == NODEMOD_CRACK)