Skip to content

Commit

Permalink
New memory allocation method for support all blocks and data types, d…
Browse files Browse the repository at this point in the history
…eleted bunch of junk code
  • Loading branch information
WRIM committed Jul 28, 2015
1 parent e9731b9 commit 001602c
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 902 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ mcmap3 changelog
Latest version is available at: http://wrim.pl/mcmap/
------------------------------------------------------

beta 3.0.3 (jul 28 2015)
-better memory organization
-improvements with custom colors
-several minor fixes

beta 3.0.2 (feb 09 2014)
added:
-support for biomes in anvil worlds
Expand Down
36 changes: 22 additions & 14 deletions colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ uint16_t colorsToID[256] =
224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255
248, 249, 24577, 20481, 16385, 12289, 8193, 4097
};

void SET_COLORNOISE(uint16_t col, uint16_t r, uint16_t g, uint16_t b, uint16_t a, uint16_t n)
Expand Down Expand Up @@ -619,21 +619,19 @@ bool loadColorsFromFile(const char *file)
printf("Skipping invalid blockid %d:%d in colors file\n", blockid, blockid3);
suffix = -1;
}
printf("Second value %d:%d in colors file\n", blockid, blockid3); //wrim
suffix = 1;
}
++ptr;
}
if (suffix < 0) continue;

