Skip to content

Commit 001602c

Browse files
committed
New memory allocation method for support all blocks and data types, deleted bunch of junk code
1 parent e9731b9 commit 001602c

10 files changed

+163
-902
lines changed

changelog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ mcmap3 changelog
22
Latest version is available at: http://wrim.pl/mcmap/
33
------------------------------------------------------
44

5+
beta 3.0.3 (jul 28 2015)
6+
-better memory organization
7+
-improvements with custom colors
8+
-several minor fixes
9+
510
beta 3.0.2 (feb 09 2014)
611
added:
712
-support for biomes in anvil worlds

colors.cpp

+22-14
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ uint16_t colorsToID[256] =
6767
224, 225, 226, 227, 228, 229, 230, 231,
6868
232, 233, 234, 235, 236, 237, 238, 239,
6969
240, 241, 242, 243, 244, 245, 246, 247,
70-
248, 249, 250, 251, 252, 253, 254, 255
70+
248, 249, 24577, 20481, 16385, 12289, 8193, 4097
7171
};
7272

7373
void SET_COLORNOISE(uint16_t col, uint16_t r, uint16_t g, uint16_t b, uint16_t a, uint16_t n)
@@ -619,21 +619,19 @@ bool loadColorsFromFile(const char *file)
619619
printf("Skipping invalid blockid %d:%d in colors file\n", blockid, blockid3);
620620
suffix = -1;
621621
}
622-
printf("Second value %d:%d in colors file\n", blockid, blockid3); //wrim
623622
suffix = 1;
624623
}
625624
++ptr;
626625
}
627626
if (suffix < 0) continue;
628627

