From 977bf09a1240d41edc5b4ec6a3e3c7bf7850dbb1 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Wed, 23 Mar 2011 20:34:49 -0400 Subject: [PATCH] Bunch of changes to make VS happy Mostly variable declarations moved to the top of blocks. is_transparent can't be inline, since it's needed in several places --- src/composite.c | 12 +++++++----- src/iterate.c | 14 ++++++++++---- src/rendermode-lighting.c | 25 +++++++++++++++++-------- src/rendermode-night.c | 4 +++- src/rendermode-spawn.c | 4 +++- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/composite.c b/src/composite.c index 3400453..162c29b 100644 --- a/src/composite.c +++ b/src/composite.c @@ -66,6 +66,8 @@ imaging_python_to_c(PyObject *obj) PyObject *brightness(PyObject *img, float factor) { Imaging imDest; + int offset, stride, x, y, xsize, ysize; + imDest = imaging_python_to_c(img); if (!imDest) return NULL; @@ -77,14 +79,14 @@ PyObject *brightness(PyObject *img, float factor) { } /* how far into image the first alpha byte resides */ - int offset = (imDest->pixelsize == 4 ? 3 : 0); + offset = (imDest->pixelsize == 4 ? 3 : 0); /* how many bytes to skip to get to the next alpha byte */ - int stride = imDest->pixelsize; + stride = imDest->pixelsize; - int x, y; + x, y; - int xsize = imDest->xsize; - int ysize = imDest->ysize; + xsize = imDest->xsize; + ysize = imDest->ysize; for (y = 0; y < ysize; y++) { UINT8 *out = (UINT8 *)imDest->image[y] + offset; diff --git a/src/iterate.c b/src/iterate.c index 3997f5b..d9f4d52 100644 --- a/src/iterate.c +++ b/src/iterate.c @@ -49,7 +49,7 @@ int init_chunk_render(void) { } -inline int +int is_transparent(unsigned char b) { PyObject *block = PyInt_FromLong(b); int ret = PySequence_Contains(transparent_blocks, block); @@ -70,6 +70,12 @@ chunk_render(PyObject *self, PyObject *args) { int imgsize0, imgsize1; PyObject *blocks_py; + + RenderModeInterface *rendermode; + + void *rm_data; + + PyObject *t = NULL; if (!PyArg_ParseTuple(args, "OOiiO", &state.self, &state.img, &xoff, &yoff, &blockdata_expanded)) return Py_BuildValue("i", "-1"); @@ -79,8 +85,8 @@ chunk_render(PyObject *self, PyObject *args) { state.chunk = chunk_mod; /* set up the render mode */ - RenderModeInterface *rendermode = get_render_mode(&state); - void* rm_data = malloc(rendermode->data_size); + rendermode = get_render_mode(&state); + rm_data = malloc(rendermode->data_size); if (rendermode->start(rm_data, &state)) { free(rm_data); return Py_BuildValue("i", "-1"); @@ -146,7 +152,7 @@ chunk_render(PyObject *self, PyObject *args) { } // everything stored here will be a borrowed ref - PyObject *t = NULL; + /* get the texture and mask from block type / ancil. data */ if (!PySequence_Contains(special_blocks, blockid)) { /* t = textures.blockmap[blockid] */ diff --git a/src/rendermode-lighting.c b/src/rendermode-lighting.c index 10d5bcd..7646f70 100644 --- a/src/rendermode-lighting.c +++ b/src/rendermode-lighting.c @@ -42,6 +42,7 @@ get_lighting_coefficient(RenderModeLighting *self, RenderState *state, PyObject *skylight = NULL; PyObject *blocklight = NULL; int local_x = x, local_y = y, local_z = z; + unsigned char block, skylevel, blocklevel; /* defaults to "guess" until told otherwise */ if (authoratative) @@ -80,7 +81,7 @@ get_lighting_coefficient(RenderModeLighting *self, RenderState *state, return self->calculate_darkness(15, 0); } - unsigned char block = getArrayByte3D(blocks, local_x, local_y, local_z); + block = getArrayByte3D(blocks, local_x, local_y, local_z); /* if this block is opaque, use a fully-lit coeff instead to prevent stippled lines along chunk boundaries! */ @@ -120,8 +121,8 @@ get_lighting_coefficient(RenderModeLighting *self, RenderState *state, return 0.0f; } - unsigned char skylevel = getArrayByte3D(skylight, local_x, local_y, local_z); - unsigned char blocklevel = getArrayByte3D(blocklight, local_x, local_y, local_z); + skylevel = getArrayByte3D(skylight, local_x, local_y, local_z); + blocklevel = getArrayByte3D(blocklight, local_x, local_y, local_z); /* no longer a guess */ if (authoratative) @@ -135,6 +136,9 @@ get_lighting_coefficient(RenderModeLighting *self, RenderState *state, static inline void do_shading_with_mask(RenderModeLighting *self, RenderState *state, int x, int y, int z, PyObject *facemask) { + float black_coeff; + PyObject *mask; + /* first, check for occlusion if the block is in the local chunk */ if (x >= 0 && x < 16 && y >= 0 && y < 16 && z >= 0 && z < 128) { unsigned char block = getArrayByte3D(state->blocks, x, y, z); @@ -144,9 +148,9 @@ do_shading_with_mask(RenderModeLighting *self, RenderState *state, } } - float black_coeff = get_lighting_coefficient(self, state, x, y, z, NULL); + black_coeff = get_lighting_coefficient(self, state, x, y, z, NULL); - PyObject *mask = PyObject_CallMethod(facemask, "copy", NULL); // new ref + mask = PyObject_CallMethod(facemask, "copy", NULL); // new ref brightness(mask, black_coeff); alpha_over(state->img, self->black_color, mask, state->imgx, state->imgy, 0, 0); Py_DECREF(mask); @@ -154,12 +158,14 @@ do_shading_with_mask(RenderModeLighting *self, RenderState *state, static int rendermode_lighting_start(void *data, RenderState *state) { + RenderModeLighting* self; + /* first, chain up */ int ret = rendermode_normal.start(data, state); if (ret != 0) return ret; - RenderModeLighting* self = (RenderModeLighting *)data; + self = (RenderModeLighting *)data; self->black_color = PyObject_GetAttrString(state->chunk, "black_color"); self->facemasks_py = PyObject_GetAttrString(state->chunk, "facemasks"); @@ -214,11 +220,14 @@ rendermode_lighting_occluded(void *data, RenderState *state) { static void rendermode_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask) { + RenderModeLighting* self; + int x, y, z; + /* first, chain up */ rendermode_normal.draw(data, state, src, mask); - RenderModeLighting* self = (RenderModeLighting *)data; - int x = state->x, y = state->y, z = state->z; + self = (RenderModeLighting *)data; + x = state->x, y = state->y, z = state->z; if (is_transparent(state->block)) { /* transparent: do shading on whole block */ diff --git a/src/rendermode-night.c b/src/rendermode-night.c index 5943b6a..d4b1eb4 100644 --- a/src/rendermode-night.c +++ b/src/rendermode-night.c @@ -27,13 +27,15 @@ static float calculate_darkness(unsigned char skylight, unsigned char blocklight static int rendermode_night_start(void *data, RenderState *state) { + RenderModeNight* self; + /* first, chain up */ int ret = rendermode_lighting.start(data, state); if (ret != 0) return ret; /* override the darkness function with our night version! */ - RenderModeNight* self = (RenderModeNight *)data; + self = (RenderModeNight *)data; self->parent.calculate_darkness = calculate_darkness; return 0; diff --git a/src/rendermode-spawn.c b/src/rendermode-spawn.c index aa7a8c6..1a7c96a 100644 --- a/src/rendermode-spawn.c +++ b/src/rendermode-spawn.c @@ -20,13 +20,15 @@ static int rendermode_spawn_start(void *data, RenderState *state) { + RenderModeSpawn* self; + /* first, chain up */ int ret = rendermode_night.start(data, state); if (ret != 0) return ret; /* now do custom initializations */ - RenderModeSpawn* self = (RenderModeSpawn *)data; + self = (RenderModeSpawn *)data; self->solid_blocks = PyObject_GetAttrString(state->chunk, "solid_blocks"); self->nospawn_blocks = PyObject_GetAttrString(state->chunk, "nospawn_blocks"); self->fluid_blocks = PyObject_GetAttrString(state->chunk, "fluid_blocks");