From 84e42c2e8d2a94f936ebcf7ce14a8e02d2e8be6e Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Fri, 28 Apr 2017 23:35:37 -0700 Subject: [PATCH] fix stbi_shiftsigned to be shifting a value that's unsigned --- stb_image.h | 5 +++-- tests/caveview/cave_mesher.c | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/stb_image.h b/stb_image.h index ae2ada6..a81c5ac 100644 --- a/stb_image.h +++ b/stb_image.h @@ -4960,7 +4960,7 @@ static int stbi__bitcount(unsigned int a) return a & 0xff; } -static int stbi__shiftsigned(int v, int shift, int bits) +static unsigned int stbi__shiftsigned(unsigned int v, int shift, int bits) { int result; int z=0; @@ -4969,6 +4969,7 @@ static int stbi__shiftsigned(int v, int shift, int bits) else v >>= shift; result = v; + // replicate the high bits to the low bits z = bits; while (z < 8) { result += v >> z; @@ -5185,7 +5186,7 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req int bpp = info.bpp; for (i=0; i < (int) s->img_x; ++i) { stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s)); - int a; + unsigned int a; out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount)); out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount)); out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount)); diff --git a/tests/caveview/cave_mesher.c b/tests/caveview/cave_mesher.c index 1fac297..1f76c89 100644 --- a/tests/caveview/cave_mesher.c +++ b/tests/caveview/cave_mesher.c @@ -37,7 +37,8 @@ extern void ods(char *fmt, ...); #define FAST_CHUNK #define IN_PLACE -#define SKIP_TERRAIN 48 // use to avoid building underground stuff +#define SKIP_TERRAIN 0 +//#define SKIP_TERRAIN 48 // use to avoid building underground stuff // allows you to see what perf would be like if underground was efficiently culled, // or if you were making a game without underground @@ -131,7 +132,8 @@ unsigned char minecraft_info[256][7] = { C_solid, 35,35,35,35,4,4, }, // 48 - { C_solid, 36,36,36,36,36,36 }, + //{ C_solid, 36,36,36,36,36,36 }, + { C_force, 36,36,36,36,36,36 }, { C_solid, 37,37,37,37,37,37 }, { C_cross, 80,80,80,80,80,80 }, // torch { C_empty }, // fire @@ -142,6 +144,7 @@ unsigned char minecraft_info[256][7] = // 56 { C_solid, 50,50,50,50,50,50 }, + //{ C_force, 50,50,50,50,50,50 }, { C_solid, 26,26,26,26,26,26 }, { C_solid, 60,59,59,59,43,43 }, { C_cross, 95,95,95,95 }, @@ -831,6 +834,8 @@ void mesh_init(void) minecraft_color_for_blocktype[161][i] = 37 | 64; // green minecraft_color_for_blocktype[10][i] = 63; // emissive lava minecraft_color_for_blocktype[11][i] = 63; // emissive + //minecraft_color_for_blocktype[56][i] = 63; // emissive diamond + minecraft_color_for_blocktype[48][i] = 63; // emissive dungeon } #ifdef VHEIGHT_TEST