added 'minerals' option to mineral overlay
This commit is contained in:
@@ -17,13 +17,13 @@
|
|||||||
|
|
||||||
#include "overviewer.h"
|
#include "overviewer.h"
|
||||||
|
|
||||||
struct OreColor {
|
struct MineralColor {
|
||||||
unsigned char blockid;
|
unsigned char blockid;
|
||||||
unsigned char r, g, b;
|
unsigned char r, g, b;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* put more valuable ores first -- they take precedence */
|
/* put more valuable ores first -- they take precedence */
|
||||||
static struct OreColor orecolors[] = {
|
static struct MineralColor default_minerals[] = {
|
||||||
{48 /* Mossy Stone */, 31, 153, 9},
|
{48 /* Mossy Stone */, 31, 153, 9},
|
||||||
|
|
||||||
{56 /* Diamond Ore */, 32, 230, 220},
|
{56 /* Diamond Ore */, 32, 230, 220},
|
||||||
@@ -44,18 +44,20 @@ static void get_color(void *data, RenderState *state,
|
|||||||
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
|
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
|
||||||
|
|
||||||
int x = state->x, y = state->y, z_max = state->z, z;
|
int x = state->x, y = state->y, z_max = state->z, z;
|
||||||
//RenderModeMineral* self = (RenderModeMineral *)data;
|
int max_i = -1;
|
||||||
|
RenderModeMineral* self = (RenderModeMineral *)data;
|
||||||
|
struct MineralColor *minerals = (struct MineralColor *)(self->minerals);
|
||||||
*a = 0;
|
*a = 0;
|
||||||
|
|
||||||
for (z = 0; z <= z_max; z++) {
|
for (z = 0; z <= z_max; z++) {
|
||||||
int i, tmp, max_i = sizeof(orecolors) / sizeof(struct OreColor);
|
int i, tmp;
|
||||||
unsigned char blockid = getArrayByte3D(state->blocks, x, y, z);
|
unsigned char blockid = getArrayByte3D(state->blocks, x, y, z);
|
||||||
|
|
||||||
for (i = 0; i < max_i && orecolors[i].blockid != 0; i++) {
|
for (i = 0; (max_i == -1 || i < max_i) && minerals[i].blockid != 0; i++) {
|
||||||
if (orecolors[i].blockid == blockid) {
|
if (minerals[i].blockid == blockid) {
|
||||||
*r = orecolors[i].r;
|
*r = minerals[i].r;
|
||||||
*g = orecolors[i].g;
|
*g = minerals[i].g;
|
||||||
*b = orecolors[i].b;
|
*b = minerals[i].b;
|
||||||
|
|
||||||
tmp = (128 - z_max + z) * 2 - 40;
|
tmp = (128 - z_max + z) * 2 - 40;
|
||||||
*a = MIN(MAX(0, tmp), 255);
|
*a = MIN(MAX(0, tmp), 255);
|
||||||
@@ -69,6 +71,7 @@ static void get_color(void *data, RenderState *state,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
rendermode_mineral_start(void *data, RenderState *state, PyObject *options) {
|
rendermode_mineral_start(void *data, RenderState *state, PyObject *options) {
|
||||||
|
PyObject *opt;
|
||||||
RenderModeMineral* self;
|
RenderModeMineral* self;
|
||||||
|
|
||||||
/* first, chain up */
|
/* first, chain up */
|
||||||
@@ -79,6 +82,35 @@ rendermode_mineral_start(void *data, RenderState *state, PyObject *options) {
|
|||||||
/* now do custom initializations */
|
/* now do custom initializations */
|
||||||
self = (RenderModeMineral *)data;
|
self = (RenderModeMineral *)data;
|
||||||
|
|
||||||
|
opt = PyDict_GetItemString(options, "minerals");
|
||||||
|
if (opt) {
|
||||||
|
struct MineralColor *minerals = NULL;
|
||||||
|
Py_ssize_t minerals_size = 0, i;
|
||||||
|
/* create custom minerals */
|
||||||
|
|
||||||
|
if (!PyList_Check(opt)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "'minerals' must be a list");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
minerals_size = PyList_GET_SIZE(opt);
|
||||||
|
minerals = self->minerals = calloc(minerals_size + 1, sizeof(struct MineralColor));
|
||||||
|
if (minerals == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < minerals_size; i++) {
|
||||||
|
PyObject *mineral = PyList_GET_ITEM(opt, i);
|
||||||
|
if (!PyArg_ParseTuple(mineral, "b(bbb)", &(minerals[i].blockid), &(minerals[i].r), &(minerals[i].g), &(minerals[i].b))) {
|
||||||
|
free(minerals);
|
||||||
|
self->minerals = NULL;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self->minerals = default_minerals;
|
||||||
|
}
|
||||||
|
|
||||||
/* setup custom color */
|
/* setup custom color */
|
||||||
self->parent.get_color = get_color;
|
self->parent.get_color = get_color;
|
||||||
|
|
||||||
@@ -88,7 +120,11 @@ rendermode_mineral_start(void *data, RenderState *state, PyObject *options) {
|
|||||||
static void
|
static void
|
||||||
rendermode_mineral_finish(void *data, RenderState *state) {
|
rendermode_mineral_finish(void *data, RenderState *state) {
|
||||||
/* first free all *our* stuff */
|
/* first free all *our* stuff */
|
||||||
//RenderModeMineral* self = (RenderModeMineral *)data;
|
RenderModeMineral* self = (RenderModeMineral *)data;
|
||||||
|
|
||||||
|
if (self->minerals && self->minerals != default_minerals) {
|
||||||
|
free(self->minerals);
|
||||||
|
}
|
||||||
|
|
||||||
/* now, chain up */
|
/* now, chain up */
|
||||||
rendermode_overlay.finish(data, state);
|
rendermode_overlay.finish(data, state);
|
||||||
@@ -106,9 +142,14 @@ rendermode_mineral_draw(void *data, RenderState *state, PyObject *src, PyObject
|
|||||||
rendermode_overlay.draw(data, state, src, mask, mask_light);
|
rendermode_overlay.draw(data, state, src, mask, mask_light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RenderModeOption rendermode_mineral_options[] = {
|
||||||
|
{"minerals", "a list of (blockid, (r, g, b)) tuples for coloring minerals"},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
RenderModeInterface rendermode_mineral = {
|
RenderModeInterface rendermode_mineral = {
|
||||||
"mineral", "draws a colored overlay showing where ores are located",
|
"mineral", "draws a colored overlay showing where ores are located",
|
||||||
NULL,
|
rendermode_mineral_options,
|
||||||
&rendermode_overlay,
|
&rendermode_overlay,
|
||||||
sizeof(RenderModeMineral),
|
sizeof(RenderModeMineral),
|
||||||
rendermode_mineral_start,
|
rendermode_mineral_start,
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ extern RenderModeInterface rendermode_cave;
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
/* inherits from overlay */
|
/* inherits from overlay */
|
||||||
RenderModeOverlay parent;
|
RenderModeOverlay parent;
|
||||||
|
|
||||||
|
void *minerals;
|
||||||
} RenderModeMineral;
|
} RenderModeMineral;
|
||||||
extern RenderModeInterface rendermode_mineral;
|
extern RenderModeInterface rendermode_mineral;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user