diff options
author | admin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-11-04 17:27:11 +0100 |
---|---|---|
committer | admin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-11-04 17:27:11 +0100 |
commit | 563028f6dbaad33152a873ca68f4b619839a9589 (patch) | |
tree | 37de244a7e14441b58f55ad904e502e51f2ab163 | |
parent | Added cRedstone to project file (diff) | |
download | cuberite-563028f6dbaad33152a873ca68f4b619839a9589.tar cuberite-563028f6dbaad33152a873ca68f4b619839a9589.tar.gz cuberite-563028f6dbaad33152a873ca68f4b619839a9589.tar.bz2 cuberite-563028f6dbaad33152a873ca68f4b619839a9589.tar.lz cuberite-563028f6dbaad33152a873ca68f4b619839a9589.tar.xz cuberite-563028f6dbaad33152a873ca68f4b619839a9589.tar.zst cuberite-563028f6dbaad33152a873ca68f4b619839a9589.zip |
-rw-r--r-- | converter/cQuicksort.cpp (renamed from converter/quicksort.cpp) | 33 | ||||
-rw-r--r-- | converter/cQuicksort.h | 16 | ||||
-rw-r--r-- | converter/cTimer.cpp (renamed from converter/timer.cpp) | 2 | ||||
-rw-r--r-- | converter/cTimer.h (renamed from converter/timer.h) | 0 | ||||
-rwxr-xr-x | converter/denotch | bin | 221817 -> 221872 bytes | |||
-rw-r--r-- | converter/main.cpp (renamed from converter/cConvert.cpp) | 77 | ||||
-rw-r--r-- | converter/makefile | 2 | ||||
-rw-r--r-- | converter/quicksort.h | 9 |
8 files changed, 44 insertions, 95 deletions
diff --git a/converter/quicksort.cpp b/converter/cQuicksort.cpp index 9bc1d477f..8a00805eb 100644 --- a/converter/quicksort.cpp +++ b/converter/cQuicksort.cpp @@ -1,21 +1,11 @@ -#include "quicksort.h" - +#include "cQuicksort.h" +#include <ctype.h> // Quicksort controller function, it partitions the different pieces of our array. -void quicksort(int *arIntegers, int left, int right) +void cQuicksort::quicksort(int *arIntegers, int left, int right) { -/* cout << "quicksort ([" << arIntegers[0] << "," - << arIntegers[1] << "," - << arIntegers[2] << "," - << arIntegers[3] << "," - << arIntegers[4] << "," - << arIntegers[5] << "," - << arIntegers[6] << "]," - << left << "," - << right << ")\n"; -*/ if (right > left) { int pivotIndex = median3(arIntegers,left,right); @@ -27,7 +17,7 @@ void quicksort(int *arIntegers, int left, int right) } } -int median3(int *arIntegers,int left,int right) +int cQuicksort::median3(int *arIntegers,int left,int right) { int center = (left+right)/2; @@ -45,18 +35,8 @@ int median3(int *arIntegers,int left,int right) // This function takes an array (or one half an array) and sorts it. // It then returns a new pivot index number back to quicksort. -int partition(int *arIntegers, int left, int right, int pivot) +int cQuicksort::partition(int *arIntegers, int left, int right, int pivot) { -/* cout << "partition ("<< arIntegers[0] << "," - << arIntegers[1] << "," - << arIntegers[2] << "," - << arIntegers[3] << "," - << arIntegers[4] << "," - << arIntegers[5] << "," - << arIntegers[6] << "]," - << left << "," - << right << ")\n"; -*/ int pivotValue = arIntegers[pivot]; // Swap it out all the way to the end of the array @@ -79,10 +59,9 @@ int partition(int *arIntegers, int left, int right, int pivot) } // Simple swap function for our in place swapping. -void swap(int &val1, int &val2) +void cQuicksort::swap(int &val1, int &val2) { int temp = val1; val1 = val2; val2 = temp; } - diff --git a/converter/cQuicksort.h b/converter/cQuicksort.h new file mode 100644 index 000000000..b9327bd7d --- /dev/null +++ b/converter/cQuicksort.h @@ -0,0 +1,16 @@ +#pragma once + + +class cQuicksort { + + +public: + void quicksort(int*, int, int); + + +private: + int partition(int*, int, int, int); + int median3(int*,int,int); + void swap(int &, int &); + +}; diff --git a/converter/timer.cpp b/converter/cTimer.cpp index f9f9aea3e..afd7b4db1 100644 --- a/converter/timer.cpp +++ b/converter/cTimer.cpp @@ -1,4 +1,4 @@ -#include "timer.h" +#include "cTimer.h" double diffclock(clock_t clock1,clock_t clock2) { diff --git a/converter/timer.h b/converter/cTimer.h index 1c7134ef6..1c7134ef6 100644 --- a/converter/timer.h +++ b/converter/cTimer.h diff --git a/converter/denotch b/converter/denotch Binary files differindex afef48860..e478255b8 100755 --- a/converter/denotch +++ b/converter/denotch diff --git a/converter/cConvert.cpp b/converter/main.cpp index 4ee5b6b74..08a480dd1 100644 --- a/converter/cConvert.cpp +++ b/converter/main.cpp @@ -1,13 +1,14 @@ #include <iostream> #include <fstream> #include <string> +#include <cstring> #include <stdio.h> //#include <string.h> #include <ctype.h> #include "zlib.h" #include "cNBTData.h" -#include "timer.h" -#include "quicksort.h" +#include "cTimer.h" +#include "cQuicksort.h" #include <dirent.h> //#include "dircont.h" @@ -112,7 +113,9 @@ int main () { if( fread( &trash, sizeof(byte4), 1, f) != 1 ) { cout << "ERROR 2jkd READING FROM FILE " << SourceFile; fclose(f); return false; } } frloc = 8192; //current location of fread is at 4096+ 4096 since we read through and collected important info from the header. - quicksort(toffarr, 0, 1023); //sort the array from smallest to larget offset locations so we only have to read through the file once. + + cQuicksort Quick; + Quick.cQuicksort::quicksort(toffarr, 0, 1023); //sort the array from smallest to larget offset locations so we only have to read through the file once. for ( short ia = 0; ia < 1024; ia++ ) {//a region file can hold a maximum of 1024 chunks (32*32) if (ia < 3500 ) { //only run chunk # 3 @@ -129,20 +132,13 @@ int main () { compdlength = ((byte1*256*256*256) + (byte2*256*256) + (byte3*256) + byte4 - 0); //length of compressed chunk data if( fread( &byte5, sizeof(byte5), 1, f) != 1 ) { cout << "ERROR 2341 READING FROM FILE " << SourceFile; fclose(f); return false; } //compression type, 1 = GZip (RFC1952) (unused in practice) , 2 = Zlib (RFC1950) - //printf("byte1: %i\n", byte1); - //printf("byte2: %i\n", byte2); - //printf("byte3: %i\n", byte3); - //printf("byte4: %i\n", byte4); - //printf("byte5: %i\n", byte5); - frloc += 5; //moved ahead 5 bytes while reading data. - // TODO - delete [] temparr after you're done with it, now it's a memory leak - char* compBlockData = new char[compdlength]; //can't get fread to read more than one char at a time into a char array... so that's what I'll do. :( At least it works. + char* compBlockData = new char[compdlength]; if( fread( compBlockData, compdlength, 1, f) != 1 ) { cout << "ERROR rf22 READING FROM FILE " << SourceFile; fclose(f); return false; } frloc = frloc + compdlength; - uLongf DestSize = 98576;// uncompressed chunks should never be larger than this + uLongf DestSize = 128576;// uncompressed chunks should never be larger than this char* BlockData = new char[ DestSize ]; @@ -168,7 +164,6 @@ int main () { - //testing of nbtparser. NumChunks++; cNBTData* NBTData = new cNBTData(BlockData, (int)DestSize); NBTData->ParseData(); @@ -200,37 +195,18 @@ int main () { char* CompressedChunk = new char[ CompressedSize ]; int UnChunkArrLoc = 0; int xPos = NBTData->GetInteger("xPos"); - char* xtemppos = (char *)&xPos; int zPos = NBTData->GetInteger("zPos"); - char* ztemppos = (char *)&zPos; + memcpy( t_FakeHeader + t_FakeHeaderSz + 1, &xPos, sizeof(int) );t_FakeHeaderSz += sizeof(int); + memcpy( t_FakeHeader + t_FakeHeaderSz + 1, &zPos, sizeof(int) );t_FakeHeaderSz += sizeof(int); - for(unsigned int i = 0; i < sizeof(int); i++) { - t_FakeHeader[t_FakeHeaderSz+1] = xtemppos[i]; - t_FakeHeaderSz ++; - } - for(unsigned int i = 0; i < sizeof(int); i++) { - t_FakeHeader[t_FakeHeaderSz+1] = ztemppos[i]; - t_FakeHeaderSz ++; - } //todo: inserert json code and add it to chunk data - for(unsigned int i = 0; i < 32768; i++) { - UncompressedChunk[ UnChunkArrLoc ] = NBTData->GetByteArray("Blocks")[i]; - UnChunkArrLoc ++; - } - for(unsigned int i = 0; i < 16384; i++) { - UncompressedChunk[ UnChunkArrLoc ] = NBTData->GetByteArray("Data")[i]; - UnChunkArrLoc ++; - } - for(unsigned int i = 0; i < 16384; i++) { - UncompressedChunk[ UnChunkArrLoc ] = NBTData->GetByteArray("BlockLight")[i]; - UnChunkArrLoc ++; - } - for(unsigned int i = 0; i < 16384; i++) { - UncompressedChunk[ UnChunkArrLoc ] = NBTData->GetByteArray("SkyLight")[i]; - UnChunkArrLoc ++; - } + + memcpy( UncompressedChunk + UnChunkArrLoc, NBTData->GetByteArray("Blocks"), 32768 );UnChunkArrLoc += 32768; + memcpy( UncompressedChunk + UnChunkArrLoc, NBTData->GetByteArray("Data"), 16384 );UnChunkArrLoc += 16384; + memcpy( UncompressedChunk + UnChunkArrLoc, NBTData->GetByteArray("BlockLight"), 16384 );UnChunkArrLoc += 16384; + memcpy( UncompressedChunk + UnChunkArrLoc, NBTData->GetByteArray("SkyLight"), 16384 );UnChunkArrLoc += 16384; errorcode = compress2( (Bytef*)CompressedChunk, &CompressedSize, (const Bytef*)UncompressedChunk, UncompressedChunkSz, Z_DEFAULT_COMPRESSION); if( errorcode != Z_OK ) @@ -239,34 +215,19 @@ int main () { break; } - char* c_sizetemppos = (char *)&CompressedSize; - char* uc_sizetemppos = (char *)&UncompressedChunkSz; - - for(unsigned int i = 0; i < sizeof(int); i++) { - t_FakeHeader[t_FakeHeaderSz+1] = c_sizetemppos[i]; - t_FakeHeaderSz ++; - } - for(unsigned int i = 0; i < sizeof(int); i++) { - t_FakeHeader[t_FakeHeaderSz+1] = uc_sizetemppos[i]; - t_FakeHeaderSz ++; - } - for(unsigned int i = 0; i < CompressedSize; i++) { - t_CompChunk[t_CompChunkSz+1] = CompressedChunk[i]; - t_CompChunkSz ++; - } + memcpy( t_FakeHeader + t_FakeHeaderSz + 1, &CompressedSize, sizeof(int) );t_FakeHeaderSz += sizeof(int); + memcpy( t_FakeHeader + t_FakeHeaderSz + 1, &UncompressedChunkSz, sizeof(int) );t_FakeHeaderSz += sizeof(int); + memcpy( t_CompChunk + t_CompChunkSz + 1, CompressedChunk, CompressedSize );t_CompChunkSz += CompressedSize; - //printf("Coord(X,Z):ChunkSize: %i,%i:%i\n", NBTData->GetInteger("xPos"), NBTData->GetInteger("zPos"), (int)CompressedSize ); - NBTData->CloseCompound();// Close the compounds after you're done NBTData->CloseCompound(); - //fwrite( BlockData, DestSize, 1, wf ); - delete [] UncompressedChunk; delete [] CompressedChunk; delete [] compBlockData; delete [] BlockData; + delete [] NBTData; while ( (frloc < toffarr[ia+1]) && (ia<1023) ) { //loop through Notch's junk data until we get to another chunk offset possition to start the loop again if( fread( &trash, sizeof(byte4), 1, f) != 1 ) { cout << "ERROR 2nkd READING FROM FILE " << SourceFile; fclose(f); return false; } diff --git a/converter/makefile b/converter/makefile new file mode 100644 index 000000000..50cbf7433 --- /dev/null +++ b/converter/makefile @@ -0,0 +1,2 @@ +all: + g++ main.cpp cNBTData.cpp cTimer.cpp cQuicksort.cpp -lz -o denotch diff --git a/converter/quicksort.h b/converter/quicksort.h deleted file mode 100644 index b3be0e36b..000000000 --- a/converter/quicksort.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include <ctype.h> - -void quicksort(int*, int, int); -int partition(int*, int, int, int); -int median3(int*,int,int); -void swap(int &, int &); - |