#include "mapsector.h"
#include "mapblock.h"
#include "main.h"
+#ifndef SERVER
#include "client.h"
+#endif
#include "filesys.h"
#include "utility.h"
#include "voxel.h"
#include "settings.h"
#include "log.h"
#include "profiler.h"
+#include "nodedef.h"
+#include "gamedef.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Map
*/
-Map::Map(std::ostream &dout):
+Map::Map(std::ostream &dout, IGameDef *gamedef):
m_dout(dout),
+ m_gamedef(gamedef),
m_sector_cache(NULL)
{
/*m_sector_mutex.Init();
core::map<v3s16, bool> & light_sources,
core::map<v3s16, MapBlock*> & modified_blocks)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
v3s16 dirs[6] = {
v3s16(0,0,1), // back
v3s16(0,1,0), // top
If the neighbor is dimmer than what was specified
as oldlight (the light of the previous node)
*/
- if(n2.getLight(bank) < oldlight)
+ if(n2.getLight(bank, nodemgr) < oldlight)
{
/*
And the neighbor is transparent and it has some light
*/
- if(n2.light_propagates() && n2.getLight(bank) != 0)
+ if(nodemgr->get(n2).light_propagates
+ && n2.getLight(bank, nodemgr) != 0)
{
/*
Set light to 0 and add to queue
*/
- u8 current_light = n2.getLight(bank);
- n2.setLight(bank, 0);
+ u8 current_light = n2.getLight(bank, nodemgr);
+ n2.setLight(bank, 0, nodemgr);
block->setNode(relpos, n2);
unlighted_nodes.insert(n2pos, current_light);
core::map<v3s16, bool> & from_nodes,
core::map<v3s16, MapBlock*> & modified_blocks)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
const v3s16 dirs[6] = {
v3s16(0,0,1), // back
v3s16(0,1,0), // top
// Get node straight from the block
MapNode n = block->getNode(relpos);
- u8 oldlight = n.getLight(bank);
+ u8 oldlight = n.getLight(bank, nodemgr);
u8 newlight = diminish_light(oldlight);
// Loop through 6 neighbors
If the neighbor is brighter than the current node,
add to list (it will light up this node on its turn)
*/
- if(n2.getLight(bank) > undiminish_light(oldlight))
+ if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
{
lighted_nodes.insert(n2pos, true);
//lighted_nodes.push_back(n2pos);
If the neighbor is dimmer than how much light this node
would spread on it, add to list
*/
- if(n2.getLight(bank) < newlight)
+ if(n2.getLight(bank, nodemgr) < newlight)
{
- if(n2.light_propagates())
+ if(nodemgr->get(n2).light_propagates)
{
- n2.setLight(bank, newlight);
+ n2.setLight(bank, newlight, nodemgr);
block->setNode(relpos, n2);
lighted_nodes.insert(n2pos, true);
//lighted_nodes.push_back(n2pos);
v3s16 Map::getBrightestNeighbour(enum LightBank bank, v3s16 p)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
v3s16 dirs[6] = {
v3s16(0,0,1), // back
v3s16(0,1,0), // top
{
continue;
}
- if(n2.getLight(bank) > brightest_light || found_something == false){
- brightest_light = n2.getLight(bank);
+ if(n2.getLight(bank, nodemgr) > brightest_light || found_something == false){
+ brightest_light = n2.getLight(bank, nodemgr);
brightest_pos = n2pos;
found_something = true;
}
s16 Map::propagateSunlight(v3s16 start,
core::map<v3s16, MapBlock*> & modified_blocks)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
s16 y = start.Y;
for(; ; y--)
{
v3s16 relpos = pos - blockpos*MAP_BLOCKSIZE;
MapNode n = block->getNode(relpos);
- if(n.sunlight_propagates())
+ if(nodemgr->get(n).sunlight_propagates)
{
- n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
+ n.setLight(LIGHTBANK_DAY, LIGHT_SUN, nodemgr);
block->setNode(relpos, n);
modified_blocks.insert(blockpos, block);
core::map<v3s16, MapBlock*> & a_blocks,
core::map<v3s16, MapBlock*> & modified_blocks)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
/*m_dout<<DTIME<<"Map::updateLighting(): "
<<a_blocks.size()<<" blocks."<<std::endl;*/
try{
v3s16 p(x,y,z);
MapNode n = block->getNode(v3s16(x,y,z));
- u8 oldlight = n.getLight(bank);
- n.setLight(bank, 0);
+ u8 oldlight = n.getLight(bank, nodemgr);
+ n.setLight(bank, 0, nodemgr);
block->setNode(v3s16(x,y,z), n);
// Collect borders for unlighting
{
//TimeTaker timer("unSpreadLight");
- vmanip.unspreadLight(bank, unlight_from, light_sources);
+ vmanip.unspreadLight(bank, unlight_from, light_sources, nodemgr);
}
{
//TimeTaker timer("spreadLight");
- vmanip.spreadLight(bank, light_sources);
+ vmanip.spreadLight(bank, light_sources, nodemgr);
}
{
//TimeTaker timer("blitBack");
void Map::addNodeAndUpdate(v3s16 p, MapNode n,
core::map<v3s16, MapBlock*> &modified_blocks, std::string &player_name)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
/*PrintInfo(m_dout);
m_dout<<DTIME<<"Map::addNodeAndUpdate(): p=("
<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
try{
MapNode topnode = getNode(toppos);
- if(topnode.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
+ if(topnode.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN)
node_under_sunlight = false;
}
catch(InvalidPositionException &e)
/*
If the new node is solid and there is grass below, change it to mud
*/
- if(content_features(n).walkable == true)
+ if(nodemgr->get(n).walkable == true)
{
try{
MapNode bottomnode = getNode(bottompos);
{
enum LightBank bank = banks[i];
- u8 lightwas = getNode(p).getLight(bank);
+ u8 lightwas = getNode(p).getLight(bank, nodemgr);
// Add the block of the added node to modified_blocks
v3s16 blockpos = getNodeBlockPos(p);
// light again into this.
unLightNeighbors(bank, p, lightwas, light_sources, modified_blocks);
- n.setLight(bank, 0);
+ n.setLight(bank, 0, nodemgr);
}
/*
If node lets sunlight through and is under sunlight, it has
sunlight too.
*/
- if(node_under_sunlight && content_features(n).sunlight_propagates)
+ if(node_under_sunlight && nodemgr->get(n).sunlight_propagates)
{
- n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
+ n.setLight(LIGHTBANK_DAY, LIGHT_SUN, nodemgr);
}
/*
Add intial metadata
*/
- NodeMetadata *meta_proto = content_features(n).initial_metadata;
+ NodeMetadata *meta_proto = nodemgr->get(n).initial_metadata;
if(meta_proto)
{
- NodeMetadata *meta = meta_proto->clone();
+ NodeMetadata *meta = meta_proto->clone(m_gamedef);
meta->setOwner(player_name);
setNodeMetadata(p, meta);
}
TODO: This could be optimized by mass-unlighting instead
of looping
*/
- if(node_under_sunlight && !content_features(n).sunlight_propagates)
+ if(node_under_sunlight && !nodemgr->get(n).sunlight_propagates)
{
s16 y = p.Y - 1;
for(;; y--){
break;
}
- if(n2.getLight(LIGHTBANK_DAY) == LIGHT_SUN)
+ if(n2.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN)
{
unLightNeighbors(LIGHTBANK_DAY,
- n2pos, n2.getLight(LIGHTBANK_DAY),
+ n2pos, n2.getLight(LIGHTBANK_DAY, nodemgr),
light_sources, modified_blocks);
- n2.setLight(LIGHTBANK_DAY, 0);
+ n2.setLight(LIGHTBANK_DAY, 0, nodemgr);
setNode(n2pos, n2);
}
else
v3s16 p2 = p + dirs[i];
MapNode n2 = getNode(p2);
- if(content_liquid(n2.getContent()) || n2.getContent() == CONTENT_AIR)
+ if(nodemgr->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
{
m_transforming_liquid.push_back(p2);
}
void Map::removeNodeAndUpdate(v3s16 p,
core::map<v3s16, MapBlock*> &modified_blocks)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
/*PrintInfo(m_dout);
m_dout<<DTIME<<"Map::removeNodeAndUpdate(): p=("
<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/
try{
MapNode topnode = getNode(toppos);
- if(topnode.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
+ if(topnode.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN)
node_under_sunlight = false;
}
catch(InvalidPositionException &e)
Unlight neighbors (in case the node is a light source)
*/
unLightNeighbors(bank, p,
- getNode(p).getLight(bank),
+ getNode(p).getLight(bank, nodemgr),
light_sources, modified_blocks);
}
// TODO: Is this needed? Lighting is cleared up there already.
try{
MapNode n = getNode(p);
- n.setLight(LIGHTBANK_DAY, 0);
+ n.setLight(LIGHTBANK_DAY, 0, nodemgr);
setNode(p, n);
}
catch(InvalidPositionException &e)
v3s16 p2 = p + dirs[i];
MapNode n2 = getNode(p2);
- if(content_liquid(n2.getContent()) || n2.getContent() == CONTENT_AIR)
+ if(nodemgr->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
{
m_transforming_liquid.push_back(p2);
}
void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
DSTACK(__FUNCTION_NAME);
//TimeTaker timer("transformLiquids()");
*/
s8 liquid_level = -1;
u8 liquid_kind = CONTENT_IGNORE;
- LiquidType liquid_type = content_features(n0.getContent()).liquid_type;
+ LiquidType liquid_type = nodemgr->get(n0).liquid_type;
switch (liquid_type) {
case LIQUID_SOURCE:
liquid_level = LIQUID_LEVEL_SOURCE;
- liquid_kind = content_features(n0.getContent()).liquid_alternative_flowing;
+ liquid_kind = nodemgr->get(n0).liquid_alternative_flowing;
break;
case LIQUID_FLOWING:
liquid_level = (n0.param2 & LIQUID_LEVEL_MASK);
}
v3s16 npos = p0 + dirs[i];
NodeNeighbor nb = {getNodeNoEx(npos), nt, npos};
- switch (content_features(nb.n.getContent()).liquid_type) {
+ switch (nodemgr->get(nb.n.getContent()).liquid_type) {
case LIQUID_NONE:
if (nb.n.getContent() == CONTENT_AIR) {
airs[num_airs++] = nb;
case LIQUID_SOURCE:
// if this node is not (yet) of a liquid type, choose the first liquid type we encounter
if (liquid_kind == CONTENT_AIR)
- liquid_kind = content_features(nb.n.getContent()).liquid_alternative_flowing;
- if (content_features(nb.n.getContent()).liquid_alternative_flowing !=liquid_kind) {
+ liquid_kind = nodemgr->get(nb.n.getContent()).liquid_alternative_flowing;
+ if (nodemgr->get(nb.n.getContent()).liquid_alternative_flowing !=liquid_kind) {
neutrals[num_neutrals++] = nb;
} else {
sources[num_sources++] = nb;
case LIQUID_FLOWING:
// if this node is not (yet) of a liquid type, choose the first liquid type we encounter
if (liquid_kind == CONTENT_AIR)
- liquid_kind = content_features(nb.n.getContent()).liquid_alternative_flowing;
- if (content_features(nb.n.getContent()).liquid_alternative_flowing != liquid_kind) {
+ liquid_kind = nodemgr->get(nb.n.getContent()).liquid_alternative_flowing;
+ if (nodemgr->get(nb.n.getContent()).liquid_alternative_flowing != liquid_kind) {
neutrals[num_neutrals++] = nb;
} else {
flows[num_flows++] = nb;
// liquid_kind will be set to either the flowing alternative of the node (if it's a liquid)
// or the flowing alternative of the first of the surrounding sources (if it's air), so
// it's perfectly safe to use liquid_kind here to determine the new node content.
- new_node_content = content_features(liquid_kind).liquid_alternative_source;
+ new_node_content = nodemgr->get(liquid_kind).liquid_alternative_source;
} else if (num_sources == 1 && sources[0].t != NEIGHBOR_LOWER) {
// liquid_kind is set properly, see above
new_node_content = liquid_kind;
}
}
- u8 viscosity = content_features(liquid_kind).liquid_viscosity;
+ u8 viscosity = nodemgr->get(liquid_kind).liquid_viscosity;
if (viscosity > 1 && max_node_level != liquid_level) {
// amount to gain, limited by viscosity
// must be at least 1 in absolute value
/*
check if anything has changed. if not, just continue with the next node.
*/
- if (new_node_content == n0.getContent() && (content_features(n0.getContent()).liquid_type != LIQUID_FLOWING ||
+ if (new_node_content == n0.getContent() && (nodemgr->get(n0.getContent()).liquid_type != LIQUID_FLOWING ||
((n0.param2 & LIQUID_LEVEL_MASK) == (u8)new_node_level &&
((n0.param2 & LIQUID_FLOW_DOWN_MASK) == LIQUID_FLOW_DOWN_MASK)
== flowing_down)))
/*
update the current node
*/
- bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK));
- if (content_features(new_node_content).liquid_type == LIQUID_FLOWING) {
+ //bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK));
+ if (nodemgr->get(new_node_content).liquid_type == LIQUID_FLOWING) {
// set level to last 3 bits, flowing down bit to 4th bit
n0.param2 = (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK);
} else {
if(block != NULL) {
modified_blocks.insert(blockpos, block);
// If node emits light, MapBlock requires lighting update
- if(content_features(n0).light_source != 0)
+ if(nodemgr->get(n0).light_source != 0)
lighting_modified_blocks[block->getPos()] = block;
}
/*
enqueue neighbors for update if neccessary
*/
- switch (content_features(n0.getContent()).liquid_type) {
+ switch (nodemgr->get(n0.getContent()).liquid_type) {
case LIQUID_SOURCE:
case LIQUID_FLOWING:
// make sure source flows into all neighboring nodes
<<std::endl;
return NULL;
}
- NodeMetadata *meta = block->m_node_metadata.get(p_rel);
+ NodeMetadata *meta = block->m_node_metadata->get(p_rel);
return meta;
}
<<std::endl;
return;
}
- block->m_node_metadata.set(p_rel, meta);
+ block->m_node_metadata->set(p_rel, meta);
}
void Map::removeNodeMetadata(v3s16 p)
<<std::endl;
return;
}
- block->m_node_metadata.remove(p_rel);
+ block->m_node_metadata->remove(p_rel);
}
void Map::nodeMetadataStep(float dtime,
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{
MapBlock *block = *i;
- bool changed = block->m_node_metadata.step(dtime);
+ bool changed = block->m_node_metadata->step(dtime);
if(changed)
changed_blocks[block->getPos()] = block;
}
ServerMap
*/
-ServerMap::ServerMap(std::string savedir):
- Map(dout_server),
+ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
+ Map(dout_server, gamedef),
m_seed(0),
m_map_metadata_changed(true),
m_database(NULL),
data->no_op = false;
data->seed = m_seed;
data->blockpos = blockpos;
+ data->nodemgr = m_gamedef->ndef();
/*
Create the whole area of this and the neighboring blocks
Generate blank sector
*/
- sector = new ServerMapSector(this, p2d);
+ sector = new ServerMapSector(this, p2d, m_gamedef);
// Sector position on map in nodes
v2s16 nodepos2d = p2d * MAP_BLOCKSIZE;
<<fullpath<<" doesn't exist but directory does."
<<" Continuing with a sector with no metadata."
<<std::endl;*/
- sector = new ServerMapSector(this, p2d);
+ sector = new ServerMapSector(this, p2d, m_gamedef);
m_sectors.insert(p2d, sector);
}
else
else
{
sector = ServerMapSector::deSerialize
- (is, this, p2d, m_sectors);
+ (is, this, p2d, m_sectors, m_gamedef);
if(save_after_load)
saveSectorMeta(sector);
}
ClientMap::ClientMap(
Client *client,
+ IGameDef *gamedef,
MapDrawControl &control,
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id
):
- Map(dout_client),
+ Map(dout_client, gamedef),
scene::ISceneNode(parent, mgr, id),
m_client(client),
m_control(control),
}
// Create a sector
- ClientMapSector *sector = new ClientMapSector(this, p2d);
+ ClientMapSector *sector = new ClientMapSector(this, p2d, m_gamedef);
{
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
ISceneNode::OnRegisterSceneNode();
}
+static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
+ float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr)
+{
+ float d0 = (float)BS * p0.getDistanceFrom(p1);
+ v3s16 u0 = p1 - p0;
+ v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
+ uf.normalize();
+ v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
+ u32 count = 0;
+ for(float s=start_off; s<d0+end_off; s+=step){
+ v3f pf = p0f + uf * s;
+ v3s16 p = floatToInt(pf, BS);
+ MapNode n = map->getNodeNoEx(p);
+ bool is_transparent = false;
+ const ContentFeatures &f = nodemgr->get(n);
+ if(f.solidness == 0)
+ is_transparent = (f.visual_solidness != 2);
+ else
+ is_transparent = (f.solidness != 2);
+ if(!is_transparent){
+ count++;
+ if(count >= needed_count)
+ return true;
+ }
+ step *= stepfac;
+ }
+ return false;
+}
+
void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
//m_dout<<DTIME<<"Rendering map..."<<std::endl;
DSTACK(__FUNCTION_NAME);
bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
+ std::string prefix;
+ if(pass == scene::ESNRP_SOLID)
+ prefix = "CM: solid: ";
+ else
+ prefix = "CM: transparent: ";
+
/*
This is called two times per frame, reset on the non-transparent one
*/
Get all blocks and draw all visible ones
*/
- v3s16 cam_pos_nodes(
- camera_position.X / BS,
- camera_position.Y / BS,
- camera_position.Z / BS);
-
+ v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
+
v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
// Take a fair amount as we will be dropping more out later
+ // Umm... these additions are a bit strange but they are needed.
v3s16 p_blocks_min(
- p_nodes_min.X / MAP_BLOCKSIZE - 2,
- p_nodes_min.Y / MAP_BLOCKSIZE - 2,
- p_nodes_min.Z / MAP_BLOCKSIZE - 2);
+ p_nodes_min.X / MAP_BLOCKSIZE - 3,
+ p_nodes_min.Y / MAP_BLOCKSIZE - 3,
+ p_nodes_min.Z / MAP_BLOCKSIZE - 3);
v3s16 p_blocks_max(
p_nodes_max.X / MAP_BLOCKSIZE + 1,
p_nodes_max.Y / MAP_BLOCKSIZE + 1,
// For limiting number of mesh updates per frame
u32 mesh_update_count = 0;
+ // Number of blocks in rendering range
+ u32 blocks_in_range = 0;
+ // Number of blocks occlusion culled
+ u32 blocks_occlusion_culled = 0;
+ // Number of blocks in rendering range but don't have a mesh
+ u32 blocks_in_range_without_mesh = 0;
+ // Blocks that had mesh that would have been drawn according to
+ // rendering range (if max blocks limit didn't kick in)
u32 blocks_would_have_drawn = 0;
+ // Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
+ // Blocks which had a corresponding meshbuffer for this pass
+ u32 blocks_had_pass_meshbuf = 0;
+ // Blocks from which stuff was actually drawn
+ u32 blocks_without_stuff = 0;
+
+ /*
+ Collect a set of blocks for drawing
+ */
+
+ core::map<v3s16, MapBlock*> drawset;
- int timecheck_counter = 0;
- core::map<v2s16, MapSector*>::Iterator si;
- si = m_sectors.getIterator();
- for(; si.atEnd() == false; si++)
{
- {
- timecheck_counter++;
- if(timecheck_counter > 50)
- {
- timecheck_counter = 0;
- int time2 = time(0);
- if(time2 > time1 + 4)
- {
- infostream<<"ClientMap::renderMap(): "
- "Rendering takes ages, returning."
- <<std::endl;
- return;
- }
- }
- }
+ ScopeProfiler sp(g_profiler, prefix+"collecting blocks for drawing", SPT_AVG);
+ for(core::map<v2s16, MapSector*>::Iterator
+ si = m_sectors.getIterator();
+ si.atEnd() == false; si++)
+ {
MapSector *sector = si.getNode()->getValue();
v2s16 sp = sector->getPos();
sector->getBlocks(sectorblocks);
/*
- Draw blocks
+ Loop through blocks in sector
*/
-
- u32 sector_blocks_drawn = 0;
+ u32 sector_blocks_drawn = 0;
+
core::list< MapBlock * >::Iterator i;
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{
float range = 100000 * BS;
if(m_control.range_all == false)
range = m_control.wanted_range * BS;
-
+
float d = 0.0;
if(isBlockInSight(block->getPos(), camera_position,
camera_direction, camera_fov,
continue;
}
- // Okay, this block will be drawn. Reset usage timer.
- block->resetUsageTimer();
-
// This is ugly (spherical distance limit?)
/*if(m_control.range_all == false &&
d - 0.5*BS*MAP_BLOCKSIZE > range)
continue;*/
+ blocks_in_range++;
+
#if 1
/*
Update expired mesh (used for day/night change)
// Mesh has not been expired and there is no mesh:
// block has no content
- if(block->mesh == NULL && mesh_expired == false)
+ if(block->mesh == NULL && mesh_expired == false){
+ blocks_in_range_without_mesh++;
continue;
+ }
}
f32 faraway = BS*50;
mesh_expired = false;
}
-
#endif
+
+ /*
+ Occlusion culling
+ */
+
+ v3s16 cpn = block->getPos() * MAP_BLOCKSIZE;
+ cpn += v3s16(MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2);
+ float step = BS*1;
+ float stepfac = 1.1;
+ float startoff = BS*1;
+ float endoff = -BS*MAP_BLOCKSIZE*1.42*1.42;
+ v3s16 spn = cam_pos_nodes + v3s16(0,0,0);
+ s16 bs2 = MAP_BLOCKSIZE/2 + 1;
+ u32 needed_count = 1;
+ if(
+ isOccluded(this, spn, cpn + v3s16(0,0,0),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(bs2,bs2,bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(bs2,bs2,-bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(bs2,-bs2,bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(bs2,-bs2,-bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(-bs2,bs2,bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(-bs2,bs2,-bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr) &&
+ isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,-bs2),
+ step, stepfac, startoff, endoff, needed_count, nodemgr)
+ )
+ {
+ blocks_occlusion_culled++;
+ continue;
+ }
+
+ // This block is in range. Reset usage timer.
+ block->resetUsageTimer();
+
/*
- Draw the faces of the block
+ Ignore if mesh doesn't exist
*/
{
JMutexAutoLock lock(block->mesh_mutex);
scene::SMesh *mesh = block->mesh;
-
- if(mesh == NULL)
- continue;
- blocks_would_have_drawn++;
- if(blocks_drawn >= m_control.wanted_max_blocks
- && m_control.range_all == false
- && d > m_control.wanted_min_range * BS)
+ if(mesh == NULL){
+ blocks_in_range_without_mesh++;
continue;
+ }
+ }
+
+ // Limit block count in case of a sudden increase
+ blocks_would_have_drawn++;
+ if(blocks_drawn >= m_control.wanted_max_blocks
+ && m_control.range_all == false
+ && d > m_control.wanted_min_range * BS)
+ continue;
+
+ // Add to set
+ drawset[block->getPos()] = block;
+
+ sector_blocks_drawn++;
+ blocks_drawn++;
- blocks_drawn++;
- sector_blocks_drawn++;
+ } // foreach sectorblocks
- u32 c = mesh->getMeshBufferCount();
- meshbuffer_count += c;
+ if(sector_blocks_drawn != 0)
+ m_last_drawn_sectors[sp] = true;
+ }
+ } // ScopeProfiler
+
+ /*
+ Draw the selected MapBlocks
+ */
+
+ {
+ ScopeProfiler sp(g_profiler, prefix+"drawing blocks", SPT_AVG);
- for(u32 i=0; i<c; i++)
+ int timecheck_counter = 0;
+ for(core::map<v3s16, MapBlock*>::Iterator
+ i = drawset.getIterator();
+ i.atEnd() == false; i++)
+ {
+ {
+ timecheck_counter++;
+ if(timecheck_counter > 50)
+ {
+ timecheck_counter = 0;
+ int time2 = time(0);
+ if(time2 > time1 + 4)
{
- scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
- const video::SMaterial& material = buf->getMaterial();
- video::IMaterialRenderer* rnd =
- driver->getMaterialRenderer(material.MaterialType);
- bool transparent = (rnd && rnd->isTransparent());
- // Render transparent on transparent pass and likewise.
- if(transparent == is_transparent_pass)
- {
- /*
- This *shouldn't* hurt too much because Irrlicht
- doesn't change opengl textures if the old
- material is set again.
- */
- driver->setMaterial(buf->getMaterial());
- driver->drawMeshBuffer(buf);
- vertex_count += buf->getVertexCount();
- }
+ infostream<<"ClientMap::renderMap(): "
+ "Rendering takes ages, returning."
+ <<std::endl;
+ return;
}
}
- } // foreach sectorblocks
+ }
+
+ MapBlock *block = i.getNode()->getValue();
- if(sector_blocks_drawn != 0)
+ /*
+ Draw the faces of the block
+ */
{
- m_last_drawn_sectors[sp] = true;
+ JMutexAutoLock lock(block->mesh_mutex);
+
+ scene::SMesh *mesh = block->mesh;
+ assert(mesh);
+
+ u32 c = mesh->getMeshBufferCount();
+ bool stuff_actually_drawn = false;
+ for(u32 i=0; i<c; i++)
+ {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
+ const video::SMaterial& material = buf->getMaterial();
+ video::IMaterialRenderer* rnd =
+ driver->getMaterialRenderer(material.MaterialType);
+ bool transparent = (rnd && rnd->isTransparent());
+ // Render transparent on transparent pass and likewise.
+ if(transparent == is_transparent_pass)
+ {
+ if(buf->getVertexCount() == 0)
+ errorstream<<"Block ["<<analyze_block(block)
+ <<"] contains an empty meshbuf"<<std::endl;
+ /*
+ This *shouldn't* hurt too much because Irrlicht
+ doesn't change opengl textures if the old
+ material has the same texture.
+ */
+ driver->setMaterial(buf->getMaterial());
+ driver->drawMeshBuffer(buf);
+ vertex_count += buf->getVertexCount();
+ meshbuffer_count++;
+ stuff_actually_drawn = true;
+ }
+ }
+ if(stuff_actually_drawn)
+ blocks_had_pass_meshbuf++;
+ else
+ blocks_without_stuff++;
}
}
+ } // ScopeProfiler
+ // Log only on solid pass because values are the same
if(pass == scene::ESNRP_SOLID){
- g_profiler->avg("CM: blocks drawn on solid pass", blocks_drawn);
- g_profiler->avg("CM: vertices drawn on solid pass", vertex_count);
- if(blocks_drawn != 0)
- g_profiler->avg("CM: solid meshbuffers per block",
- (float)meshbuffer_count / (float)blocks_drawn);
- } else {
- g_profiler->avg("CM: blocks drawn on transparent pass", blocks_drawn);
- g_profiler->avg("CM: vertices drawn on transparent pass", vertex_count);
+ g_profiler->avg("CM: blocks in range", blocks_in_range);
+ g_profiler->avg("CM: blocks occlusion culled", blocks_occlusion_culled);
+ if(blocks_in_range != 0)
+ g_profiler->avg("CM: blocks in range without mesh (frac)",
+ (float)blocks_in_range_without_mesh/blocks_in_range);
+ g_profiler->avg("CM: blocks drawn", blocks_drawn);
}
+ g_profiler->avg(prefix+"vertices drawn", vertex_count);
+ if(blocks_had_pass_meshbuf != 0)
+ g_profiler->avg(prefix+"meshbuffers per block",
+ (float)meshbuffer_count / (float)blocks_had_pass_meshbuf);
+ if(blocks_drawn != 0)
+ g_profiler->avg(prefix+"empty blocks (frac)",
+ (float)blocks_without_stuff / blocks_drawn);
+
m_control.blocks_drawn = blocks_drawn;
m_control.blocks_would_have_drawn = blocks_would_have_drawn;
void ClientMap::renderPostFx()
{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
// Sadly ISceneManager has no "post effects" render pass, in that case we
// could just register for that and handle it in renderMap().
// - If the player is in a solid node, make everything black.
// - If the player is in liquid, draw a semi-transparent overlay.
- ContentFeatures& features = content_features(n);
+ const ContentFeatures& features = nodemgr->get(n);
video::SColor post_effect_color = features.post_effect_color;
if(features.solidness == 2 && g_settings->getBool("free_move") == false)
{