Big clean up in defs.c and related content. The usual stuff...

- factor out many identical checks in a convenient function; some messages
  may read slightly differently now and tile ranges may be handled more strictly
  (error out if one of the limits is invalid)
- factor out two instances of identical (up to one arg) code into
  tile_from_truecolpic
- factor out setting picsiz[] and stuff into set_picsizanm
- some checks
- Make "undefmodelof" non-functional and warn.
- in "animtilerange", if the tile difference is >= 64, error out since we
  can't store it in picanm[]

git-svn-id: https://svn.eduke32.com/eduke32@2588 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-04-04 18:58:19 +00:00
parent c0a8fb0588
commit b7df5ffa5f
4 changed files with 205 additions and 252 deletions

View file

@ -556,6 +556,8 @@ void delete_maphack_lights();
int32_t clipmapinfo_load(void); int32_t clipmapinfo_load(void);
#endif #endif
int32_t saveboard(const char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum); int32_t saveboard(const char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum);
void set_picsizanm(int32_t picnum, int16_t dasizx, int16_t dasizy, int32_t daanm);
int32_t loadpics(const char *filename, int32_t askedsize); int32_t loadpics(const char *filename, int32_t askedsize);
void loadtile(int16_t tilenume); void loadtile(int16_t tilenume);
int32_t qloadkvx(int32_t voxindex, const char *filename); int32_t qloadkvx(int32_t voxindex, const char *filename);

View file

