From 3ac2abb0b5f84819abe6feea9d7b883b40369610 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 13 Dec 2010 21:32:35 +0200 Subject: commit before content-tile separation --- src/constants.h | 2 + src/main.cpp | 14 ++-- src/map.cpp | 9 +-- src/mapblock.cpp | 89 +++++++++++++++++++++--- src/mapblock.h | 4 +- src/mapnode.h | 18 ++--- src/serialization.cpp | 182 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/serialization.h | 7 +- src/server.cpp | 26 +++++--- src/test.cpp | 64 +++++++++++++++++- src/utility.h | 2 +- src/voxel.h | 1 + 12 files changed, 365 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/constants.h b/src/constants.h index d59597774..bbd9fa823 100644 --- a/src/constants.h +++ b/src/constants.h @@ -41,6 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #define SERVERMAP_DELETE_UNUSED_SECTORS_TIMEOUT (60*10) #define SERVER_MAP_SAVE_INTERVAL (60) +/*#define SERVERMAP_DELETE_UNUSED_SECTORS_TIMEOUT (10) +#define SERVER_MAP_SAVE_INTERVAL (10)*/ #define FOV_ANGLE (PI/2.5) diff --git a/src/main.cpp b/src/main.cpp index 6aa95d879..b1d88090c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -172,25 +172,23 @@ TODO: Remove LazyMeshUpdater. It is not used as supposed. FIXME: Rats somehow go underground sometimes (you can see it in water) - Does their position get saved to a border value or something? + - Does this happen anymore? SUGG: MovingObject::move and Player::move are basically the same. combine them. -TODO: Transfer sign texts as metadata of block and not as data of - object - SUGG: Implement a "Fast check queue" (a queue with a map for checking if something is already in it) - - TODO: Use it in active block queue in water flowing - -TODO: Proper looking torches. - - Signs could be done in the same way? + - Use it in active block queue in water flowing -TODO: A mapper to map contents to tile names (for each side) +SUGG: Signs could be done in the same way as torches. For this, blocks + need an additional metadata field for the texts Doing now: ====================================================================== +TODO: A mapper to map contents to tile names (for each side) + ====================================================================== */ diff --git a/src/map.cpp b/src/map.cpp index 8bc914cfd..f9adbd00a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1504,7 +1504,8 @@ MapSector * ServerMap::emergeSector(v2s16 p2d) sector->setHeightmap(p_in_sector, hm); //TODO: Make these values configurable - hm->generateContinued(1.0, 0.2, corners); + hm->generateContinued(0.0, 0.0, corners); + //hm->generateContinued(1.0, 0.2, corners); //hm->generateContinued(2.0, 0.2, corners); //hm->print(); @@ -3242,8 +3243,8 @@ MapVoxelManipulator::MapVoxelManipulator(Map *map) MapVoxelManipulator::~MapVoxelManipulator() { - dstream<<"MapVoxelManipulator: blocks: "<vertices[3] = video::S3DVertex(vertex_pos[3], zerovector, c, core::vector2d(0,0)); - f->material = material; + f->tile = tile; return f; } @@ -475,7 +477,9 @@ void MapBlock::updateMesh() const u16 indices[] = {0,1,2,2,3,0}; - collector.append(g_materials[f->material], f->vertices, 4, + /*collector.append(g_materials[f->material], f->vertices, 4, + indices, 6);*/ + collector.append(g_materials[f->tile], f->vertices, 4, indices, 6); } @@ -817,8 +821,7 @@ void MapBlock::serialize(std::ostream &os, u8 version) os.write((char*)*dest, dest.getSize()); } - // All otherversions - else + else if(version <= 10) { /* With compression. @@ -857,6 +860,44 @@ void MapBlock::serialize(std::ostream &os, u8 version) compress(pressuredata, os, version); } } + // All other versions (newest) + else + { + // First byte + os.write((char*)&is_underground, 1); + + u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; + + /* + Get data + */ + + SharedBuffer databuf(nodecount*3); + + // Get contents + for(u32 i=0; i -*/ - #include "serialization.h" #include "utility.h" +#include "zlib.h" + +/* report a zlib or i/o error */ +void zerr(int ret) +{ + fputs("zerr: ", stderr); + switch (ret) { + case Z_ERRNO: + if (ferror(stdin)) + fputs("error reading stdin\n", stderr); + if (ferror(stdout)) + fputs("error writing stdout\n", stderr); + break; + case Z_STREAM_ERROR: + fputs("invalid compression level\n", stderr); + break; + case Z_DATA_ERROR: + fputs("invalid or incomplete deflate data\n", stderr); + break; + case Z_MEM_ERROR: + fputs("out of memory\n", stderr); + break; + case Z_VERSION_ERROR: + fputs("zlib version mismatch!\n", stderr); + break; + default: + dstream<<"return value = "< data, std::ostream &os) +{ + z_stream z; + const s32 bufsize = 16384; + //char input_buffer[bufsize]; + char output_buffer[bufsize]; + int input_i = 0; + int status = 0; + int ret; + + z.zalloc = Z_NULL; + z.zfree = Z_NULL; + z.opaque = Z_NULL; + + ret = deflateInit(&z, -1); + if(ret != Z_OK) + throw SerializationError("compressZlib: deflateInit failed"); + + z.avail_in = 0; + + for(;;) + { + int flush = Z_NO_FLUSH; + z.next_out = (Bytef*)output_buffer; + z.avail_out = bufsize; + + if(z.avail_in == 0) + { + //z.next_in = (char*)&data[input_i]; + z.next_in = (Bytef*)&data[input_i]; + z.avail_in = data.getSize() - input_i; + input_i += z.avail_in; + if(input_i == (int)data.getSize()) + flush = Z_FINISH; + } + if(z.avail_in == 0) + break; + status = deflate(&z, flush); + if(status == Z_NEED_DICT || status == Z_DATA_ERROR + || status == Z_MEM_ERROR) + { + zerr(status); + throw SerializationError("compressZlib: deflate failed"); + } + int count = bufsize - z.avail_out; + if(count) + os.write(output_buffer, count); + } + + deflateEnd(&z); + +} + +void decompressZlib(std::istream &is, std::ostream &os) +{ + z_stream z; + const s32 bufsize = 16384; + char input_buffer[bufsize]; + char output_buffer[bufsize]; + int status = 0; + int ret; + int bytes_read = 0; + int input_buffer_len = 0; + + z.zalloc = Z_NULL; + z.zfree = Z_NULL; + z.opaque = Z_NULL; + + ret = inflateInit(&z); + if(ret != Z_OK) + throw SerializationError("compressZlib: inflateInit failed"); + + z.avail_in = 0; + + //dstream<<"initial fail="< data, std::ostream &os, u8 version) { - if(data.getSize() == 0) + if(version >= 11) + { + compressZlib(data, os); return; + } + if(data.getSize() == 0) + return; + // Write length (u32) u8 tmp[4]; @@ -63,6 +229,12 @@ void compress(SharedBuffer data, std::ostream &os, u8 version) void decompress(std::istream &is, std::ostream &os, u8 version) { + if(version >= 11) + { + decompressZlib(is, os); + return; + } + // Read length (u32) u8 tmp[4]; diff --git a/src/serialization.h b/src/serialization.h index 8d3c5fee2..c15a2a235 100644 --- a/src/serialization.h +++ b/src/serialization.h @@ -17,10 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/* -(c) 2010 Perttu Ahola -*/ - #ifndef SERIALIZATION_HEADER #define SERIALIZATION_HEADER @@ -47,11 +43,12 @@ with this program; if not, write to the Free Software Foundation, Inc., 8: (dev) server-initiated block transfers and all kinds of stuff 9: (dev) block objects 10: (dev) water pressure + 11: (dev) zlib'd blocks */ // This represents an uninitialized or invalid format #define SER_FMT_VER_INVALID 255 // Highest supported serialization version -#define SER_FMT_VER_HIGHEST 10 +#define SER_FMT_VER_HIGHEST 11 // Lowest supported serialization version #define SER_FMT_VER_LOWEST 2 diff --git a/src/server.cpp b/src/server.cpp index c7b589e7a..139731a9c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -412,8 +412,10 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime, maximum_simultaneous_block_sends; if(d <= BLOCK_SEND_DISABLE_LIMITS_MAX_D) - maximum_simultaneous_block_sends_now = - maximum_simultaneous_block_sends_setting; + { + maximum_simultaneous_block_sends_now = + maximum_simultaneous_block_sends_setting; + } { JMutexAutoLock lock(m_blocks_sending_mutex); @@ -971,11 +973,19 @@ void Server::AsyncRunStep() { JMutexAutoLock lock1(m_step_dtime_mutex); dtime = m_step_dtime; - if(dtime < 0.001) - return; - m_step_dtime = 0.0; } + // Send blocks to clients + SendBlocks(dtime); + + if(dtime < 0.001) + return; + + { + JMutexAutoLock lock1(m_step_dtime_mutex); + m_step_dtime = 0.0; + } + //dstream<<"Server steps "< fromdata(4); fromdata[0]=1; fromdata[1]=5; @@ -123,6 +125,64 @@ struct TestCompress { assert(str_out2[i] == fromdata[i]); } + + } + + { // ver HIGHEST + + SharedBuffer 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()="< "; + for(u32 i=0; i &list, u16 d) /* This is an optimized sequence of coordinates. */ + list.push_back(v3s16( 0, 1, 0)); // top list.push_back(v3s16( 0, 0, 1)); // back list.push_back(v3s16(-1, 0, 0)); // left list.push_back(v3s16( 1, 0, 0)); // right list.push_back(v3s16( 0, 0,-1)); // front list.push_back(v3s16( 0,-1, 0)); // bottom - list.push_back(v3s16( 0, 1, 0)); // top // 6 list.push_back(v3s16(-1, 0, 1)); // back left list.push_back(v3s16( 1, 0, 1)); // back right diff --git a/src/voxel.h b/src/voxel.h index 43e0baa7a..a90fc37e8 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "debug.h" #include "mapnode.h" +// For VC++ #undef min #undef max -- cgit v1.2.3