Recalibrate structure size after layer operations

master
bzt 2019-12-08 10:09:20 +01:00
parent 879eb853b5
commit 3432d1571b
5 changed files with 32 additions and 24 deletions

Binary file not shown.

Binary file not shown.

View File

@ -42,20 +42,18 @@ void edit_placenode(int y, int z, int x, int i)
if(x >= 0 && x < 256 && y >= 0 && y < 256 && z >=0 && z < 256 && i != nodes[y][z][x].param0) {
mts_getbounds(0, NULL, NULL);
hist_add(y, z, x, nodes[y][z][x].param0, nodes[y][z][x].param2, i, nodes[y][z][x].param2);
if(i) {
if(x < mix) mix = x;
if(x > max) max = x;
if(y < miy) miy = y;
if(y > may) may = y;
if(z < miz) miz = z;
if(z > maz) maz = z;
if(nodes[y][z][x].param0) {
for(k = 0, j = 1; j < 15; j++)
if(palette[j] == nodes[y][z][x].param0) { k = j; break; }
if(!k) {
for(j = 15; j > activeblock + 1; j--) palette[j] = palette[j - 1];
palette[activeblock + 1] = nodes[y][z][x].param0;
}
if(x < mix) mix = x;
if(x > max) max = x;
if(y < miy) miy = y;
if(y > may) may = y;
if(z < miz) miz = z;
if(z > maz) maz = z;
if(nodes[y][z][x].param0) {
for(k = 0, j = 1; j < 15; j++)
if(palette[j] == nodes[y][z][x].param0) { k = j; break; }
if(!k) {
for(j = 15; j > activeblock + 1; j--) palette[j] = palette[j - 1];
palette[activeblock + 1] = nodes[y][z][x].param0;
}
}
blocks[nodes[y][z][x].param0].numref--;

View File

@ -90,7 +90,7 @@ void mts_load(unsigned char *data, unsigned int size)
{
unsigned char *buff = NULL, *un = NULL, *b;
unsigned int idx;
int i, j, k, l, n, x, y, z, min_x = 0, min_y = 0, min_z = 0;
int i, j, k, l, n, x, y, z, min_x = 0, min_y = 0, min_z = 0, *palref;
unsigned short *tr = NULL;
if(!data[4] && (data[5] == 3 || data[5] == 4) && !data[6] && data[7] && !data[8] && data[9] && !data[10] && data[11]) {
@ -100,7 +100,8 @@ void mts_load(unsigned char *data, unsigned int size)
min_y = 127 - mts_y / 2;
min_z = 127 - mts_z / 2;
buff = data + 12;
if(data[5] == 4) {
/* guess if we have layer probability map or not for version 3 */
if(buff[0] > 3 || data[5] == 4) {
memcpy(layerprob + min_y, buff, mts_y);
buff += mts_y;
}
@ -109,6 +110,9 @@ void mts_load(unsigned char *data, unsigned int size)
buff += 2;
tr = (unsigned short*)malloc(n * sizeof(unsigned short));
if(!tr) error(lang[ERR_MEM]);
palref = (int*)malloc(numpalettes * sizeof(int));
if(!palref) error(lang[ERR_MEM]);
memset(palref, 0, numpalettes * sizeof(int));
for(i = 0; i < n; i++) {
tr[i] = numblocks;
j = buff[1];
@ -119,7 +123,7 @@ void mts_load(unsigned char *data, unsigned int size)
!memcmp(blocks[k].name, buff, j)) || (blocks[k].blocknames && blocks[k].blocknames[l] &&
(int)strlen(blocks[k].blocknames[l]) == j && !memcmp(blocks[k].blocknames[l], buff, j))) {
if(!l && k) { blocks[k].dobiome = 1; savebiome = 1; }
if(l && l - 1 > savepal) savepal = l - 1;
if(l) palref[l - 1]++;
tr[i] = k;
break;
}
@ -138,6 +142,10 @@ void mts_load(unsigned char *data, unsigned int size)
}
buff += j;
}
/* pick the node palette which has the most node reference */
for(i = savepal = 0; i < numpalettes; i++)
if(palref[i] > palref[savepal]) savepal = i;
free(palref);
size -= (int)(buff - data);
un = (uint8_t*)stbi_zlib_decode_malloc_guesssize_headerflag((const char*)buff, size, 4096, &i, 1);
if(un) { buff = un; size = (unsigned int)i; }
@ -505,7 +513,8 @@ void mts_flip()
}
}
}
x = maz; maz = miz; miz = x;
bound_valid = 0;
mts_getbounds(0, NULL, NULL);
}
/**
@ -516,7 +525,7 @@ void mts_addy(int y, int copy)
int x, Y, z;
mts_getbounds(0, NULL, NULL);
if(miy > may) return;
if(miy > may || y < miy || y > may) return;
for(Y = miy-1 < 0 ? 0 : miy-1; Y < y; Y++)
for(z = miz; z <= maz; z++)
@ -537,7 +546,7 @@ void mts_dely(int y)
int x, Y, z;
mts_getbounds(0, NULL, NULL);
if(miy > may) return;
if(miy > may || y < miy || y > may) return;
for(Y = y; Y >= miy; Y--)
for(z = miz; z <= maz; z++)
@ -557,7 +566,7 @@ void mts_addx(int x, int copy)
int X, y, z;
mts_getbounds(0, NULL, NULL);
if(mix > max) return;
if(mix > max || x < mix || x > max) return;
for(y = miy; y <= may; y++)
for(z = miz; z <= maz; z++)
@ -578,7 +587,7 @@ void mts_delx(int x)
int X, y, z;
mts_getbounds(0, NULL, NULL);
if(mix > max) return;
if(mix > max || x < mix || x > max) return;
for(y = miy; y <= may; y++)
for(z = miz; z <= maz; z++)
@ -598,7 +607,7 @@ void mts_addz(int z, int copy)
int x, y, Z;
mts_getbounds(0, NULL, NULL);
if(miz > maz) return;
if(miz > maz || z < miz || z > maz) return;
for(y = miy; y <= may; y++)
for(Z = miz-1 < 0 ? 0 : miz-1; Z < z; Z++)
@ -619,7 +628,7 @@ void mts_delz(int z)
int x, y, Z;
mts_getbounds(0, NULL, NULL);
if(miz > maz) return;
if(miz > maz || z < miz || z > maz) return;
for(y = miy; y <= may; y++)
for(Z = z; Z >= miz; Z--)

View File

@ -80,6 +80,7 @@ void readschem()
status = NULL;
if(isdir(mtsfile)) return;
bound_valid = 0;
mts_x = mts_y = mts_z = 0; currlayer = 127;
memset(layerprob, 127, sizeof(layerprob));
memset(nodes, 0, sizeof(nodes));