3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "clientmap.h"
22 #include "mapblock_mesh.h"
23 #include <IMaterialRenderer.h>
26 #include "mapsector.h"
27 #include "main.h" // dout_client, g_settings
32 #include "camera.h" // CameraModes
33 #include "util/mathconstants.h"
36 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
41 MapDrawControl &control,
42 scene::ISceneNode* parent,
43 scene::ISceneManager* mgr,
46 Map(dout_client, gamedef),
47 scene::ISceneNode(parent, mgr, id),
50 m_camera_position(0,0,0),
51 m_camera_direction(0,0,1),
54 m_box = core::aabbox3d<f32>(-BS*1000000,-BS*1000000,-BS*1000000,
55 BS*1000000,BS*1000000,BS*1000000);
58 ClientMap::~ClientMap()
60 /*JMutexAutoLock lock(mesh_mutex);
69 MapSector * ClientMap::emergeSector(v2s16 p2d)
71 DSTACK(__FUNCTION_NAME);
72 // Check that it doesn't exist already
74 return getSectorNoGenerate(p2d);
76 catch(InvalidPositionException &e)
81 ClientMapSector *sector = new ClientMapSector(this, p2d, m_gamedef);
84 //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
85 m_sectors[p2d] = sector;
92 void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
94 DSTACK(__FUNCTION_NAME);
95 ClientMapSector *sector = NULL;
97 //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
99 core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p2d);
103 sector = (ClientMapSector*)n->getValue();
104 assert(sector->getId() == MAPSECTOR_CLIENT);
108 sector = new ClientMapSector(this, p2d);
110 //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
111 m_sectors.insert(p2d, sector);
115 sector->deSerialize(is);
119 void ClientMap::OnRegisterSceneNode()
123 SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
124 SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
127 ISceneNode::OnRegisterSceneNode();
130 static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
131 float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr)
133 float d0 = (float)BS * p0.getDistanceFrom(p1);
135 v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
137 v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
139 for(float s=start_off; s<d0+end_off; s+=step){
140 v3f pf = p0f + uf * s;
141 v3s16 p = floatToInt(pf, BS);
142 MapNode n = map->getNodeNoEx(p);
143 bool is_transparent = false;
144 const ContentFeatures &f = nodemgr->get(n);
146 is_transparent = (f.visual_solidness != 2);
148 is_transparent = (f.solidness != 2);
151 if(count >= needed_count)
159 void ClientMap::updateDrawList(video::IVideoDriver* driver)
161 ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
162 g_profiler->add("CM::updateDrawList() count", 1);
164 INodeDefManager *nodemgr = m_gamedef->ndef();
166 for(std::map<v3s16, MapBlock*>::iterator
167 i = m_drawlist.begin();
168 i != m_drawlist.end(); ++i)
170 MapBlock *block = i->second;
175 m_camera_mutex.Lock();
176 v3f camera_position = m_camera_position;
177 v3f camera_direction = m_camera_direction;
178 f32 camera_fov = m_camera_fov;
179 v3s16 camera_offset = m_camera_offset;
180 m_camera_mutex.Unlock();
182 // Use a higher fov to accomodate faster camera movements.
183 // Blocks are cropped better when they are drawn.
184 // Or maybe they aren't? Well whatever.
187 v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
188 v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
189 v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
190 v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
191 // Take a fair amount as we will be dropping more out later
192 // Umm... these additions are a bit strange but they are needed.
194 p_nodes_min.X / MAP_BLOCKSIZE - 3,
195 p_nodes_min.Y / MAP_BLOCKSIZE - 3,
196 p_nodes_min.Z / MAP_BLOCKSIZE - 3);
198 p_nodes_max.X / MAP_BLOCKSIZE + 1,
199 p_nodes_max.Y / MAP_BLOCKSIZE + 1,
200 p_nodes_max.Z / MAP_BLOCKSIZE + 1);
202 // Number of blocks in rendering range
203 u32 blocks_in_range = 0;
204 // Number of blocks occlusion culled
205 u32 blocks_occlusion_culled = 0;
206 // Number of blocks in rendering range but don't have a mesh
207 u32 blocks_in_range_without_mesh = 0;
208 // Blocks that had mesh that would have been drawn according to
209 // rendering range (if max blocks limit didn't kick in)
210 u32 blocks_would_have_drawn = 0;
211 // Blocks that were drawn and had a mesh
212 u32 blocks_drawn = 0;
213 // Blocks which had a corresponding meshbuffer for this pass
214 //u32 blocks_had_pass_meshbuf = 0;
215 // Blocks from which stuff was actually drawn
216 //u32 blocks_without_stuff = 0;
217 // Distance to farthest drawn block
218 float farthest_drawn = 0;
220 for(std::map<v2s16, MapSector*>::iterator
221 si = m_sectors.begin();
222 si != m_sectors.end(); ++si)
224 MapSector *sector = si->second;
225 v2s16 sp = sector->getPos();
227 if(m_control.range_all == false)
229 if(sp.X < p_blocks_min.X
230 || sp.X > p_blocks_max.X
231 || sp.Y < p_blocks_min.Z
232 || sp.Y > p_blocks_max.Z)
236 std::list< MapBlock * > sectorblocks;
237 sector->getBlocks(sectorblocks);
240 Loop through blocks in sector
243 u32 sector_blocks_drawn = 0;
245 std::list< MapBlock * >::iterator i;
246 for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
248 MapBlock *block = *i;
251 Compare block position to camera position, skip
252 if not seen on display
255 if (block->mesh != NULL)
256 block->mesh->updateCameraOffset(m_camera_offset);
258 float range = 100000 * BS;
259 if(m_control.range_all == false)
260 range = m_control.wanted_range * BS;
263 if(isBlockInSight(block->getPos(), camera_position,
264 camera_direction, camera_fov,
270 // This is ugly (spherical distance limit?)
271 /*if(m_control.range_all == false &&
272 d - 0.5*BS*MAP_BLOCKSIZE > range)
278 Ignore if mesh doesn't exist
281 //JMutexAutoLock lock(block->mesh_mutex);
283 if(block->mesh == NULL){
284 blocks_in_range_without_mesh++;
293 // No occlusion culling when free_move is on and camera is
295 bool occlusion_culling_enabled = true;
296 if(g_settings->getBool("free_move")){
297 MapNode n = getNodeNoEx(cam_pos_nodes);
298 if(n.getContent() == CONTENT_IGNORE ||
299 nodemgr->get(n).solidness == 2)
300 occlusion_culling_enabled = false;
303 v3s16 cpn = block->getPos() * MAP_BLOCKSIZE;
304 cpn += v3s16(MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2);
307 float startoff = BS*1;
308 float endoff = -BS*MAP_BLOCKSIZE*1.42*1.42;
309 v3s16 spn = cam_pos_nodes + v3s16(0,0,0);
310 s16 bs2 = MAP_BLOCKSIZE/2 + 1;
311 u32 needed_count = 1;
313 occlusion_culling_enabled &&
314 isOccluded(this, spn, cpn + v3s16(0,0,0),
315 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
316 isOccluded(this, spn, cpn + v3s16(bs2,bs2,bs2),
317 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
318 isOccluded(this, spn, cpn + v3s16(bs2,bs2,-bs2),
319 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
320 isOccluded(this, spn, cpn + v3s16(bs2,-bs2,bs2),
321 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
322 isOccluded(this, spn, cpn + v3s16(bs2,-bs2,-bs2),
323 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
324 isOccluded(this, spn, cpn + v3s16(-bs2,bs2,bs2),
325 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
326 isOccluded(this, spn, cpn + v3s16(-bs2,bs2,-bs2),
327 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
328 isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,bs2),
329 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
330 isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,-bs2),
331 step, stepfac, startoff, endoff, needed_count, nodemgr)
334 blocks_occlusion_culled++;
338 // This block is in range. Reset usage timer.
339 block->resetUsageTimer();
341 // Limit block count in case of a sudden increase
342 blocks_would_have_drawn++;
343 if(blocks_drawn >= m_control.wanted_max_blocks
344 && m_control.range_all == false
345 && d > m_control.wanted_min_range * BS)
350 m_drawlist[block->getPos()] = block;
352 sector_blocks_drawn++;
354 if(d/BS > farthest_drawn)
355 farthest_drawn = d/BS;
357 } // foreach sectorblocks
359 if(sector_blocks_drawn != 0)
360 m_last_drawn_sectors.insert(sp);
363 m_control.blocks_would_have_drawn = blocks_would_have_drawn;
364 m_control.blocks_drawn = blocks_drawn;
365 m_control.farthest_drawn = farthest_drawn;
367 g_profiler->avg("CM: blocks in range", blocks_in_range);
368 g_profiler->avg("CM: blocks occlusion culled", blocks_occlusion_culled);
369 if(blocks_in_range != 0)
370 g_profiler->avg("CM: blocks in range without mesh (frac)",
371 (float)blocks_in_range_without_mesh/blocks_in_range);
372 g_profiler->avg("CM: blocks drawn", blocks_drawn);
373 g_profiler->avg("CM: farthest drawn", farthest_drawn);
374 g_profiler->avg("CM: wanted max blocks", m_control.wanted_max_blocks);
380 std::list<scene::IMeshBuffer*> bufs;
383 struct MeshBufListList
385 std::list<MeshBufList> lists;
392 void add(scene::IMeshBuffer *buf)
394 for(std::list<MeshBufList>::iterator i = lists.begin();
395 i != lists.end(); ++i){
397 if(l.m == buf->getMaterial()){
398 l.bufs.push_back(buf);
403 l.m = buf->getMaterial();
404 l.bufs.push_back(buf);
409 void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
411 DSTACK(__FUNCTION_NAME);
413 bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
416 if(pass == scene::ESNRP_SOLID)
417 prefix = "CM: solid: ";
419 prefix = "CM: transparent: ";
422 This is called two times per frame, reset on the non-transparent one
424 if(pass == scene::ESNRP_SOLID)
426 m_last_drawn_sectors.clear();
429 bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
430 bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
431 bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
434 Get time for measuring timeout.
436 Measuring time is very useful for long delays when the
437 machine is swapping a lot.
442 Get animation parameters
444 float animation_time = m_client->getAnimationTime();
445 int crack = m_client->getCrackLevel();
446 u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
448 m_camera_mutex.Lock();
449 v3f camera_position = m_camera_position;
450 v3f camera_direction = m_camera_direction;
451 f32 camera_fov = m_camera_fov;
452 m_camera_mutex.Unlock();
455 Get all blocks and draw all visible ones
458 v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
460 v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
462 v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
463 v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
465 // Take a fair amount as we will be dropping more out later
466 // Umm... these additions are a bit strange but they are needed.
468 p_nodes_min.X / MAP_BLOCKSIZE - 3,
469 p_nodes_min.Y / MAP_BLOCKSIZE - 3,
470 p_nodes_min.Z / MAP_BLOCKSIZE - 3);
472 p_nodes_max.X / MAP_BLOCKSIZE + 1,
473 p_nodes_max.Y / MAP_BLOCKSIZE + 1,
474 p_nodes_max.Z / MAP_BLOCKSIZE + 1);
476 u32 vertex_count = 0;
477 u32 meshbuffer_count = 0;
479 // For limiting number of mesh animations per frame
480 u32 mesh_animate_count = 0;
481 u32 mesh_animate_count_far = 0;
483 // Blocks that were drawn and had a mesh
484 u32 blocks_drawn = 0;
485 // Blocks which had a corresponding meshbuffer for this pass
486 u32 blocks_had_pass_meshbuf = 0;
487 // Blocks from which stuff was actually drawn
488 u32 blocks_without_stuff = 0;
491 Draw the selected MapBlocks
495 ScopeProfiler sp(g_profiler, prefix+"drawing blocks", SPT_AVG);
497 MeshBufListList drawbufs;
499 for(std::map<v3s16, MapBlock*>::iterator
500 i = m_drawlist.begin();
501 i != m_drawlist.end(); ++i)
503 MapBlock *block = i->second;
505 // If the mesh of the block happened to get deleted, ignore it
506 if(block->mesh == NULL)
510 if(isBlockInSight(block->getPos(), camera_position,
511 camera_direction, camera_fov,
512 100000*BS, &d) == false)
519 //JMutexAutoLock lock(block->mesh_mutex);
520 MapBlockMesh *mapBlockMesh = block->mesh;
521 assert(mapBlockMesh);
522 // Pretty random but this should work somewhat nicely
523 bool faraway = d >= BS*50;
524 //bool faraway = d >= m_control.wanted_range * BS;
525 if(mapBlockMesh->isAnimationForced() ||
527 mesh_animate_count_far < (m_control.range_all ? 200 : 50))
529 bool animated = mapBlockMesh->animate(
535 mesh_animate_count++;
536 if(animated && faraway)
537 mesh_animate_count_far++;
541 mapBlockMesh->decreaseAnimationForceTimer();
546 Get the meshbuffers of the block
549 //JMutexAutoLock lock(block->mesh_mutex);
551 MapBlockMesh *mapBlockMesh = block->mesh;
552 assert(mapBlockMesh);
554 scene::SMesh *mesh = mapBlockMesh->getMesh();
557 u32 c = mesh->getMeshBufferCount();
558 for(u32 i=0; i<c; i++)
560 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
562 buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
563 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
564 buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
566 const video::SMaterial& material = buf->getMaterial();
567 video::IMaterialRenderer* rnd =
568 driver->getMaterialRenderer(material.MaterialType);
569 bool transparent = (rnd && rnd->isTransparent());
570 if(transparent == is_transparent_pass)
572 if(buf->getVertexCount() == 0)
573 errorstream<<"Block ["<<analyze_block(block)
574 <<"] contains an empty meshbuf"<<std::endl;
581 std::list<MeshBufList> &lists = drawbufs.lists;
583 int timecheck_counter = 0;
584 for(std::list<MeshBufList>::iterator i = lists.begin();
585 i != lists.end(); ++i)
589 if(timecheck_counter > 50)
591 timecheck_counter = 0;
593 if(time2 > time1 + 4)
595 infostream<<"ClientMap::renderMap(): "
596 "Rendering takes ages, returning."
603 MeshBufList &list = *i;
605 driver->setMaterial(list.m);
607 for(std::list<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
608 j != list.bufs.end(); ++j)
610 scene::IMeshBuffer *buf = *j;
611 driver->drawMeshBuffer(buf);
612 vertex_count += buf->getVertexCount();
617 Draw the faces of the block
620 //JMutexAutoLock lock(block->mesh_mutex);
622 MapBlockMesh *mapBlockMesh = block->mesh;
623 assert(mapBlockMesh);
625 scene::SMesh *mesh = mapBlockMesh->getMesh();
628 u32 c = mesh->getMeshBufferCount();
629 bool stuff_actually_drawn = false;
630 for(u32 i=0; i<c; i++)
632 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
633 const video::SMaterial& material = buf->getMaterial();
634 video::IMaterialRenderer* rnd =
635 driver->getMaterialRenderer(material.MaterialType);
636 bool transparent = (rnd && rnd->isTransparent());
637 // Render transparent on transparent pass and likewise.
638 if(transparent == is_transparent_pass)
640 if(buf->getVertexCount() == 0)
641 errorstream<<"Block ["<<analyze_block(block)
642 <<"] contains an empty meshbuf"<<std::endl;
644 This *shouldn't* hurt too much because Irrlicht
645 doesn't change opengl textures if the old
646 material has the same texture.
648 driver->setMaterial(buf->getMaterial());
649 driver->drawMeshBuffer(buf);
650 vertex_count += buf->getVertexCount();
652 stuff_actually_drawn = true;
655 if(stuff_actually_drawn)
656 blocks_had_pass_meshbuf++;
658 blocks_without_stuff++;
664 // Log only on solid pass because values are the same
665 if(pass == scene::ESNRP_SOLID){
666 g_profiler->avg("CM: animated meshes", mesh_animate_count);
667 g_profiler->avg("CM: animated meshes (far)", mesh_animate_count_far);
670 g_profiler->avg(prefix+"vertices drawn", vertex_count);
671 if(blocks_had_pass_meshbuf != 0)
672 g_profiler->avg(prefix+"meshbuffers per block",
673 (float)meshbuffer_count / (float)blocks_had_pass_meshbuf);
674 if(blocks_drawn != 0)
675 g_profiler->avg(prefix+"empty blocks (frac)",
676 (float)blocks_without_stuff / blocks_drawn);
678 /*infostream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
679 <<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
682 static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
683 float step_multiplier, float start_distance, float end_distance,
684 INodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d,
685 int *result, bool *sunlight_seen)
687 int brightness_sum = 0;
688 int brightness_count = 0;
689 float distance = start_distance;
692 pf += dir * distance;
694 bool nonlight_seen = false;
695 bool allow_allowing_non_sunlight_propagates = false;
696 bool allow_non_sunlight_propagates = false;
697 // Check content nearly at camera position
699 v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS);
700 MapNode n = map->getNodeNoEx(p);
701 if(ndef->get(n).param_type == CPT_LIGHT &&
702 !ndef->get(n).sunlight_propagates)
703 allow_allowing_non_sunlight_propagates = true;
705 // If would start at CONTENT_IGNORE, start closer
707 v3s16 p = floatToInt(pf, BS);
708 MapNode n = map->getNodeNoEx(p);
709 if(n.getContent() == CONTENT_IGNORE){
711 pf = p0 + dir * 2*newd;
716 for(int i=0; distance < end_distance; i++){
719 step *= step_multiplier;
721 v3s16 p = floatToInt(pf, BS);
722 MapNode n = map->getNodeNoEx(p);
723 if(allow_allowing_non_sunlight_propagates && i == 0 &&
724 ndef->get(n).param_type == CPT_LIGHT &&
725 !ndef->get(n).sunlight_propagates){
726 allow_non_sunlight_propagates = true;
728 if(ndef->get(n).param_type != CPT_LIGHT ||
729 (!ndef->get(n).sunlight_propagates &&
730 !allow_non_sunlight_propagates)){
731 nonlight_seen = true;
737 if(distance >= sunlight_min_d && *sunlight_seen == false
738 && nonlight_seen == false)
739 if(n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
740 *sunlight_seen = true;
742 brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef));
746 if(brightness_count == 0)
748 *result = brightness_sum / brightness_count;
749 /*std::cerr<<"Sampled "<<brightness_count<<" points; result="
750 <<(*result)<<std::endl;*/
754 int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
755 int oldvalue, bool *sunlight_seen_result)
757 const bool debugprint = false;
758 INodeDefManager *ndef = m_gamedef->ndef();
759 static v3f z_directions[50] = {
762 static f32 z_offsets[sizeof(z_directions)/sizeof(*z_directions)] = {
765 if(z_directions[0].X < -99){
766 for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
767 z_directions[i] = v3f(
768 0.01 * myrand_range(-100, 100),
770 0.01 * myrand_range(-100, 100)
772 z_offsets[i] = 0.01 * myrand_range(0,100);
776 std::cerr<<"In goes "<<PP(m_camera_direction)<<", out comes ";
777 int sunlight_seen_count = 0;
778 float sunlight_min_d = max_d*0.8;
779 if(sunlight_min_d > 35*BS)
780 sunlight_min_d = 35*BS;
781 std::vector<int> values;
782 for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
783 v3f z_dir = z_directions[i];
785 core::CMatrix4<f32> a;
786 a.buildRotateFromTo(v3f(0,1,0), z_dir);
787 v3f dir = m_camera_direction;
792 step = max_d / 35 * 1.5;
793 float off = step * z_offsets[i];
794 bool sunlight_seen_now = false;
795 bool ok = getVisibleBrightness(this, m_camera_position, dir,
796 step, 1.0, max_d*0.6+off, max_d, ndef, daylight_factor,
798 &br, &sunlight_seen_now);
799 if(sunlight_seen_now)
800 sunlight_seen_count++;
803 values.push_back(br);
804 // Don't try too much if being in the sun is clear
805 if(sunlight_seen_count >= 20)
808 int brightness_sum = 0;
809 int brightness_count = 0;
810 std::sort(values.begin(), values.end());
811 u32 num_values_to_use = values.size();
812 if(num_values_to_use >= 10)
813 num_values_to_use -= num_values_to_use/2;
814 else if(num_values_to_use >= 7)
815 num_values_to_use -= num_values_to_use/3;
816 u32 first_value_i = (values.size() - num_values_to_use) / 2;
818 for(u32 i=0; i < first_value_i; i++)
819 std::cerr<<values[i]<<" ";
822 for(u32 i=first_value_i; i < first_value_i+num_values_to_use; i++){
824 std::cerr<<values[i]<<" ";
825 brightness_sum += values[i];
830 for(u32 i=first_value_i+num_values_to_use; i < values.size(); i++)
831 std::cerr<<values[i]<<" ";
834 if(brightness_count == 0){
835 MapNode n = getNodeNoEx(floatToInt(m_camera_position, BS));
836 if(ndef->get(n).param_type == CPT_LIGHT){
837 ret = decode_light(n.getLightBlend(daylight_factor, ndef));
840 //ret = blend_light(255, 0, daylight_factor);
843 /*float pre = (float)brightness_sum / (float)brightness_count;
849 ret = MYMAX(0, MYMIN(255, preint));*/
850 ret = brightness_sum / brightness_count;
853 std::cerr<<"Result: "<<ret<<" sunlight_seen_count="
854 <<sunlight_seen_count<<std::endl;
855 *sunlight_seen_result = (sunlight_seen_count > 0);
859 void ClientMap::renderPostFx()
861 INodeDefManager *nodemgr = m_gamedef->ndef();
863 // Sadly ISceneManager has no "post effects" render pass, in that case we
864 // could just register for that and handle it in renderMap().
866 m_camera_mutex.Lock();
867 v3f camera_position = m_camera_position;
868 m_camera_mutex.Unlock();
870 LocalPlayer *player = m_client->getEnv().getLocalPlayer();
872 MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
874 // - If the player is in a solid node, make everything black.
875 // - If the player is in liquid, draw a semi-transparent overlay.
876 // - Do not if player is in third person mode
877 const ContentFeatures& features = nodemgr->get(n);
878 video::SColor post_effect_color = features.post_effect_color;
879 if(features.solidness == 2 && !(g_settings->getBool("noclip") && m_gamedef->checkLocalPrivilege("noclip")) && player->camera_mode == CAMERA_MODE_FIRST)
881 post_effect_color = video::SColor(255, 0, 0, 0);
883 if (post_effect_color.getAlpha() != 0)
885 // Draw a full-screen rectangle
886 video::IVideoDriver* driver = SceneManager->getVideoDriver();
887 v2u32 ss = driver->getScreenSize();
888 core::rect<s32> rect(0,0, ss.X, ss.Y);
889 driver->draw2DRectangle(post_effect_color, rect);
893 void ClientMap::PrintInfo(std::ostream &out)