X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftest.cpp;h=1de902787987e72acfdd280e0ffbfe2f8bf835cb;hb=c137946a3fc3d2cdbed35fe84cced1a52185bfa3;hp=ce7540e8d7e1fd7b4366007c17276873766a3e8d;hpb=626ed6338aa90eb07038adee29643e692fec6545;p=dragonfireclient.git diff --git a/src/test.cpp b/src/test.cpp index ce7540e8d..1de902787 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -23,21 +23,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "player.h" #include "main.h" -#include "heightmap.h" #include "socket.h" #include "connection.h" #include "utility.h" #include "serialization.h" #include "voxel.h" #include - -#ifdef _WIN32 - #include - #define sleep_ms(x) Sleep(x) -#else - #include - #define sleep_ms(x) usleep(x*1000) -#endif +#include "porting.h" /* Asserts that the exception occurs @@ -194,12 +186,13 @@ struct TestMapNode // Default values assert(n.d == CONTENT_AIR); - assert(n.getLight() == 0); + assert(n.getLight(LIGHTBANK_DAY) == 0); + assert(n.getLight(LIGHTBANK_NIGHT) == 0); // Transparency n.d = CONTENT_AIR; assert(n.light_propagates() == true); - n.d = 0; + n.d = CONTENT_STONE; assert(n.light_propagates() == false); } }; @@ -274,6 +267,7 @@ struct TestVoxelManipulator assert(v.getNode(v3s16(-1,0,-1)).d == 2); EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1))); +#if 0 /* Water stuff */ @@ -338,6 +332,7 @@ struct TestVoxelManipulator dstream<<"Final result of flowWater:"< light_sources; // The bottom block is invalid, because we have a shadowing node assert(b.propagateSunlight(light_sources) == false); - assert(b.getNode(v3s16(1,4,0)).getLight() == LIGHT_SUN); - assert(b.getNode(v3s16(1,3,0)).getLight() == LIGHT_SUN); - assert(b.getNode(v3s16(1,2,0)).getLight() == 0); - assert(b.getNode(v3s16(1,1,0)).getLight() == 0); - assert(b.getNode(v3s16(1,0,0)).getLight() == 0); - assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN); - assert(b.getFaceLight(p, v3s16(0,1,0)) == LIGHT_SUN); - assert(b.getFaceLight(p, v3s16(0,-1,0)) == 0); + assert(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + assert(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + assert(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0); + assert(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0); + assert(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0); + assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); + assert(b.getFaceLight(1000, p, v3s16(0,1,0)) == LIGHT_SUN); + assert(b.getFaceLight(1000, p, v3s16(0,-1,0)) == 0); + assert(b.getFaceLight(0, p, v3s16(0,-1,0)) == 0); // According to MapBlock::getFaceLight, // The face on the z+ side should have double-diminished light //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX))); - assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX)); + // The face on the z+ side should have diminished light + assert(b.getFaceLight(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX)); } /* Check how the block handles being in between blocks with some non-sunlight @@ -533,15 +534,15 @@ struct TestMapBlock // Make neighbours to exist and set some non-sunlight to them parent.position_valid = true; b.setIsUnderground(true); - parent.node.setLight(LIGHT_MAX/2); + parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2); core::map light_sources; // The block below should be valid because there shouldn't be // sunlight in there either - assert(b.propagateSunlight(light_sources) == true); + assert(b.propagateSunlight(light_sources, true) == true); // Should not touch nodes that are not affected (that is, all of them) //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN); // Should set light of non-sunlighted blocks to 0. - assert(b.getNode(v3s16(1,2,3)).getLight() == 0); + assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0); } /* Set up a situation where: @@ -560,7 +561,7 @@ struct TestMapBlock for(u16 x=0; x light_sources; // Bottom block is not valid assert(b.propagateSunlight(light_sources) == false); @@ -626,9 +627,7 @@ struct TestMapSector parent.position_valid = false; // Create one with no heightmaps - ServerMapSector sector(&parent, v2s16(1,1), 0); - //ConstantGenerator *dummyheightmap = new ConstantGenerator(); - //sector->setHeightmap(dummyheightmap); + ServerMapSector sector(&parent, v2s16(1,1)); EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0)); EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1)); @@ -652,116 +651,6 @@ struct TestMapSector } }; -struct TestHeightmap -{ - void TestSingleFixed() - { - const s16 BS1 = 4; - OneChildHeightmap hm1(BS1); - - // Test that it is filled with < GROUNDHEIGHT_VALID_MINVALUE - for(s16 y=0; y<=BS1; y++){ - for(s16 x=0; x<=BS1; x++){ - v2s16 p(x,y); - assert(hm1.m_child.getGroundHeight(p) - < GROUNDHEIGHT_VALID_MINVALUE); - } - } - - hm1.m_child.setGroundHeight(v2s16(1,0), 2.0); - //hm1.m_child.print(); - assert(fabs(hm1.getGroundHeight(v2s16(1,0))-2.0)<0.001); - hm1.setGroundHeight(v2s16(0,1), 3.0); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(0,1))-3.0)<0.001); - - // Fill with -1.0 - for(s16 y=0; y<=BS1; y++){ - for(s16 x=0; x<=BS1; x++){ - v2s16 p(x,y); - hm1.m_child.setGroundHeight(p, -1.0); - } - } - - f32 corners[] = {0.0, 0.0, 1.0, 1.0}; - hm1.m_child.generateContinued(0.0, 0.0, corners); - - hm1.m_child.print(); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(1,0))-0.2)<0.05); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(4,3))-0.7)<0.05); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(4,4))-1.0)<0.05); - } - - void TestUnlimited() - { - //g_heightmap_debugprint = true; - const s16 BS1 = 4; - UnlimitedHeightmap hm1(BS1, - new ConstantGenerator(0.0), - new ConstantGenerator(0.0), - new ConstantGenerator(5.0)); - // Go through it so it generates itself - for(s16 y=0; y<=BS1; y++){ - for(s16 x=0; x<=BS1; x++){ - v2s16 p(x,y); - hm1.getGroundHeight(p); - } - } - // Print it - dstream<<"UnlimitedHeightmap hm1:"<setGroundHeight(p1, v1); - // Read from UnlimitedHeightmap - assert(fabs(hm1.getGroundHeight(p1)-v1)<0.001); - } - - void Random() - { - dstream<<"Running random code (get a human to check this)"<generateContinued(0.0, 0.0, corners); - hm1.print();*/ - - //assert(0); - } - - void Run() - { - //srand(7); // Get constant random - srand(time(0)); // Get better random - - TestSingleFixed(); - TestUnlimited(); - Random(); - } -}; - struct TestSocket { void Run() @@ -1070,8 +959,8 @@ struct TestConnection dstream<<"Sending data (size="<<1100<<"):"; for(int i=0; i<1100 && i<20; i++){ - if(i%2==0) printf(" "); - printf("%.2X", ((int)((const char*)*data1)[i])&0xff); + if(i%2==0) DEBUGPRINT(" "); + DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff); } if(1100>20) dstream<<"..."; @@ -1091,8 +980,8 @@ struct TestConnection dstream<<"Received data (size="<20) dstream<<"..."; @@ -1129,7 +1018,6 @@ void run_tests() TEST(TestVoxelManipulator); TEST(TestMapBlock); TEST(TestMapSector); - TEST(TestHeightmap); if(INTERNET_SIMULATOR == false){ TEST(TestSocket); dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<