Skip to content

Commit

Permalink
Merge pull request #7 from dalandis/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory-AM authored Jul 24, 2023
2 parents de70858 + c346aa0 commit e17b71e
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 256 deletions.
10 changes: 4 additions & 6 deletions overviewer_core/src/iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ static inline void load_chunk_section(ChunkData* dest, int32_t i, PyObject* sect
dest->sections[i].data = (PyArrayObject*)PyDict_GetItemString(section, "Data");
dest->sections[i].skylight = (PyArrayObject*)PyDict_GetItemString(section, "SkyLight");
dest->sections[i].blocklight = (PyArrayObject*)PyDict_GetItemString(section, "BlockLight");
dest->sections[i].biomes = (PyArrayObject*)PyDict_GetItemString(section, "Biomes");
Py_INCREF(dest->sections[i].biomes);
Py_INCREF(dest->sections[i].blocks);
Py_INCREF(dest->sections[i].data);
Py_INCREF(dest->sections[i].skylight);
Expand All @@ -131,12 +133,12 @@ bool load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
return false;

/* set reasonable defaults */
dest->biomes = NULL;
for (i = 0; i < SECTIONS_PER_CHUNK; i++) {
dest->sections[i].blocks = NULL;
dest->sections[i].data = NULL;
dest->sections[i].skylight = NULL;
dest->sections[i].blocklight = NULL;
dest->sections[i].biomes = NULL;
}
dest->loaded = 1;

Expand Down Expand Up @@ -166,10 +168,6 @@ bool load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
return true;
}

dest->biomes = (PyArrayObject*)PyDict_GetItemString(chunk, "Biomes");
Py_INCREF(dest->biomes);
dest->new_biomes = PyObject_IsTrue(PyDict_GetItemString(chunk, "NewBiomes"));

for (i = 0; i < PySequence_Fast_GET_SIZE(sections); i++) {
PyObject* ycoord = NULL;
int32_t sectiony = 0;
Expand All @@ -195,12 +193,12 @@ unload_all_chunks(RenderState* state) {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
if (state->chunks[i][j].loaded) {
Py_XDECREF(state->chunks[i][j].biomes);
for (k = 0; k < SECTIONS_PER_CHUNK; k++) {
Py_XDECREF(state->chunks[i][j].sections[k].blocks);
Py_XDECREF(state->chunks[i][j].sections[k].data);
Py_XDECREF(state->chunks[i][j].sections[k].skylight);
Py_XDECREF(state->chunks[i][j].sections[k].blocklight);
Py_XDECREF(state->chunks[i][j].sections[k].biomes);
}
state->chunks[i][j].loaded = 0;
}
Expand Down
16 changes: 4 additions & 12 deletions overviewer_core/src/overviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

// increment this value if you've made a change to the c extension
// and want to force users to rebuild
#define OVERVIEWER_EXTENSION_VERSION 117
#define OVERVIEWER_EXTENSION_VERSION 118

#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -82,14 +82,10 @@ typedef struct _RenderMode RenderMode;
typedef struct {
/* whether this chunk is loaded: use load_chunk to load */
int32_t loaded;
/* chunk biome array */
PyArrayObject* biomes;
/* whether this is a 3d biome array */
bool new_biomes;
/* all the sections in a given chunk */
struct {
/* all there is to know about each section */
PyArrayObject *blocks, *data, *skylight, *blocklight;
PyArrayObject *blocks, *data, *skylight, *blocklight, *biomes;
} sections[SECTIONS_PER_CHUNK];
} ChunkData;
typedef struct {
Expand Down Expand Up @@ -212,7 +208,7 @@ static inline uint32_t get_data(RenderState* state, DataType type, int32_t x, in
data_array = state->chunks[chunkx][chunkz].sections[chunky].skylight;
break;
case BIOMES:
data_array = state->chunks[chunkx][chunkz].biomes;
data_array = state->chunks[chunkx][chunkz].sections[chunky].biomes;
};

if (data_array == NULL)
Expand All @@ -221,11 +217,7 @@ static inline uint32_t get_data(RenderState* state, DataType type, int32_t x, in
if (type == BLOCKS)
return getArrayShort3D(data_array, x, y, z);
if (type == BIOMES) {
if (state->chunks[chunkx][chunkz].new_biomes) {
return getArrayByte3D(data_array, x / 4, y / 4, z / 4);
} else {
return getArrayByte2D(data_array, x, z);
}
return getArrayByte3D(data_array, x / 4, y / 4, z / 4);
}
return getArrayByte3D(data_array, x, y, z);
}
Expand Down
61 changes: 44 additions & 17 deletions overviewer_core/src/primitives/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,16 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
(((state->block == block_pumpkin_stem) || (state->block == block_melon_stem)) && (state->block_data != 7)) ||
/* doublePlant grass & ferns */
(state->block == block_double_plant && (state->block_data == 2 || state->block_data == 3)) ||
/* sugarcane/reeds (according to minecraft-fandom) */
(state->block == block_reeds) ||
/* doublePlant grass & ferns tops */
(state->block == block_double_plant && below_block == block_double_plant && (below_data == 2 || below_data == 3))) {
/* do the biome stuff! */
PyObject* facemask = mask;
uint8_t r = 255, g = 255, b = 255;
PyObject* color_table = NULL;
bool flip_xy = false;
bool is_water = false;

if (state->block == block_grass) {
/* grass needs a special facemask */
Expand All @@ -129,6 +132,8 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
color_table = self->grasscolor;
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water, block_water}, 2)) {
color_table = self->watercolor;
//we dont use color_table for water but i am too lazy for refactoring :(
is_water = true;
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_leaves, block_leaves2}, 2)) {
color_table = self->foliagecolor;
/* birch foliage color is flipped XY-ways */
Expand Down Expand Up @@ -158,9 +163,16 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec

temp += biome_table[biome].temperature;
rain += biome_table[biome].rainfall;
multr += biome_table[biome].r;
multg += biome_table[biome].g;
multb += biome_table[biome].b;
if (is_water) {
multr += biome_table[biome].water_r;
multg += biome_table[biome].water_g;
multb += biome_table[biome].water_b;
//printf("%s, (%d, %d, %d) ->\n", biome_table[biome].name, biome_table[biome].water_r, biome_table[biome].water_g, biome_table[biome].water_b);
} else {
multr += biome_table[biome].r;
multg += biome_table[biome].g;
multb += biome_table[biome].b;
}
}
}

