- migrated voxel parsing stuff.

This commit is contained in:
Christoph Oelckers 2021-04-11 18:37:11 +02:00
parent c33eea2540
commit aebcc13c4a
4 changed files with 114 additions and 130 deletions

View file

@ -583,7 +583,7 @@ int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, f
// int32_t md_tilehasmodel(int32_t tilenume, int32_t pal);
EXTERN int32_t nextvoxid;
EXTERN int8_t voxreserve[(MAXVOXELS+7)>>3];
EXTERN FixedBitArray<MAXVOXELS>voxreserve;
#ifdef USE_OPENGL
// TODO: dynamically allocate this

View file

@ -144,7 +144,7 @@ enum scripttoken_t
T_SURFACE, T_VIEW,
};
static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
static int32_t lastmodelid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
static const char *skyfaces[6] =
{
@ -853,50 +853,11 @@ static int32_t defsparser(scriptfile *script)
}
break;
case T_DEFINEVOXEL:
{
FString fn;
if (scriptfile_getstring(script,&fn))
break; //voxel filename
while (nextvoxid < MAXVOXELS && (voxreserve[nextvoxid>>3]&(1<<(nextvoxid&7))))
nextvoxid++;
if (nextvoxid == MAXVOXELS)
{
Printf("Maximum number of voxels (%d) already defined.\n", MAXVOXELS);
break;
}
if (voxDefine(nextvoxid, fn))
{
Printf("Failure loading voxel file \"%s\"\n",fn.GetChars());
break;
}
lastvoxid = nextvoxid++;
}
break;
parseDefineVoxel(*script, pos);
break;
case T_DEFINEVOXELTILES:
{
int32_t ftilenume, ltilenume, tilex;
if (scriptfile_getsymbol(script,&ftilenume)) break; //1st tile #
if (scriptfile_getsymbol(script,&ltilenume)) break; //last tile #
if (check_tile_range("definevoxeltiles", &ftilenume, &ltilenume, script, pos))
break;
if (lastvoxid < 0)
{
Printf("Warning: Ignoring voxel tiles definition.\n");
break;
}
for (tilex = ftilenume; tilex <= ltilenume; tilex++)
tiletovox[tilex] = lastvoxid;
}
break;
parseDefineVoxelTiles(*script, pos);
break;
// NEW (ENCOURAGED) DEFINITION SYNTAX
case T_MODEL:
@ -1312,88 +1273,8 @@ static int32_t defsparser(scriptfile *script)
}
break;
case T_VOXEL:
{
auto voxelpos = scriptfile_getposition(script);
FScanner::SavedPos modelend;
FString fn;
int32_t tile0 = MAXTILES, tile1 = -1, tilex = -1;
static const tokenlist voxeltokens[] =
{
{ "tile", T_TILE },
{ "tile0", T_TILE0 },
{ "tile1", T_TILE1 },
{ "scale", T_SCALE },
{ "rotate", T_ROTATE },
};
if (scriptfile_getstring(script,&fn))
break; //voxel filename
while (nextvoxid < MAXVOXELS && (voxreserve[nextvoxid>>3]&(1<<(nextvoxid&7))))
nextvoxid++;
if (nextvoxid == MAXVOXELS)
{
voxelpos.Message(MSG_ERROR, "Maximum number of voxels (%d) already defined.", MAXVOXELS);
break;
}
if (voxDefine(nextvoxid, fn))
{
voxelpos.Message(MSG_ERROR, "Failure loading voxel file \"%s\"",fn.GetChars());
break;
}
lastvoxid = nextvoxid++;
if (scriptfile_getbraces(script,&modelend)) break;
while (!scriptfile_endofblock(script, modelend))
{
switch (getatoken(script, voxeltokens, countof(voxeltokens)))
{
//case T_ERROR: Printf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break;
case T_TILE:
scriptfile_getsymbol(script,&tilex);
if (check_tile("voxel", tilex, script, voxelpos))
break;
tiletovox[tilex] = lastvoxid;
break;
case T_TILE0:
scriptfile_getsymbol(script,&tile0);
break; //1st tile #
case T_TILE1:
scriptfile_getsymbol(script,&tile1);
if (check_tile_range("voxel", &tile0, &tile1, script, voxelpos))
break;
for (tilex=tile0; tilex<=tile1; tilex++)
tiletovox[tilex] = lastvoxid;
break; //last tile number (inclusive)
case T_SCALE:
{
double scale=1.0;
scriptfile_getdouble(script,&scale);
voxscale[lastvoxid] = (float)scale;
if (voxmodels[lastvoxid])
voxmodels[lastvoxid]->scale = scale;
break;
}
case T_ROTATE:
voxrotate.Set(lastvoxid);
break;
}
}
lastvoxid = -1;
}
break;
parseVoxel(*script, pos);
break;
case T_SKYBOX:
parseSkybox(*script, pos);
break;

