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 "util/mathconstants.h"
34 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
39 MapDrawControl &control,
40 scene::ISceneNode* parent,
41 scene::ISceneManager* mgr,
44 Map(dout_client, gamedef),
45 scene::ISceneNode(parent, mgr, id),
48 m_camera_position(0,0,0),
49 m_camera_direction(0,0,1),
52 m_camera_mutex.Init();
53 assert(m_camera_mutex.IsInitialized());
55 m_box = core::aabbox3d<f32>(-BS*1000000,-BS*1000000,-BS*1000000,
56 BS*1000000,BS*1000000,BS*1000000);
59 ClientMap::~ClientMap()
61 /*JMutexAutoLock lock(mesh_mutex);
70 MapSector * ClientMap::emergeSector(v2s16 p2d)
72 DSTACK(__FUNCTION_NAME);
73 // Check that it doesn't exist already
75 return getSectorNoGenerate(p2d);
77 catch(InvalidPositionException &e)
82 ClientMapSector *sector = new ClientMapSector(this, p2d, m_gamedef);
85 //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
86 m_sectors.insert(p2d, sector);
93 void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
95 DSTACK(__FUNCTION_NAME);
96 ClientMapSector *sector = NULL;
98 //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
100 core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p2d);
104 sector = (ClientMapSector*)n->getValue();
105 assert(sector->getId() == MAPSECTOR_CLIENT);
109 sector = new ClientMapSector(this, p2d);
111 //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
112 m_sectors.insert(p2d, sector);
116 sector->deSerialize(is);
120 void ClientMap::OnRegisterSceneNode()
124 SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
125 SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
128 ISceneNode::OnRegisterSceneNode();
131 static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
132 float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr)
134 float d0 = (float)BS * p0.getDistanceFrom(p1);
136 v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
138 v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
140 for(float s=start_off; s<d0+end_off; s+=step){
141 v3f pf = p0f + uf * s;
142 v3s16 p = floatToInt(pf, BS);
143 MapNode n = map->getNodeNoEx(p);
144 bool is_transparent = false;
145 const ContentFeatures &f = nodemgr->get(n);
147 is_transparent = (f.visual_solidness != 2);
149 is_transparent = (f.solidness != 2);
152 if(count >= needed_count)
160 void ClientMap::updateDrawList(video::IVideoDriver* driver)
162 ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
163 g_profiler->add("CM::updateDrawList() count", 1);
165 INodeDefManager *nodemgr = m_gamedef->ndef();
167 for(core::map<v3s16, MapBlock*>::Iterator
168 i = m_drawlist.getIterator();
169 i.atEnd() == false; i++)
171 MapBlock *block = i.getNode()->getValue();
176 m_camera_mutex.Lock();
177 v3f camera_position = m_camera_position;
178 v3f camera_direction = m_camera_direction;
179 f32 camera_fov = m_camera_fov;
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;
218 for(core::map<v2s16, MapSector*>::Iterator
219 si = m_sectors.getIterator();
220 si.atEnd() == false; si++)
222 MapSector *sector = si.getNode()->getValue();
223 v2s16 sp = sector->getPos();
225 if(m_control.range_all == false)
227 if(sp.X < p_blocks_min.X
228 || sp.X > p_blocks_max.X
229 || sp.Y < p_blocks_min.Z
230 || sp.Y > p_blocks_max.Z)
234 core::list< MapBlock * > sectorblocks;
235 sector->getBlocks(sectorblocks);
238 Loop through blocks in sector
241 u32 sector_blocks_drawn = 0;
243 core::list< MapBlock * >::Iterator i;
244 for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
246 MapBlock *block = *i;
249 Compare block position to camera position, skip
250 if not seen on display
253 float range = 100000 * BS;
254 if(m_control.range_all == false)
255 range = m_control.wanted_range * BS;
258 if(isBlockInSight(block->getPos(), camera_position,
259 camera_direction, camera_fov,
265 // This is ugly (spherical distance limit?)
266 /*if(m_control.range_all == false &&
267 d - 0.5*BS*MAP_BLOCKSIZE > range)
273 Ignore if mesh doesn't exist
276 //JMutexAutoLock lock(block->mesh_mutex);
278 if(block->mesh == NULL){
279 blocks_in_range_without_mesh++;
288 // No occlusion culling when free_move is on and camera is
290 bool occlusion_culling_enabled = true;
291 if(g_settings->getBool("free_move")){
292 MapNode n = getNodeNoEx(cam_pos_nodes);
293 if(n.getContent() == CONTENT_IGNORE ||
294 nodemgr->get(n).solidness == 2)
295 occlusion_culling_enabled = false;
298 v3s16 cpn = block->getPos() * MAP_BLOCKSIZE;
299 cpn += v3s16(MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2);
302 float startoff = BS*1;
303 float endoff = -BS*MAP_BLOCKSIZE*1.42*1.42;
304 v3s16 spn = cam_pos_nodes + v3s16(0,0,0);
305 s16 bs2 = MAP_BLOCKSIZE/2 + 1;
306 u32 needed_count = 1;
308 occlusion_culling_enabled &&
309 isOccluded(this, spn, cpn + v3s16(0,0,0),
310 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
311 isOccluded(this, spn, cpn + v3s16(bs2,bs2,bs2),
312 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
313 isOccluded(this, spn, cpn + v3s16(bs2,bs2,-bs2),
314 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
315 isOccluded(this, spn, cpn + v3s16(bs2,-bs2,bs2),
316 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
317 isOccluded(this, spn, cpn + v3s16(bs2,-bs2,-bs2),
318 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
319 isOccluded(this, spn, cpn + v3s16(-bs2,bs2,bs2),
320 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
321 isOccluded(this, spn, cpn + v3s16(-bs2,bs2,-bs2),
322 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
323 isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,bs2),
324 step, stepfac, startoff, endoff, needed_count, nodemgr) &&
325 isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,-bs2),
326 step, stepfac, startoff, endoff, needed_count, nodemgr)
329 blocks_occlusion_culled++;
333 // This block is in range. Reset usage timer.
334 block->resetUsageTimer();
336 // Limit block count in case of a sudden increase
337 blocks_would_have_drawn++;
338 if(blocks_drawn >= m_control.wanted_max_blocks
339 && m_control.range_all == false
340 && d > m_control.wanted_min_range * BS)
345 m_drawlist[block->getPos()] = block;
347 sector_blocks_drawn++;
350 } // foreach sectorblocks
352 if(sector_blocks_drawn != 0)
353 m_last_drawn_sectors[sp] = true;
356 m_control.blocks_would_have_drawn = blocks_would_have_drawn;
357 m_control.blocks_drawn = blocks_drawn;
359 g_profiler->avg("CM: blocks in range", blocks_in_range);
360 g_profiler->avg("CM: blocks occlusion culled", blocks_occlusion_culled);
361 if(blocks_in_range != 0)
362 g_profiler->avg("CM: blocks in range without mesh (frac)",
363 (float)blocks_in_range_without_mesh/blocks_in_range);
364 g_profiler->avg("CM: blocks drawn", blocks_drawn);
365 g_profiler->avg("CM: wanted max blocks", m_control.wanted_max_blocks);
371 core::list<scene::IMeshBuffer*> bufs;
374 struct MeshBufListList
376 core::list<MeshBufList> lists;
383 void add(scene::IMeshBuffer *buf)
385 for(core::list<MeshBufList>::Iterator i = lists.begin();
386 i != lists.end(); i++){
388 if(l.m == buf->getMaterial()){
389 l.bufs.push_back(buf);
394 l.m = buf->getMaterial();
395 l.bufs.push_back(buf);
400 void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
402 DSTACK(__FUNCTION_NAME);
404 bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
407 if(pass == scene::ESNRP_SOLID)
408 prefix = "CM: solid: ";
410 prefix = "CM: transparent: ";
413 This is called two times per frame, reset on the non-transparent one
415 if(pass == scene::ESNRP_SOLID)
417 m_last_drawn_sectors.clear();
420 bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
421 bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
422 bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
425 Get time for measuring timeout.
427 Measuring time is very useful for long delays when the
428 machine is swapping a lot.
433 Get animation parameters
435 float animation_time = m_client->getAnimationTime();
436 int crack = m_client->getCrackLevel();
437 u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
439 m_camera_mutex.Lock();
440 v3f camera_position = m_camera_position;
441 v3f camera_direction = m_camera_direction;
442 f32 camera_fov = m_camera_fov;
443 m_camera_mutex.Unlock();
446 Get all blocks and draw all visible ones
449 v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
451 v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
453 v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
454 v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
456 // Take a fair amount as we will be dropping more out later
457 // Umm... these additions are a bit strange but they are needed.
459 p_nodes_min.X / MAP_BLOCKSIZE - 3,
460 p_nodes_min.Y / MAP_BLOCKSIZE - 3,
461 p_nodes_min.Z / MAP_BLOCKSIZE - 3);
463 p_nodes_max.X / MAP_BLOCKSIZE + 1,
464 p_nodes_max.Y / MAP_BLOCKSIZE + 1,
465 p_nodes_max.Z / MAP_BLOCKSIZE + 1);
467 u32 vertex_count = 0;
468 u32 meshbuffer_count = 0;
470 // For limiting number of mesh animations per frame
471 u32 mesh_animate_count = 0;
472 u32 mesh_animate_count_far = 0;
474 // Blocks that were drawn and had a mesh
475 u32 blocks_drawn = 0;
476 // Blocks which had a corresponding meshbuffer for this pass
477 u32 blocks_had_pass_meshbuf = 0;
478 // Blocks from which stuff was actually drawn
479 u32 blocks_without_stuff = 0;
482 Draw the selected MapBlocks
486 ScopeProfiler sp(g_profiler, prefix+"drawing blocks", SPT_AVG);
488 MeshBufListList drawbufs;
490 for(core::map<v3s16, MapBlock*>::Iterator
491 i = m_drawlist.getIterator();
492 i.atEnd() == false; i++)
494 MapBlock *block = i.getNode()->getValue();
496 // If the mesh of the block happened to get deleted, ignore it
497 if(block->mesh == NULL)
501 if(isBlockInSight(block->getPos(), camera_position,
502 camera_direction, camera_fov,
503 100000*BS, &d) == false)
510 //JMutexAutoLock lock(block->mesh_mutex);
511 MapBlockMesh *mapBlockMesh = block->mesh;
512 assert(mapBlockMesh);
513 // Pretty random but this should work somewhat nicely
514 bool faraway = d >= BS*50;
515 //bool faraway = d >= m_control.wanted_range * BS;
516 if(mapBlockMesh->isAnimationForced() ||
518 mesh_animate_count_far < (m_control.range_all ? 200 : 50))
520 bool animated = mapBlockMesh->animate(
526 mesh_animate_count++;
527 if(animated && faraway)
528 mesh_animate_count_far++;
532 mapBlockMesh->decreaseAnimationForceTimer();
537 Get the meshbuffers of the block
540 //JMutexAutoLock lock(block->mesh_mutex);
542 MapBlockMesh *mapBlockMesh = block->mesh;
543 assert(mapBlockMesh);
545 scene::SMesh *mesh = mapBlockMesh->getMesh();
548 u32 c = mesh->getMeshBufferCount();
549 for(u32 i=0; i<c; i++)
551 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
553 buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
554 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
555 buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
557 const video::SMaterial& material = buf->getMaterial();
558 video::IMaterialRenderer* rnd =
559 driver->getMaterialRenderer(material.MaterialType);
560 bool transparent = (rnd && rnd->isTransparent());
561 if(transparent == is_transparent_pass)
563 if(buf->getVertexCount() == 0)
564 errorstream<<"Block ["<<analyze_block(block)
565 <<"] contains an empty meshbuf"<<std::endl;
572 core::list<MeshBufList> &lists = drawbufs.lists;
574 int timecheck_counter = 0;
575 for(core::list<MeshBufList>::Iterator i = lists.begin();
576 i != lists.end(); i++)
580 if(timecheck_counter > 50)
582 timecheck_counter = 0;
584 if(time2 > time1 + 4)
586 infostream<<"ClientMap::renderMap(): "
587 "Rendering takes ages, returning."
594 MeshBufList &list = *i;
596 driver->setMaterial(list.m);
598 for(core::list<scene::IMeshBuffer*>::Iterator j = list.bufs.begin();
599 j != list.bufs.end(); j++)
601 scene::IMeshBuffer *buf = *j;
602 driver->drawMeshBuffer(buf);
603 vertex_count += buf->getVertexCount();
608 Draw the faces of the block
611 //JMutexAutoLock lock(block->mesh_mutex);
613 MapBlockMesh *mapBlockMesh = block->mesh;
614 assert(mapBlockMesh);
616 scene::SMesh *mesh = mapBlockMesh->getMesh();
619 u32 c = mesh->getMeshBufferCount();
620 bool stuff_actually_drawn = false;
621 for(u32 i=0; i<c; i++)
623 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
624 const video::SMaterial& material = buf->getMaterial();
625 video::IMaterialRenderer* rnd =
626 driver->getMaterialRenderer(material.MaterialType);
627 bool transparent = (rnd && rnd->isTransparent());
628 // Render transparent on transparent pass and likewise.
629 if(transparent == is_transparent_pass)
631 if(buf->getVertexCount() == 0)
632 errorstream<<"Block ["<<analyze_block(block)
633 <<"] contains an empty meshbuf"<<std::endl;
635 This *shouldn't* hurt too much because Irrlicht
636 doesn't change opengl textures if the old
637 material has the same texture.
639 driver->setMaterial(buf->getMaterial());
640 driver->drawMeshBuffer(buf);
641 vertex_count += buf->getVertexCount();
643 stuff_actually_drawn = true;
646 if(stuff_actually_drawn)
647 blocks_had_pass_meshbuf++;
649 blocks_without_stuff++;
655 // Log only on solid pass because values are the same
656 if(pass == scene::ESNRP_SOLID){
657 g_profiler->avg("CM: animated meshes", mesh_animate_count);
658 g_profiler->avg("CM: animated meshes (far)", mesh_animate_count_far);
661 g_profiler->avg(prefix+"vertices drawn", vertex_count);
662 if(blocks_had_pass_meshbuf != 0)
663 g_profiler->avg(prefix+"meshbuffers per block",
664 (float)meshbuffer_count / (float)blocks_had_pass_meshbuf);
665 if(blocks_drawn != 0)
666 g_profiler->avg(prefix+"empty blocks (frac)",
667 (float)blocks_without_stuff / blocks_drawn);
669 /*infostream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
670 <<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
673 static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
674 float step_multiplier, float start_distance, float end_distance,
675 INodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d,
676 int *result, bool *sunlight_seen)
678 int brightness_sum = 0;
679 int brightness_count = 0;
680 float distance = start_distance;
683 pf += dir * distance;
685 bool nonlight_seen = false;
686 bool allow_allowing_non_sunlight_propagates = false;
687 bool allow_non_sunlight_propagates = false;
688 // Check content nearly at camera position
690 v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS);
691 MapNode n = map->getNodeNoEx(p);
692 if(ndef->get(n).param_type == CPT_LIGHT &&
693 !ndef->get(n).sunlight_propagates)
694 allow_allowing_non_sunlight_propagates = true;
696 // If would start at CONTENT_IGNORE, start closer
698 v3s16 p = floatToInt(pf, BS);
699 MapNode n = map->getNodeNoEx(p);
700 if(n.getContent() == CONTENT_IGNORE){
702 pf = p0 + dir * 2*newd;
707 for(int i=0; distance < end_distance; i++){
710 step *= step_multiplier;
712 v3s16 p = floatToInt(pf, BS);
713 MapNode n = map->getNodeNoEx(p);
714 if(allow_allowing_non_sunlight_propagates && i == 0 &&
715 ndef->get(n).param_type == CPT_LIGHT &&
716 !ndef->get(n).sunlight_propagates){
717 allow_non_sunlight_propagates = true;
719 if(ndef->get(n).param_type != CPT_LIGHT ||
720 (!ndef->get(n).sunlight_propagates &&
721 !allow_non_sunlight_propagates)){
722 nonlight_seen = true;
728 if(distance >= sunlight_min_d && *sunlight_seen == false
729 && nonlight_seen == false)
730 if(n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
731 *sunlight_seen = true;
733 brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef));
737 if(brightness_count == 0)
739 *result = brightness_sum / brightness_count;
740 /*std::cerr<<"Sampled "<<brightness_count<<" points; result="
741 <<(*result)<<std::endl;*/
745 int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
746 int oldvalue, bool *sunlight_seen_result)
748 const bool debugprint = false;
749 INodeDefManager *ndef = m_gamedef->ndef();
750 static v3f z_directions[50] = {
753 static f32 z_offsets[sizeof(z_directions)/sizeof(*z_directions)] = {
756 if(z_directions[0].X < -99){
757 for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
758 z_directions[i] = v3f(
759 0.01 * myrand_range(-100, 100),
761 0.01 * myrand_range(-100, 100)
763 z_offsets[i] = 0.01 * myrand_range(0,100);
767 std::cerr<<"In goes "<<PP(m_camera_direction)<<", out comes ";
768 int sunlight_seen_count = 0;
769 float sunlight_min_d = max_d*0.8;
770 if(sunlight_min_d > 35*BS)
771 sunlight_min_d = 35*BS;
772 core::array<int> values;
773 for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
774 v3f z_dir = z_directions[i];
776 core::CMatrix4<f32> a;
777 a.buildRotateFromTo(v3f(0,1,0), z_dir);
778 v3f dir = m_camera_direction;
783 step = max_d / 35 * 1.5;
784 float off = step * z_offsets[i];
785 bool sunlight_seen_now = false;
786 bool ok = getVisibleBrightness(this, m_camera_position, dir,
787 step, 1.0, max_d*0.6+off, max_d, ndef, daylight_factor,
789 &br, &sunlight_seen_now);
790 if(sunlight_seen_now)
791 sunlight_seen_count++;
794 values.push_back(br);
795 // Don't try too much if being in the sun is clear
796 if(sunlight_seen_count >= 20)
799 int brightness_sum = 0;
800 int brightness_count = 0;
802 u32 num_values_to_use = values.size();
803 if(num_values_to_use >= 10)
804 num_values_to_use -= num_values_to_use/2;
805 else if(num_values_to_use >= 7)
806 num_values_to_use -= num_values_to_use/3;
807 u32 first_value_i = (values.size() - num_values_to_use) / 2;
809 for(u32 i=0; i < first_value_i; i++)
810 std::cerr<<values[i]<<" ";
813 for(u32 i=first_value_i; i < first_value_i+num_values_to_use; i++){
815 std::cerr<<values[i]<<" ";
816 brightness_sum += values[i];
821 for(u32 i=first_value_i+num_values_to_use; i < values.size(); i++)
822 std::cerr<<values[i]<<" ";
825 if(brightness_count == 0){
826 MapNode n = getNodeNoEx(floatToInt(m_camera_position, BS));
827 if(ndef->get(n).param_type == CPT_LIGHT){
828 ret = decode_light(n.getLightBlend(daylight_factor, ndef));
831 //ret = blend_light(255, 0, daylight_factor);
834 /*float pre = (float)brightness_sum / (float)brightness_count;
840 ret = MYMAX(0, MYMIN(255, preint));*/
841 ret = brightness_sum / brightness_count;
844 std::cerr<<"Result: "<<ret<<" sunlight_seen_count="
845 <<sunlight_seen_count<<std::endl;
846 *sunlight_seen_result = (sunlight_seen_count > 0);
850 void ClientMap::renderPostFx()
852 INodeDefManager *nodemgr = m_gamedef->ndef();
854 // Sadly ISceneManager has no "post effects" render pass, in that case we
855 // could just register for that and handle it in renderMap().
857 m_camera_mutex.Lock();
858 v3f camera_position = m_camera_position;
859 m_camera_mutex.Unlock();
861 MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
863 // - If the player is in a solid node, make everything black.
864 // - If the player is in liquid, draw a semi-transparent overlay.
865 const ContentFeatures& features = nodemgr->get(n);
866 video::SColor post_effect_color = features.post_effect_color;
867 if(features.solidness == 2 && !(g_settings->getBool("noclip") && m_gamedef->checkLocalPrivilege("noclip")))
869 post_effect_color = video::SColor(255, 0, 0, 0);
871 if (post_effect_color.getAlpha() != 0)
873 // Draw a full-screen rectangle
874 video::IVideoDriver* driver = SceneManager->getVideoDriver();
875 v2u32 ss = driver->getScreenSize();
876 core::rect<s32> rect(0,0, ss.X, ss.Y);
877 driver->draw2DRectangle(post_effect_color, rect);
881 void ClientMap::PrintInfo(std::ostream &out)