Merge branch 'acs-netlumps' into 'master'

ACS netlumps

See merge request kart-krew-dev/ring-racers-internal!2876
This commit is contained in:
AJ Martinez 2025-09-26 17:57:39 +00:00
commit 3f8ee05db8
6 changed files with 111 additions and 15 deletions

View file

@ -25,6 +25,7 @@
#include "Script.hpp"
#include "Serial.hpp"
#include "Thread.hpp"
#include "../../../w_wad.h"
#include <iostream>
#include <list>
@ -596,7 +597,12 @@ namespace ACSVM
ModuleName Environment::readModuleName(Serial &in) const
{
auto s = readString(in);
auto i = ReadVLN<std::size_t>(in);
size_t i = ReadVLN<std::size_t>(in);
if ((i = W_LumpFromNetSave(i)) == LUMPERROR)
{
CONS_Debug(DBG_GAMELOGIC, "lumpnum not found for ACS module '%s'\n", s->str);
}
return {s, nullptr, i};
}
@ -768,7 +774,7 @@ namespace ACSVM
void Environment::writeModuleName(Serial &out, ModuleName const &in) const
{
writeString(out, in.s);
WriteVLN(out, in.i);
WriteVLN<std::size_t>(out, W_LumpIntoNetSave(in.i));
}
//

View file

@ -4639,10 +4639,10 @@ static void Command_ListWADS_f(void)
nameonly(tempname = va("%s", wadfiles[i]->filename));
if (!i)
CONS_Printf("\x82 IWAD\x80: %s\n", tempname);
else if (i <= mainwads)
else if (i < mainwads)
CONS_Printf("\x82 * %.2d\x80: %s\n", i, tempname);
else if (!wadfiles[i]->important)
CONS_Printf("\x86 %c %.2d: %s\n", ((i <= mainwads + musicwads) ? '*' : ' '), i, tempname);
CONS_Printf("\x86 %c %.2d: %s\n", ((i < mainwads + musicwads) ? '*' : ' '), i, tempname);
else
CONS_Printf(" %.2d: %s\n", i, tempname);
}

View file

@ -163,10 +163,10 @@ UINT8 *PutFileNeeded(UINT16 firstfile)
#ifdef DEVELOP
i = 0;
#else
i = mainwads + 1;
i = mainwads + musicwads;
#endif
for (; i < numwadfiles; i++) //mainwads+1, otherwise we start on the first mainwad
for (; i < numwadfiles; i++) //mainwads+musicwads, otherwise we start on the first mainwad
{
// If it has only music/sound lumps, don't put it in the list
if (!wadfiles[i]->important)
@ -197,7 +197,7 @@ UINT8 *PutFileNeeded(UINT16 firstfile)
/* don't send mainwads!! */
#ifdef DEVELOP
if (i <= mainwads)
if (i < mainwads)
filestatus += (2 << 4);
#endif
@ -565,7 +565,7 @@ INT32 CL_CheckFiles(void)
#ifdef DEVELOP
j = 0;
#else
j = mainwads + 1;
j = mainwads + musicwads;
#endif
for (i = 0; i < fileneedednum || j < numwadfiles;)
{

View file

@ -1293,7 +1293,7 @@ Rloadtextures (INT32 i, INT32 w)
}
INT32 sizeLimit = 2048;
if (w <= mainwads)
if (w < mainwads)
{
// TODO: we ran out of time to do this properly.
// 4096 limit on textures may be incompatible with some older graphics cards (circa 2005-2008?).

View file

@ -1397,7 +1397,7 @@ lumpnum_t W_CheckNumForName(const char *name)
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME);
strncpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 8);
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check;
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check;
lumpnumcache[lumpnumcacheindex].lumphash = hash;
return lumpnumcache[lumpnumcacheindex].lumpnum;
@ -1454,11 +1454,11 @@ lumpnum_t W_CheckNumForLongName(const char *name)
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME);
strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, LUMPNUMCACHENAME);
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check;
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check;
lumpnumcache[lumpnumcacheindex].lumphash = hash;
}
return (i << 16) + check;
return (i << 16) | check;
}
}
@ -1505,11 +1505,11 @@ lumpnum_t W_CheckNumForMap(const char *name, boolean checktofirst)
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME);
strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, LUMPNUMCACHENAME);
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) + check;
lumpnumcache[lumpnumcacheindex].lumpnum = (i << 16) | check;
lumpnumcache[lumpnumcacheindex].lumphash = hash;
}
return (i << 16) + check;
return (i << 16) | check;
}
}
@ -1608,7 +1608,7 @@ lumpnum_t W_CheckNumForNameInFolder(const char *lump, const char *folder)
check = W_CheckNumForLongNamePwad(lump, (UINT16)i, fsid);
if (check < feid)
{
return (i<<16) + check; // found it, in our constraints
return (i<<16) | check; // found it, in our constraints
}
}
}
@ -1634,6 +1634,93 @@ UINT8 W_LumpExists(const char *name)
return false;
}
// Thanks to the introduction of "client side WAD files",
// a notion which is insanity in any other branch of DOOM,
// any direct wadnum ID is not a guaranteed index (and
// lumpnum_t, which has it in their upper bits, suffer too)
// We can do an O(n) conversion back and forth, which is
// better than nothing, but still kind of annoying to do.
// It was either this or killing musicwads lmao ~toast 180925
lumpnum_t W_LumpIntoNetSave(lumpnum_t lump)
{
UINT32 wad = (lump >> 16);
if (lump == LUMPERROR // Bad already
|| wad < mainwads) // Same between client/server
{
// Give what we get.
return lump;
}
if (wad >= numwadfiles // Outside of range
|| !wadfiles[wad]->important) // Can't convert local lumpnum
{
// No good return result!
return LUMPERROR;
}
// Count previous local files the client might not have.
UINT32 i = (mainwads + musicwads), localoffset = 0;
for (; i < wad; i++)
{
if (wadfiles[i]->important)
continue;
localoffset++;
}
if (!localoffset)
{
// No local files, return unchanged.
return lump;
}
if (localoffset <= wad)
{
// Success, return with the conversion.
return ((wad - localoffset) << 16) | (lump & UINT16_MAX);
}
// Death!!
return LUMPERROR;
}
lumpnum_t W_LumpFromNetSave(lumpnum_t lump)
{
UINT32 netwad = (lump >> 16);
if (lump == LUMPERROR // Bad already
|| netwad < mainwads) // Same between client/server
{
// Give what we get.
return lump;
}
// Count previous local files the server would ignore.
UINT32 i = (mainwads + musicwads), localoffset = 0;
for (; (i - localoffset) <= netwad && i < numwadfiles; i++)
{
if (wadfiles[i]->important)
continue;
localoffset++;
}
if (!localoffset)
{
// No local files, return unchanged.
return lump;
}
if (netwad + localoffset < numwadfiles)
{
// Success, return with the conversion.
return ((netwad + localoffset) << 16) | (lump & UINT16_MAX);
}
// Death!!
return LUMPERROR;
}
size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump)
{
if (!TestValidLump(wad, lump))

View file

@ -188,6 +188,9 @@ lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, con
lumpnum_t W_CheckNumForNameInFolder(const char *lump, const char *folder);
UINT8 W_LumpExists(const char *name); // Lua uses this.
lumpnum_t W_LumpIntoNetSave(lumpnum_t lump);
lumpnum_t W_LumpFromNetSave(lumpnum_t lump);
size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump);
size_t W_LumpLength(lumpnum_t lumpnum);