occlusion culling fix, a little reshaping of map rendering for more useful profiler output and dynamic profiler text size

master
Perttu Ahola 2011-11-02 18:13:56 +02:00
parent 03db16d55b
commit 1726b82a16
4 changed files with 157 additions and 100 deletions

View File

@ -46,6 +46,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("keymap_screenshot", "KEY_F12");
settings->setDefault("keymap_toggle_profiler", "KEY_F2");
settings->setDefault("keymap_toggle_force_fog_off", "KEY_F3");
settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
// Some (temporary) keys for debugging
settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");

View File

@ -888,11 +888,11 @@ void the_game(
//guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
core::list<ChatLine> chat_lines;
// Profiler text
// Profiler text (size is updated when text is updated)
gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
L"<Profiler>",
core::rect<s32>(6, 4+(text_height+5)*3, 400,
(text_height+5)*3 + text_height*35),
core::rect<s32>(6, 4+(text_height+5)*2, 400,
(text_height+5)*2 + text_height*35),
false, false);
guitext_profiler->setBackgroundColor(video::SColor(80,0,0,0));
guitext_profiler->setVisible(false);
@ -951,8 +951,8 @@ void the_game(
bool respawn_menu_active = false;
bool show_profiler = false;
bool force_fog_off = false;
bool disable_camera_update = false;
/*
Main loop
@ -1188,9 +1188,18 @@ void the_game(
std::ostringstream os(std::ios_base::binary);
g_profiler->print(os);
guitext_profiler->setText(narrow_to_wide(os.str()).c_str());
std::wstring text = narrow_to_wide(os.str());
guitext_profiler->setText(text.c_str());
g_profiler->clear();
s32 w = font->getDimension(text.c_str()).Width;
if(w < 400)
w = 400;
core::rect<s32> rect(6, 4+(text_height+5)*2, 12+w,
8+(text_height+5)*2 +
font->getDimension(text.c_str()).Height);
guitext_profiler->setRelativePosition(rect);
}
/*
@ -1324,10 +1333,26 @@ void the_game(
{
show_profiler = !show_profiler;
guitext_profiler->setVisible(show_profiler);
if(show_profiler)
chat_lines.push_back(ChatLine(L"Profiler disabled"));
else
chat_lines.push_back(ChatLine(L"Profiler enabled"));
}
else if(input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off")))
{
force_fog_off = !force_fog_off;
if(force_fog_off)
chat_lines.push_back(ChatLine(L"Fog disabled"));
else
chat_lines.push_back(ChatLine(L"Fog enabled"));
}
else if(input->wasKeyDown(getKeySetting("keymap_toggle_update_camera")))
{
disable_camera_update = !disable_camera_update;
if(disable_camera_update)
chat_lines.push_back(ChatLine(L"Camera update disabled"));
else
chat_lines.push_back(ChatLine(L"Camera update enabled"));
}
// Item selection with mouse wheel
@ -1573,11 +1598,10 @@ void the_game(
v3f camera_direction = camera.getDirection();
f32 camera_fov = camera.getFovMax();
if(FIELD_OF_VIEW_TEST)
client.updateCamera(v3f(0,0,0), v3f(0,0,1), camera_fov);
else
if(!disable_camera_update){
client.updateCamera(camera_position,
camera_direction, camera_fov);
}
//timer2.stop();
//TimeTaker //timer3("//timer3");

View File

@ -3620,6 +3620,12 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
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
*/
@ -3689,27 +3695,19 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
// Blocks from which stuff was actually drawn
u32 blocks_without_stuff = 0;
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;
}
}
}
/*
Collect a set of blocks for drawing
*/
core::map<v3s16, MapBlock*> drawset;
{
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();
@ -3726,7 +3724,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
sector->getBlocks(sectorblocks);
/*
Draw blocks
Loop through blocks in sector
*/
u32 sector_blocks_drawn = 0;
@ -3753,14 +3751,14 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
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;*/
// This block is in range. Reset usage timer.
block->resetUsageTimer();
blocks_in_range++;
#if 1
@ -3812,11 +3810,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
mesh_expired = false;
}
#endif
/*
Draw the faces of the block
*/
{
JMutexAutoLock lock(block->mesh_mutex);
@ -3832,9 +3827,58 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
&& m_control.range_all == false
&& d > m_control.wanted_min_range * BS)
continue;
}
drawset[block->getPos()] = block;
blocks_drawn++;
sector_blocks_drawn++;
blocks_drawn++;
} // foreach sectorblocks
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);
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)
{
infostream<<"ClientMap::renderMap(): "
"Rendering takes ages, returning."
<<std::endl;
return;
}
}
}
MapBlock *block = i.getNode()->getValue();
/*
Draw the faces of the block
*/
{
JMutexAutoLock lock(block->mesh_mutex);
scene::SMesh *mesh = block->mesh;
assert(mesh);
u32 c = mesh->getMeshBufferCount();
bool stuff_actually_drawn = false;
@ -3868,30 +3912,18 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
else
blocks_without_stuff++;
}
} // foreach sectorblocks
if(sector_blocks_drawn != 0)
{
m_last_drawn_sectors[sp] = true;
}
}
std::string prefix = "CM: ";
} // ScopeProfiler
// Log only on solid pass because values are the same
if(pass == scene::ESNRP_SOLID){
g_profiler->avg(prefix+"blocks in range", blocks_in_range);
g_profiler->avg("CM: blocks in range", blocks_in_range);
if(blocks_in_range != 0)
g_profiler->avg(prefix+"blocks in range without mesh (frac)",
g_profiler->avg("CM: blocks in range without mesh (frac)",
(float)blocks_in_range_without_mesh/blocks_in_range);
g_profiler->avg(prefix+"blocks drawn", blocks_drawn);
g_profiler->avg("CM: blocks drawn", blocks_drawn);
}
if(pass == scene::ESNRP_SOLID)
prefix = "CM: solid: ";
else
prefix = "CM: transparent: ";
g_profiler->avg(prefix+"vertices drawn", vertex_count);
if(blocks_had_pass_meshbuf != 0)
g_profiler->avg(prefix+"meshbuffers per block",

View File

@ -236,21 +236,21 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
// If block is (nearly) touching the camera, don't
// bother validating further (that is, render it anyway)
if(d > block_max_radius)
{
if(d < block_max_radius)
return true;
// Cosine of the angle between the camera direction
// and the block direction (camera_dir is an unit vector)
f32 cosangle = dforward / d;
// Compensate for the size of the block
// (as the block has to be shown even if it's a bit off FOV)
// This is an estimate.
cosangle += block_max_radius / dforward;
// This is an estimate, plus an arbitary factor
cosangle += block_max_radius / d * 0.5;
// If block is not in the field of view, skip it
if(cosangle < cos(camera_fov / 2))
return false;
}
return true;
}