uint8_t vals[5];
uint8_t vals[5] = {0,0};
bool valid = true;
for (int i = 0; i < 5; ++i) {
while (*ptr == ' ' || *ptr == '\t') {
++ptr;
}
if (*ptr == '\0' || *ptr == '#' || *ptr == '\12') {
printf("Too few arguments for block %d, ignoring line.\n", blockid);
valid = false;
break;
}
Expand All @@ -642,10 +640,23 @@ bool loadColorsFromFile(const char *file)
++ptr;
}
}
if (!valid) {
if (!valid) { //TODO
if (vals[0] != 0)
{
if (g_lowMemory)
{

}
else
{

}
printf("%d:%d copied to %d:%d\n", blockid, blockid3, vals[0], vals[1] & 0x0F);
}
else printf("Too few arguments for block %d, ignoring line.\n", blockid);
continue;
}
int blockidSET = (blockid3 << 12)+blockid;
int blockidSET = (blockid3 << 12) + blockid;
if (g_lowMemory)
{
if (lowmemCounter > 255)
Expand Down Expand Up @@ -683,22 +694,19 @@ bool dumpColorsToFile(const char *file)
return false;
}
fprintf(f, "# For Block IDs see http://minecraftwiki.net/wiki/Data_values\n"
"# and http://wrim.pl/mcmap (for blocks introduced since Minecraft 1.3.1 and mcmap 2.4)\n"
"# Note that noise or alpha (or both) do not work for a few blocks like snow, torches, fences, steps, ...\n"
"# Actually, if you see any block has an alpha value of 254 you should leave it that way to prevent black artifacts.\n"
"# If you want to set alpha of grass to <255, use -blendall or you won't get what you expect.\n"
"# Noise is supposed to look normal using -noise 10\n"
"# 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"
"# half-steps of sand, wood and cobblestone are 232 to 236\n\n");
uint16_t j = 0;
"# Noise is supposed to look normal using -noise 10\n\n");
uint16_t head = 0;
for (size_t i = 1; i < 4096; ++i) {
uint8_t *c = colors[i];
if (c[PALPHA] == 0) continue; // if color doesn't exist, don't dump it
if (++j % 15 == 1) { //wrim - 3 cases - color only for :0, common for : and different for every :x
fprintf(f, "#ID R G B A Noise\n");//wrim - block types dump
if (++head % 15 == 1) {
fprintf(f, "#ID R G B A Noise\n");
}
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]));
for (int j = 0; j < 16; j++)
for (int j = 1; j < 16; j++)
{
uint8_t *c2 = colors[i+(j<<12)];
if (c2[PALPHA] != 0 && (c[PRED] != c2[PRED] || c[PGREEN] != c2[PGREEN] || c[PBLUE] != c2[PBLUE] || c[PALPHA] != c2[PALPHA] || c[NOISE] != c2[NOISE]))
Expand Down
142 changes: 3 additions & 139 deletions draw_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,9 @@ uint64_t calcImageSize(const int mapChunksX, const int mapChunksZ, const size_t
return uint64_t(pixelsX) * BYTESPERPIXEL * uint64_t(pixelsY);
}

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
{
uint16_t color16 = colorsToID[color];
setPixel(x, y, color16, fsub, biome);
}

void setPixel(const size_t x, const size_t y, const uint16_t color, const float fsub, const uint8_t biome)
{

// Sets pixels around x,y where A is the anchor
// T = given color, D = darker, L = lighter
// A T T T
Expand Down Expand Up @@ -670,37 +665,7 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
case BLOCKRAILROAD:
setRailroad(x, y, c);
return;
} /*
if (color == SNOW || color == TRAPDOOR
|| color == 141 || color == 142 || color == 158 || color == 149
|| color == 131 || color == 132 || color == 150 || color == 147 || color == 148 || color == 68 || color == 69 || color == 70
|| color == 72 || color == 77 || color == 143 || color == 36) { //three lines of carpets ID's I can't do this other way
setSnowBA(x, y, c);
return;
}
if (color == TORCH || color == REDTORCH_ON || color == REDTORCH_OFF) {
setTorchBA(x, y, c);
return;
}
if (color == FLOWERR || color == FLOWERY || color == MUSHROOMB || color == MUSHROOMR || color == MELON_STEM || color == PUMPKIN_STEM || color == SHRUB || color == COBWEB || color == LILYPAD || color == NETHER_WART
|| 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 ) {
setFlowerBA(x, y, c);
return;
}
if (color == FENCE || color == FENCE_GATE || color == VINES || color == IRON_BARS || color == NETHER_BRICK_FENCE
|| color == 139) {
setFence(x, y, c);
return;
}
if (color == REDWIRE || color == TRIPWIRE) {
setRedwire(x, y, c);
return;
}
if (color == RAILROAD || color == POW_RAILROAD || color == DET_RAILROAD) {
setRailroad(x, y, c);
return;
}
*/
// All the above blocks didn't need the shaded down versions of the color, so we only calc them here
// They are for the sides of blocks
memcpy(L, c, BYTESPERPIXEL);
Expand All @@ -723,25 +688,6 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
setUpStepBA(x, y, c, L, D);
return;
}
/*
if (color == GRASS) {
setGrassBA(x, y, c, L, D, sub);
return;
}
if (color == FIRE || color == TALL_GRASS || color == COCOA_PLANT) {
setFire(x, y, c, L, D);
return;
}
if (color == STEP || color == CAKE || color == BED || color == SANDSTEP || color == WOODSTEP || color == COBBLESTEP || color == BRICKSTEP || color == STONEBRICKSTEP || color == PINESTEP || color == BIRCHSTEP || color == JUNGLESTEP
|| color == 151) {
setStepBA(x, y, c, L, D);
return;
}
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) {
setUpStepBA(x, y, c, L, D);
return;
}
*/
} else {
// Then check the block type, as some types will be drawn differently
switch (colortype)
Expand All @@ -765,36 +711,6 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
setRailroad(x, y, c);
return;
}
/*
if (color == SNOW || color == TRAPDOOR
|| color == 141 || color == 142 || color == 158 || color == 149
|| color == 131 || color == 132 || color == 150 || color == 147 || color == 148 || color == 68 || color == 69 || color == 70
|| color == 72 || color == 77 || color == 143 || color == 36) { //three lines of carpets ID's I can't do this other way
setSnow(x, y, c);
return;
}
if (color == TORCH || color == REDTORCH_ON || color == REDTORCH_OFF) {
setTorch(x, y, c);
return;
}
if (color == FLOWERR || color == FLOWERY || color == MUSHROOMB || color == MUSHROOMR || color == MELON_STEM || color == PUMPKIN_STEM || color == SHRUB || color == COBWEB || color == LILYPAD || color == NETHER_WART
|| 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 ) {
setFlower(x, y, c);
return;
}
if (color == FENCE || color == FENCE_GATE || color == VINES || color == IRON_BARS || color == NETHER_BRICK_FENCE) {
setFence(x, y, c);
return;
}
if (color == REDWIRE || color == TRIPWIRE) {
setRedwire(x, y, c);
return;
}
if (color == RAILROAD || color == POW_RAILROAD || color == DET_RAILROAD) {
setRailroad(x, y, c);
return;
}
*/
// All the above blocks didn't need the shaded down versions of the color, so we only calc them here
// They are for the sides of blocks
memcpy(L, c, BYTESPERPIXEL);
Expand All @@ -817,25 +733,6 @@ void setPixel(const size_t x, const size_t y, const uint16_t color, const float
setUpStep(x, y, c, L, D);
return;
}
/*
if (color == GRASS) {
setGrass(x, y, c, L, D, sub);
return;
}
if (color == FIRE || color == TALL_GRASS || color == COCOA_PLANT) {
setFire(x, y, c, L, D);
return;
}
if (color == STEP || color == CAKE || color == BED || color == SANDSTEP || color == WOODSTEP || color == COBBLESTEP || color == BRICKSTEP || color == STONEBRICKSTEP || color == PINESTEP || color == BIRCHSTEP || color == JUNGLESTEP
|| color == 151) {
setStep(x, y, c, L, D);
return;
}
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) {
setUpStep(x, y, c, L, D);
return;
}
*/
}
// In case the user wants noise, calc the strength now, depending on the desired intensity and the block's brightness
int noise = 0;
Expand Down Expand Up @@ -966,41 +863,8 @@ namespace
//do there what you want, this code response for changing single pixel depending on its biome
//note this works only for anvli format. old one still requires donkey kong biome extractor