629-
uint8_t vals[5];
628+
uint8_t vals[5] = {0,0};
630629
bool valid = true;
631630
for (int i = 0; i < 5; ++i) {
632631
while (*ptr == ' ' || *ptr == '\t') {
633632
++ptr;
634633
}
635634
if (*ptr == '\0' || *ptr == '#' || *ptr == '\12') {
636-
printf("Too few arguments for block %d, ignoring line.\n", blockid);
637635
valid = false;
638636
break;
639637
}
@@ -642,10 +640,23 @@ bool loadColorsFromFile(const char *file)
642640
++ptr;
643641
}
644642
}
645-
if (!valid) {
643+
if (!valid) { //TODO
644+
if (vals[0] != 0)
645+
{
646+
if (g_lowMemory)
647+
{
648+
649+
}
650+
else
651+
{
652+
653+
}
654+
printf("%d:%d copied to %d:%d\n", blockid, blockid3, vals[0], vals[1] & 0x0F);
655+
}
656+
else printf("Too few arguments for block %d, ignoring line.\n", blockid);
646657
continue;
647658
}
648-
int blockidSET = (blockid3 << 12)+blockid;
659+
int blockidSET = (blockid3 << 12) + blockid;
649660
if (g_lowMemory)
650661
{
651662
if (lowmemCounter > 255)
@@ -683,22 +694,19 @@ bool dumpColorsToFile(const char *file)
683694
return false;
684695
}
685696
fprintf(f, "# For Block IDs see http://minecraftwiki.net/wiki/Data_values\n"
686-
"# and http://wrim.pl/mcmap (for blocks introduced since Minecraft 1.3.1 and mcmap 2.4)\n"
687697
"# Note that noise or alpha (or both) do not work for a few blocks like snow, torches, fences, steps, ...\n"
688698
"# Actually, if you see any block has an alpha value of 254 you should leave it that way to prevent black artifacts.\n"
689699
"# If you want to set alpha of grass to <255, use -blendall or you won't get what you expect.\n"
690-
"# Noise is supposed to look normal using -noise 10\n"
691-
"# Dyed wool ranges from ID 240 to 254, it's orange to black in the order described at http://www.minecraftwiki.net/wiki/Data_values#Wool\n"
692-
"# half-steps of sand, wood and cobblestone are 232 to 236\n\n");
693-
uint16_t j = 0;
700+
"# Noise is supposed to look normal using -noise 10\n\n");
701+
uint16_t head = 0;
694702
for (size_t i = 1; i < 4096; ++i) {
695703
uint8_t *c = colors[i];
696704
if (c[PALPHA] == 0) continue; // if color doesn't exist, don't dump it
697-
if (++j % 15 == 1) { //wrim - 3 cases - color only for :0, common for : and different for every :x
698-
fprintf(f, "#ID R G B A Noise\n");//wrim - block types dump
705+
if (++head % 15 == 1) {
706+
fprintf(f, "#ID R G B A Noise\n");
699707
}
700708
fprintf(f, "%3d\t%3d\t%3d\t%3d\t%3d\t%3d\n", int(i), int(c[PRED]), int(c[PGREEN]), int(c[PBLUE]), int(c[PALPHA]), int(c[NOISE]));
701-
for (int j = 0; j < 16; j++)
709+
for (int j = 1; j < 16; j++)
702710
{
703711
uint8_t *c2 = colors[i+(j<<12)];
704712
if (c2[PALPHA] != 0 && (c[PRED] != c2[PRED] || c[PGREEN] != c2[PGREEN] || c[PBLUE] != c2[PBLUE] || c[PALPHA] != c2[PALPHA] || c[NOISE] != c2[NOISE]))

draw_png.cpp

+3-139
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,9 @@ uint64_t calcImageSize(const int mapChunksX, const int mapChunksZ, const size_t
625625
return uint64_t(pixelsX) * BYTESPERPIXEL * uint64_t(pixelsY);
626626
}
627627

628-
void setPixel(const size_t x, const size_t y, const uint8_t color, const float fsub, const uint8_t biome) //not used but left just in case
629-
{
630-
uint16_t color16 = colorsToID[color];
631-
setPixel(x, y, color16, fsub, biome);
632-
}
633-
634628
void setPixel(const size_t x, const size_t y, const uint16_t color, const float fsub, const uint8_t biome)
635629
{
630+
636631
// Sets pixels around x,y where A is the anchor
637632
// T = given color, D = darker, L = lighter
638633
// A T T T
@@ -670,37 +665,7 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
670665
case BLOCKRAILROAD:
671666
setRailroad(x, y, c);
672667
return;
673-
} /*
674-
if (color == SNOW || color == TRAPDOOR
675-
|| color == 141 || color == 142 || color == 158 || color == 149
676-
|| color == 131 || color == 132 || color == 150 || color == 147 || color == 148 || color == 68 || color == 69 || color == 70
677-
|| color == 72 || color == 77 || color == 143 || color == 36) { //three lines of carpets ID's I can't do this other way
678-
setSnowBA(x, y, c);
679-
return;
680-
}
681-
if (color == TORCH || color == REDTORCH_ON || color == REDTORCH_OFF) {
682-
setTorchBA(x, y, c);
683-
return;
684-
}
685-
if (color == FLOWERR || color == FLOWERY || color == MUSHROOMB || color == MUSHROOMR || color == MELON_STEM || color == PUMPKIN_STEM || color == SHRUB || color == COBWEB || color == LILYPAD || color == NETHER_WART
686-
|| color == 175 || color == BLUE_ORCHID || color == ALLIUM || color == AZURE_BLUET || color == RED_TULIP || color == ORANGE_TULIP || color == WHITE_TULIP || color == PINK_TULIP || color == OXEYE_DAISY || color == SUNFLOWER || color == LILAC || color == PEONY ) {
687-
setFlowerBA(x, y, c);
688-
return;
689-
}
690-
if (color == FENCE || color == FENCE_GATE || color == VINES || color == IRON_BARS || color == NETHER_BRICK_FENCE
691-
|| color == 139) {
692-
setFence(x, y, c);
693-
return;
694-
}
695-
if (color == REDWIRE || color == TRIPWIRE) {
696-
setRedwire(x, y, c);
697-
return;
698668
}
699-
if (color == RAILROAD || color == POW_RAILROAD || color == DET_RAILROAD) {
700-
setRailroad(x, y, c);
701-
return;
702-
}
703-
*/
704669
// All the above blocks didn't need the shaded down versions of the color, so we only calc them here
705670
// They are for the sides of blocks
706671
memcpy(L, c, BYTESPERPIXEL);
@@ -723,25 +688,6 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
723688
setUpStepBA(x, y, c, L, D);
724689
return;
725690
}
726-
/*
727-
if (color == GRASS) {
728-
setGrassBA(x, y, c, L, D, sub);
729-
return;
730-
}
731-
if (color == FIRE || color == TALL_GRASS || color == COCOA_PLANT) {
732-
setFire(x, y, c, L, D);
733-
return;
734-
}
735-
if (color == STEP || color == CAKE || color == BED || color == SANDSTEP || color == WOODSTEP || color == COBBLESTEP || color == BRICKSTEP || color == STONEBRICKSTEP || color == PINESTEP || color == BIRCHSTEP || color == JUNGLESTEP
736-
|| color == 151) {
737-
setStepBA(x, y, c, L, D);
738-
return;
739-
}
740-
if (color == UP_STEP || color == UP_SANDSTEP || color == UP_WOODSTEP || color == UP_COBBLESTEP || color == UP_BRICKSTEP || color == UP_STONEBRICKSTEP || color == UP_WOODSTEP2 || color == UP_PINESTEP || color == UP_BIRCHSTEP || color == UP_JUNGLESTEP) {
741-
setUpStepBA(x, y, c, L, D);
742-
return;
743-
}
744-
*/
745691
} else {
746692
// Then check the block type, as some types will be drawn differently
747693
switch (colortype)
@@ -765,36 +711,6 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
765711
setRailroad(x, y, c);
766712
return;
767713
}
768-
/*
769-
if (color == SNOW || color == TRAPDOOR
770-
|| color == 141 || color == 142 || color == 158 || color == 149
771-
|| color == 131 || color == 132 || color == 150 || color == 147 || color == 148 || color == 68 || color == 69 || color == 70
772-
|| color == 72 || color == 77 || color == 143 || color == 36) { //three lines of carpets ID's I can't do this other way
773-
setSnow(x, y, c);
774-
return;
775-
}
776-
if (color == TORCH || color == REDTORCH_ON || color == REDTORCH_OFF) {
777-
setTorch(x, y, c);
778-
return;
779-
}
780-
if (color == FLOWERR || color == FLOWERY || color == MUSHROOMB || color == MUSHROOMR || color == MELON_STEM || color == PUMPKIN_STEM || color == SHRUB || color == COBWEB || color == LILYPAD || color == NETHER_WART
781-
|| color == 175 || color == BLUE_ORCHID || color == ALLIUM || color == AZURE_BLUET || color == RED_TULIP || color == ORANGE_TULIP || color == WHITE_TULIP || color == PINK_TULIP || color == OXEYE_DAISY || color == SUNFLOWER || color == LILAC || color == PEONY ) {
782-
setFlower(x, y, c);
783-
return;
784-
}
785-
if (color == FENCE || color == FENCE_GATE || color == VINES || color == IRON_BARS || color == NETHER_BRICK_FENCE) {
786-
setFence(x, y, c);
787-
return;
788-
}
789-
if (color == REDWIRE || color == TRIPWIRE) {
790-
setRedwire(x, y, c);
791-
return;
792-
}
793-
if (color == RAILROAD || color == POW_RAILROAD || color == DET_RAILROAD) {
794-
setRailroad(x, y, c);
795-
return;
796-
}
797-
*/
798714
// All the above blocks didn't need the shaded down versions of the color, so we only calc them here
799715
// They are for the sides of blocks
800716
memcpy(L, c, BYTESPERPIXEL);
@@ -817,25 +733,6 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
817733
setUpStep(x, y, c, L, D);
818734
return;
819735
}
820-
/*
821-
if (color == GRASS) {
822-
setGrass(x, y, c, L, D, sub);
823-
return;
824-
}
825-
if (color == FIRE || color == TALL_GRASS || color == COCOA_PLANT) {
826-
setFire(x, y, c, L, D);
827-
return;
828-
}
829-
if (color == STEP || color == CAKE || color == BED || color == SANDSTEP || color == WOODSTEP || color == COBBLESTEP || color == BRICKSTEP || color == STONEBRICKSTEP || color == PINESTEP || color == BIRCHSTEP || color == JUNGLESTEP
830-
|| color == 151) {
831-
setStep(x, y, c, L, D);
832-
return;
833-
}
834-
if (color == UP_STEP || color == UP_SANDSTEP || color == UP_WOODSTEP || color == UP_COBBLESTEP || color == UP_BRICKSTEP || color == UP_STONEBRICKSTEP || color == UP_WOODSTEP2 || color == UP_PINESTEP || color == UP_BIRCHSTEP || color == UP_JUNGLESTEP) {
835-
setUpStep(x, y, c, L, D);
836-
return;
837-
}
838-
*/
839736
}
840737
// In case the user wants noise, calc the strength now, depending on the desired intensity and the block's brightness
841738
int noise = 0;
@@ -966,41 +863,8 @@ namespace
966863
//do there what you want, this code response for changing single pixel depending on its biome
967864
//note this works only for anvli format. old one still requires donkey kong biome extractor
968865

