diff --git a/source/core/actorinfo.cpp b/source/core/actorinfo.cpp index 8463c22ec..3f46a8ffb 100644 --- a/source/core/actorinfo.cpp +++ b/source/core/actorinfo.cpp @@ -247,7 +247,7 @@ void FActorInfo::ResolveTextures(const char* clsname, DCoreActor* defaults) SpriteSet.Resize(SpriteSetNames.Size()); for (unsigned i = 0; i < SpriteSet.Size(); i++) { - SpriteSet[i] = TileFiles.tileForName(SpriteSetNames[i]); + SpriteSet[i] = tileForName(SpriteSetNames[i]); // This should later be enabled to user content. //if (SpriteSet[i] == -1) Printf(TEXTCOLOR_RED "Unknown texture '%s' in sprite set for class %s\n", SpriteSetNames[i].GetChars(), clsname); } diff --git a/source/core/defparser.cpp b/source/core/defparser.cpp index ceb2f4622..ff9588f7b 100644 --- a/source/core/defparser.cpp +++ b/source/core/defparser.cpp @@ -2370,7 +2370,7 @@ static void parseTileFlags(FScanner& sc, FScriptPosition& pos) while (!sc.CheckString("}")) { sc.MustGetString(); - int tile = TileFiles.tileForName(sc.String); + int tile = tileForName(sc.String); if (tile == -1) { pos.Message(MSG_ERROR, "tileflags:Unknown tile name '%s'", sc.String); diff --git a/source/core/g_mapinfo.cpp b/source/core/g_mapinfo.cpp index d2ea16b20..93c731a5f 100644 --- a/source/core/g_mapinfo.cpp +++ b/source/core/g_mapinfo.cpp @@ -293,7 +293,7 @@ void FMapInfoParser::ParseSpawnClasses() sc.MustGetString(); const char* p = sc.String; if (*p == '*') { fullbright |= 1; p++; } - basetex = TileFiles.tileForName(p); + basetex = tileForName(p); if (basetex < 0) sc.ScriptMessage("Unknown texture '%s' in definition for spawn ID # %d", sc.String, num); if (sc.CheckString(",")) { @@ -302,7 +302,7 @@ void FMapInfoParser::ParseSpawnClasses() if (*p) { if (*p == '*') { fullbright |= 2; p++; } - brokentex = TileFiles.tileForName(p); + brokentex = tileForName(p); if (brokentex < 0) sc.ScriptMessage("Unknown texture '%s' in definition for spawn ID # %d", sc.String, num); } if (sc.CheckString(",")) @@ -363,7 +363,7 @@ void FMapInfoParser::ParseBreakWall() sc.MustGetString(); FString basename = sc.String; // save for printing error messages. - basetile = TileFiles.tileForName(sc.String); + basetile = tileForName(sc.String); if (basetile < 0) { sc.ScriptMessage("Unknown texture '%s' in breakwall definition", sc.String, basetile); @@ -371,7 +371,7 @@ void FMapInfoParser::ParseBreakWall() } ParseAssign(); sc.MustGetString(); - breaktile = TileFiles.tileForName(sc.String); + breaktile = tileForName(sc.String); if (*sc.String && breaktile < 0) sc.ScriptMessage("Unknown texture '%s' in breakwall definition", sc.String, breaktile); if (sc.CheckString(",")) { @@ -428,7 +428,7 @@ void FMapInfoParser::ParseBreakCeiling() sc.MustGetString(); FString basename = sc.String; // save for printing error messages. - basetile = TileFiles.tileForName(sc.String); + basetile = tileForName(sc.String); if (basetile < 0) { sc.ScriptMessage("Unknown texture '%s' in breakceiling definition", sc.String, basetile); @@ -436,7 +436,7 @@ void FMapInfoParser::ParseBreakCeiling() } ParseAssign(); sc.MustGetString(); - breaktile = TileFiles.tileForName(sc.String); + breaktile = tileForName(sc.String); if (*sc.String && breaktile < 0) sc.ScriptMessage("Unknown texture '%s' in breakceiling definition", sc.String, breaktile); if (sc.CheckString(",")) { @@ -500,7 +500,7 @@ void FMapInfoParser::ParseTextureFlags() do { sc.MustGetString(); - int tile = TileFiles.tileForName(sc.String); + int tile = tileForName(sc.String); if (tile == -1) { diff --git a/source/core/psky.cpp b/source/core/psky.cpp index 77f69c74d..6f6458fb1 100644 --- a/source/core/psky.cpp +++ b/source/core/psky.cpp @@ -124,7 +124,7 @@ void defineSky(int tilenum, int lognumtiles, const int16_t *tileofs, int yoff, f void defineSky(const char* tilename, int lognumtiles, const int16_t* tileofs, int yoff, float yscale, int yoff2) { - int tile = TileFiles.tileForName(tilename); + int tile = tileForName(tilename); if (tile >= 0) defineSky(tile, lognumtiles, tileofs, yoff, yscale, yoff2); } diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index 6a667e6b0..6fb14d490 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -308,15 +308,6 @@ struct BuildTiles } } - int tileForName(const char* name) - { - FName nm(name, true); - if (nm == NAME_None) return -1; - auto nmm = nametoindex.CheckKey(nm); - if (!nmm) return -1; - return *nmm; - } - void SetAliases(); @@ -369,6 +360,15 @@ void tileDelete(int tile); extern BuildTiles TileFiles; +inline int tileForName(const char* name) +{ + FName nm(name, true); + if (nm == NAME_None) return -1; + auto nmm = TileFiles.nametoindex.CheckKey(nm); + if (!nmm) return -1; + return *nmm; +} + // Some hacks to allow accessing the no longer existing arrays as if they still were arrays to avoid changing hundreds of lines of code. struct PicAnm { diff --git a/source/core/vmexports.cpp b/source/core/vmexports.cpp index 6d9b64319..a2781333c 100644 --- a/source/core/vmexports.cpp +++ b/source/core/vmexports.cpp @@ -493,7 +493,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, checktexture, sector_checktexture) void sector_settexturename(sectortype* sec, int place, int intname) { if (!sec) ThrowAbortException(X_READ_NIL, nullptr); - int tilenum = TileFiles.tileForName(FName(ENamedName(intname)).GetChars()); + int tilenum = tileForName(FName(ENamedName(intname)).GetChars()); (place == 0 ? sec->ceilingpicnum : sec->floorpicnum) = tilenum; } DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, settexturename, sector_settexturename) @@ -721,7 +721,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_walltype, twosided, wall_twosided) void wall_settexturename(walltype* sec, int place, int intname) { if (!sec) ThrowAbortException(X_READ_NIL, nullptr); - int tilenum = TileFiles.tileForName(FName(ENamedName(intname)).GetChars()); + int tilenum = tileForName(FName(ENamedName(intname)).GetChars()); (place ? sec->overpicnum : sec->wallpicnum) = tilenum; } DEFINE_ACTION_FUNCTION_NATIVE(_walltype, settexturename, wall_settexturename) diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 43637b98b..3b495465e 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -78,7 +78,7 @@ static int ccmd_spawn(CCmdFuncPtr parm) } else { - picnum = TileFiles.tileForName(parm->parms[0]); + picnum = tileForName(parm->parms[0]); if (picnum < 0) { picnum = getlabelvalue(parm->parms[0]); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 2b696d532..c109e0797 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -552,7 +552,7 @@ void CallStandingOn(DDukeActor* actor, player_struct* p) CCMD(changewalltexture) { if (argv.argc() < 2) return; - int tile = TileFiles.tileForName(argv[1]); + int tile = tileForName(argv[1]); if (tile < 0) tile = (int)strtol(argv[1], nullptr, 10); HitInfoBase hit; hitscan(ps[0].actor->spr.pos, ps[0].cursector, DVector3(ps[0].actor->spr.Angles.Yaw.ToVector(), 0) * 1024, hit, CLIPMASK1); diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 5f6b31010..d4bc326b3 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -37,7 +37,7 @@ int PicForName(int intname) for (auto& p : classes) { - classnameToTile.Insert(FName(p.first), TileFiles.tileForName(p.second)); + classnameToTile.Insert(FName(p.first), tileForName(p.second)); } } auto p = classnameToTile.CheckKey(FName(ENamedName(intname))); @@ -558,7 +558,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, hitasprite, hitasprite) void DukeActor_detonate(DDukeActor* origin, int intname) { // all callers use "EXPLOSION2", so ignore the parameter for now. This should be fixed once EXPLOSION2 gets scriptified. - int picnum = TileFiles.tileForName("EXPLOSION2"); + int picnum = tileForName("EXPLOSION2"); detonate(origin, picnum); } @@ -747,7 +747,7 @@ DEFINE_ACTION_FUNCTION(DDukeActor, checktype) // for temporary checking of types { PARAM_SELF_PROLOGUE(DDukeActor); PARAM_STRING(name); - ACTION_RETURN_BOOL(self->spr.picnum == TileFiles.tileForName(name)); + ACTION_RETURN_BOOL(self->spr.picnum == tileForName(name)); }