change xchar to other typedefs

One of the drivers of this change was that screen coordinates require a
type that can hold values greater than 127. Parameters to the window
port routines require a large type in order to be able to have values
a fair bit larger than COLNO and ROWNO passed to them, particularly for
their use to the right of the map window.

This splits the uses of xchar into 3 different situations, and adjusts
their type and size:

                        xchar
                          |
               -----------------------
               |          |          |
            coordxy     xint16     xint8

coordxy: Actual x or y coordinates for various things (moved to 16-bits).

xint16:  Same data size as coordxy, but for non-coordinate use (16-bits).

xint8:   There are only a few use cases initially, where it was very
         plain to see that the variable could remain as 8-bits, rather
         than be bumped to 16-bits.  There are probably more such cases
         that could be changed after additional review.

Note: This first changed all xchar variables to coordxy. Some were
reviewed and got changed to xint16 or xint8 when it became apparent that
their usage was not for coordinates.

This increments EDITLEVEL in patchlevel.h
This commit is contained in:
nhmall
2022-06-30 23:48:18 -04:00
parent 751b6e646f
commit 30b557f7d5
104 changed files with 1016 additions and 996 deletions

View File

@@ -14,7 +14,7 @@ static int l_selection_not(lua_State *);
static int l_selection_filter_percent(lua_State *);
static int l_selection_rndcoord(lua_State *);
static boolean params_sel_2coords(lua_State *, struct selectionvar **,
xchar *, xchar *, xchar *, xchar *);
coordxy *, coordxy *, coordxy *, coordxy *);
static int l_selection_line(lua_State *);
static int l_selection_randline(lua_State *);
static int l_selection_rect(lua_State *);
@@ -136,7 +136,7 @@ static int
l_selection_setpoint(lua_State *L)
{
struct selectionvar *sel = (struct selectionvar *) 0;
xchar x = -1, y = -1;
coordxy x = -1, y = -1;
int val = 1;
int argc = lua_gettop(L);
long crd = 0L;
@@ -146,15 +146,15 @@ l_selection_setpoint(lua_State *L)
} else if (argc == 1) {
sel = l_selection_check(L, 1);
} else if (argc == 2) {
x = (xchar) luaL_checkinteger(L, 1);
y = (xchar) luaL_checkinteger(L, 2);
x = (coordxy) luaL_checkinteger(L, 1);
y = (coordxy) luaL_checkinteger(L, 2);
lua_pop(L, 2);
(void) l_selection_new(L);
sel = l_selection_check(L, 1);
} else {
sel = l_selection_check(L, 1);
x = (xchar) luaL_checkinteger(L, 2);
y = (xchar) luaL_checkinteger(L, 3);
x = (coordxy) luaL_checkinteger(L, 2);
y = (coordxy) luaL_checkinteger(L, 3);
val = (int) luaL_optinteger(L, 4, 1);
}
@@ -180,7 +180,7 @@ static int
l_selection_getpoint(lua_State *L)
{
struct selectionvar *sel = l_selection_check(L, 1);
xchar x, y;
coordxy x, y;
int ix, iy;
int val;
long crd;
@@ -190,8 +190,8 @@ l_selection_getpoint(lua_State *L)
nhl_error(L, "l_selection_getpoint: Incorrect params");
return 0;
}
x = (xchar) ix;
y = (xchar) iy;
x = (coordxy) ix;
y = (coordxy) iy;
if (x == -1 && y == -1)
crd = SP_COORD_PACK_RANDOM(0);
@@ -299,8 +299,8 @@ l_selection_sub(lua_State *L)
for (x = 0; x < selr->wid; x++) {
for (y = 0; y < selr->hei; y++) {
xchar a_pt = selection_getpoint(x, y, sela);
xchar b_pt = selection_getpoint(x, y, selb);
coordxy a_pt = selection_getpoint(x, y, sela);
coordxy b_pt = selection_getpoint(x, y, selb);
int val = (a_pt ^ b_pt) & a_pt;
selection_setpoint(x, y, selr, val);
}
@@ -335,7 +335,7 @@ l_selection_rndcoord(lua_State *L)
{
struct selectionvar *sel = l_selection_check(L, 1);
int removeit = (int) luaL_optinteger(L, 2, 0);
xchar x = -1, y = -1;
coordxy x = -1, y = -1;
selection_rndcoord(sel, &x, &y, removeit);
if (!(x == -1 && y == -1)) {
update_croom();
@@ -362,16 +362,16 @@ l_selection_rndcoord(lua_State *L)
/* selection:function(x1,y1, x2,y2) */
static boolean
params_sel_2coords(lua_State *L, struct selectionvar **sel,
xchar *x1, xchar *y1, xchar *x2, xchar *y2)
coordxy *x1, coordxy *y1, coordxy *x2, coordxy *y2)
{
int argc = lua_gettop(L);
if (argc == 4) {
(void) l_selection_new(L);
*x1 = (xchar) luaL_checkinteger(L, 1);
*y1 = (xchar) luaL_checkinteger(L, 2);
*x2 = (xchar) luaL_checkinteger(L, 3);
*y2 = (xchar) luaL_checkinteger(L, 4);
*x1 = (coordxy) luaL_checkinteger(L, 1);
*y1 = (coordxy) luaL_checkinteger(L, 2);
*x2 = (coordxy) luaL_checkinteger(L, 3);
*y2 = (coordxy) luaL_checkinteger(L, 4);
*sel = l_selection_check(L, 5);
lua_remove(L, 1);
lua_remove(L, 1);
@@ -380,10 +380,10 @@ params_sel_2coords(lua_State *L, struct selectionvar **sel,
return TRUE;
} else if (argc == 5) {
*sel = l_selection_check(L, 1);
*x1 = (xchar) luaL_checkinteger(L, 2);
*y1 = (xchar) luaL_checkinteger(L, 3);
*x2 = (xchar) luaL_checkinteger(L, 4);
*y2 = (xchar) luaL_checkinteger(L, 5);
*x1 = (coordxy) luaL_checkinteger(L, 2);
*y1 = (coordxy) luaL_checkinteger(L, 3);
*x2 = (coordxy) luaL_checkinteger(L, 4);
*y2 = (coordxy) luaL_checkinteger(L, 5);
lua_pop(L, 4);
return TRUE;
}
@@ -397,7 +397,7 @@ static int
l_selection_line(lua_State *L)
{
struct selectionvar *sel = NULL;
xchar x1, y1, x2, y2;
coordxy x1, y1, x2, y2;
if (!params_sel_2coords(L, &sel, &x1, &y1, &x2, &y2)) {
nhl_error(L, "selection.line: illegal arguments");
@@ -417,7 +417,7 @@ static int
l_selection_rect(lua_State *L)
{
struct selectionvar *sel = NULL;
xchar x1, y1, x2, y2;
coordxy x1, y1, x2, y2;
if (!params_sel_2coords(L, &sel, &x1, &y1, &x2, &y2)) {
nhl_error(L, "selection.rect: illegal arguments");
@@ -446,7 +446,7 @@ l_selection_fillrect(lua_State *L)
{
struct selectionvar *sel = NULL;
int y;
xchar x1, y1, x2, y2;
coordxy x1, y1, x2, y2;
if (!params_sel_2coords(L, &sel, &x1, &y1, &x2, &y2)) {
nhl_error(L, "selection.fillrect: illegal arguments");
@@ -478,22 +478,22 @@ l_selection_randline(lua_State *L)
{
int argc = lua_gettop(L);
struct selectionvar *sel = (struct selectionvar *) 0;
xchar x1 = 0, y1 = 0, x2 = 0, y2 = 0;
coordxy x1 = 0, y1 = 0, x2 = 0, y2 = 0;
int roughness = 7;
if (argc == 6) {
sel = l_selection_check(L, 1);
x1 = (xchar) luaL_checkinteger(L, 2);
y1 = (xchar) luaL_checkinteger(L, 3);
x2 = (xchar) luaL_checkinteger(L, 4);
y2 = (xchar) luaL_checkinteger(L, 5);
x1 = (coordxy) luaL_checkinteger(L, 2);
y1 = (coordxy) luaL_checkinteger(L, 3);
x2 = (coordxy) luaL_checkinteger(L, 4);
y2 = (coordxy) luaL_checkinteger(L, 5);
roughness = (int) luaL_checkinteger(L, 6);
lua_pop(L, 5);
} else if (argc == 5 && lua_type(L, 1) == LUA_TNUMBER) {
x1 = (xchar) luaL_checkinteger(L, 1);
y1 = (xchar) luaL_checkinteger(L, 2);
x2 = (xchar) luaL_checkinteger(L, 3);
y2 = (xchar) luaL_checkinteger(L, 4);
x1 = (coordxy) luaL_checkinteger(L, 1);
y1 = (coordxy) luaL_checkinteger(L, 2);
x2 = (coordxy) luaL_checkinteger(L, 3);
y2 = (coordxy) luaL_checkinteger(L, 4);
roughness = (int) luaL_checkinteger(L, 5);
lua_pop(L, 5);
(void) l_selection_new(L);
@@ -540,7 +540,7 @@ l_selection_filter_mapchar(lua_State *L)
int argc = lua_gettop(L);
struct selectionvar *sel = l_selection_check(L, 1);
char *mapchr = dupstr(luaL_checkstring(L, 2));
xchar typ = check_mapchr(mapchr);
coordxy typ = check_mapchr(mapchr);
int lit = (int) luaL_optinteger(L, 3, -2); /* TODO: special lit values */
struct selectionvar *tmp, *tmp2;
@@ -612,12 +612,12 @@ l_selection_flood(lua_State *L)
{
int argc = lua_gettop(L);
struct selectionvar *sel = (struct selectionvar *) 0;
xchar x = 0, y = 0;
coordxy x = 0, y = 0;
boolean diagonals = FALSE;
if (argc == 2 || argc == 3) {
x = (xchar) luaL_checkinteger(L, 1);
y = (xchar) luaL_checkinteger(L, 2);
x = (coordxy) luaL_checkinteger(L, 1);
y = (coordxy) luaL_checkinteger(L, 2);
if (argc == 3)
diagonals = lua_toboolean(L, 3);
lua_pop(L, argc);
@@ -648,20 +648,20 @@ l_selection_circle(lua_State *L)
{
int argc = lua_gettop(L);
struct selectionvar *sel = (struct selectionvar *) 0;
xchar x = 0, y = 0;
coordxy x = 0, y = 0;
int r = 0, filled = 0;
if (argc == 3) {
x = (xchar) luaL_checkinteger(L, 1);
y = (xchar) luaL_checkinteger(L, 2);
x = (coordxy) luaL_checkinteger(L, 1);
y = (coordxy) luaL_checkinteger(L, 2);
r = (int) luaL_checkinteger(L, 3);
lua_pop(L, 3);
(void) l_selection_new(L);
sel = l_selection_check(L, 1);
filled = 0;
} else if (argc == 4 && lua_type(L, 1) == LUA_TNUMBER) {
x = (xchar) luaL_checkinteger(L, 1);
y = (xchar) luaL_checkinteger(L, 2);
x = (coordxy) luaL_checkinteger(L, 1);
y = (coordxy) luaL_checkinteger(L, 2);
r = (int) luaL_checkinteger(L, 3);
filled = (int) luaL_checkinteger(L, 4); /* TODO: boolean*/
lua_pop(L, 4);
@@ -669,8 +669,8 @@ l_selection_circle(lua_State *L)
sel = l_selection_check(L, 1);
} else if (argc == 4 || argc == 5) {
sel = l_selection_check(L, 1);
x = (xchar) luaL_checkinteger(L, 2);
y = (xchar) luaL_checkinteger(L, 3);
x = (coordxy) luaL_checkinteger(L, 2);
y = (coordxy) luaL_checkinteger(L, 3);
r = (int) luaL_checkinteger(L, 4);
filled = (int) luaL_optinteger(L, 5, 0); /* TODO: boolean */
} else {
@@ -696,12 +696,12 @@ l_selection_ellipse(lua_State *L)
{
int argc = lua_gettop(L);
struct selectionvar *sel = (struct selectionvar *) 0;
xchar x = 0, y = 0;
coordxy x = 0, y = 0;
int r1 = 0, r2 = 0, filled = 0;
if (argc == 4) {
x = (xchar) luaL_checkinteger(L, 1);
y = (xchar) luaL_checkinteger(L, 2);
x = (coordxy) luaL_checkinteger(L, 1);
y = (coordxy) luaL_checkinteger(L, 2);
r1 = (int) luaL_checkinteger(L, 3);
r2 = (int) luaL_checkinteger(L, 4);
lua_pop(L, 4);
@@ -709,8 +709,8 @@ l_selection_ellipse(lua_State *L)
sel = l_selection_check(L, 1);
filled = 0;
} else if (argc == 5 && lua_type(L, 1) == LUA_TNUMBER) {
x = (xchar) luaL_checkinteger(L, 1);
y = (xchar) luaL_checkinteger(L, 2);
x = (coordxy) luaL_checkinteger(L, 1);
y = (coordxy) luaL_checkinteger(L, 2);
r1 = (int) luaL_checkinteger(L, 3);
r2 = (int) luaL_checkinteger(L, 4);
filled = (int) luaL_optinteger(L, 5, 0); /* TODO: boolean */
@@ -719,8 +719,8 @@ l_selection_ellipse(lua_State *L)
sel = l_selection_check(L, 1);
} else if (argc == 5 || argc == 6) {
sel = l_selection_check(L, 1);
x = (xchar) luaL_checkinteger(L, 2);
y = (xchar) luaL_checkinteger(L, 3);
x = (coordxy) luaL_checkinteger(L, 2);
y = (coordxy) luaL_checkinteger(L, 3);
r1 = (int) luaL_checkinteger(L, 4);
r2 = (int) luaL_checkinteger(L, 5);
filled = (int) luaL_optinteger(L, 6, 0); /* TODO: boolean */
@@ -750,11 +750,11 @@ l_selection_gradient(lua_State *L)
struct selectionvar *sel = (struct selectionvar *) 0;
/* if x2 and y2 aren't set, the gradient has a single center point of x,y;
* if they are set, the gradient is centered on a (x,y) to (x2,y2) line */
xchar x = 0, y = 0, x2 = -1, y2 = -1;
coordxy x = 0, y = 0, x2 = -1, y2 = -1;
/* points will not be added within mindist of the center; the chance for a
* point between mindist and maxdist to be added to the selection starts at
* 0% at mindist and increases linearly to 100% at maxdist */
xchar mindist = 0, maxdist = 0;
coordxy mindist = 0, maxdist = 0;
/* if limited is true, no points farther than maxdist will be added; if
* false, all points farther than maxdist will be added */
boolean limited = FALSE;
@@ -769,10 +769,10 @@ l_selection_gradient(lua_State *L)
if (argc == 1 && lua_type(L, 1) == LUA_TTABLE) {
lcheck_param_table(L);
type = gradtypes2i[get_table_option(L, "type", "radial", gradtypes)];
x = (xchar) get_table_int(L, "x");
y = (xchar) get_table_int(L, "y");
x2 = (xchar) get_table_int_opt(L, "x2", -1);
y2 = (xchar) get_table_int_opt(L, "y2", -1);
x = (coordxy) get_table_int(L, "x");
y = (coordxy) get_table_int(L, "y");
x2 = (coordxy) get_table_int_opt(L, "x2", -1);
y2 = (coordxy) get_table_int_opt(L, "y2", -1);
/* maxdist is required because there's no obvious default value for it,
* whereas mindist has an obvious defalt of 0 */
maxdist = get_table_int(L, "maxdist");