Skip to content

Commit 735fc2a

Browse files
juhdanadrubenwardy
authored andcommitted
Remove unused light updating code
Also remove the unit test that tests the removed algorithms.
1 parent cf0bceb commit 735fc2a

7 files changed

+0
-709
lines changed

src/mapblock.cpp

-192
Original file line numberDiff line numberDiff line change
@@ -132,198 +132,6 @@ std::string MapBlock::getModifiedReasonString()
132132
return reason;
133133
}
134134

135-
/*
136-
Propagates sunlight down through the block.
137-
Doesn't modify nodes that are not affected by sunlight.
138-
139-
Returns false if sunlight at bottom block is invalid.
140-
Returns true if sunlight at bottom block is valid.
141-
Returns true if bottom block doesn't exist.
142-
143-
If there is a block above, continues from it.
144-
If there is no block above, assumes there is sunlight, unless
145-
is_underground is set or highest node is water.
146-
147-
All sunlighted nodes are added to light_sources.
148-
149-
if remove_light==true, sets non-sunlighted nodes black.
150-
151-
if black_air_left!=NULL, it is set to true if non-sunlighted
152-
air is left in block.
153-
*/
154-
bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
155-
bool remove_light, bool *black_air_left)
156-
{
157-
INodeDefManager *nodemgr = m_gamedef->ndef();
158-
159-
// Whether the sunlight at the top of the bottom block is valid
160-
bool block_below_is_valid = true;
161-
162-
v3s16 pos_relative = getPosRelative();
163-
164-
for(s16 x=0; x<MAP_BLOCKSIZE; x++)
165-
{
166-
for(s16 z=0; z<MAP_BLOCKSIZE; z++)
167-
{
168-
#if 1
169-
bool no_sunlight = false;
170-
//bool no_top_block = false;
171-
172-
// Check if node above block has sunlight
173-
174-
bool is_valid_position;
175-
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z),
176-
&is_valid_position);
177-
if (is_valid_position)
178-
{
179-
if(n.getContent() == CONTENT_IGNORE)
180-
{
181-
// Trust heuristics
182-
no_sunlight = is_underground;
183-
}
184-
else if(n.getLight(LIGHTBANK_DAY, m_gamedef->ndef()) != LIGHT_SUN)
185-
{
186-
no_sunlight = true;
187-
}
188-
}
189-
else
190-
{
191-
//no_top_block = true;
192-
193-
// NOTE: This makes over-ground roofed places sunlighted
194-
// Assume sunlight, unless is_underground==true
195-
if(is_underground)
196-
{
197-
no_sunlight = true;
198-
}
199-
else
200-
{
201-
MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
202-
if (!m_gamedef->ndef()->get(n).sunlight_propagates) {
203-
no_sunlight = true;
204-
}
205-
}
206-
// NOTE: As of now, this just would make everything dark.
207-
// No sunlight here
208-
//no_sunlight = true;
209-
}
210-
#endif
211-
#if 0 // Doesn't work; nothing gets light.
212-
bool no_sunlight = true;
213-
bool no_top_block = false;
214-
// Check if node above block has sunlight
215-
try{
216-
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z));
217-
if(n.getLight(LIGHTBANK_DAY) == LIGHT_SUN)
218-
{
219-
no_sunlight = false;
220-
}
221-
}
222-
catch(InvalidPositionException &e)
223-
{
224-
no_top_block = true;
225-
}
226-
#endif
227-
228-
/*std::cout<<"("<<x<<","<<z<<"): "
229-
<<"no_top_block="<<no_top_block
230-
<<", is_underground="<<is_underground
231-
<<", no_sunlight="<<no_sunlight
232-
<<std::endl;*/
233-
234-
s16 y = MAP_BLOCKSIZE-1;
235-
236-
// This makes difference to diminishing in water.
237-
bool stopped_to_solid_object = false;
238-
239-
u8 current_light = no_sunlight ? 0 : LIGHT_SUN;
240-
241-
for(; y >= 0; y--)
242-
{
243-
v3s16 pos(x, y, z);
244-
MapNode &n = getNodeRef(pos);
245-
246-
if(current_light == 0)
247-
{
248-
// Do nothing
249-
}
250-
else if(current_light == LIGHT_SUN && nodemgr->get(n).sunlight_propagates)
251-
{
252-
// Do nothing: Sunlight is continued
253-
} else if (!nodemgr->get(n).light_propagates) {
254-
// A solid object is on the way.
255-
stopped_to_solid_object = true;
256-
257-
// Light stops.
258-
current_light = 0;
259-
}
260-
else
261-
{
262-
// Diminish light
263-
current_light = diminish_light(current_light);
264-
}
265-
266-
u8 old_light = n.getLight(LIGHTBANK_DAY, nodemgr);
267-
268-
if(current_light > old_light || remove_light)
269-
{
270-
n.setLight(LIGHTBANK_DAY, current_light, nodemgr);
271-
}
272-
273-
if(diminish_light(current_light) != 0)
274-
{
275-
light_sources.insert(pos_relative + pos);
276-
}
277-
278-
if(current_light == 0 && stopped_to_solid_object)
279-
{
280-
if(black_air_left)
281-
{
282-
*black_air_left = true;
283-
}
284-
}
285-
}
286-
287-
// Whether or not the block below should see LIGHT_SUN
288-
bool sunlight_should_go_down = (current_light == LIGHT_SUN);
289-
290-
/*
291-
If the block below hasn't already been marked invalid:
292-
293-
Check if the node below the block has proper sunlight at top.
294-
If not, the block below is invalid.
295-
296-
Ignore non-transparent nodes as they always have no light
297-
*/
298-
299-
if(block_below_is_valid)
300-
{
301-
MapNode n = getNodeParent(v3s16(x, -1, z), &is_valid_position);
302-
if (is_valid_position) {
303-
if(nodemgr->get(n).light_propagates)
304-
{
305-
if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
306-
&& !sunlight_should_go_down)
307-
block_below_is_valid = false;
308-
else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
309-
&& sunlight_should_go_down)
310-
block_below_is_valid = false;
311-
}
312-
}
313-
else
314-
{
315-
/*std::cout<<"InvalidBlockException for bottom block node"
316-
<<std::endl;*/
317-
// Just no block below, no need to panic.
318-
}
319-
}
320-
}
321-
}
322-
323-
return block_below_is_valid;
324-
}
325-
326-
327135
void MapBlock::copyTo(VoxelManipulator &dst)
328136
{
329137
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);

