//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);
bool respawn_menu_active = false;
bool show_profiler = false;
-
bool force_fog_off = false;
+ bool disable_camera_update = false;
/*
Main loop
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);
}
/*
{
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
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");
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
*/
// 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++)
+ /*
+ Collect a set of blocks for drawing
+ */
+
+ core::map<v3s16, MapBlock*> drawset;
+
{
- {
- 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++;
+ // This block is in range. Reset usage timer.
+ block->resetUsageTimer();
+ blocks_in_range++;
+
#if 1
/*
Update expired mesh (used for day/night change)
mesh_expired = false;
}
-
#endif
- /*
- Draw the faces of the block
- */
+
{
JMutexAutoLock lock(block->mesh_mutex);
&& m_control.range_all == false
&& d > m_control.wanted_min_range * BS)
continue;
+ }
+
+ drawset[block->getPos()] = block;
+
+ sector_blocks_drawn++;
+ blocks_drawn++;
- blocks_drawn++;
- sector_blocks_drawn++;
+ } // foreach sectorblocks
- u32 c = mesh->getMeshBufferCount();
- bool stuff_actually_drawn = false;
- for(u32 i=0; i<c; i++)
+ 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)
{
- 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;
- }
+ infostream<<"ClientMap::renderMap(): "
+ "Rendering takes ages, returning."
+ <<std::endl;
+ return;
}
- if(stuff_actually_drawn)
- blocks_had_pass_meshbuf++;
- else
- blocks_without_stuff++;
}
- } // 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
- std::string prefix = "CM: ";
-
// 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",