Merge branch 'NetHack-3.7' into NetHack-3.7-Jan2020

This commit is contained in:
nhmall
2020-01-27 08:52:17 -05:00
25 changed files with 1438 additions and 530 deletions

View File

@@ -95,9 +95,6 @@ static XtSignalId X11_sig_id;
#endif
#endif
/* this is only needed until X11_status_* routines are written */
extern NEARDATA winid WIN_STATUS;
/* Interface definition, for windows.c */
struct window_procs X11_procs = {
"X11",

View File

@@ -19,9 +19,6 @@ winid WIN_WORN = WIN_ERR;
extern void tty_raw_print(const char *);
extern void tty_raw_print_bold(const char *);
/* this is only needed until gnome_status_* routines are written */
extern NEARDATA winid WIN_STATUS;
/* Interface definition, for windows.c */
struct window_procs Gnome_procs = {
"Gnome", WC_COLOR | WC_HILITE_PET | WC_INVERSE, 0L,

View File

@@ -107,15 +107,6 @@ struct TileSetImage *image;
if (!read_info_header(fp, &header2)) goto error;
if (!check_info_header(&header2)) goto error;
#if 0 /* TODO */
if (header2.Compression == BI_PNG) {
/* Image data is an embedded PNG bit stream */
boolean ok = do_read_png_tiles(fp, image));
fclose(fp);
return ok;
}
#endif
/* header2.Height < 0 means the Y coordinate is reversed; the origin is
* top left rather than bottom left */
image->width = header2.Width;
@@ -300,7 +291,7 @@ struct TileSetImage *image;
break;
case 32:
for (x = 0; x < image->width; ++x) {
uint32 color = read_u32(row_bytes + x * 2);
uint32 color = read_u32(row_bytes + x * 4);
row[x] = build_pixel(&header2, color);
}
break;
@@ -609,7 +600,7 @@ uint32 color;
if (mask == 0) return 0;
bits = 0xFFFF; /* 0xFF, 0xF, 0x3, 0x1 */
shift = 16; /* 8, 4, 2, 1 */
while (bits != 0) {
while (shift != 0) {
if ((mask & bits) == 0) {
mask >>= shift;
color >>= shift;

View File

@@ -6,6 +6,7 @@
#include "tileset.h"
static void FDECL(get_tile_map, (const char *));
static unsigned FDECL(gcd, (unsigned, unsigned));
static void FDECL(split_tiles, (const struct TileSetImage *));
static void FDECL(free_image, (struct TileSetImage *));
@@ -100,6 +101,29 @@ error:
return FALSE;
}
/* Free tile memory not required by the chosen display mode */
boolean
set_tile_type(true_color)
boolean true_color;
{
unsigned i;
if (tiles) {
if (true_color) {
for (i = 0; i < num_tiles; ++i) {
free((genericptr_t) tiles[i].indexes);
tiles[i].indexes = NULL;
}
have_palette = FALSE;
} else {
for (i = 0; i < num_tiles; ++i) {
free((genericptr_t) tiles[i].pixels);
tiles[i].pixels = NULL;
}
}
}
}
const struct Pixel *
get_palette()
{
@@ -155,6 +179,112 @@ unsigned tile_index;
return &tiles[tile_index];
}
/* Note that any tile returned by this function must be freed */
struct TileImage *
stretch_tile(inp_tile, out_width, out_height)
const struct TileImage *inp_tile;
unsigned out_width, out_height;
{
unsigned x_scale_inp, x_scale_out, y_scale_inp, y_scale_out;
unsigned divisor;
unsigned size;
struct TileImage *out_tile;
unsigned x_inp, y_inp, x2, y2, x_out, y_out;
unsigned pos;
/* Derive the scale factors */
divisor = gcd(out_width, inp_tile->width);
x_scale_inp = inp_tile->width / divisor;
x_scale_out = out_width / divisor;
divisor = gcd(out_height, inp_tile->height);
y_scale_inp = inp_tile->height / divisor;
y_scale_out = out_height / divisor;
/* Derive the stretched tile */
out_tile = (struct TileImage *) alloc(sizeof(struct TileImage));
out_tile->width = out_width;
out_tile->height = out_height;
size = out_width * out_height;
if (inp_tile->pixels != NULL) {
out_tile->pixels = (struct Pixel *) alloc(size * sizeof(struct Pixel));
divisor = x_scale_inp * y_scale_inp;
for (y_out = 0; y_out < out_height; ++y_out) {
for (x_out = 0; x_out < out_width; ++x_out) {
unsigned r, g, b, a;
/* Derive output pixels by blending input pixels */
r = 0;
g = 0;
b = 0;
a = 0;
for (y2 = 0; y2 < y_scale_inp; ++y2) {
y_inp = (y_out * y_scale_inp + y2) / y_scale_out;
for (x2 = 0; x2 < x_scale_inp; ++x2) {
x_inp = (x_out * x_scale_inp + x2) / x_scale_out;
pos = y_inp * inp_tile->width + x_inp;
r += inp_tile->pixels[pos].r;
g += inp_tile->pixels[pos].g;
b += inp_tile->pixels[pos].b;
a += inp_tile->pixels[pos].a;
}
}
pos = y_out * out_width + x_out;
out_tile->pixels[pos].r = r / divisor;
out_tile->pixels[pos].g = g / divisor;
out_tile->pixels[pos].b = b / divisor;
out_tile->pixels[pos].a = a / divisor;
}
}
} else {
out_tile->pixels = NULL;
}
/* If the output device uses a palette, we can't blend; just pick
a subset of the pixels */
if (inp_tile->indexes != NULL) {
out_tile->indexes = (unsigned char *) alloc(size);
for (y_out = 0; y_out < out_height; ++y_out) {
for (x_out = 0; x_out < out_width; ++x_out) {
pos = y_out * out_width + x_out;
x_inp = x_out * x_scale_inp / x_scale_out;
y_inp = y_out * y_scale_inp / y_scale_out;
out_tile->indexes[pos] =
inp_tile->indexes[y_inp * inp_tile->width + x_inp];
}
}
} else {
out_tile->indexes = NULL;
}
return out_tile;
}
/* Free a tile returned by stretch_tile */
/* Do NOT use this with tiles returned by get_tile */
void
free_tile(tile)
struct TileImage *tile;
{
if (tile != NULL) {
free(tile->indexes);
free(tile->pixels);
free(tile);
}
}
/* Return the greatest common divisor */
static unsigned
gcd(a, b)
unsigned a, b;
{
while (TRUE) {
if (b == 0) return a;
a %= b;
if (a == 0) return b;
b %= a;
}
}
static void
split_tiles(image)
const struct TileSetImage *image;

View File

@@ -72,9 +72,6 @@ extern short glyph2tile[];
#define HUPSKIP_RESULT(RES) /*empty*/
#endif /* ?HANGUP_HANDLING */
/* this is only needed until tty_status_* routines are written */
extern NEARDATA winid WIN_STATUS;
/* Interface definition, for windows.c */
struct window_procs tty_procs = {
"tty",
@@ -155,11 +152,12 @@ char defmorestr[] = "--More--";
#if defined(USE_TILES) && defined(MSDOS)
boolean clipping = FALSE; /* clipping on? */
int clipx = 0, clipxmax = 0;
int clipy = 0, clipymax = 0;
#else
static boolean clipping = FALSE; /* clipping on? */
static int clipx = 0, clipxmax = 0;
#endif
static int clipy = 0, clipymax = 0;
#endif
#endif /* CLIPPING */
#if defined(USE_TILES) && defined(MSDOS)