added night rendermode
This commit is contained in:
2
setup.py
2
setup.py
@@ -45,7 +45,7 @@ except AttributeError:
|
||||
|
||||
|
||||
c_overviewer_files = ['src/main.c', 'src/composite.c', 'src/iterate.c']
|
||||
c_overviewer_files += ['src/rendermodes.c', 'src/rendermode-normal.c', 'src/rendermode-lighting.c']
|
||||
c_overviewer_files += ['src/rendermodes.c', 'src/rendermode-normal.c', 'src/rendermode-lighting.c', 'src/rendermode-night.c']
|
||||
setup_kwargs['ext_modules'].append(Extension('c_overviewer', c_overviewer_files, include_dirs=['.', numpy_include], extra_link_args=["/MANIFEST"] if platform.system() == "Windows" else []))
|
||||
# tell build_ext to build the extension in-place
|
||||
# (NOT in build/)
|
||||
|
||||
66
src/rendermode-night.c
Normal file
66
src/rendermode-night.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "overviewer.h"
|
||||
#include <math.h>
|
||||
|
||||
/* figures out the black_coeff from a given skylight and blocklight, used in
|
||||
lighting calculations -- note this is *different* from the one in
|
||||
rendermode-lighting.c (the "skylight - 11" part) */
|
||||
static float calculate_darkness(unsigned char skylight, unsigned char blocklight) {
|
||||
return 1.0f - powf(0.8f, 15.0 - MAX(blocklight, skylight - 11));
|
||||
}
|
||||
|
||||
static int
|
||||
rendermode_night_start(void *data, RenderState *state) {
|
||||
/* 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->parent.calculate_darkness = calculate_darkness;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
rendermode_night_finish(void *data, RenderState *state) {
|
||||
/* nothing special to do */
|
||||
rendermode_lighting.finish(data, state);
|
||||
}
|
||||
|
||||
static int
|
||||
rendermode_night_occluded(void *data, RenderState *state) {
|
||||
/* no special occlusion here */
|
||||
return rendermode_lighting.occluded(data, state);
|
||||
}
|
||||
|
||||
static void
|
||||
rendermode_night_draw(void *data, RenderState *state, PyObject *src, PyObject *mask) {
|
||||
/* nothing special to do */
|
||||
rendermode_lighting.draw(data, state, src, mask);
|
||||
}
|
||||
|
||||
RenderModeInterface rendermode_night = {
|
||||
sizeof(RenderModeNight),
|
||||
rendermode_night_start,
|
||||
rendermode_night_finish,
|
||||
rendermode_night_occluded,
|
||||
rendermode_night_draw,
|
||||
};
|
||||
@@ -27,6 +27,8 @@ RenderModeInterface *get_render_mode(RenderState *state) {
|
||||
|
||||
if (strcmp(rendermode, "lighting") == 0) {
|
||||
iface = &rendermode_lighting;
|
||||
} else if (strcmp(rendermode, "night") == 0) {
|
||||
iface = &rendermode_night;
|
||||
}
|
||||
|
||||
Py_DECREF(rendermode_py);
|
||||
|
||||
@@ -21,12 +21,13 @@
|
||||
* * add a data struct and extern'd interface declaration below
|
||||
*
|
||||
* * fill in this interface struct in rendermode-(yourmode).c
|
||||
* (see rendermodes.c for an example: the "normal" mode)
|
||||
* (see rendermodes-normal.c for an example: the "normal" mode)
|
||||
*
|
||||
* * if you want to derive from (say) the "normal" mode, put
|
||||
* a RenderModeNormal entry at the top of your data struct, and
|
||||
* be sure to call your parent's functions in your own!
|
||||
* (see rendermode-lighting.c for an example)
|
||||
* (see rendermode-night.c for a simple example derived from
|
||||
* the "lighting" mode)
|
||||
*
|
||||
* * add a condition to get_render_mode() in rendermodes.c
|
||||
*/
|
||||
@@ -82,4 +83,11 @@ typedef struct {
|
||||
} RenderModeLighting;
|
||||
extern RenderModeInterface rendermode_lighting;
|
||||
|
||||
/* NIGHT */
|
||||
typedef struct {
|
||||
/* inherits from lighting */
|
||||
RenderModeLighting parent;
|
||||
} RenderModeNight;
|
||||
extern RenderModeInterface rendermode_night;
|
||||
|
||||
#endif /* __RENDERMODES_H_INCLUDED__ */
|
||||
|
||||
Reference in New Issue
Block a user