aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/camera.cpp5
-rw-r--r--src/client.cpp52
-rw-r--r--src/clientiface.cpp15
-rw-r--r--src/clientmap.h4
-rw-r--r--src/content_sao.cpp18
-rw-r--r--src/content_sao.h6
-rw-r--r--src/localplayer.cpp2
-rw-r--r--src/localplayer.h2
-rw-r--r--src/network/networkprotocol.h2
-rw-r--r--src/network/serverpackethandler.cpp13
-rw-r--r--src/server.cpp8
11 files changed, 99 insertions, 28 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index b86f218fe..43980db1c 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -484,13 +484,12 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
void Camera::updateViewingRange()
{
+ f32 viewing_range = g_settings->getFloat("viewing_range");
+ m_draw_control.wanted_range = viewing_range;
if (m_draw_control.range_all) {
m_cameranode->setFarValue(100000.0);
return;
}
-
- f32 viewing_range = g_settings->getFloat("viewing_range");
- m_draw_control.wanted_range = viewing_range;
m_cameranode->setFarValue((viewing_range < 2000) ? 2000 * BS : viewing_range * BS);
}
diff --git a/src/client.cpp b/src/client.cpp
index 3726f5bc4..5a3dc5df7 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -930,13 +930,16 @@ void Client::Send(NetworkPacket* pkt)
}
// Will fill up 12 + 12 + 4 + 4 + 4 bytes
-void writePlayerPos(LocalPlayer *myplayer, NetworkPacket *pkt)
+void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt)
{
- v3f pf = myplayer->getPosition() * 100;
- v3f sf = myplayer->getSpeed() * 100;
- s32 pitch = myplayer->getPitch() * 100;
- s32 yaw = myplayer->getYaw() * 100;
- u32 keyPressed = myplayer->keyPressed;
+ v3f pf = myplayer->getPosition() * 100;
+ v3f sf = myplayer->getSpeed() * 100;
+ s32 pitch = myplayer->getPitch() * 100;
+ s32 yaw = myplayer->getYaw() * 100;
+ u32 keyPressed = myplayer->keyPressed;
+ // scaled by 80, so that pi can fit into a u8
+ u8 fov = clientMap->getCameraFov() * 80;
+ u8 wanted_range = clientMap->getControl().wanted_range / MAP_BLOCKSIZE;
v3s32 position(pf.X, pf.Y, pf.Z);
v3s32 speed(sf.X, sf.Y, sf.Z);
@@ -948,9 +951,11 @@ void writePlayerPos(LocalPlayer *myplayer, NetworkPacket *pkt)
[12+12] s32 pitch*100
[12+12+4] s32 yaw*100
[12+12+4+4] u32 keyPressed
+ [12+12+4+4+1] u8 fov*80
+ [12+12+4+4+4+1] u8 wanted_range / MAP_BLOCKSIZE
*/
-
*pkt << position << speed << pitch << yaw << keyPressed;
+ *pkt << fov << wanted_range;
}
void Client::interact(u8 action, const PointedThing& pointed)
@@ -992,7 +997,7 @@ void Client::interact(u8 action, const PointedThing& pointed)
pkt.putLongString(tmp_os.str());
- writePlayerPos(myplayer, &pkt);
+ writePlayerPos(myplayer, &m_env.getClientMap(), &pkt);
Send(&pkt);
}
@@ -1296,19 +1301,30 @@ void Client::sendPlayerPos()
if(myplayer == NULL)
return;
+ ClientMap &map = m_env.getClientMap();
+
+ u8 camera_fov = map.getCameraFov();
+ u8 wanted_range = map.getControl().wanted_range;
+
// Save bandwidth by only updating position when something changed
if(myplayer->last_position == myplayer->getPosition() &&
- myplayer->last_speed == myplayer->getSpeed() &&
- myplayer->last_pitch == myplayer->getPitch() &&
- myplayer->last_yaw == myplayer->getYaw() &&
- myplayer->last_keyPressed == myplayer->keyPressed)
+ myplayer->last_speed == myplayer->getSpeed() &&
+ myplayer->last_pitch == myplayer->getPitch() &&
+ myplayer->last_yaw == myplayer->getYaw() &&
+ myplayer->last_keyPressed == myplayer->keyPressed &&
+ myplayer->last_camera_fov == camera_fov &&
+ myplayer->last_wanted_range == wanted_range)
return;
- myplayer->last_position = myplayer->getPosition();
- myplayer->last_speed = myplayer->getSpeed();
- myplayer->last_pitch = myplayer->getPitch();
- myplayer->last_yaw = myplayer->getYaw();
- myplayer->last_keyPressed = myplayer->keyPressed;
+ myplayer->last_position = myplayer->getPosition();
+ myplayer->last_speed = myplayer->getSpeed();
+ myplayer->last_pitch = myplayer->getPitch();
+ myplayer->last_yaw = myplayer->getYaw();
+ myplayer->last_keyPressed = myplayer->keyPressed;
+ myplayer->last_camera_fov = camera_fov;
+ myplayer->last_wanted_range = wanted_range;
+
+ //infostream << "Sending Player Position information" << std::endl;
u16 our_peer_id;
{
@@ -1324,7 +1340,7 @@ void Client::sendPlayerPos()
NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4);
- writePlayerPos(myplayer, &pkt);
+ writePlayerPos(myplayer, &map, &pkt);
Send(&pkt);
}
diff --git a/src/clientiface.cpp b/src/clientiface.cpp
index bdc16f31c..abe878ecc 100644
--- a/src/clientiface.cpp
+++ b/src/clientiface.cpp
@@ -173,12 +173,20 @@ void RemoteClient::GetNextBlocks (
*/
s32 new_nearest_unsent_d = -1;
- const s16 full_d_max = g_settings->getS16("max_block_send_distance");
- const s16 d_opt = g_settings->getS16("block_send_optimize_distance");
+ // get view range and camera fov from the client
+ s16 wanted_range = sao->getWantedRange();
+ float camera_fov = sao->getFov();
+ // if FOV, wanted_range are not available (old client), fall back to old default
+ if (wanted_range <= 0) wanted_range = 1000;
+ if (camera_fov <= 0) camera_fov = (72.0*M_PI/180) * 4./3.;
+
+ const s16 full_d_max = MYMIN(g_settings->getS16("max_block_send_distance"), wanted_range);
+ const s16 d_opt = MYMIN(g_settings->getS16("block_send_optimize_distance"), wanted_range);
const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
+ //infostream << "Fov from client " << camera_fov << " full_d_max " << full_d_max << std::endl;
s16 d_max = full_d_max;
- s16 d_max_gen = g_settings->getS16("max_block_generate_distance");
+ s16 d_max_gen = MYMIN(g_settings->getS16("max_block_generate_distance"), wanted_range);
// Don't loop very much at a time
s16 max_d_increment_at_time = 2;
@@ -242,7 +250,6 @@ void RemoteClient::GetNextBlocks (
FOV setting. The default of 72 degrees is fine.
*/
- float camera_fov = (72.0*M_PI/180) * 4./3.;
if(isBlockInSight(p, camera_pos, camera_dir, camera_fov, d_blocks_in_sight) == false)
{
continue;
diff --git a/src/clientmap.h b/src/clientmap.h
index 8855eecf6..cb686ff33 100644
--- a/src/clientmap.h
+++ b/src/clientmap.h
@@ -138,7 +138,9 @@ public:
{
return (m_last_drawn_sectors.find(p) != m_last_drawn_sectors.end());
}
-
+
+ const MapDrawControl & getControl() const { return m_control; }
+ f32 getCameraFov() const { return m_camera_fov; }
private:
Client *m_client;
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 609673ed9..77ab51a02 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -781,6 +781,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, u16 peer_id_, bool is_singleplayer
m_attachment_sent(false),
m_breath(PLAYER_MAX_BREATH),
m_pitch(0),
+ m_fov(0),
+ m_wanted_range(0),
// public
m_physics_override_speed(1),
m_physics_override_jump(1),
@@ -1099,6 +1101,22 @@ void PlayerSAO::setYaw(const float yaw)
UnitSAO::setYaw(yaw);
}
+void PlayerSAO::setFov(const float fov)
+{
+ if (m_player && fov != m_fov)
+ m_player->setDirty(true);
+
+ m_fov = fov;
+}
+
+void PlayerSAO::setWantedRange(const s16 range)
+{
+ if (m_player && range != m_wanted_range)
+ m_player->setDirty(true);
+
+ m_wanted_range = range;
+}
+
void PlayerSAO::setYawAndSend(const float yaw)
{
setYaw(yaw);
diff --git a/src/content_sao.h b/src/content_sao.h
index c5b066f50..86255183d 100644
--- a/src/content_sao.h
+++ b/src/content_sao.h
@@ -214,6 +214,10 @@ public:
f32 getRadPitch() const { return m_pitch * core::DEGTORAD; }
// Deprecated
f32 getRadPitchDep() const { return -1.0 * m_pitch * core::DEGTORAD; }
+ void setFov(const float pitch);
+ f32 getFov() const { return m_fov; }
+ void setWantedRange(const s16 range);
+ s16 getWantedRange() const { return m_wanted_range; }
/*
Interaction interface
@@ -364,6 +368,8 @@ private:
bool m_attachment_sent;
u16 m_breath;
f32 m_pitch;
+ f32 m_fov;
+ s16 m_wanted_range;
public:
float m_physics_override_speed;
float m_physics_override_jump;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 71efb2343..4d0ca0600 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -56,6 +56,8 @@ LocalPlayer::LocalPlayer(Client *gamedef, const char *name):
last_pitch(0),
last_yaw(0),
last_keyPressed(0),
+ last_camera_fov(0),
+ last_wanted_range(0),
camera_impact(0.f),
last_animation(NO_ANIM),
hotbar_image(""),
diff --git a/src/localplayer.h b/src/localplayer.h
index 749f8f8ce..7a1cb7466 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -75,6 +75,8 @@ public:
float last_pitch;
float last_yaw;
unsigned int last_keyPressed;
+ u8 last_camera_fov;
+ u8 last_wanted_range;
float camera_impact;
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index e3fcae0c6..c9919e1c4 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -651,6 +651,8 @@ enum ToServerCommand
[2+12+12] s32 pitch*100
[2+12+12+4] s32 yaw*100
[2+12+12+4+4] u32 keyPressed
+ [2+12+12+4+4+1] u8 fov*80
+ [2+12+12+4+4+4+1] u8 wanted_range / MAP_BLOCKSIZE
*/
TOSERVER_GOTBLOCKS = 0x24,
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 70eb0a828..5e50bb865 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -782,6 +782,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
v3s32 ps, ss;
s32 f32pitch, f32yaw;
+ u8 f32fov;
*pkt >> ps;
*pkt >> ss;
@@ -792,8 +793,18 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
f32 yaw = (f32)f32yaw / 100.0;
u32 keyPressed = 0;
+ // default behavior (in case an old client doesn't send these)
+ f32 fov = (72.0*M_PI/180) * 4./3.;
+ u8 wanted_range = 0;
+
if (pkt->getRemainingBytes() >= 4)
*pkt >> keyPressed;
+ if (pkt->getRemainingBytes() >= 1) {
+ *pkt >> f32fov;
+ fov = (f32)f32fov / 80.0;
+ }
+ if (pkt->getRemainingBytes() >= 1)
+ *pkt >> wanted_range;
v3f position((f32)ps.X / 100.0, (f32)ps.Y / 100.0, (f32)ps.Z / 100.0);
v3f speed((f32)ss.X / 100.0, (f32)ss.Y / 100.0, (f32)ss.Z / 100.0);
@@ -805,6 +816,8 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
player->setSpeed(speed);
playersao->setPitch(pitch);
playersao->setYaw(yaw);
+ playersao->setFov(fov);
+ playersao->setWantedRange(wanted_range);
player->keyPressed = keyPressed;
player->control.up = (keyPressed & 1);
player->control.down = (keyPressed & 2);
diff --git a/src/server.cpp b/src/server.cpp
index fe67ac96e..c9d5c7129 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -705,11 +705,15 @@ void Server::AsyncRunStep(bool initial_step)
if (playersao == NULL)
continue;
+ s16 my_radius = MYMIN(radius, playersao->getWantedRange() * MAP_BLOCKSIZE);
+ if (my_radius <= 0) my_radius = radius;
+ //infostream << "Server: Active Radius " << my_radius << std::endl;
+
std::queue<u16> removed_objects;
std::queue<u16> added_objects;
- m_env->getRemovedActiveObjects(playersao, radius, player_radius,
+ m_env->getRemovedActiveObjects(playersao, my_radius, player_radius,
client->m_known_objects, removed_objects);
- m_env->getAddedActiveObjects(playersao, radius, player_radius,
+ m_env->getAddedActiveObjects(playersao, my_radius, player_radius,
client->m_known_objects, added_objects);
// Ignore if nothing happened
n class="hl opt">.MinEdge.Z; z<=m_area.MaxEdge.Z; z++) { for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++) { u8 f = m_flags[m_area.index(x,y,z)]; char c; if(f & VOXELFLAG_NO_DATA) c = 'N'; else { c = 'X'; MapNode n = m_data[m_area.index(x,y,z)]; content_t m = n.getContent(); u8 pr = n.param2; if(mode == VOXELPRINT_MATERIAL) { if(m <= 9) c = m + '0'; } else if(mode == VOXELPRINT_WATERPRESSURE) { if(ndef->get(m).isLiquid()) { c = 'w'; if(pr <= 9) c = pr + '0'; } else if(m == CONTENT_AIR) { c = ' '; } else { c = '#'; } } else if(mode == VOXELPRINT_LIGHT_DAY) { if(ndef->get(m).light_source != 0) c = 'S'; else if(ndef->get(m).light_propagates == false) c = 'X'; else { u8 light = n.getLight(LIGHTBANK_DAY, ndef); if(light < 10) c = '0' + light; else c = 'a' + (light-10); } } } o<<c; } o<<' '; } o<<std::endl; } } void VoxelManipulator::addArea(const VoxelArea &area) { // Cancel if requested area has zero volume if (area.hasEmptyExtent()) return; // Cancel if m_area already contains the requested area if(m_area.contains(area)) return; TimeTaker timer("addArea", &addarea_time); // Calculate new area VoxelArea new_area; // New area is the requested area if m_area has zero volume if(m_area.hasEmptyExtent()) { new_area = area; } // Else add requested area to m_area else { new_area = m_area; new_area.addArea(area); } s32 new_size = new_area.getVolume(); /*dstream<<"adding area "; area.print(dstream); dstream<<", old area "; m_area.print(dstream); dstream<<", new area "; new_area.print(dstream); dstream<<", new_size="<<new_size; dstream<<std::endl;*/ // Allocate new data and clear flags MapNode *new_data = new MapNode[new_size]; assert(new_data); u8 *new_flags = new u8[new_size]; assert(new_flags); memset(new_flags, VOXELFLAG_NO_DATA, new_size); // Copy old data s32 old_x_width = m_area.MaxEdge.X - m_area.MinEdge.X + 1; for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++) for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++) { unsigned int old_index = m_area.index(m_area.MinEdge.X,y,z); unsigned int new_index = new_area.index(m_area.MinEdge.X,y,z); memcpy(&new_data[new_index], &m_data[old_index], old_x_width * sizeof(MapNode)); memcpy(&new_flags[new_index], &m_flags[old_index], old_x_width * sizeof(u8)); } // Replace area, data and flags m_area = new_area; MapNode *old_data = m_data; u8 *old_flags = m_flags; /*dstream<<"old_data="<<(int)old_data<<", new_data="<<(int)new_data <<", old_flags="<<(int)m_flags<<", new_flags="<<(int)new_flags<<std::endl;*/ m_data = new_data; m_flags = new_flags; delete[] old_data; delete[] old_flags; //dstream<<"addArea done"<<std::endl; } void VoxelManipulator::copyFrom(MapNode *src, const VoxelArea& src_area, v3s16 from_pos, v3s16 to_pos, v3s16 size) { /* The reason for this optimised code is that we're a member function * and the data type/layout of m_data is know to us: it's stored as * [z*h*w + y*h + x]. Therefore we can take the calls to m_area index * (which performs the preceding mapping/indexing of m_data) out of the * inner loop and calculate the next index as we're iterating to gain * performance. * * src_step and dest_step is the amount required to be added to our index * every time y increments. Because the destination area may be larger * than the source area we need one additional variable (otherwise we could * just continue adding dest_step as is done for the source data): dest_mod. * dest_mod is the difference in size between a "row" in the source data * and a "row" in the destination data (I am using the term row loosely * and for illustrative purposes). E.g. * * src <-------------------->|'''''' dest mod '''''''' * dest <---------------------------------------------> * * dest_mod (it's essentially a modulus) is added to the destination index * after every full iteration of the y span. * * This method falls under the category "linear array and incrementing * index". */ s32 src_step = src_area.getExtent().X; s32 dest_step = m_area.getExtent().X; s32 dest_mod = m_area.index(to_pos.X, to_pos.Y, to_pos.Z + 1) - m_area.index(to_pos.X, to_pos.Y, to_pos.Z) - dest_step * size.Y; s32 i_src = src_area.index(from_pos.X, from_pos.Y, from_pos.Z); s32 i_local = m_area.index(to_pos.X, to_pos.Y, to_pos.Z); for (s16 z = 0; z < size.Z; z++) { for (s16 y = 0; y < size.Y; y++) { memcpy(&m_data[i_local], &src[i_src], size.X * sizeof(*m_data)); memset(&m_flags[i_local], 0, size.X); i_src += src_step; i_local += dest_step; } i_local += dest_mod; } } void VoxelManipulator::copyTo(MapNode *dst, const VoxelArea& dst_area, v3s16 dst_pos, v3s16 from_pos, v3s16 size) { for(s16 z=0; z<size.Z; z++) for(s16 y=0; y<size.Y; y++) { s32 i_dst = dst_area.index(dst_pos.X, dst_pos.Y+y, dst_pos.Z+z); s32 i_local = m_area.index(from_pos.X, from_pos.Y+y, from_pos.Z+z); for (s16 x = 0; x < size.X; x++) { if (m_data[i_local].getContent() != CONTENT_IGNORE) dst[i_dst] = m_data[i_local]; i_dst++; i_local++; } } } /* Algorithms ----------------------------------------------------- */ void VoxelManipulator::clearFlag(u8 flags) { // 0-1ms on moderate area TimeTaker timer("clearFlag", &clearflag_time); //v3s16 s = m_area.getExtent(); /*dstream<<"clearFlag clearing area of size " <<""<<s.X<<"x"<<s.Y<<"x"<<s.Z<<"" <<std::endl;*/ //s32 count = 0; /*for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++) for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++) for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++) { u8 f = m_flags[m_area.index(x,y,z)]; m_flags[m_area.index(x,y,z)] &= ~flags; if(m_flags[m_area.index(x,y,z)] != f) count++; }*/ s32 volume = m_area.getVolume(); for(s32 i=0; i<volume; i++) { m_flags[i] &= ~flags; } /*s32 volume = m_area.getVolume(); for(s32 i=0; i<volume; i++) { u8 f = m_flags[i]; m_flags[i] &= ~flags; if(m_flags[i] != f) count++; } dstream<<"clearFlag changed "<<count<<" flags out of " <<volume<<" nodes"<<std::endl;*/ } void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, std::set<v3s16> & light_sources, INodeDefManager *nodemgr) { v3s16 dirs[6] = { v3s16(0,0,1), // back v3s16(0,1,0), // top v3s16(1,0,0), // right v3s16(0,0,-1), // front v3s16(0,-1,0), // bottom v3s16(-1,0,0), // left }; VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); addArea(voxel_area); // Loop through 6 neighbors for(u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = p + dirs[i]; u32 n2i = m_area.index(n2pos); if(m_flags[n2i] & VOXELFLAG_NO_DATA) continue; MapNode &n2 = m_data[n2i]; /* If the neighbor is dimmer than what was specified as oldlight (the light of the previous node) */ u8 light2 = n2.getLight(bank, nodemgr); if(light2 < oldlight) { /* And the neighbor is transparent and it has some light */ if(nodemgr->get(n2).light_propagates && light2 != 0) { /* Set light to 0 and add to queue */ n2.setLight(bank, 0, nodemgr); unspreadLight(bank, n2pos, light2, light_sources, nodemgr); /* Remove from light_sources if it is there NOTE: This doesn't happen nearly at all */ /*if(light_sources.find(n2pos)) { std::cout<<"Removed from light_sources"<<std::endl; light_sources.remove(n2pos); }*/ } } else{ light_sources.insert(n2pos); } } } /* Goes recursively through the neighbours of the node. Alters only transparent nodes. If the lighting of the neighbour is lower than the lighting of the node was (before changing it to 0 at the step before), the lighting of the neighbour is set to 0 and then the same stuff repeats for the neighbour. The ending nodes of the routine are stored in light_sources. This is useful when a light is removed. In such case, this routine can be called for the light node and then again for light_sources to re-light the area without the removed light. values of from_nodes are lighting values. */ void VoxelManipulator::unspreadLight(enum LightBank bank, std::map<v3s16, u8> & from_nodes, std::set<v3s16> & light_sources, INodeDefManager *nodemgr) { if(from_nodes.empty()) return; for(std::map<v3s16, u8>::iterator j = from_nodes.begin(); j != from_nodes.end(); ++j) { unspreadLight(bank, j->first, j->second, light_sources, nodemgr); } } void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr) { const v3s16 dirs[6] = { v3s16(0,0,1), // back v3s16(0,1,0), // top v3s16(1,0,0), // right v3s16(0,0,-1), // front v3s16(0,-1,0), // bottom v3s16(-1,0,0), // left }; VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); addArea(voxel_area); u32 i = m_area.index(p); if(m_flags[i] & VOXELFLAG_NO_DATA) return; MapNode &n = m_data[i]; u8 oldlight = n.getLight(bank, nodemgr); u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors for(u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = p + dirs[i]; u32 n2i = m_area.index(n2pos); if(m_flags[n2i] & VOXELFLAG_NO_DATA) continue; MapNode &n2 = m_data[n2i]; u8 light2 = n2.getLight(bank, nodemgr); /* If the neighbor is brighter than the current node, add to list (it will light up this node on its turn) */ if(light2 > undiminish_light(oldlight)) { spreadLight(bank, n2pos, nodemgr); } /* If the neighbor is dimmer than how much light this node would spread on it, add to list */ if(light2 < newlight) { if(nodemgr->get(n2).light_propagates) { n2.setLight(bank, newlight, nodemgr); spreadLight(bank, n2pos, nodemgr); } } } } const MapNode VoxelManipulator::ContentIgnoreNode = MapNode(CONTENT_IGNORE); /* Lights neighbors of from_nodes, collects all them and then goes on recursively. */ void VoxelManipulator::spreadLight(enum LightBank bank, std::set<v3s16> & from_nodes, INodeDefManager *nodemgr) { const v3s16 dirs[6] = { v3s16(0,0,1), // back v3s16(0,1,0), // top v3s16(1,0,0), // right v3s16(0,0,-1), // front v3s16(0,-1,0), // bottom v3s16(-1,0,0), // left }; if(from_nodes.empty()) return; std::set<v3s16> lighted_nodes; for(std::set<v3s16>::iterator j = from_nodes.begin(); j != from_nodes.end(); ++j) { v3s16 pos = *j; VoxelArea voxel_area(pos - v3s16(1,1,1), pos + v3s16(1,1,1)); addArea(voxel_area); u32 i = m_area.index(pos); if(m_flags[i] & VOXELFLAG_NO_DATA) continue; MapNode &n = m_data[i]; u8 oldlight = n.getLight(bank, nodemgr); u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors for(u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = pos + dirs[i]; try { u32 n2i = m_area.index(n2pos); if(m_flags[n2i] & VOXELFLAG_NO_DATA) continue; MapNode &n2 = m_data[n2i]; u8 light2 = n2.getLight(bank, nodemgr); /* If the neighbor is brighter than the current node, add to list (it will light up this node on its turn) */ if(light2 > undiminish_light(oldlight)) { lighted_nodes.insert(n2pos); } /* If the neighbor is dimmer than how much light this node would spread on it, add to list */ if(light2 < newlight) { if(nodemgr->get(n2).light_propagates) { n2.setLight(bank, newlight, nodemgr); lighted_nodes.insert(n2pos); } } } catch(InvalidPositionException &e) { continue; } } } /*dstream<<"spreadLight(): Changed block " <<blockchangecount<<" times" <<" for "<<from_nodes.size()<<" nodes" <<std::endl;*/ if(!lighted_nodes.empty()) spreadLight(bank, lighted_nodes, nodemgr); } //END