View file

@ -346,6 +346,111 @@ void parseAlphahackRange(FScanner& sc, FScriptPosition& pos)
TileFiles.tiledata[i].texture->alphaThreshold = (float)sc.Number;
}
//===========================================================================
//
//
//
//===========================================================================
static int lastvoxid = -1;
void parseDefineVoxel(FScanner& sc, FScriptPosition& pos)
{
sc.MustGetString();
while (nextvoxid < MAXVOXELS && voxreserve[nextvoxid]) nextvoxid++;
if (nextvoxid == MAXVOXELS)
{
pos.Message(MSG_ERROR, "Maximum number of voxels (%d) already defined.\n", MAXVOXELS);
return;
}
if (voxDefine(nextvoxid, sc.String))
{
pos.Message(MSG_ERROR, "Unable to load voxel file \"%s\"\n", sc.String);
return;
}
lastvoxid = nextvoxid++;
}
//===========================================================================
//
//
//
//===========================================================================
void parseDefineVoxelTiles(FScanner& sc, FScriptPosition& pos)
{
int tilestart, tileend;
if (!sc.GetNumber(tilestart, true)) return;
if (!sc.GetNumber(tileend, true)) return;
if (!ValidateTileRange("definevoxeltiles", tilestart, tileend, pos)) return;
if (lastvoxid < 0)
{
pos.Message(MSG_WARNING, "Warning: Ignoring voxel tiles definition without valid voxel.\n");
return;
}
for (int i = tilestart; i <= tileend; i++) tiletovox[i] = lastvoxid;
}
//===========================================================================
//
//
//
//===========================================================================
void parseVoxel(FScanner& sc, FScriptPosition& pos)
{
FScanner::SavedPos blockend;
int tile0 = MAXTILES, tile1 = -1;
FString fn;
if (!sc.GetString(fn)) return;
while (nextvoxid < MAXVOXELS && voxreserve[nextvoxid]) nextvoxid++;
if (nextvoxid == MAXVOXELS)
{
pos.Message(MSG_ERROR, "Maximum number of voxels (%d) already defined.\n", MAXVOXELS);
return;
}
if (voxDefine(nextvoxid, fn))
{
pos.Message(MSG_ERROR, "Unable to load voxel file \"%s\"\n", fn.GetChars());
return;
}
int lastvoxid = nextvoxid++;
if (sc.StartBraces(&blockend)) return;
while (!sc.FoundEndBrace(blockend))
{
sc.MustGetString();
if (sc.Compare("tile"))
{
sc.GetNumber(true);
if (ValidateTilenum("voxel", sc.Number, pos)) tiletovox[sc.Number] = lastvoxid;
}
if (sc.Compare("tile0")) sc.GetNumber(tile0, true);
if (sc.Compare("tile1"))
{
sc.GetNumber(tile1, true);
if (ValidateTileRange("voxel", tile0, tile1, pos))
{
for (int i = tile0; i <= tile1; i++) tiletovox[i] = lastvoxid;
}
}
if (sc.Compare("scale"))
{
sc.GetFloat(true);
voxscale[lastvoxid] = (float)sc.Float;
}
if (sc.Compare("rotate")) voxrotate.Set(lastvoxid);
}
}
//===========================================================================
//
//
@ -412,8 +517,6 @@ void parseNoFloorpalRange(FScanner& sc, FScriptPosition& pos)
void parseTint(FScanner& sc, FScriptPosition& pos)
{
int red = 255, green = 255, blue = 255, shadered = 0, shadegreen = 0, shadeblue = 0, pal = -1, flags = 0;
FScanner::SavedPos tintend;
FScanner::SavedPos blockend;
if (sc.StartBraces(&blockend)) return;

View file

@ -74,7 +74,7 @@ int tileInit(char a1, const char *a2)
for (int i = 0; i < kMaxTiles; i++)
{
if (voxelIndex[i] >= 0 && voxelIndex[i] < kMaxVoxels)
SetBitString((char*)voxreserve, voxelIndex[i]);
voxreserve.Set(voxelIndex[i]);
}
artLoaded = 1;