969-
//wrim - TODO - affect only to certain blocks
970-
971-
//uint8_t blockbase = block % 4096;
972-
//if (blockbase == LEAVES || blockbase == GRASS || blockbase == TALL_GRASS || blockbase == LEAVES2 || blockbase == VINES || blockbase == LILYPAD)
973866
if (colors[block][BLOCKTYPE] / BLOCKBIOME)
974867
addColor(color, biomes[biome]);
975-
976-
return;
977-
if (block == 2 || block == LEAVES||block==TALL_GRASS)
978-
switch (biome)
979-
{
980-
case 4:
981-
case 29:
982-
{
983-
int16_t c[4] = {255, 250, 250, 160};
984-
//memcpy(color, c, 3);
985-
addColor(color, c);
986-
}
987-
break;
988-
case 2:
989-
case 1:
990-
{
991-
int16_t c[4] = {255, 0, 0, 100};
992-
//memcpy(color, c, 3);
993-
addColor(color, c);
994-
}
995-
break;
996-
case 35:
997-
{
998-
int16_t c1[4] = {0, 255, 0, 70};
999-
//memcpy(color, c1, 3);
1000-
addColor(color, c1);
1001-
}
1002-
break;
1003-
}
1004868
}
1005869

1006870
inline void blend(uint8_t * const destination, const uint8_t * const source)
@@ -1209,8 +1073,8 @@ namespace
12091073
{
12101074
// this will make grass look like dirt from the side
12111075
uint8_t L[CHANSPERPIXEL], D[CHANSPERPIXEL];
1212-
memcpy(L, colors[DIRT], BYTESPERPIXEL);
1213-
memcpy(D, colors[DIRT], BYTESPERPIXEL);
1076+
memcpy(L, colors[GRASSBOTTOM], BYTESPERPIXEL);
1077+
memcpy(D, colors[GRASSBOTTOM], BYTESPERPIXEL);
12141078
modColor(L, sub - 15);
12151079
modColor(D, sub - 25);
12161080
// consider noise

draw_png.h

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ void createImageBuffer(const size_t width, const size_t height, const bool split
1212
bool createImage(FILE *fh, const size_t width, const size_t height, const bool splitUp);
1313
bool saveImage();
1414
int loadImagePart(const int startx, const int starty, const int width, const int height);
15-
void setPixel(const size_t x, const size_t y, const uint8_t color, const float fsub, const uint8_t biome);
1615
void setPixel(const size_t x, const size_t y, const uint16_t color, const float fsub, const uint8_t biome);
1716
void blendPixel(const size_t x, const size_t y, const uint8_t color, const float fsub);
1817
bool saveImagePart();

globals.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int g_TotalFromChunkX, g_TotalFromChunkZ, g_TotalToChunkX, g_TotalToChunkZ;
44
int g_FromChunkX = UNDEFINED, g_FromChunkZ = UNDEFINED, g_ToChunkX = UNDEFINED, g_ToChunkZ = UNDEFINED;
5-
size_t g_MapsizeZ = 0, g_MapsizeX = 0;
5+
size_t g_MapsizeZ = 0, g_MapsizeX = 0, g_Terrainsize = 0;
66
int g_MapminY = 0, g_MapsizeY = 256, g_OffsetY = 2;
77

88
int g_WorldFormat = -1;
@@ -23,8 +23,7 @@ uint8_t *g_Grasscolor = NULL, *g_Leafcolor = NULL, *g_TallGrasscolor = NULL;
2323
uint16_t *g_BiomeMap = NULL;
2424
int g_GrasscolorDepth = 0, g_FoliageDepth = 0;
2525

26-
uint16_t *g_Terrain = NULL;
27-
uint8_t *g_TerrainLow = NULL, *g_Light = NULL;
26+
uint8_t *g_Terrain = NULL, *g_Light = NULL;
2827
uint16_t *g_HeightMap = NULL;
2928

3029
int g_MarkerCount = 0;

globals.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _GLOBALS_H_
22
#define _GLOBALS_H_
33

4-
#define VERSION "beta 3.0.2 (compatible with Minecraft 1.7.4)"
4+
#define VERSION "beta 3.0.3"
55

66
#include <stdint.h>
77
#include <cstdlib>
@@ -26,7 +26,7 @@ extern int g_TotalFromChunkX, g_TotalFromChunkZ, g_TotalToChunkX, g_TotalToChunk
2626
// Current area of world being rendered
2727
extern int g_FromChunkX, g_FromChunkZ, g_ToChunkX, g_ToChunkZ;
2828
// size of that area in blocks (no offset)
29-
extern size_t g_MapsizeZ, g_MapsizeX;
29+
extern size_t g_MapsizeZ, g_MapsizeX, g_Terrainsize;
3030
extern int g_MapminY, g_MapsizeY;
3131

3232
extern int g_OffsetY; // y pixel offset in the final image for one y step in 3d array (2 or 3)
@@ -53,8 +53,7 @@ extern int g_MarkerCount;
5353
extern Marker g_Markers[MAX_MARKERS];
5454

5555
// 3D arrays holding terrain/lightmap
56-
extern uint16_t *g_Terrain;
57-
extern uint8_t *g_TerrainLow, *g_Light;
56+
extern uint8_t *g_Terrain, *g_Light;
5857
// 2D array to store min and max block height per X/Z - it's 2 bytes per index, upper for highest, lower for lowest (don't ask!)
5958
extern uint16_t *g_HeightMap;
6059

helper.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@
1010
// Some macros for easier array access
1111
// First: Block array
1212
#define BLOCKAT(x,y,z) g_Terrain[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
13+
#define BLOCKDATA(x,y,z) g_Terrain[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY + g_Terrainsize]
1314
#define BLOCKEAST(x,y,z) g_Terrain[(y) + ((g_MapsizeZ - ((x) + 1)) + ((z) * g_MapsizeZ)) * g_MapsizeY]
1415
#define BLOCKWEST(x,y,z) g_Terrain[(y) + ((x) + ((g_MapsizeX - ((z) + 1)) * g_MapsizeZ)) * g_MapsizeY]
1516
#define BLOCKNORTH(x,y,z) g_Terrain[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
1617
#define BLOCKSOUTH(x,y,z) g_Terrain[(y) + ((g_MapsizeZ - ((z) + 1)) + ((g_MapsizeX - ((x) + 1)) * g_MapsizeZ)) * g_MapsizeY]
17-
// Some macros for easier array access
18-
// First: Block array
19-
#define BLOCKAT8(x,y,z) g_TerrainLow[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
20-
#define BLOCKEAST8(x,y,z) g_TerrainLow[(y) + ((g_MapsizeZ - ((x) + 1)) + ((z) * g_MapsizeZ)) * g_MapsizeY]
21-
#define BLOCKWEST8(x,y,z) g_TerrainLow[(y) + ((x) + ((g_MapsizeX - ((z) + 1)) * g_MapsizeZ)) * g_MapsizeY]
22-
#define BLOCKNORTH8(x,y,z) g_TerrainLow[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
23-
#define BLOCKSOUTH8(x,y,z) g_TerrainLow[(y) + ((g_MapsizeZ - ((z) + 1)) + ((g_MapsizeX - ((x) + 1)) * g_MapsizeZ)) * g_MapsizeY]
2418
//#define BLOCKAT(x,y,z) g_Terrain[(x) + ((z) + ((y) * g_MapsizeZ)) * g_MapsizeX]
2519
//#define BLOCKEAST(x,y,z) g_Terrain[(z) + ((g_MapsizeZ - ((x) + 1)) + ((y) * g_MapsizeZ)) * g_MapsizeX]
2620
// Same for lightmap

0 commit comments

Comments
 (0)