added endianness helper functions, and reading biome data directly
This commit is contained in:
2
setup.py
2
setup.py
@@ -46,7 +46,7 @@ except AttributeError:
|
||||
numpy_include = numpy.get_numpy_include()
|
||||
|
||||
|
||||
c_overviewer_files = ['src/main.c', 'src/composite.c', 'src/iterate.c']
|
||||
c_overviewer_files = ['src/main.c', 'src/composite.c', 'src/iterate.c', 'src/endian.c']
|
||||
c_overviewer_files += ['src/rendermodes.c', 'src/rendermode-normal.c', 'src/rendermode-lighting.c', 'src/rendermode-night.c', 'src/rendermode-spawn.c']
|
||||
setup_kwargs['ext_modules'].append(Extension('c_overviewer', c_overviewer_files, include_dirs=['.', numpy_include], extra_link_args=[]))
|
||||
# tell build_ext to build the extension in-place
|
||||
|
||||
39
src/endian.c
Normal file
39
src/endian.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of the Minecraft Overviewer.
|
||||
*
|
||||
* Minecraft Overviewer is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Minecraft Overviewer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* simple routines for dealing with endian conversion */
|
||||
|
||||
#define UNKNOWN_ENDIAN 0
|
||||
#define BIG_ENDIAN 1
|
||||
#define LITTLE_ENDIAN 2
|
||||
|
||||
static int endianness = UNKNOWN_ENDIAN;
|
||||
|
||||
void init_endian() {
|
||||
/* figure out what our endianness is! */
|
||||
short word = 0x0001;
|
||||
char* byte = (char*)(&word);
|
||||
endianness = byte[0] ? LITTLE_ENDIAN : BIG_ENDIAN;
|
||||
}
|
||||
|
||||
unsigned short big_endian_ushort(unsigned short in) {
|
||||
return (endianness == LITTLE_ENDIAN) ? ((in >> 8) | (in << 8)) : in;
|
||||
}
|
||||
|
||||
unsigned int big_endian_uint(unsigned int in) {
|
||||
return (endianness == LITTLE_ENDIAN) ? (((in & 0x000000FF) << 24) + ((in & 0x0000FF00) << 8) + ((in & 0x00FF0000) >> 8) + ((in & 0xFF000000) >> 24)) : in;
|
||||
}
|
||||
@@ -37,4 +37,6 @@ initc_overviewer(void)
|
||||
fprintf(stderr, "failed to init_chunk_render\n");
|
||||
exit(1); // TODO better way to indicate error?
|
||||
}
|
||||
|
||||
init_endian();
|
||||
}
|
||||
|
||||
@@ -78,4 +78,9 @@ PyObject *chunk_render(PyObject *self, PyObject *args);
|
||||
/* pull in the rendermode info */
|
||||
#include "rendermodes.h"
|
||||
|
||||
/* in endian.c */
|
||||
void init_endian();
|
||||
unsigned short big_endian_ushort(unsigned short in);
|
||||
unsigned int big_endian_uint(unsigned int in);
|
||||
|
||||
#endif /* __OVERVIEWER_H_INCLUDED__ */
|
||||
|
||||
@@ -128,16 +128,11 @@ rendermode_normal_draw(void *data, RenderState *state, PyObject *src, PyObject *
|
||||
if (self->biome_data) {
|
||||
/* do the biome stuff! */
|
||||
unsigned int index;
|
||||
PyObject *index_py, *color = NULL, *facemask = NULL;
|
||||
PyObject *color = NULL, *facemask = NULL;
|
||||
unsigned char r, g, b;
|
||||
|
||||
index = ((self->chunk_y * 16) + state->y) * 16 * 32 + (self->chunk_x * 16) + state->x;
|
||||
/* TODO for some reason, this one doesn't work:
|
||||
* index = getArrayShort1D(self->biome_data, index);
|
||||
*/
|
||||
index_py = PySequence_GetItem(self->biome_data, index);
|
||||
index = PyInt_AsLong(index_py);
|
||||
Py_DECREF(index_py);
|
||||
index = big_endian_ushort(getArrayShort1D(self->biome_data, index));
|
||||
|
||||
switch (state->block) {
|
||||
case 2:
|
||||
|
||||
Reference in New Issue
Block a user