src/mapblock.h

-4
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,6 @@ class MapBlock
348348
setNode(x0 + x, y0 + y, z0 + z, node);
349349
}
350350

351-
// See comments in mapblock.cpp
352-
bool propagateSunlight(std::set<v3s16> &light_sources,
353-
bool remove_light=false, bool *black_air_left=NULL);
354-
355351
// Copies data to VoxelManipulator to getPosRelative()
356352
void copyTo(VoxelManipulator &dst);
357353

src/unittest/test_voxelalgorithms.cpp

-162
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class TestVoxelAlgorithms : public TestBase {
3030

3131
void runTests(IGameDef *gamedef);
3232

33-
void testPropogateSunlight(INodeDefManager *ndef);
34-
void testClearLightAndCollectSources(INodeDefManager *ndef);
3533
void testVoxelLineIterator(INodeDefManager *ndef);
3634
};
3735

@@ -41,171 +39,11 @@ void TestVoxelAlgorithms::runTests(IGameDef *gamedef)
4139
{
4240
INodeDefManager *ndef = gamedef->getNodeDefManager();
4341

44-
TEST(testPropogateSunlight, ndef);
45-
TEST(testClearLightAndCollectSources, ndef);
4642
TEST(testVoxelLineIterator, ndef);
4743
}
4844

4945
////////////////////////////////////////////////////////////////////////////////
5046

