returns encoded light value.
*/
-u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
+u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
v3s16 face_dir)
{
try{
#ifndef SERVER
-void MapBlock::makeFastFace(TileSpec tile, u8 light, v3f p,
+void makeFastFace(TileSpec tile, u8 light, v3f p,
v3s16 dir, v3f scale, v3f posRelative_f,
core::array<FastFace> &dest)
{
Gets node tile from any place relative to block.
Returns TILE_NODE if doesn't exist or should not be drawn.
*/
-TileSpec MapBlock::getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
+TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
NodeModMap &temp_mods)
{
TileSpec spec;
return spec;
}
-u8 MapBlock::getNodeContent(v3s16 p, MapNode mn, NodeModMap &temp_mods)
+u8 getNodeContent(v3s16 p, MapNode mn, NodeModMap &temp_mods)
{
/*
Check temporary modifications on this node
translate_dir: unit vector with only one of x, y or z
face_dir: unit vector with only one of x, y or z
*/
-void MapBlock::updateFastFaceRow(
+void updateFastFaceRow(
u32 daynight_ratio,
v3f posRelative_f,
v3s16 startpos,
v3s16 face_dir,
v3f face_dir_f,
core::array<FastFace> &dest,
- NodeModMap &temp_mods)
+ NodeModMap &temp_mods,
+ VoxelManipulator &vmanip,
+ v3s16 blockpos_nodes)
{
v3s16 p = startpos;
u16 continuous_tiles_count = 0;
- MapNode n0 = getNodeParentNoEx(p);
- MapNode n1 = getNodeParentNoEx(p + face_dir);
-
- u8 light = getFaceLight(daynight_ratio, n0, n1, face_dir);
-
+ MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
+ MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods);
TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods);
+ u8 light = getFaceLight(daynight_ratio, n0, n1, face_dir);
for(u16 j=0; j<length; j++)
{
if(j != length - 1)
{
p_next = p + translate_dir;
- n0_next = getNodeParentNoEx(p_next);
- n1_next = getNodeParentNoEx(p_next + face_dir);
+
+ n0_next = vmanip.getNodeNoEx(blockpos_nodes + p_next);
+ n1_next = vmanip.getNodeNoEx(blockpos_nodes + p_next + face_dir);
tile0_next = getNodeTile(n0_next, p_next, face_dir, temp_mods);
tile1_next = getNodeTile(n1_next,p_next+face_dir,-face_dir, temp_mods);
light_next = getFaceLight(daynight_ratio, n0_next, n1_next, face_dir);
core::array<PreMeshBuffer> m_prebuffers;
};
-void MapBlock::updateMesh(u32 daynight_ratio)
+scene::SMesh* makeMapBlockMesh(
+ u32 daynight_ratio,
+ NodeModMap &temp_mods,
+ VoxelManipulator &vmanip,
+ v3s16 blockpos_nodes)
{
-#if 0
- /*
- DEBUG: If mesh has been generated, don't generate it again
- */
- {
- JMutexAutoLock meshlock(mesh_mutex);
- if(mesh != NULL)
- return;
- }
-#endif
-
// 4-21ms for MAP_BLOCKSIZE=16
// 24-155ms for MAP_BLOCKSIZE=32
- //TimeTaker timer1("updateMesh()");
+ //TimeTaker timer1("makeMapBlockMesh()");
core::array<FastFace> fastfaces_new;
- v3f posRelative_f(getPosRelative().X, getPosRelative().Y,
- getPosRelative().Z); // floating point conversion
-
- /*
- Avoid interlocks by copying m_temp_mods
- */
- NodeModMap temp_mods;
- {
- JMutexAutoLock lock(m_temp_mods_mutex);
- m_temp_mods.copy(temp_mods);
- }
+ // floating point conversion
+ v3f posRelative_f(blockpos_nodes.X, blockpos_nodes.Y, blockpos_nodes.Z);
/*
Some settings
v3s16(0,1,0), //face dir
v3f (0,1,0),
fastfaces_new,
- temp_mods);
+ temp_mods,
+ vmanip,
+ blockpos_nodes);
}
}
/*
v3s16(1,0,0),
v3f (1,0,0),
fastfaces_new,
- temp_mods);
+ temp_mods,
+ vmanip,
+ blockpos_nodes);
}
}
/*
v3s16(0,0,1),
v3f (0,0,1),
fastfaces_new,
- temp_mods);
+ temp_mods,
+ vmanip,
+ blockpos_nodes);
}
}
}
{
v3s16 p(x,y,z);
- MapNode &n = getNodeRef(x,y,z);
+ MapNode &n = vmanip.getNodeRef(blockpos_nodes+p);
/*
Add torches to mesh
if(dir == v3s16(0,1,0))
vertices[i].Pos.rotateXZBy(-45);
- vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
+ vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
// Set material
if(dir == v3s16(0,1,0))
vertices[i].Pos.rotateXYBy(90);
- vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
+ vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
// Set material
{
bool top_is_water = false;
try{
- MapNode n = getNodeParent(v3s16(x,y+1,z));
+ MapNode n = vmanip.getNode(blockpos_nodes + v3s16(x,y+1,z));
if(n.d == CONTENT_WATER || n.d == CONTENT_WATERSOURCE)
top_is_water = true;
}catch(InvalidPositionException &e){}
try{
// Check neighbor
v3s16 p2 = p + neighbor_dirs[i];
- MapNode n2 = getNodeParent(p2);
+ MapNode n2 = vmanip.getNode(blockpos_nodes + p2);
content = n2.d;
// NOTE: This doesn't get executed if neighbor
// doesn't exist
p2.Y += 1;
- n2 = getNodeParent(p2);
+ n2 = vmanip.getNode(blockpos_nodes + p2);
if(n2.d == CONTENT_WATERSOURCE || n2.d == CONTENT_WATER)
flags |= neighborflag_top_is_water;
}
if(dir == v3s16(1,0,-0))
vertices[j].Pos.rotateXZBy(-90);
- vertices[j].Pos += intToFloat(p + getPosRelative(), BS);
+ vertices[j].Pos += intToFloat(p + blockpos_nodes, BS);
}
u16 indices[] = {0,1,2,2,3,0};
//vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
s32 j = corner_resolve[i];
vertices[i].Pos.Y += corner_levels[j];
- vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
+ vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
u16 indices[] = {0,1,2,2,3,0};
//bool top_is_water = false;
bool top_is_air = false;
try{
- MapNode n = getNodeParent(v3s16(x,y+1,z));
+ MapNode n = vmanip.getNode(blockpos_nodes + v3s16(x,y+1,z));
/*if(n.d == CONTENT_WATER || n.d == CONTENT_WATERSOURCE)
top_is_water = true;*/
if(n.d == CONTENT_AIR)
for(s32 i=0; i<4; i++)
{
vertices[i].Pos.Y += (-0.5+node_water_level)*BS;
- vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
+ vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
u16 indices[] = {0,1,2,2,3,0};
for(u16 i=0; i<4; i++)
{
- vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
+ vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
u16 indices[] = {0,1,2,2,3,0};
the hardware buffer and then delete the mesh
*/
}
+
+ return mesh_new;
+
+ //std::cout<<"added "<<fastfaces.getSize()<<" faces."<<std::endl;
+}
+
+/*scene::SMesh* makeMapBlockMesh(
+ u32 daynight_ratio,
+ NodeModMap &temp_mods,
+ VoxelManipulator &vmanip,
+ v3s16 blockpos_nodes)
+{
+}*/
+
+#if 1
+void MapBlock::updateMesh(u32 daynight_ratio)
+{
+#if 0
+ /*
+ DEBUG: If mesh has been generated, don't generate it again
+ */
+ {
+ JMutexAutoLock meshlock(mesh_mutex);
+ if(mesh != NULL)
+ return;
+ }
+#endif
+
+ /*
+ Avoid interlocks by copying m_temp_mods
+ */
+ NodeModMap temp_mods;
+ copyTempMods(temp_mods);
+
+ v3s16 blockpos_nodes = getPosRelative();
+
+ VoxelManipulator vmanip;
+ // Allocate this block + borders
+ vmanip.addArea(VoxelArea(blockpos_nodes-v3s16(1,1,1),
+ blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE));
+ // Copy our data
+ copyTo(vmanip);
+ // Copy borders from map
+ // +-Z
+ for(s16 x=-1; x<=MAP_BLOCKSIZE; x++)
+ for(s16 y=-1; y<=MAP_BLOCKSIZE; y++)
+ for(s16 z=-1; z<=MAP_BLOCKSIZE; z+=MAP_BLOCKSIZE+1)
+ {
+ v3s16 p(x,y,z);
+ vmanip.setNodeNoRef(blockpos_nodes+p, getNodeParentNoEx(p));
+ }
+ // +-Y
+ for(s16 x=-1; x<=MAP_BLOCKSIZE; x++)
+ for(s16 y=-1; y<=MAP_BLOCKSIZE; y+=MAP_BLOCKSIZE+1)
+ for(s16 z=-1; z<=MAP_BLOCKSIZE; z++)
+ {
+ v3s16 p(x,y,z);
+ vmanip.setNodeNoRef(blockpos_nodes+p, getNodeParentNoEx(p));
+ }
+ // +-Z
+ for(s16 x=-1; x<=MAP_BLOCKSIZE; x+=MAP_BLOCKSIZE+1)
+ for(s16 y=-1; y<=MAP_BLOCKSIZE; y++)
+ for(s16 z=-1; z<=MAP_BLOCKSIZE; z++)
+ {
+ v3s16 p(x,y,z);
+ vmanip.setNodeNoRef(blockpos_nodes+p, getNodeParentNoEx(p));
+ }
+
+ scene::SMesh *mesh_new = makeMapBlockMesh(
+ daynight_ratio,
+ temp_mods,
+ vmanip,
+ getPosRelative()
+ );
/*
Replace the mesh
*/
+ replaceMesh(mesh_new);
+
+}
+#endif
+
+void MapBlock::replaceMesh(scene::SMesh *mesh_new)
+{
mesh_mutex.Lock();
//scene::SMesh *mesh_old = mesh[daynight_i];
}
mesh_mutex.Unlock();
-
- //std::cout<<"added "<<fastfaces.getSize()<<" faces."<<std::endl;
}
-
-/*void MapBlock::updateMeshes(s32 first_i)
-{
- assert(first_i >= 0 && first_i <= DAYNIGHT_CACHE_COUNT);
- updateMesh(first_i);
- for(s32 i=0; i<DAYNIGHT_CACHE_COUNT; i++)
- {
- if(i == first_i)
- continue;
- updateMesh(i);
- }
-}*/
-
+
#endif // !SERVER
/*
return block_below_is_valid;
}
+
void MapBlock::copyTo(VoxelManipulator &dst)
{
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
#include "voxel.h"
#include "nodemetadata.h"
+
// Named by looking towards z+
enum{
FACE_BACK=0,
virtual u16 nodeContainerId() const = 0;
};
+/*
+ Plain functions in mapblock.cpp
+*/
+
+u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
+ v3s16 face_dir);
+
+scene::SMesh* makeMapBlockMesh(
+ u32 daynight_ratio,
+ NodeModMap &temp_mods,
+ VoxelManipulator &vmanip,
+ v3s16 blockpos_nodes);
+
+/*
+ MapBlock itself
+*/
+
class MapBlock : public NodeContainer
{
public:
Graphics-related methods
*/
- // A quick version with nodes passed as parameters
+ /*// A quick version with nodes passed as parameters
u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
- v3s16 face_dir);
- // A more convenient version
+ v3s16 face_dir);*/
+ /*// A more convenient version
u8 getFaceLight(u32 daynight_ratio, v3s16 p, v3s16 face_dir)
+ {
+ return getFaceLight(daynight_ratio,
+ getNodeParentNoEx(p),
+ getNodeParentNoEx(p + face_dir),
+ face_dir);
+ }*/
+ u8 getFaceLight2(u32 daynight_ratio, v3s16 p, v3s16 face_dir)
{
return getFaceLight(daynight_ratio,
getNodeParentNoEx(p),
#ifndef SERVER
// light = 0...255
- static void makeFastFace(TileSpec tile, u8 light, v3f p,
+ /*static void makeFastFace(TileSpec tile, u8 light, v3f p,
v3s16 dir, v3f scale, v3f posRelative_f,
- core::array<FastFace> &dest);
+ core::array<FastFace> &dest);*/
- TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
- NodeModMap &temp_mods);
- u8 getNodeContent(v3s16 p, MapNode mn,
- NodeModMap &temp_mods);
+ /*TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
+ NodeModMap &temp_mods);*/
+ /*u8 getNodeContent(v3s16 p, MapNode mn,
+ NodeModMap &temp_mods);*/
/*
Generates the FastFaces of a node row. This has a
translate_dir: unit vector with only one of x, y or z
face_dir: unit vector with only one of x, y or z
*/
- void updateFastFaceRow(
+ /*void updateFastFaceRow(
u32 daynight_ratio,
v3f posRelative_f,
v3s16 startpos,
v3s16 face_dir,
v3f face_dir_f,
core::array<FastFace> &dest,
- NodeModMap &temp_mods);
+ NodeModMap &temp_mods);*/
/*
Thread-safely updates the whole mesh of the mapblock.
*/
+#if 1
void updateMesh(u32 daynight_ratio);
+#endif
+
+ void replaceMesh(scene::SMesh *mesh_new);
#endif // !SERVER
return m_temp_mods.clear();
}
+ void copyTempMods(NodeModMap &dst)
+ {
+ JMutexAutoLock lock(m_temp_mods_mutex);
+ m_temp_mods.copy(dst);
+ }
#endif
/*