#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 <sstream>
-
-#ifdef _WIN32
- #include <windows.h>
- #define sleep_ms(x) Sleep(x)
-#else
- #include <unistd.h>
- #define sleep_ms(x) usleep(x*1000)
-#endif
+#include "porting.h"
/*
Asserts that the exception occurs
{
void Run()
{
+ { // ver 0
+
SharedBuffer<u8> fromdata(4);
fromdata[0]=1;
fromdata[1]=5;
{
assert(str_out2[i] == fromdata[i]);
}
+
+ }
+
+ { // ver HIGHEST
+
+ SharedBuffer<u8> fromdata(4);
+ fromdata[0]=1;
+ fromdata[1]=5;
+ fromdata[2]=5;
+ fromdata[3]=1;
+
+ std::ostringstream os(std::ios_base::binary);
+ compress(fromdata, os, SER_FMT_VER_HIGHEST);
+
+ std::string str_out = os.str();
+
+ dstream<<"str_out.size()="<<str_out.size()<<std::endl;
+ dstream<<"TestCompress: 1,5,5,1 -> ";
+ for(u32 i=0; i<str_out.size(); i++)
+ {
+ dstream<<(u32)str_out[i]<<",";
+ }
+ dstream<<std::endl;
+
+ /*assert(str_out.size() == 10);
+
+ assert(str_out[0] == 0);
+ assert(str_out[1] == 0);
+ assert(str_out[2] == 0);
+ assert(str_out[3] == 4);
+ assert(str_out[4] == 0);
+ assert(str_out[5] == 1);
+ assert(str_out[6] == 1);
+ assert(str_out[7] == 5);
+ assert(str_out[8] == 0);
+ assert(str_out[9] == 1);*/
+
+ std::istringstream is(str_out, std::ios_base::binary);
+ std::ostringstream os2(std::ios_base::binary);
+
+ decompress(is, os2, SER_FMT_VER_HIGHEST);
+ std::string str_out2 = os2.str();
+
+ dstream<<"decompress: ";
+ for(u32 i=0; i<str_out2.size(); i++)
+ {
+ dstream<<(u32)str_out2[i]<<",";
+ }
+ dstream<<std::endl;
+
+ assert(str_out2.size() == fromdata.getSize());
+
+ for(u32 i=0; i<str_out2.size(); i++)
+ {
+ assert(str_out2[i] == fromdata[i]);
+ }
+
+ }
}
};
// 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);
}
};
assert(v.getNode(v3s16(-1,0,-1)).d == 2);
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
+#if 0
/*
Water stuff
*/
v.print(dstream, VOXELPRINT_WATERPRESSURE);
- s16 highest_y = -32768;
+ //s16 highest_y = -32768;
/*
NOTE: These are commented out because this behaviour is changed
all the time
active_nodes.clear();
active_nodes[v3s16(9,1,0)] = 1;
- //v.flowWater(active_nodes, 0, false);
- v.flowWater(active_nodes, 0, true, 1000);
+ //v.flowWater(active_nodes, 0, true, 1000);
+ v.flowWater(active_nodes, 0, false, 1000);
dstream<<"Final result of flowWater:"<<std::endl;
v.print(dstream, VOXELPRINT_WATERPRESSURE);
+#endif
//assert(0);
}
// All nodes should have been set to
// .d=CONTENT_AIR and .getLight() = 0
for(u16 z=0; z<MAP_BLOCKSIZE; z++)
- for(u16 y=0; y<MAP_BLOCKSIZE; y++)
- for(u16 x=0; x<MAP_BLOCKSIZE; x++){
- assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
- assert(b.getNode(v3s16(x,y,z)).getLight() == 0);
- }
+ for(u16 y=0; y<MAP_BLOCKSIZE; y++)
+ for(u16 x=0; x<MAP_BLOCKSIZE; x++)
+ {
+ assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
+ assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
+ assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
+ }
/*
Parent fetch functions
n.d = 4;
b.setNode(p, n);
assert(b.getNode(p).d == 4);
- assert(b.getNodeTile(p) == 4);
- assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);
+ //TODO: Update to new system
+ /*assert(b.getNodeTile(p) == 4);
+ assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
/*
propagateSunlight()
for(u16 y=0; y<MAP_BLOCKSIZE; y++){
for(u16 x=0; x<MAP_BLOCKSIZE; x++){
MapNode n = b.getNode(v3s16(x,y,z));
- n.setLight(0);
+ n.setLight(LIGHTBANK_DAY, 0);
+ n.setLight(LIGHTBANK_NIGHT, 0);
b.setNode(v3s16(x,y,z), n);
}
}
parent.position_valid = true;
b.setIsUnderground(false);
parent.node.d = CONTENT_AIR;
- parent.node.setLight(LIGHT_SUN);
+ parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
+ parent.node.setLight(LIGHTBANK_NIGHT, 0);
core::map<v3s16, bool> 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.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
+ assert(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
+ assert(b.getFaceLight2(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(diminish_light(LIGHT_MAX)));
+ // The face on the z+ side should have diminished light
+ assert(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
}
/*
Check how the block handles being in between blocks with some non-sunlight
// 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<v3s16, bool> 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:
for(u16 x=0; x<MAP_BLOCKSIZE; x++){
MapNode n;
n.d = CONTENT_AIR;
- n.setLight(0);
+ n.setLight(LIGHTBANK_DAY, 0);
b.setNode(v3s16(x,y,z), n);
}
}
parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
}
// Lighting value for the valid nodes
- parent.node.setLight(LIGHT_MAX/2);
+ parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
core::map<v3s16, bool> light_sources;
// Bottom block is not valid
assert(b.propagateSunlight(light_sources) == false);
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));
}
};
-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:"<<std::endl;
- hm1.print();
-
- dstream<<"testing UnlimitedHeightmap set/get"<<std::endl;
- v2s16 p1(0,3);
- f32 v1(234.01);
- // Get first heightmap and try setGroundHeight
- FixedHeightmap * href = hm1.getHeightmap(v2s16(0,0));
- href->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)"<<std::endl;
- dstream<<"rand() values: ";
- for(u16 i=0; i<5; i++)
- dstream<<(u16)rand()<<" ";
- dstream<<std::endl;
-
- const s16 BS1 = 8;
- UnlimitedHeightmap hm1(BS1,
- new ConstantGenerator(10.0),
- new ConstantGenerator(0.3),
- new ConstantGenerator(0.0));
-
- // Force hm1 to generate a some heightmap
- hm1.getGroundHeight(v2s16(0,0));
- hm1.getGroundHeight(v2s16(0,BS1));
- /*hm1.getGroundHeight(v2s16(BS1,-1));
- hm1.getGroundHeight(v2s16(BS1-1,-1));*/
- hm1.print();
-
- // Get the (0,0) and (1,0) heightmaps
- /*FixedHeightmap * hr00 = hm1.getHeightmap(v2s16(0,0));
- FixedHeightmap * hr01 = hm1.getHeightmap(v2s16(1,0));
- f32 corners[] = {1.0, 1.0, 1.0, 1.0};
- hr00->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()
assert(got_exception);
}
{
- //u8 data1[1100];
- SharedBuffer<u8> data1(1100);
- for(u16 i=0; i<1100; i++){
+ const int datasize = 30000;
+ SharedBuffer<u8> data1(datasize);
+ for(u16 i=0; i<datasize; i++){
data1[i] = i/4;
}
- 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);
+ dstream<<"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(1100>20)
+ if(datasize>20)
dstream<<"...";
dstream<<std::endl;
sleep_ms(50);
- u8 recvdata[2000];
+ u8 recvdata[datasize + 1000];
dstream<<"** running client.Receive()"<<std::endl;
u16 peer_id = 132;
- u16 size = client.Receive(peer_id, recvdata, 2000);
+ u16 size = client.Receive(peer_id, recvdata, datasize + 1000);
dstream<<"** Client received: peer_id="<<peer_id
<<", size="<<size
<<std::endl;
dstream<<"Received data (size="<<size<<"):";
for(int i=0; i<size && i<20; i++){
- if(i%2==0) printf(" ");
- printf("%.2X", ((int)((const char*)recvdata)[i])&0xff);
+ if(i%2==0) DEBUGPRINT(" ");
+ DEBUGPRINT("%.2X", ((int)((const char*)recvdata)[i])&0xff);
}
if(size>20)
dstream<<"...";
TEST(TestVoxelManipulator);
TEST(TestMapBlock);
TEST(TestMapSector);
- TEST(TestHeightmap);
if(INTERNET_SIMULATOR == false){
TEST(TestSocket);
dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;