51-
void TestVoxelAlgorithms::testPropogateSunlight(INodeDefManager *ndef)
52-
{
53-
VoxelManipulator v;
54-
55-
for (u16 z = 0; z < 3; z++)
56-
for (u16 y = 0; y < 3; y++)
57-
for (u16 x = 0; x < 3; x++) {
58-
v3s16 p(x,y,z);
59-
v.setNodeNoRef(p, MapNode(CONTENT_AIR));
60-
}
61-
62-
VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
63-
64-
{
65-
std::set<v3s16> light_sources;
66-
voxalgo::setLight(v, a, 0, ndef);
67-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
68-
v, a, true, light_sources, ndef);
69-
//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
70-
UASSERT(res.bottom_sunlight_valid == true);
71-
UASSERT(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef)
72-
== LIGHT_SUN);
73-
}
74-
75-
v.setNodeNoRef(v3s16(0,0,0), MapNode(t_CONTENT_STONE));
76-
77-
{
78-
std::set<v3s16> light_sources;
79-
voxalgo::setLight(v, a, 0, ndef);
80-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
81-
v, a, true, light_sources, ndef);
82-
UASSERT(res.bottom_sunlight_valid == true);
83-
UASSERT(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef)
84-
== LIGHT_SUN);
85-
}
86-
87-
{
88-
std::set<v3s16> light_sources;
89-
voxalgo::setLight(v, a, 0, ndef);
90-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
91-
v, a, false, light_sources, ndef);
92-
UASSERT(res.bottom_sunlight_valid == true);
93-
UASSERT(v.getNode(v3s16(2,0,2)).getLight(LIGHTBANK_DAY, ndef)
94-
== 0);
95-
}
96-
97-
v.setNodeNoRef(v3s16(1,3,2), MapNode(t_CONTENT_STONE));
98-
99-
{
100-
std::set<v3s16> light_sources;
101-
voxalgo::setLight(v, a, 0, ndef);
102-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
103-
v, a, true, light_sources, ndef);
104-
UASSERT(res.bottom_sunlight_valid == true);
105-
UASSERT(v.getNode(v3s16(1,1,2)).getLight(LIGHTBANK_DAY, ndef)
106-
== 0);
107-
}
108-
109-
{
110-
std::set<v3s16> light_sources;
111-
voxalgo::setLight(v, a, 0, ndef);
112-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
113-
v, a, false, light_sources, ndef);
114-
UASSERT(res.bottom_sunlight_valid == true);
115-
UASSERT(v.getNode(v3s16(1,0,2)).getLight(LIGHTBANK_DAY, ndef)
116-
== 0);
117-
}
118-
119-
{
120-
MapNode n(CONTENT_AIR);
121-
n.setLight(LIGHTBANK_DAY, 10, ndef);
122-
v.setNodeNoRef(v3s16(1,-1,2), n);
123-
}
124-
125-
{
126-
std::set<v3s16> light_sources;
127-
voxalgo::setLight(v, a, 0, ndef);
128-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
129-
v, a, true, light_sources, ndef);
130-
UASSERT(res.bottom_sunlight_valid == true);
131-
}
132-
133-
{
134-
std::set<v3s16> light_sources;
135-
voxalgo::setLight(v, a, 0, ndef);
136-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
137-
v, a, false, light_sources, ndef);
138-
UASSERT(res.bottom_sunlight_valid == true);
139-
}
140-
141-
{
142-
MapNode n(CONTENT_AIR);
143-
n.setLight(LIGHTBANK_DAY, LIGHT_SUN, ndef);
144-
v.setNodeNoRef(v3s16(1,-1,2), n);
145-
}
146-
147-
{
148-
std::set<v3s16> light_sources;
149-
voxalgo::setLight(v, a, 0, ndef);
150-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
151-
v, a, true, light_sources, ndef);
152-
UASSERT(res.bottom_sunlight_valid == false);
153-
}
154-
155-
{
156-
std::set<v3s16> light_sources;
157-
voxalgo::setLight(v, a, 0, ndef);
158-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
159-
v, a, false, light_sources, ndef);
160-
UASSERT(res.bottom_sunlight_valid == false);
161-
}
162-
163-
v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_IGNORE));
164-
165-
{
166-
std::set<v3s16> light_sources;
167-
voxalgo::setLight(v, a, 0, ndef);
168-
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
169-
v, a, true, light_sources, ndef);
170-
UASSERT(res.bottom_sunlight_valid == true);
171-
}
172-
}
173-
174-
void TestVoxelAlgorithms::testClearLightAndCollectSources(INodeDefManager *ndef)
175-
{
176-
VoxelManipulator v;
177-
178-
for (u16 z = 0; z < 3; z++)
179-
for (u16 y = 0; y < 3; y++)
180-
for (u16 x = 0; x < 3; x++) {
181-
v3s16 p(x,y,z);
182-
v.setNode(p, MapNode(CONTENT_AIR));
183-
}
184-
185-
VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
186-
v.setNodeNoRef(v3s16(0,0,0), MapNode(t_CONTENT_STONE));
187-
v.setNodeNoRef(v3s16(1,1,1), MapNode(t_CONTENT_TORCH));
188-
189-
{
190-
MapNode n(CONTENT_AIR);
191-
n.setLight(LIGHTBANK_DAY, 1, ndef);
192-
v.setNode(v3s16(1,1,2), n);
193-
}
194-
195-
{
196-
std::set<v3s16> light_sources;
197-
std::map<v3s16, u8> unlight_from;
198-
voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
199-
ndef, light_sources, unlight_from);
200-
//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
201-
UASSERT(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef) == 0);
202-
UASSERT(light_sources.find(v3s16(1,1,1)) != light_sources.end());
203-
UASSERT(light_sources.size() == 1);
204-
UASSERT(unlight_from.find(v3s16(1,1,2)) != unlight_from.end());
205-
UASSERT(unlight_from.size() == 1);
206-
}
207-
}
208-
20947
void TestVoxelAlgorithms::testVoxelLineIterator(INodeDefManager *ndef)
21048
{
21149
// Test some lines

0 commit comments

Comments
 (0)