aboutsummaryrefslogtreecommitdiff
path: root/src/mapblock_mesh.cpp
diff options
context:
space:
mode:
authorsapier <sapier at gmx dot net>2012-02-04 12:41:25 +0100
committersapier <sapier at gmx dot net>2012-02-04 12:41:25 +0100
commit77df09540c4d7eadef760779e123af88a48aafaa (patch)
treefebf1009328d30c31a14a1a1ca1600e99b4c3e6b /src/mapblock_mesh.cpp
parent3454e6779337d8523ae76c7fa16eb8c565aa2381 (diff)
parenta1eb2836c0764829ebad1462432bb3c5f32750df (diff)
downloadminetest-77df09540c4d7eadef760779e123af88a48aafaa.tar.xz
Merge remote branch 'upstream/master' into sapier_experimental
Conflicts: src/scriptapi.cpp
Diffstat (limited to 'src/mapblock_mesh.cpp')
-rw-r--r--src/mapblock_mesh.cpp159
1 files changed, 83 insertions, 76 deletions
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index c051dda50..b843448c4 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -25,10 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "profiler.h"
#include "nodedef.h"
-#include "tile.h"
#include "gamedef.h"
#include "content_mapblock.h"
-#include "mineral.h" // For mineral_block_texture
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{
@@ -83,6 +81,39 @@ void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
}
}
+void MeshMakeData::fillSingleNode(u32 daynight_ratio, MapNode *node)
+{
+ m_daynight_ratio = daynight_ratio;
+ m_blockpos = v3s16(0,0,0);
+ m_temp_mods.clear();
+
+ v3s16 blockpos_nodes = v3s16(0,0,0);
+ VoxelArea area(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
+ blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1));
+ s32 volume = area.getVolume();
+ s32 our_node_index = area.index(1,1,1);
+
+ // Allocate this block + neighbors
+ m_vmanip.clear();
+ m_vmanip.addArea(area);
+
+ // Fill in data
+ MapNode *data = new MapNode[volume];
+ for(s32 i = 0; i < volume; i++)
+ {
+ if(i == our_node_index)
+ {
+ data[i] = *node;
+ }
+ else
+ {
+ data[i] = MapNode(CONTENT_AIR, LIGHT_MAX, 0);
+ }
+ }
+ m_vmanip.copyFrom(data, area, area.MinEdge, area.MinEdge, area.getExtent());
+ delete[] data;
+}
+
/*
vertex_dirs: v3s16[4]
*/
@@ -207,8 +238,8 @@ static void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p,
else if(scale.Y < 0.999 || scale.Y > 1.001) abs_scale = scale.Y;
else if(scale.Z < 0.999 || scale.Z > 1.001) abs_scale = scale.Z;
- v3f zerovector = v3f(0,0,0);
-
+ v3f normal(dir.X, dir.Y, dir.Z);
+
u8 alpha = tile.alpha;
/*u8 alpha = 255;
if(tile.id == TILE_WATER)
@@ -230,16 +261,16 @@ static void makeFastFace(TileSpec tile, u8 li0, u8 li1, u8 li2, u8 li3, v3f p,
face.vertices[3] = video::S3DVertex(vertex_pos[3], v3f(0,1,0), c,
core::vector2d<f32>(x0+w*abs_scale, y0));*/
- face.vertices[0] = video::S3DVertex(vertex_pos[0], v3f(0,1,0),
+ face.vertices[0] = video::S3DVertex(vertex_pos[0], normal,
MapBlock_LightColor(alpha, li0),
core::vector2d<f32>(x0+w*abs_scale, y0+h));
- face.vertices[1] = video::S3DVertex(vertex_pos[1], v3f(0,1,0),
+ face.vertices[1] = video::S3DVertex(vertex_pos[1], normal,
MapBlock_LightColor(alpha, li1),
core::vector2d<f32>(x0, y0+h));
- face.vertices[2] = video::S3DVertex(vertex_pos[2], v3f(0,1,0),
+ face.vertices[2] = video::S3DVertex(vertex_pos[2], normal,
MapBlock_LightColor(alpha, li2),
core::vector2d<f32>(x0, y0));
- face.vertices[3] = video::S3DVertex(vertex_pos[3], v3f(0,1,0),
+ face.vertices[3] = video::S3DVertex(vertex_pos[3], normal,
MapBlock_LightColor(alpha, li3),
core::vector2d<f32>(x0+w*abs_scale, y0));
@@ -250,70 +281,48 @@ 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);
-
- if(f.param_type == CPT_FACEDIR_SIMPLE)
- dir = facedir_rotate(node.param1, dir);
-
- TileSpec spec;
-
- s32 dir_i = -1;
+ // 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(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]];
}
/*
Gets node tile from any place relative to block.
Returns TILE_NODE if doesn't exist or should not be drawn.
*/
-static TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
- NodeModMap &temp_mods, ITextureSource *tsrc, INodeDefManager *ndef)
+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
@@ -325,13 +334,15 @@ static TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
{
struct NodeMod mod = n->getValue();*/
NodeMod mod;
- if(temp_mods.get(p, &mod))
+ if(temp_mods && temp_mods->get(p, &mod))
{
+ #if 0 // NODEMOD_CHANGECONTENT isn't used at the moment
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)
{
/*
@@ -361,19 +372,14 @@ static TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
return spec;
}
-static content_t getNodeContent(v3s16 p, MapNode mn, NodeModMap &temp_mods)
+static content_t getNodeContent(v3s16 p, MapNode mn, NodeModMap *temp_mods)
{
/*
Check temporary modifications on this node
*/
- /*core::map<v3s16, NodeMod>::Node *n;
- n = m_temp_mods.find(p);
- // If modified
- if(n != NULL)
- {
- struct NodeMod mod = n->getValue();*/
+ #if 0 // NODEMOD_CHANGECONTENT isn't used at the moment
NodeMod mod;
- if(temp_mods.get(p, &mod))
+ if(temp_mods && temp_mods->get(p, &mod))
{
if(mod.type == NODEMOD_CHANGECONTENT)
{
@@ -395,6 +401,7 @@ static content_t getNodeContent(v3s16 p, MapNode mn, NodeModMap &temp_mods)
*/
}
}
+ #endif
return mn.getContent();
}
@@ -469,7 +476,7 @@ static void getTileInfo(
v3s16 face_dir,
u32 daynight_ratio,
VoxelManipulator &vmanip,
- NodeModMap &temp_mods,
+ NodeModMap *temp_mods,
bool smooth_lighting,
IGameDef *gamedef,
// Output:
@@ -553,7 +560,7 @@ static void updateFastFaceRow(
v3s16 face_dir,
v3f face_dir_f,
core::array<FastFace> &dest,
- NodeModMap &temp_mods,
+ NodeModMap *temp_mods,
VoxelManipulator &vmanip,
v3s16 blockpos_nodes,
bool smooth_lighting,
@@ -749,7 +756,7 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data, IGameDef *gamedef)
v3s16(0,1,0), //face dir
v3f (0,1,0),
fastfaces_new,
- data->m_temp_mods,
+ &data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
smooth_lighting,
@@ -768,7 +775,7 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data, IGameDef *gamedef)
v3s16(1,0,0),
v3f (1,0,0),
fastfaces_new,
- data->m_temp_mods,
+ &data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
smooth_lighting,
@@ -787,7 +794,7 @@ scene::SMesh* makeMapBlockMesh(MeshMakeData *data, IGameDef *gamedef)
v3s16(0,0,1),
v3f (0,0,1),
fastfaces_new,
- data->m_temp_mods,
+ &data->m_temp_mods,
data->m_vmanip,
blockpos_nodes,
smooth_lighting,