예제 #1
0
static int
edge_lines_start(void *data, RenderState *state, PyObject *support) {
    PrimitiveEdgeLines *self = (PrimitiveEdgeLines *)data;
    if (!render_mode_parse_option(support, "opacity", "f", &(self->opacity)))
        return 1;
    return 0;
}
예제 #2
0
static int
lighting_start(void *data, RenderState *state, PyObject *support) {
    RenderPrimitiveLighting* self;
    self = (RenderPrimitiveLighting *)data;
    
    /* don't skip sides by default */
    self->skip_sides = 0;

    if (!render_mode_parse_option(support, "strength", "f", &(self->strength)))
        return 1;
    if (!render_mode_parse_option(support, "night", "i", &(self->night)))
        return 1;
    if (!render_mode_parse_option(support, "color", "i", &(self->color)))
        return 1;
    
    self->facemasks_py = PyObject_GetAttrString(support, "facemasks");
    // borrowed references, don't need to be decref'd
    self->facemasks[0] = PyTuple_GetItem(self->facemasks_py, 0);
    self->facemasks[1] = PyTuple_GetItem(self->facemasks_py, 1);
    self->facemasks[2] = PyTuple_GetItem(self->facemasks_py, 2);
    
    if (self->night) {
        self->calculate_light_color = calculate_light_color_night;
    } else {
        self->calculate_light_color = calculate_light_color;
    }
    
    if (self->color) {
        self->lightcolor = PyObject_CallMethod(state->textures, "load_light_color", "");
        if (self->lightcolor == Py_None) {
            Py_DECREF(self->lightcolor);
            self->lightcolor = NULL;
            self->color = 0;
        } else {
            if (self->night) {
                self->calculate_light_color = calculate_light_color_fancy_night;
            } else {
                self->calculate_light_color = calculate_light_color_fancy;
            }
        }
    } else {
        self->lightcolor = NULL;
    }
    
    return 0;
}
예제 #3
0
static int
overlay_start(void *data, RenderState *state, PyObject *support) {
    PyObject *opt = NULL;
    OverlayColor *color = NULL;
    RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
    
    self->facemask_top = PyObject_GetAttrString(support, "facemask_top");
    self->white_color = PyObject_GetAttrString(support, "whitecolor");
    self->get_color = get_color;
    
    color = self->color = calloc(1, sizeof(OverlayColor));

    if (color == NULL) {
        return 1;
    }
    
    self->default_color.r = 200;
    self->default_color.g = 200;
    self->default_color.b = 255;
    self->default_color.a = 155;
    
    if(!render_mode_parse_option(support, "overlay_color", "bbbb", &(color->r), &(color->g), &(color->b), &(color->a))) {
        if(PyErr_Occurred())
            PyErr_Clear();
        free(color);
        self->color = &self->default_color;
        // Check if it is None, if it is, continue and use the default, if it isn't, return an error
        if(render_mode_parse_option(support, "overlay_color", "O", &(opt))) {
            // If it is an object, check to see if it is None, if it is, use the default.
            if(opt && opt != Py_None) {
                return 1;
            }
        }
    }

    return 0;
}
예제 #4
0
static int
base_start(void *data, RenderState *state, PyObject *support) {
    PrimitiveBase *self = (PrimitiveBase *)data;
    
    if (!render_mode_parse_option(support, "biomes", "i", &(self->use_biomes)))
        return 1;
    
    /* biome-compliant grass mask (includes sides!) */
    self->grass_texture = PyObject_GetAttrString(state->textures, "biome_grass_texture");
    
    /* color lookup tables */
    self->foliagecolor = PyObject_CallMethod(state->textures, "load_foliage_color", "");
    self->grasscolor = PyObject_CallMethod(state->textures, "load_grass_color", "");
    self->watercolor = PyObject_CallMethod(state->textures, "load_water_color", "");
    
    return 0;
}
예제 #5
0
static int
hide_start(void *data, RenderState *state, PyObject *support) {
    PyObject *opt;
    RenderPrimitiveHide* self = (RenderPrimitiveHide *)data;
    self->rules = NULL;
    
    if (!render_mode_parse_option(support, "blocks", "O", &(opt)))
        return 1;
    if (opt && opt != Py_None) {
        Py_ssize_t blocks_size = 0, i;
        
        if (!PyList_Check(opt)) {
            PyErr_SetString(PyExc_TypeError, "'blocks' must be a list");
            return 1;
        }
        
        blocks_size = PyList_GET_SIZE(opt);
        self->rules = calloc(blocks_size + 1, sizeof(struct HideRule));
        if (self->rules == NULL) {
            return 1;
        }

        for (i = 0; i < blocks_size; i++) {
            PyObject *block = PyList_GET_ITEM(opt, i);
            
            if (PyInt_Check(block)) {
                /* format 1: just a block id */
                self->rules[i].blockid = PyInt_AsLong(block);
                self->rules[i].has_data = 0;
            } else if (PyArg_ParseTuple(block, "Hb", &(self->rules[i].blockid), &(self->rules[i].data))) {
                /* format 2: (blockid, data) */
                self->rules[i].has_data = 1;
            } else {
                /* format not recognized */
                free(self->rules);
                self->rules = NULL;
                return 1;
            }
        }
    }
    
    return 0;
}
static int
rendermode_lighting_start(void *data, RenderState *state, PyObject *options) {
    RenderModeLighting* self;

    /* first, chain up */
    int ret = rendermode_normal.start(data, state, options);
    if (ret != 0)
        return ret;
    
    self = (RenderModeLighting *)data;
    
    /* skip sides by default */
    self->skip_sides = 1;

    self->shade_strength = 1.0;
    if (!render_mode_parse_option(options, "shade_strength", "f", &(self->shade_strength)))
        return 1;
    
    self->black_color = PyObject_GetAttrString(state->chunk, "black_color");
    self->facemasks_py = PyObject_GetAttrString(state->chunk, "facemasks");
    // borrowed references, don't need to be decref'd
    self->facemasks[0] = PyTuple_GetItem(self->facemasks_py, 0);
    self->facemasks[1] = PyTuple_GetItem(self->facemasks_py, 1);
    self->facemasks[2] = PyTuple_GetItem(self->facemasks_py, 2);
    
    self->skylight = PyObject_GetAttrString(state->self, "skylight");
    self->blocklight = PyObject_GetAttrString(state->self, "blocklight");
    self->left_skylight = PyObject_GetAttrString(state->self, "left_skylight");
    self->left_blocklight = PyObject_GetAttrString(state->self, "left_blocklight");
    self->right_skylight = PyObject_GetAttrString(state->self, "right_skylight");
    self->right_blocklight = PyObject_GetAttrString(state->self, "right_blocklight");
    
    self->calculate_darkness = calculate_darkness;
    
    return 0;
}
static int
rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
    PyObject *chunk_x_py, *chunk_y_py, *world, *use_biomes, *worlddir;
    RenderModeNormal *self = (RenderModeNormal *)data;
    
    /* load up the given options, first */
    
    self->edge_opacity = 0.15;
    if (!render_mode_parse_option(options, "edge_opacity", "f", &(self->edge_opacity)))
        return 1;
    
    self->min_depth = 0;
    if (!render_mode_parse_option(options, "min_depth", "I", &(self->min_depth)))
        return 1;

    self->max_depth = 127;
    if (!render_mode_parse_option(options, "max_depth", "I", &(self->max_depth)))
        return 1;

    self->height_fading = 0;
    if (!render_mode_parse_option(options, "height_fading", "i", &(self->height_fading)))
        return 1;
    
    self->nether = 0;
    if (!render_mode_parse_option(options, "nether", "i", &(self->nether)))
        return 1;
    
    if (self->height_fading) {
        self->black_color = PyObject_GetAttrString(state->chunk, "black_color");
        self->white_color = PyObject_GetAttrString(state->chunk, "white_color");
    }
    
    /* biome-compliant grass mask (includes sides!) */
    self->grass_texture = PyObject_GetAttrString(state->textures, "biome_grass_texture");

    chunk_x_py = PyObject_GetAttrString(state->self, "chunkX");
    chunk_y_py = PyObject_GetAttrString(state->self, "chunkY");
    
    /* careful now -- C's % operator works differently from python's
       we can't just do x % 32 like we did before */
    self->chunk_x = PyInt_AsLong(chunk_x_py);
    self->chunk_y = PyInt_AsLong(chunk_y_py);
    
    while (self->chunk_x < 0)
        self->chunk_x += 32;
    while (self->chunk_y < 0)
        self->chunk_y += 32;
    
    self->chunk_x %= 32;
    self->chunk_y %= 32;
    
    /* fetch the biome data from textures.py, if needed */
    world = PyObject_GetAttrString(state->self, "world");
    worlddir = PyObject_GetAttrString(world, "worlddir");
    use_biomes = PyObject_GetAttrString(world, "useBiomeData");
    Py_DECREF(world);
    
    if (PyObject_IsTrue(use_biomes)) {
        self->biome_data = PyObject_CallMethod(state->textures, "getBiomeData", "OOO",
                                               worlddir, chunk_x_py, chunk_y_py);
        if (self->biome_data == Py_None) {
            Py_DECREF(self->biome_data);
            self->biome_data = NULL;
            self->foliagecolor = NULL;
            self->grasscolor = NULL;
        } else {
            self->foliagecolor = PyObject_GetAttrString(state->textures, "foliagecolor");
            self->grasscolor = PyObject_GetAttrString(state->textures, "grasscolor");
            self->watercolor = PyObject_GetAttrString(state->textures, "watercolor");
            if (self->watercolor == Py_None)
            {
                Py_DECREF(self->watercolor);
                self->watercolor = NULL;
            }
        }
    } else {
        self->biome_data = NULL;
        self->foliagecolor = NULL;
        self->grasscolor = NULL;
        self->watercolor = NULL;
    }
    
    Py_DECREF(use_biomes);
    Py_DECREF(worlddir);
    Py_DECREF(chunk_x_py);
    Py_DECREF(chunk_y_py);
    
    return 0;
}
static int
overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
    PyObject *opt;
    RenderPrimitiveBiomes* self;
    unsigned char alpha_tmp=0;

    /* first, chain up */
    int ret = primitive_overlay.start(data, state, support);
    if (ret != 0)
        return ret;
    
    /* now do custom initializations */
    self = (RenderPrimitiveBiomes *)data;
    
    // opt is a borrowed reference.  do not deref 
    if (!render_mode_parse_option(support, "biomes", "O", &(opt)))
        return 1;
    if (opt && opt != Py_None) {
        struct BiomeColor *biomes = NULL;
        Py_ssize_t biomes_size = 0, i;
        /* create custom biomes */
        
        if (!PyList_Check(opt)) {
            PyErr_SetString(PyExc_TypeError, "'biomes' must be a list");
            return 1;
        }
        
        biomes_size = PyList_GET_SIZE(opt);
        biomes = self->biomes = calloc(biomes_size + 1, sizeof(struct BiomeColor));
        if (biomes == NULL) {
            return 1;
        }
        
        for (i = 0; i < biomes_size; i++) {
            PyObject *biome = PyList_GET_ITEM(opt, i);
	    char *tmpname = NULL;
            int j = 0;

            if (!PyArg_ParseTuple(biome, "s(bbb)", &tmpname, &(biomes[i].r), &(biomes[i].g), &(biomes[i].b))) {
                free(biomes);
                self->biomes = NULL;
                return 1;
            }

            //printf("%s, (%d, %d, %d) ->", tmpname, biomes[i].r, biomes[i].g, biomes[i].b);
            for (j = 0; j < NUM_BIOMES; j++) {
                if (strncmp(biome_table[j].name, tmpname, strlen(tmpname))==0) {
                    //printf("biome_table index=%d", j);
                    biomes[i].biome = j;
                    break;
                }
            }
	    //printf("\n");
        }
	biomes[biomes_size].biome = 255; //Because 0 is a valid biome, have to use 255 as the end of list marker instead. Fragile!

    } else {
        self->biomes = default_biomes;
    }
    
    if (!render_mode_parse_option(support, "alpha", "b", &(alpha_tmp))) {
        if (PyErr_Occurred()) {
            PyErr_Clear();
	    alpha_tmp = 240;
        }

	self->parent.color->a = alpha_tmp;
    }
    /* setup custom color */
    self->parent.get_color = get_color;
    
    return 0;
}