aboutsummaryrefslogtreecommitdiff
path: root/src/test.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-01-27 13:24:06 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-03-27 19:01:51 +0300
commit0f3c2f65414f332fad510fb8651dd59d506aad2e (patch)
treedda3c34cf10d3e3458830cb53820866f4d535c3a /src/test.cpp
parent56496ad5d8a7662b0ae5c9f25d1348cb7b677b65 (diff)
downloadminetest-0f3c2f65414f332fad510fb8651dd59d506aad2e.tar.xz
voxalgo::clearLightAndCollectSources
Diffstat (limited to 'src/test.cpp')
-rw-r--r--src/test.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test.cpp b/src/test.cpp
index ecced33c3..cb01edffd 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -55,6 +55,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define CONTENT_STONE 0
#define CONTENT_GRASS 0x800
+#define CONTENT_TORCH 100
void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *ndef)
{
@@ -105,6 +106,22 @@ void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *n
f.is_ground_content = true;
idef->registerItem(itemdef);
ndef->set(i, f);
+
+ /*
+ Torch (minimal definition for lighting tests)
+ */
+ i = CONTENT_TORCH;
+ itemdef = ItemDefinition();
+ itemdef.type = ITEM_NODE;
+ itemdef.name = "default:torch";
+ f = ContentFeatures();
+ f.name = itemdef.name;
+ f.param_type = CPT_LIGHT;
+ f.light_propagates = true;
+ f.sunlight_propagates = true;
+ f.light_source = LIGHT_MAX-1;
+ idef->registerItem(itemdef);
+ ndef->set(i, f);
}
struct TestUtilities
@@ -488,6 +505,9 @@ struct TestVoxelAlgorithms
{
void Run(INodeDefManager *ndef)
{
+ /*
+ voxalgo::propagateSunlight
+ */
{
VoxelManipulator v;
for(u16 z=0; z<3; z++)
@@ -593,6 +613,40 @@ struct TestVoxelAlgorithms
assert(res.bottom_sunlight_valid == true);
}
}
+ /*
+ voxalgo::clearLightAndCollectSources
+ */
+ {
+ VoxelManipulator v;
+ for(u16 z=0; z<3; z++)
+ for(u16 y=0; y<3; y++)
+ for(u16 x=0; x<3; x++)
+ {
+ v3s16 p(x,y,z);
+ v.setNode(p, MapNode(CONTENT_AIR));
+ }
+ VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
+ v.setNodeNoRef(v3s16(0,0,0), MapNode(CONTENT_STONE));
+ v.setNodeNoRef(v3s16(1,1,1), MapNode(CONTENT_TORCH));
+ {
+ MapNode n(CONTENT_AIR);
+ n.setLight(LIGHTBANK_DAY, 1, ndef);
+ v.setNode(v3s16(1,1,2), n);
+ }
+ {
+ core::map<v3s16, bool> light_sources;
+ core::map<v3s16, u8> unlight_from;
+ voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
+ ndef, light_sources, unlight_from);
+ //v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
+ assert(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef)
+ == 0);
+ assert(light_sources.find(v3s16(1,1,1)) != NULL);
+ assert(light_sources.size() == 1);
+ assert(unlight_from.find(v3s16(1,1,2)) != NULL);
+ assert(unlight_from.size() == 1);
+ }
+ }
}
};