From 56496ad5d8a7662b0ae5c9f25d1348cb7b677b65 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 27 Jan 2012 12:58:52 +0200 Subject: Implement propagateSunlight for VoxelManipulator --- src/test.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) (limited to 'src/test.cpp') diff --git a/src/test.cpp b/src/test.cpp index 1b9dfcb5d..ecced33c3 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "log.h" #include "utility_string.h" +#include "voxelalgorithms.h" /* Asserts that the exception occurs @@ -483,6 +484,118 @@ struct TestVoxelManipulator } }; +struct TestVoxelAlgorithms +{ + void Run(INodeDefManager *ndef) + { + { + 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.setNodeNoRef(p, MapNode(CONTENT_AIR)); + } + VoxelArea a(v3s16(0,0,0), v3s16(2,2,2)); + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, true, light_sources, ndef); + //v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY); + assert(res.bottom_sunlight_valid == true); + assert(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef) + == LIGHT_SUN); + } + v.setNodeNoRef(v3s16(0,0,0), MapNode(CONTENT_STONE)); + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, true, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + assert(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef) + == LIGHT_SUN); + } + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, false, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + assert(v.getNode(v3s16(2,0,2)).getLight(LIGHTBANK_DAY, ndef) + == 0); + } + v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_STONE)); + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, true, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + assert(v.getNode(v3s16(1,1,2)).getLight(LIGHTBANK_DAY, ndef) + == 0); + } + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, false, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + assert(v.getNode(v3s16(1,0,2)).getLight(LIGHTBANK_DAY, ndef) + == 0); + } + { + MapNode n(CONTENT_AIR); + n.setLight(LIGHTBANK_DAY, 10, ndef); + v.setNodeNoRef(v3s16(1,-1,2), n); + } + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, true, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + } + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, false, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + } + { + MapNode n(CONTENT_AIR); + n.setLight(LIGHTBANK_DAY, LIGHT_SUN, ndef); + v.setNodeNoRef(v3s16(1,-1,2), n); + } + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, true, light_sources, ndef); + assert(res.bottom_sunlight_valid == false); + } + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, false, light_sources, ndef); + assert(res.bottom_sunlight_valid == false); + } + v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_IGNORE)); + { + core::map light_sources; + voxalgo::setLight(v, a, 0, ndef); + voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight( + v, a, true, light_sources, ndef); + assert(res.bottom_sunlight_valid == true); + } + } + } +}; + /* NOTE: These tests became non-working then NodeContainer was removed. These should be redone, utilizing some kind of a virtual @@ -1279,6 +1392,7 @@ void run_tests() TEST(TestSerialization); TESTPARAMS(TestMapNode, ndef); TESTPARAMS(TestVoxelManipulator, ndef); + TESTPARAMS(TestVoxelAlgorithms, ndef); //TEST(TestMapBlock); //TEST(TestMapSector); if(INTERNET_SIMULATOR == false){ -- cgit v1.2.3