//wrim - TODO - affect only to certain blocks

//uint8_t blockbase = block % 4096;
//if (blockbase == LEAVES || blockbase == GRASS || blockbase == TALL_GRASS || blockbase == LEAVES2 || blockbase == VINES || blockbase == LILYPAD)
if (colors[block][BLOCKTYPE] / BLOCKBIOME)
addColor(color, biomes[biome]);

return;
if (block == 2 || block == LEAVES||block==TALL_GRASS)
switch (biome)
{
case 4:
case 29:
{
int16_t c[4] = {255, 250, 250, 160};
//memcpy(color, c, 3);
addColor(color, c);
}
break;
case 2:
case 1:
{
int16_t c[4] = {255, 0, 0, 100};
//memcpy(color, c, 3);
addColor(color, c);
}
break;
case 35:
{
int16_t c1[4] = {0, 255, 0, 70};
//memcpy(color, c1, 3);
addColor(color, c1);
}
break;
}
}

inline void blend(uint8_t * const destination, const uint8_t * const source)
Expand Down Expand Up @@ -1209,8 +1073,8 @@ namespace
{
// this will make grass look like dirt from the side
uint8_t L[CHANSPERPIXEL], D[CHANSPERPIXEL];
memcpy(L, colors[DIRT], BYTESPERPIXEL);
memcpy(D, colors[DIRT], BYTESPERPIXEL);
memcpy(L, colors[GRASSBOTTOM], BYTESPERPIXEL);
memcpy(D, colors[GRASSBOTTOM], BYTESPERPIXEL);
modColor(L, sub - 15);
modColor(D, sub - 25);
// consider noise
Expand Down
1 change: 0 additions & 1 deletion draw_png.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ void createImageBuffer(const size_t width, const size_t height, const bool split
bool createImage(FILE *fh, const size_t width, const size_t height, const bool splitUp);
bool saveImage();
int loadImagePart(const int startx, const int starty, const int width, const int height);
void setPixel(const size_t x, const size_t y, const uint8_t color, const float fsub, const uint8_t biome);
void setPixel(const size_t x, const size_t y, const uint16_t color, const float fsub, const uint8_t biome);
void blendPixel(const size_t x, const size_t y, const uint8_t color, const float fsub);
bool saveImagePart();
Expand Down
5 changes: 2 additions & 3 deletions globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

int g_TotalFromChunkX, g_TotalFromChunkZ, g_TotalToChunkX, g_TotalToChunkZ;
int g_FromChunkX = UNDEFINED, g_FromChunkZ = UNDEFINED, g_ToChunkX = UNDEFINED, g_ToChunkZ = UNDEFINED;
size_t g_MapsizeZ = 0, g_MapsizeX = 0;
size_t g_MapsizeZ = 0, g_MapsizeX = 0, g_Terrainsize = 0;
int g_MapminY = 0, g_MapsizeY = 256, g_OffsetY = 2;

int g_WorldFormat = -1;
Expand All @@ -23,8 +23,7 @@ uint8_t *g_Grasscolor = NULL, *g_Leafcolor = NULL, *g_TallGrasscolor = NULL;
uint16_t *g_BiomeMap = NULL;
int g_GrasscolorDepth = 0, g_FoliageDepth = 0;

uint16_t *g_Terrain = NULL;
uint8_t *g_TerrainLow = NULL, *g_Light = NULL;
uint8_t *g_Terrain = NULL, *g_Light = NULL;
uint16_t *g_HeightMap = NULL;

int g_MarkerCount = 0;
Expand Down
7 changes: 3 additions & 4 deletions globals.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _GLOBALS_H_
#define _GLOBALS_H_

#define VERSION "beta 3.0.2 (compatible with Minecraft 1.7.4)"
#define VERSION "beta 3.0.3"

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

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

// 3D arrays holding terrain/lightmap
extern uint16_t *g_Terrain;
extern uint8_t *g_TerrainLow, *g_Light;
extern uint8_t *g_Terrain, *g_Light;
// 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!)
extern uint16_t *g_HeightMap;

Expand Down
8 changes: 1 addition & 7 deletions helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@
// Some macros for easier array access
// First: Block array
#define BLOCKAT(x,y,z) g_Terrain[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKDATA(x,y,z) g_Terrain[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY + g_Terrainsize]
#define BLOCKEAST(x,y,z) g_Terrain[(y) + ((g_MapsizeZ - ((x) + 1)) + ((z) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKWEST(x,y,z) g_Terrain[(y) + ((x) + ((g_MapsizeX - ((z) + 1)) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKNORTH(x,y,z) g_Terrain[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKSOUTH(x,y,z) g_Terrain[(y) + ((g_MapsizeZ - ((z) + 1)) + ((g_MapsizeX - ((x) + 1)) * g_MapsizeZ)) * g_MapsizeY]
// Some macros for easier array access
// First: Block array
#define BLOCKAT8(x,y,z) g_TerrainLow[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKEAST8(x,y,z) g_TerrainLow[(y) + ((g_MapsizeZ - ((x) + 1)) + ((z) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKWEST8(x,y,z) g_TerrainLow[(y) + ((x) + ((g_MapsizeX - ((z) + 1)) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKNORTH8(x,y,z) g_TerrainLow[(y) + ((z) + ((x) * g_MapsizeZ)) * g_MapsizeY]
#define BLOCKSOUTH8(x,y,z) g_TerrainLow[(y) + ((g_MapsizeZ - ((z) + 1)) + ((g_MapsizeX - ((x) + 1)) * g_MapsizeZ)) * g_MapsizeY]
//#define BLOCKAT(x,y,z) g_Terrain[(x) + ((z) + ((y) * g_MapsizeZ)) * g_MapsizeX]
//#define BLOCKEAST(x,y,z) g_Terrain[(z) + ((g_MapsizeZ - ((x) + 1)) + ((y) * g_MapsizeZ)) * g_MapsizeX]
// Same for lightmap
Expand Down
Loading

0 comments on commit 001602c

Please sign in to comment.