#include "mapsector.h"
#include "settings.h"
#include "log.h"
+#include "utility_string.h"
+#include "voxelalgorithms.h"
/*
Asserts that the exception occurs
#define CONTENT_STONE 0
#define CONTENT_GRASS 0x800
+#define CONTENT_TORCH 100
void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *ndef)
{
itemdef.type = ITEM_NODE;
itemdef.name = "default:stone";
itemdef.description = "Stone";
+ itemdef.groups["cracky"] = 3;
itemdef.inventory_image = "[inventorycube"
"{default_stone.png"
"{default_stone.png"
for(int i = 0; i < 6; i++)
f.tname_tiles[i] = "default_stone.png";
f.is_ground_content = true;
- f.material.diggability = DIGGABLE_NORMAL;
- f.material.weight = 5.0;
- f.material.crackiness = 1.0;
- f.material.crumbliness = -0.1;
- f.material.cuttability = -0.2;
idef->registerItem(itemdef);
ndef->set(i, f);
itemdef.type = ITEM_NODE;
itemdef.name = "default:dirt_with_grass";
itemdef.description = "Dirt with grass";
+ itemdef.groups["crumbly"] = 3;
itemdef.inventory_image = "[inventorycube"
"{default_grass.png"
"{default_dirt.png&default_grass_side.png"
for(int i = 2; i < 6; i++)
f.tname_tiles[i] = "default_dirt.png^default_grass_side.png";
f.is_ground_content = true;
- f.material.diggability = DIGGABLE_NORMAL;
- f.material.weight = 1.2;
- f.material.crackiness = 0.0;
- f.material.crumbliness = 1.2;
- f.material.cuttability = -0.4;
+ 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);
}
assert(is_yes("YeS") == true);
assert(is_yes("") == false);
assert(is_yes("FAlse") == false);
+ const char *ends[] = {"abc", "c", "bc", NULL};
+ assert(removeStringEnd("abc", ends) == "");
+ assert(removeStringEnd("bc", ends) == "b");
+ assert(removeStringEnd("12c", ends) == "12");
+ assert(removeStringEnd("foo", ends) == "");
}
};
}
};
+struct TestVoxelAlgorithms
+{
+ void Run(INodeDefManager *ndef)
+ {
+ /*
+ voxalgo::propagateSunlight
+ */
+ {
+ 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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<v3s16, bool> 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);
+ }
+ }
+ /*
+ 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);
+ }
+ }
+ }
+};
+
/*
NOTE: These tests became non-working then NodeContainer was removed.
These should be redone, utilizing some kind of a virtual
infostream<<"Sending data (size="<<datasize<<"):";
for(int i=0; i<datasize && i<20; i++){
- if(i%2==0) DEBUGPRINT(" ");
- DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
+ if(i%2==0) infostream<<" ";
+ char buf[10];
+ snprintf(buf, 10, "%.2X", ((int)((const char*)*data1)[i])&0xff);
+ infostream<<buf;
}
if(datasize>20)
infostream<<"...";
server.Send(peer_id_client, 0, data1, true);
- sleep_ms(3000);
+ //sleep_ms(3000);
SharedBuffer<u8> recvdata;
infostream<<"** running client.Receive()"<<std::endl;
bool received = false;
u32 timems0 = porting::getTimeMs();
for(;;){
- if(porting::getTimeMs() - timems0 > 5000)
+ if(porting::getTimeMs() - timems0 > 5000 || received)
break;
try{
size = client.Receive(peer_id, recvdata);
<<", size="<<size
<<std::endl;
- infostream<<"Received data (size="<<size<<"):";
+ infostream<<"Received data (size="<<size<<"): ";
for(int i=0; i<size && i<20; i++){
- if(i%2==0) DEBUGPRINT(" ");
- DEBUGPRINT("%.2X", ((int)(recvdata[i]))&0xff);
+ if(i%2==0) infostream<<" ";
+ char buf[10];
+ snprintf(buf, 10, "%.2X", ((int)(recvdata[i]))&0xff);
+ infostream<<buf;
}
if(size>20)
infostream<<"...";
TEST(TestSerialization);
TESTPARAMS(TestMapNode, ndef);
TESTPARAMS(TestVoxelManipulator, ndef);
+ TESTPARAMS(TestVoxelAlgorithms, ndef);
//TEST(TestMapBlock);
//TEST(TestMapSector);
if(INTERNET_SIMULATOR == false){