@ -103,14 +103,14 @@ static const char *skyfaces[6] =
static int32_t defsparser(scriptfile *script); static int32_t defsparser(scriptfile *script);
static void defsparser_include(const char *fn, scriptfile *script, char *cmdtokptr) static void defsparser_include(const char *fn, const scriptfile *script, const char *cmdtokptr)
{ {
scriptfile *included; scriptfile *included;
included = scriptfile_fromfile(fn); included = scriptfile_fromfile(fn);
if (!included) if (!included)
{ {
if (!Bstrcasecmp(cmdtokptr,"null")) if (!cmdtokptr)
initprintf("Warning: Failed including %s as module\n", fn); initprintf("Warning: Failed including %s as module\n", fn);
else else
initprintf("Warning: Failed including %s on line %s:%d\n", initprintf("Warning: Failed including %s on line %s:%d\n",
@ -123,6 +123,64 @@ static void defsparser_include(const char *fn, scriptfile *script, char *cmdtokp
} }
} }
static int32_t check_tile_range(const char *defcmd, int32_t *tilebeg, int32_t *tileend,
const scriptfile *script, const char *cmdtokptr)
{
if (*tileend < *tilebeg)
{
initprintf("Warning: %s: backwards tile range on line %s:%d\n", defcmd,
script->filename, scriptfile_getlinum(script,cmdtokptr));
swaplong(tilebeg, tileend);
}
if ((unsigned)*tilebeg >= MAXTILES || (unsigned)*tileend >= MAXTILES)
{
initprintf("Error: %s: Invalid tile range on line %s:%d\n", defcmd,
script->filename, scriptfile_getlinum(script,cmdtokptr));
return 1;
}
return 0;
}
static int32_t check_tile(const char *defcmd, int32_t *tile, const scriptfile *script,
const char *cmdtokptr)
{
if ((unsigned)*tile >= MAXTILES)
{
initprintf("Error: %s: Invalid tile number on line %s:%d\n", defcmd,
script->filename, scriptfile_getlinum(script,cmdtokptr));
return 1;
}
return 0;
}
static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t alphacut)
{
const int32_t xsiz = tilesizx[tile], ysiz = tilesizy[tile];
int32_t i, j;
char *ftd = Bmalloc(xsiz*ysiz);
faketiledata[tile] = Bmalloc(xsiz*ysiz + 400);
for (i=xsiz-1; i>=0; i--)
{
for (j=ysiz-1; j>=0; j--)
{
const palette_t *col = &picptr[j*xsiz+i];
if (col->f < alphacut) { ftd[i*ysiz+j] = 255; continue; }
ftd[i*ysiz+j] = getclosestcol(col->b>>2,col->g>>2,col->r>>2);
}
// initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f);
}
faketilesiz[tile] = qlz_compress(ftd, faketiledata[tile], xsiz*ysiz, state_compress);
Bfree(ftd);
}
static int32_t defsparser(scriptfile *script) static int32_t defsparser(scriptfile *script)
{ {
int32_t tokn; int32_t tokn;
@ -295,19 +353,13 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getsymbol(script,&tilenume1)) break; if (scriptfile_getsymbol(script,&tilenume1)) break;
if (scriptfile_getsymbol(script,&tilenume2)) break; if (scriptfile_getsymbol(script,&tilenume2)) break;
if (scriptfile_getdouble(script,&alpha)) break; if (scriptfile_getdouble(script,&alpha)) break;
if (tilenume2 < tilenume1)
{ if (check_tile_range("alphahackrange", &tilenume1, &tilenume2, script, cmdtokptr))
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); break;
i = tilenume2;
tilenume2 = tilenume1;
tilenume1 = i;
}
#ifdef USE_OPENGL #ifdef USE_OPENGL
if ((unsigned)tilenume1 < MAXTILES && (unsigned)tilenume2 < MAXTILES) for (i=tilenume1; i<=tilenume2; i++)
{ alphahackarray[i] = alpha;
for (i=tilenume1; i<=tilenume2; i++)
alphahackarray[i] = alpha;
}
#endif #endif
} }
break; break;
@ -377,7 +429,7 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getsymbol(script,&tile)) break; if (scriptfile_getsymbol(script,&tile)) break;
if (tile >= MAXTILES)break; if (tile >= MAXTILES)break;
if (scriptfile_getsymbol(script,&h_xsize[tile])) break; if (scriptfile_getsymbol(script,&h_xsize[tile])) break; // XXX
if (scriptfile_getsymbol(script,&h_ysize[tile])) break; if (scriptfile_getsymbol(script,&h_ysize[tile])) break;
if (scriptfile_getsymbol(script,&tmp)) break; if (scriptfile_getsymbol(script,&tmp)) break;
h_xoffs[tile]=tmp; h_xoffs[tile]=tmp;
@ -396,50 +448,49 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getsymbol(script,&xoffs)) break; if (scriptfile_getsymbol(script,&xoffs)) break;
if (scriptfile_getsymbol(script,&yoffs)) break; if (scriptfile_getsymbol(script,&yoffs)) break;
if (tile2 < tile1) if (check_tile_range("setuptilerange", &tile1, &tile2, script, cmdtokptr))
break;
for (i=tile1; i<=tile2; i++)
{ {
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); h_xsize[i] = xsiz;
i = tile2; h_ysize[i] = ysiz;
tile2 = tile1; h_xoffs[i] = xoffs;
tile1 = i; h_yoffs[i] = yoffs;
} }
if ((unsigned)tile1 < MAXTILES && (unsigned)tile2 < MAXTILES)
{
for (i=tile1; i<=tile2; i++)
{
h_xsize[i] = xsiz;
h_ysize[i] = ysiz;
h_xoffs[i] = xoffs;
h_yoffs[i] = yoffs;
}
}
break; break;
} }
case T_ANIMTILERANGE: case T_ANIMTILERANGE:
{ {
int32_t tile1, tile2, spd, type, i; int32_t tile1, tile2, spd, type;
if (scriptfile_getsymbol(script,&tile1)) break; if (scriptfile_getsymbol(script,&tile1)) break;
if (scriptfile_getsymbol(script,&tile2)) break; if (scriptfile_getsymbol(script,&tile2)) break;
if (scriptfile_getsymbol(script,&spd)) break; if (scriptfile_getsymbol(script,&spd)) break;
if (scriptfile_getsymbol(script,&type)) break; if (scriptfile_getsymbol(script,&type)) break;
if (tile2 < tile1)
if (check_tile_range("animtilerange", &tile1, &tile2, script, cmdtokptr))
break;
if (tile2-tile1 >= 64)
{ {
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); initprintf("Error: animtilerange: tile difference can be at most 64 on line %s:%d\n",
i = tile2; script->filename, scriptfile_getlinum(script,cmdtokptr));
tile2 = tile1; break;
tile1 = i;
} }
if ((unsigned)tile1 <= MAXTILES && (unsigned)tile2 <= MAXTILES) spd = clamp(spd, 0, 15);
picanm[tile1]=(picanm[tile1]&0xffffff3f)+(spd<<24)+(type<<6)+tile2-tile1; type = clamp(type, 0, 3);
picanm[tile1] &= 0xf0ffff00; // clear animation fields
picanm[tile1] |= (spd<<24)+(type<<6)+tile2-tile1;
break; break;
} }
case T_TILEFROMTEXTURE: case T_TILEFROMTEXTURE:
{ {
char *texturetokptr = script->ltextptr, *textureend, *fn = NULL, *ftd = NULL; char *texturetokptr = script->ltextptr, *textureend, *fn = NULL;
int32_t tile=-1, token; int32_t tile=-1, token;
int32_t alphacut = 255; int32_t alphacut = 255;
int32_t xoffset = 0, yoffset = 0, goodtogo=0; int32_t xoffset = 0, yoffset = 0, goodtogo=0;
@ -499,100 +550,62 @@ static int32_t defsparser(scriptfile *script)
if (goodtogo) if (goodtogo)
{ {
int32_t xsiz, ysiz, i, j; int32_t xsiz, ysiz, j;
int32_t *picptr = NULL; palette_t *picptr = NULL;
palette_t *col;
kpzload(fn, (intptr_t *)&picptr, &j, &xsiz, &ysiz); kpzload(fn, (intptr_t *)&picptr, &j, &xsiz, &ysiz);
// initprintf("got bpl %d xsiz %d ysiz %d\n",bpl,xsiz,ysiz);
// initprintf("got bpl %d xsiz %d ysiz %d\n",bpl,xsiz,ysiz); if (!picptr)
break;
ftd = Bmalloc(xsiz*ysiz); if (xsiz <= 0 || ysiz <= 0)
faketiledata[tile] = Bmalloc(xsiz*ysiz + 400); break;
for (i=xsiz-1; i>=0; i--) xoffset = clamp(xoffset, -128, 127)&255;
{ yoffset = clamp(yoffset, -128, 127)&255;
for (j=ysiz-1; j>=0; j--)
{
col = (palette_t *)&picptr[j*xsiz+i];
if (col->f < alphacut) { ftd[i*ysiz+j] = 255; continue; }
ftd[i*ysiz+j] = getclosestcol(col->b>>2,col->g>>2,col->r>>2);
}
// initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f);
}
if (xsiz > 0 && ysiz > 0) set_picsizanm(tile, xsiz, ysiz, (picanm[tile]&0xff0000ff)+
{ (xoffset<<8)+(yoffset<<16));
tilesizx[tile] = xsiz;
tilesizy[tile] = ysiz;
faketilesiz[tile] = qlz_compress(ftd, faketiledata[tile], xsiz*ysiz, state_compress); tile_from_truecolpic(tile, picptr, alphacut);
xoffset = clamp(xoffset, -128, 127);
picanm[tile] = (picanm[tile]&0xffff00ff)+((xoffset&255)<<8);
yoffset = clamp(yoffset, -128, 127);
picanm[tile] = (picanm[tile]&0xff00ffff)+((yoffset&255)<<16);
j = 15; while ((j > 1) && (pow2long[j] > xsiz)) j--;
picsiz[tile] = ((uint8_t)j);
j = 15; while ((j > 1) && (pow2long[j] > ysiz)) j--;
picsiz[tile] += ((uint8_t)(j<<4));
}
Bfree(picptr); Bfree(picptr);
Bfree(ftd);
} }
} }
break; break;
case T_IMPORTTILE: case T_IMPORTTILE:
{ {
int32_t tile, xsiz, ysiz, j, i; int32_t tile, xsiz, ysiz;
int32_t *picptr = NULL; palette_t *picptr = NULL;
int32_t bpl; int32_t bpl;
char *fn, *ftd = NULL; char *fn;
palette_t *col;
if (scriptfile_getsymbol(script,&tile)) break; if (scriptfile_getsymbol(script,&tile)) break;
if (scriptfile_getstring(script,&fn)) break; if (scriptfile_getstring(script,&fn)) break;
kpzload(fn, (intptr_t *)&picptr, &bpl, &xsiz, &ysiz); kpzload(fn, (intptr_t *)&picptr, &bpl, &xsiz, &ysiz);
// initprintf("got bpl %d xsiz %d ysiz %d\n",bpl,xsiz,ysiz); // initprintf("got bpl %d xsiz %d ysiz %d\n",bpl,xsiz,ysiz);
ftd = Bmalloc(xsiz*ysiz); if (!picptr)
faketiledata[tile] = Bmalloc(xsiz*ysiz + 400); break; // TODO: message
for (i=xsiz-1; i>=0; i--) if (xsiz <= 0 || ysiz <= 0) // XXX: kpzload isn't robust against that!
{ break;
for (j=ysiz-1; j>=0; j--)
{
col = (palette_t *)&picptr[j*xsiz+i];
if (col->f != 255) { ftd[i*ysiz+j] = 255; continue; }
ftd[i*ysiz+j] = getclosestcol(col->b>>2,col->g>>2,col->r>>2);
}
// initprintf(" %d %d %d %d\n",col->r,col->g,col->b,col->f);
}
if (xsiz > 0 && ysiz > 0) if (check_tile("importtile", &tile, script, cmdtokptr))
{ break;
tilesizx[tile] = xsiz;
tilesizy[tile] = ysiz;
faketilesiz[tile] = qlz_compress(ftd, faketiledata[tile], xsiz*ysiz, state_compress);
picanm[tile] = 0;
j = 15; while ((j > 1) && (pow2long[j] > xsiz)) j--; set_picsizanm(tile, xsiz, ysiz, 0);
picsiz[tile] = ((uint8_t)j);
j = 15; while ((j > 1) && (pow2long[j] > ysiz)) j--; tile_from_truecolpic(tile, picptr, 255);
picsiz[tile] += ((uint8_t)(j<<4));
}
Bfree(picptr); Bfree(picptr);
Bfree(ftd);
break; break;
} }
case T_DUMMYTILE: case T_DUMMYTILE:
{ {
int32_t tile, xsiz, ysiz, j; int32_t tile, xsiz, ysiz;
if (scriptfile_getsymbol(script,&tile)) break; if (scriptfile_getsymbol(script,&tile)) break;
if (scriptfile_getsymbol(script,&xsiz)) break; if (scriptfile_getsymbol(script,&xsiz)) break;
@ -600,55 +613,33 @@ static int32_t defsparser(scriptfile *script)
if (xsiz > 0 && ysiz > 0) if (xsiz > 0 && ysiz > 0)
{ {
tilesizx[tile] = xsiz; set_picsizanm(tile, xsiz, ysiz, 0);
tilesizy[tile] = ysiz;
faketilesiz[tile] = -1; faketilesiz[tile] = -1;
picanm[tile] = 0;
j = 15; while ((j > 1) && (pow2long[j] > xsiz)) j--;
picsiz[tile] = ((uint8_t)j);
j = 15; while ((j > 1) && (pow2long[j] > ysiz)) j--;
picsiz[tile] += ((uint8_t)(j<<4));
} }
break; break;
} }
case T_DUMMYTILERANGE: case T_DUMMYTILERANGE:
{ {
int32_t tile1,tile2,xsiz,ysiz,i,j; int32_t tile1,tile2,xsiz,ysiz,i;
if (scriptfile_getnumber(script,&tile1)) break; if (scriptfile_getnumber(script,&tile1)) break;
if (scriptfile_getnumber(script,&tile2)) break; if (scriptfile_getnumber(script,&tile2)) break;
if (scriptfile_getnumber(script,&xsiz)) break; if (scriptfile_getnumber(script,&xsiz)) break;
if (scriptfile_getnumber(script,&ysiz)) break; if (scriptfile_getnumber(script,&ysiz)) break;
if (tile2 < tile1)
{
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
i = tile2;
tile2 = tile1;
tile1 = i;
}
if ((tile1 >= 0 && tile1 < MAXTILES) && (tile2 >= 0 && tile2 < MAXTILES))
{
for (i=tile1; i<=tile2; i++)
{
if ((uint32_t)i < MAXTILES)
{
if (xsiz > 0 && ysiz > 0)
{
tilesizx[i] = xsiz;
tilesizy[i] = ysiz;
faketilesiz[i] = -1;
picanm[i] = 0;
j = 15; while ((j > 1) && (pow2long[j] > xsiz)) j--; if (check_tile_range("dummytilerange", &tile1, &tile2, script, cmdtokptr))
picsiz[i] = ((uint8_t)j); break;
j = 15; while ((j > 1) && (pow2long[j] > ysiz)) j--;
picsiz[i] += ((uint8_t)(j<<4)); if (xsiz <= 0 || ysiz <= 0)
} break; // TODO: message
}
} for (i=tile1; i<=tile2; i++)
{
set_picsizanm(i, xsiz, ysiz, 0);
faketilesiz[i] = -1;
} }
break; break;
} }
@ -688,13 +679,9 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getstring(script,&framename)) break; if (scriptfile_getstring(script,&framename)) break;
if (scriptfile_getnumber(script,&ftilenume)) break; //first tile number if (scriptfile_getnumber(script,&ftilenume)) break; //first tile number
if (scriptfile_getnumber(script,&ltilenume)) break; //last tile number (inclusive) if (scriptfile_getnumber(script,&ltilenume)) break; //last tile number (inclusive)
if (ltilenume < ftilenume)
{ if (check_tile_range("definemodelframe", &ftilenume, &ltilenume, script, cmdtokptr))
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); break;
tilex = ftilenume;
ftilenume = ltilenume;
ltilenume = tilex;
}
if (lastmodelid < 0) if (lastmodelid < 0)
{ {
@ -851,20 +838,8 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getnumber(script,&ftilenume)) break; //1st tile # if (scriptfile_getnumber(script,&ftilenume)) break; //1st tile #
if (scriptfile_getnumber(script,&ltilenume)) break; //last tile # if (scriptfile_getnumber(script,&ltilenume)) break; //last tile #
if (ltilenume < ftilenume) if (check_tile_range("definevoxeltiles", &ftilenume, &ltilenume, script, cmdtokptr))
{
initprintf("Warning: backwards tile range on line %s:%d\n",
script->filename, scriptfile_getlinum(script,cmdtokptr));
tilex = ftilenume;
ftilenume = ltilenume;
ltilenume = tilex;
}
if (ltilenume < 0 || ftilenume >= MAXTILES)
{
initprintf("Invalid tile range on line %s:%d\n",
script->filename, scriptfile_getlinum(script,cmdtokptr));
break; break;
}
if (lastvoxid < 0) if (lastvoxid < 0)
{ {
@ -974,17 +949,10 @@ static int32_t defsparser(scriptfile *script)
} }
} }
if (ftilenume < 0) initprintf("Error: missing 'first tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; if (check_tile_range("model: frame", &ftilenume, &ltilenume, script, frametokptr))
if (ltilenume < 0) initprintf("Error: missing 'last tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0;
model_ok &= happy;
if (!happy) break;
if (ltilenume < ftilenume)
{ {
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)); model_ok = 0;
tilex = ftilenume; break;
ftilenume = ltilenume;
ltilenume = tilex;
} }
if (lastmodelid < 0) if (lastmodelid < 0)
@ -1243,17 +1211,10 @@ static int32_t defsparser(scriptfile *script)
} }
} }
if (ftilenume < 0) initprintf("Error: missing 'first tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; if (check_tile_range("hud", &ftilenume, &ltilenume, script, hudtokptr))
if (ltilenume < 0) initprintf("Error: missing 'last tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0;
model_ok &= happy;
if (!happy) break;
if (ltilenume < ftilenume)
{ {
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)); model_ok = 0;
tilex = ftilenume; break;
ftilenume = ltilenume;
ltilenume = tilex;
} }
if (lastmodelid < 0) if (lastmodelid < 0)
@ -1363,22 +1324,27 @@ static int32_t defsparser(scriptfile *script)
//case T_ERROR: initprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break; //case T_ERROR: initprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break;
case T_TILE: case T_TILE:
scriptfile_getsymbol(script,&tilex); scriptfile_getsymbol(script,&tilex);
if ((uint32_t)tilex < MAXTILES) tiletovox[tilex] = lastvoxid;
else initprintf("Invalid tile number on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); if (check_tile("voxel", &tilex, script, voxeltokptr))
break;
tiletovox[tilex] = lastvoxid;
break; break;
case T_TILE0: case T_TILE0:
scriptfile_getsymbol(script,&tile0); break; //1st tile # scriptfile_getsymbol(script,&tile0);
break; //1st tile #
case T_TILE1: case T_TILE1:
scriptfile_getsymbol(script,&tile1); scriptfile_getsymbol(script,&tile1);
if (tile0 > tile1)
{ if (check_tile_range("hud", &tile0, &tile1, script, voxeltokptr))
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,voxeltokptr)); break;
tilex = tile0; tile0 = tile1; tile1 = tilex;
} for (tilex=tile0; tilex<=tile1; tilex++)
if ((tile1 < 0) || (tile0 >= MAXTILES)) tiletovox[tilex] = lastvoxid;
{ initprintf("Invalid tile range on line %s:%d\n",script->filename, scriptfile_getlinum(script,voxeltokptr)); break; }
for (tilex=tile0; tilex<=tile1; tilex++) tiletovox[tilex] = lastvoxid;
break; //last tile number (inclusive) break; //last tile number (inclusive)
case T_SCALE: case T_SCALE:
{ {
double scale=1.0; double scale=1.0;
@ -1439,10 +1405,10 @@ static int32_t defsparser(scriptfile *script)
} }
} }
if (tile < 0) initprintf("Error: missing 'tile number' for skybox definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy=0; if (tile < 0) initprintf("Error: skybox: missing 'tile number' near line %s:%d\n", script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy=0;
for (i=0; i<6; i++) for (i=0; i<6; i++)
{ {
if (!fn[i]) initprintf("Error: missing '%s filename' for skybox definition near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0; if (!fn[i]) initprintf("Error: skybox: missing '%s filename' near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0;
// FIXME? // FIXME?
if (check_file_exist(fn[i])) if (check_file_exist(fn[i]))
happy = 0; happy = 0;
@ -1489,7 +1455,7 @@ static int32_t defsparser(scriptfile *script)
break; break;
} }
if ((unsigned)pal >= ((unsigned)MAXPALOOKUPS - RESERVEDPALS)) if ((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS)
{ {
initprintf("Error: missing or invalid 'palette number' for highpalookup definition near " initprintf("Error: missing or invalid 'palette number' for highpalookup definition near "
"line %s:%d\n", script->filename, scriptfile_getlinum(script,highpaltokptr)); "line %s:%d\n", script->filename, scriptfile_getlinum(script,highpaltokptr));
@ -1583,7 +1549,7 @@ static int32_t defsparser(scriptfile *script)
if (pal < 0) if (pal < 0)
{ {
initprintf("Error: missing 'palette number' for tint definition near line %s:%d\n", initprintf("Error: tint: missing 'palette number' near line %s:%d\n",
script->filename, scriptfile_getlinum(script,tinttokptr)); script->filename, scriptfile_getlinum(script,tinttokptr));
break; break;
} }
@ -1750,8 +1716,8 @@ static int32_t defsparser(scriptfile *script)
} }
} }
if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later if ((unsigned)tile >= MAXTILES) break; // message is printed later
if ((unsigned)pal >= ((unsigned)MAXPALOOKUPS - RESERVEDPALS)) if ((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS)
{ {
initprintf("Error: missing or invalid 'palette number' for texture definition near " initprintf("Error: missing or invalid 'palette number' for texture definition near "
"line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr)); "line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr));
@ -1817,7 +1783,7 @@ static int32_t defsparser(scriptfile *script)
} }
} }
if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later if ((unsigned)tile >= MAXTILES) break; // message is printed later
if (!fn) if (!fn)
{ {
initprintf("Error: missing 'file name' for texture definition near line %s:%d\n", initprintf("Error: missing 'file name' for texture definition near line %s:%d\n",
@ -1852,7 +1818,7 @@ static int32_t defsparser(scriptfile *script)
break; break;
} }
} }
if ((unsigned)tile >= (unsigned)MAXTILES) if ((unsigned)tile >= MAXTILES)
{ {
initprintf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n", initprintf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n",
script->filename, scriptfile_getlinum(script,texturetokptr)); script->filename, scriptfile_getlinum(script,texturetokptr));
@ -1870,30 +1836,20 @@ static int32_t defsparser(scriptfile *script)
if (tokn == T_UNDEFMODELRANGE) if (tokn == T_UNDEFMODELRANGE)
{ {
if (scriptfile_getsymbol(script,&r1)) break; if (scriptfile_getsymbol(script,&r1)) break;
if (r1 < r0)
{ if (check_tile_range("undefmodelrange", &r0, &r1, script, cmdtokptr))
int32_t t = r1;
r1 = r0;
r0 = t;
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
}
if (r0 < 0 || r1 >= MAXTILES)
{
initprintf("Error: invalid tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
break; break;
}
} }
else else
{ {
r1 = r0; r1 = r0;
if ((unsigned)r0 >= (unsigned)MAXTILES)
{ if (check_tile("undefmodel", &r0, script, cmdtokptr))
initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
break; break;
}
} }
#ifdef USE_OPENGL #ifdef USE_OPENGL
for (; r0 <= r1; r0++) md_undefinetile(r0); for (; r0 <= r1; r0++)
md_undefinetile(r0);
#endif #endif
} }
break; break;
@ -1906,11 +1862,13 @@ static int32_t defsparser(scriptfile *script)
#endif #endif
if (scriptfile_getsymbol(script,&r0)) break; if (scriptfile_getsymbol(script,&r0)) break;
if ((unsigned)r0 >= (unsigned)MAXTILES)
{ if (check_tile("undefmodelof", &r0, script, cmdtokptr))
initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
break; break;
}
// XXX: See comment of md_undefinemodel()
initprintf("Warning: undefmodelof: currently non-functional.\n");
break;
#ifdef USE_OPENGL #ifdef USE_OPENGL
mid = md_tilehasmodel(r0,0); mid = md_tilehasmodel(r0,0);
@ -1930,27 +1888,16 @@ static int32_t defsparser(scriptfile *script)
if (tokn == T_UNDEFTEXTURERANGE) if (tokn == T_UNDEFTEXTURERANGE)
{ {
if (scriptfile_getsymbol(script,&r1)) break; if (scriptfile_getsymbol(script,&r1)) break;
if (r1 < r0)
{ if (check_tile_range("undeftexturerange", &r0, &r1, script, cmdtokptr))
int32_t t = r1;
r1 = r0;
r0 = t;
initprintf("Warning: backwards tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
}
if (r0 < 0 || r1 >= MAXTILES)
{
initprintf("Error: invalid tile range on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
break; break;
}
} }
else else
{ {
r1 = r0; r1 = r0;
if ((unsigned)r0 >= (unsigned)MAXTILES)
{ if (check_tile("undeftexture", &r0, script, cmdtokptr))
initprintf("Error: invalid tile number on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr));
break; break;
}
} }
for (; r0 <= r1; r0++) for (; r0 <= r1; r0++)
@ -1977,7 +1924,7 @@ static int32_t defsparser(scriptfile *script)
case T_NOFLOORPALRANGE: case T_NOFLOORPALRANGE:
{ {
int32_t b,e,i; int32_t b,e;
if (scriptfile_getnumber(script,&b)) break; if (scriptfile_getnumber(script,&b)) break;
if (scriptfile_getnumber(script,&e)) break; if (scriptfile_getnumber(script,&e)) break;
@ -2041,7 +1988,7 @@ int32_t loaddefinitionsfile(const char *fn)
defsparser(script); defsparser(script);
for (i=0; i < g_defModulesNum; ++i) for (i=0; i < g_defModulesNum; ++i)
defsparser_include(g_defModules[i], NULL, "null"); defsparser_include(g_defModules[i], NULL, NULL);
flushlogwindow = f; flushlogwindow = f;
scriptfile_close(script); scriptfile_close(script);

View file

@ -10312,13 +10312,33 @@ void nextpage(void)
numframes++; numframes++;
} }
void set_picsizanm(int32_t picnum, int16_t dasizx, int16_t dasizy, int32_t daanm)
{
int32_t j;
tilesizx[picnum] = dasizx;
tilesizy[picnum] = dasizy;
picanm[picnum] = daanm;
j = 15;
while ((j > 1) && (pow2long[j] > dasizx))
j--;
picsiz[picnum] = j;
j = 15;
while ((j > 1) && (pow2long[j] > dasizy))
j--;
picsiz[picnum] += j<<4;
}
// //
// loadpics // loadpics
// //
int32_t loadpics(const char *filename, int32_t askedsize) int32_t loadpics(const char *filename, int32_t askedsize)
{ {
int32_t offscount, localtilestart, localtileend, dasiz; int32_t offscount, localtilestart, localtileend, dasiz;
int32_t i, j, fil, tilefilei, numtiles_dummy; int32_t i, fil, tilefilei, numtiles_dummy;
Bstrcpy(artfilename,filename); Bstrcpy(artfilename,filename);
@ -10407,14 +10427,7 @@ int32_t loadpics(const char *filename, int32_t askedsize)
initcache((intptr_t)pic, cachesize); initcache((intptr_t)pic, cachesize);
for (i=0; i<MAXTILES; i++) for (i=0; i<MAXTILES; i++)
{ set_picsizanm(i, tilesizx[i], tilesizy[i], picanm[i]);
j = 15;
while ((j > 1) && (pow2long[j] > tilesizx[i])) j--;
picsiz[i] = ((uint8_t)j);
j = 15;
while ((j > 1) && (pow2long[j] > tilesizy[i])) j--;
picsiz[i] += ((uint8_t)(j<<4));
}
artfil = -1; artfil = -1;
artfilnum = -1; artfilnum = -1;

View file

@ -141,17 +141,8 @@ void GAME_onshowosd(int32_t shown)
// most of this is copied from my dummytile stuff in defs.c // most of this is copied from my dummytile stuff in defs.c
if (!tilesizx[BGTILE] || !tilesizy[BGTILE]) if (!tilesizx[BGTILE] || !tilesizy[BGTILE])
{ {
int32_t j; set_picsizanm(BGTILE, BGTILE_SIZEX, BGTILE_SIZEY, 0);
tilesizx[BGTILE] = BGTILE_SIZEX;
tilesizy[BGTILE] = BGTILE_SIZEY;
faketilesiz[BGTILE] = -1; faketilesiz[BGTILE] = -1;
picanm[BGTILE] = 0;
j = 15; while ((j > 1) && (pow2long[j] > BGTILE_SIZEX)) j--;
picsiz[BGTILE] = ((uint8_t)j);
j = 15; while ((j > 1) && (pow2long[j] > BGTILE_SIZEY)) j--;
picsiz[BGTILE] += ((uint8_t)(j<<4));
} }
G_UpdateScreenArea(); G_UpdateScreenArea();