Changes to the denotch map converter. Now runs 20 times faster than before. Not done yet.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@55 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
7deed96d09
commit
563028f6db
@ -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;
|
||||
}
|
||||
|
16
converter/cQuicksort.h
Normal file
16
converter/cQuicksort.h
Normal file
@ -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 &);
|
||||
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
#include "timer.h"
|
||||
#include "cTimer.h"
|
||||
|
||||
double diffclock(clock_t clock1,clock_t clock2)
|
||||
{
|
Binary file not shown.
@ -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;
|
||||
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;
|
||||
|
||||
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 ++;
|
||||
}
|
||||
|
||||
|
||||
//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; }
|
2
converter/makefile
Normal file
2
converter/makefile
Normal file
@ -0,0 +1,2 @@
|
||||
all:
|
||||
g++ main.cpp cNBTData.cpp cTimer.cpp cQuicksort.cpp -lz -o denotch
|
@ -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 &);
|
||||
|
Loading…
Reference in New Issue
Block a user