Expand All @@ -173,9 +185,16 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
/* don't use biomes, just use the default */
temp = biome_table[DEFAULT_BIOME].temperature;
rain = biome_table[DEFAULT_BIOME].rainfall;
multr = biome_table[DEFAULT_BIOME].r;
multg = biome_table[DEFAULT_BIOME].g;
multb = biome_table[DEFAULT_BIOME].b;

if (is_water) {
multr = biome_table[DEFAULT_BIOME].water_r;
multg = biome_table[DEFAULT_BIOME].water_g;
multb = biome_table[DEFAULT_BIOME].water_b;
} else {
multr = biome_table[DEFAULT_BIOME].r;
multg = biome_table[DEFAULT_BIOME].g;
multb = biome_table[DEFAULT_BIOME].b;
}
}

/* second coordinate is actually scaled to fit inside the triangle
Expand All @@ -195,17 +214,25 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
tabley = tmp;
}

/* look up color! */
color = PySequence_GetItem(color_table, tabley * 256 + tablex);
r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
Py_DECREF(color);

/* do the after-coloration */
r = OV_MULDIV255(r, multr, tmp);
g = OV_MULDIV255(g, multg, tmp);
b = OV_MULDIV255(b, multb, tmp);
if(is_water) {
//dont use colortable, use averaged biome-watercolor
r = multr;
g = multg;
b = multb;
multb = 0, multg = 0; multb = 0;
} else {
/* look up color! */
color = PySequence_GetItem(color_table, tabley * 256 + tablex);
r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
Py_DECREF(color);

/* do the after-coloration */
r = OV_MULDIV255(r, multr, tmp);
g = OV_MULDIV255(g, multg, tmp);
b = OV_MULDIV255(b, multb, tmp);
}
}

/* final coloration */
Expand Down
Loading

0 comments on commit e17b71e

Please sign in to comment.