Skip to content

Commit

Permalink
Backend update from GZDoom.
Browse files Browse the repository at this point in the history
Mainly filesystem cleanup.
  • Loading branch information
coelckers committed Nov 24, 2024
1 parent 51ebaf9 commit 5eaa53d
Show file tree
Hide file tree
Showing 108 changed files with 1,835 additions and 1,312 deletions.
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ set (PCH_SOURCES
common/engine/cycler.cpp
common/engine/d_event.cpp
common/engine/date.cpp
common/engine/filesys_doom.cpp
common/engine/stats.cpp
common/engine/sc_man.cpp
common/engine/palettecontainer.cpp
Expand Down Expand Up @@ -1288,6 +1289,7 @@ set( GAME_SOURCES
common/filesystem/source/file_whres.cpp
common/filesystem/source/file_ssi.cpp
common/filesystem/source/file_hog.cpp
common/filesystem/source/file_hog2.cpp
common/filesystem/source/file_mvl.cpp
common/filesystem/source/file_directory.cpp
common/filesystem/source/resourcefile.cpp
Expand Down
160 changes: 135 additions & 25 deletions source/common/2d/wipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "s_soundinternal.h"
#include "i_time.h"

EXTERN_CVAR(Bool, cl_capfps)

class FBurnTexture : public FTexture
{
TArray<uint32_t> WorkBuffer;
Expand Down Expand Up @@ -163,6 +165,8 @@ class Wiper
public:
virtual ~Wiper();
virtual bool Run(int ticks) = 0;
virtual bool RunInterpolated(double ticks) { return true; };
virtual bool Interpolatable() { return false; }
virtual void SetTextures(FGameTexture* startscreen, FGameTexture* endscreen)
{
startScreen = startscreen;
Expand All @@ -177,20 +181,24 @@ class Wiper_Crossfade : public Wiper
{
public:
bool Run(int ticks) override;
bool RunInterpolated(double ticks) override;
bool Interpolatable() override { return true; }

private:
int Clock = 0;
float Clock = 0;
};

class Wiper_Melt : public Wiper
{
public:
Wiper_Melt();
bool Run(int ticks) override;
bool RunInterpolated(double ticks) override;
bool Interpolatable() override { return true; }

private:
enum { WIDTH = 320, HEIGHT = 200 };
int y[WIDTH];
double y[WIDTH];
};

class Wiper_Burn : public Wiper
Expand Down Expand Up @@ -268,7 +276,23 @@ bool Wiper_Crossfade::Run(int ticks)
Clock += ticks;
DrawTexture(twod, startScreen, 0, 0, DTA_FlipY, screen->RenderTextureIsFlipped(), DTA_Masked, false, TAG_DONE);
DrawTexture(twod, endScreen, 0, 0, DTA_FlipY, screen->RenderTextureIsFlipped(), DTA_Masked, false, DTA_Alpha, clamp(Clock / 32.f, 0.f, 1.f), TAG_DONE);
return Clock >= 32;
return Clock >= 32.;
}

//==========================================================================
//
// OpenGLFrameBuffer :: Wiper_Crossfade :: Run
//
// Fades the old screen into the new one over 32 ticks.
//
//==========================================================================

bool Wiper_Crossfade::RunInterpolated(double ticks)
{
Clock += ticks;
DrawTexture(twod, startScreen, 0, 0, DTA_FlipY, screen->RenderTextureIsFlipped(), DTA_Masked, false, TAG_DONE);
DrawTexture(twod, endScreen, 0, 0, DTA_FlipY, screen->RenderTextureIsFlipped(), DTA_Masked, false, DTA_Alpha, clamp(Clock / 32.f, 0.f, 1.f), TAG_DONE);
return Clock >= 32.;
}

//==========================================================================
Expand All @@ -282,7 +306,7 @@ Wiper_Melt::Wiper_Melt()
y[0] = -(M_Random() & 15);
for (int i = 1; i < WIDTH; ++i)
{
y[i] = clamp(y[i-1] + (M_Random() % 3) - 1, -15, 0);
y[i] = clamp(y[i-1] + (double)(M_Random() % 3) - 1., -15., 0.);
}
}

Expand All @@ -307,33 +331,33 @@ bool Wiper_Melt::Run(int ticks)
{
if (y[i] < HEIGHT)
{
if (y[i] < 0)
y[i]++;
else if (y[i] < 16)
y[i] += y[i] + 1;
if (y[i] < 0.)
y[i] = y[i] + 1.;
else if (y[i] < 16.)
y[i] += y[i] + 1.;
else
y[i] = min<int>(y[i] + 8, HEIGHT);
y[i] = min<double>(y[i] + 8., HEIGHT);
done = false;
}
if (ticks == 0)
{
struct {
int32_t x;
int32_t y;
double y;
} dpt;
struct {
int32_t left;
int32_t top;
double top;
int32_t right;
int32_t bottom;
double bottom;
} rect;

// Only draw for the final tick.

int w = startScreen->GetTexelWidth();
int h = startScreen->GetTexelHeight();
dpt.x = i * w / WIDTH;
dpt.y = max(0, y[i] * h / HEIGHT);
dpt.y = max(0., y[i] * (double)h / (double)HEIGHT);
rect.left = dpt.x;
rect.top = 0;
rect.right = (i + 1) * w / WIDTH;
Expand All @@ -348,6 +372,77 @@ bool Wiper_Melt::Run(int ticks)
return done;
}

//==========================================================================
//
// Wiper_Melt :: RunInterpolated
//
// Melts the old screen into the new one over 32 ticks (interpolated).
//
//==========================================================================

bool Wiper_Melt::RunInterpolated(double ticks)
{
bool done = false;
DrawTexture(twod, endScreen, 0, 0, DTA_FlipY, screen->RenderTextureIsFlipped(), DTA_Masked, false, TAG_DONE);

// Copy the old screen in vertical strips on top of the new one.
while (ticks > 0.)
{
done = true;
for (int i = 0; i < WIDTH; i++)
{
if (y[i] < (double)HEIGHT)
{
if (ticks > 0. && ticks < 1.)
{
if (y[i] < 0)
y[i] += ticks;
else if (y[i] < 16)
y[i] += (y[i] + 1) * ticks;
else
y[i] = min<double>(y[i] + (8 * ticks), (double)HEIGHT);
}
else if (y[i] < 0.)
y[i] = y[i] + 1.;
else if (y[i] < 16.)
y[i] += y[i] + 1.;
else
y[i] = min<double>(y[i] + 8., HEIGHT);
done = false;
}
}
ticks -= 1.;
}
for (int i = 0; i < WIDTH; i++)
{
struct {
int32_t x;
double y;
} dpt;
struct {
int32_t left;
double top;
int32_t right;
double bottom;
} rect;

// Only draw for the final tick.
int w = startScreen->GetTexelWidth();
double h = startScreen->GetTexelHeight();
dpt.x = i * w / WIDTH;
dpt.y = max(0., y[i] * (double)h / (double)HEIGHT);
rect.left = dpt.x;
rect.top = 0;
rect.right = (i + 1) * w / WIDTH;
rect.bottom = h - dpt.y;
if (rect.bottom > rect.top)
{
DrawTexture(twod, startScreen, 0, dpt.y, DTA_FlipY, screen->RenderTextureIsFlipped(), DTA_ClipLeft, rect.left, DTA_ClipRight, rect.right, DTA_Masked, false, TAG_DONE);
}
}
return done;
}

//==========================================================================
//
// OpenGLFrameBuffer :: Wiper_Burn Constructor
Expand Down Expand Up @@ -423,6 +518,7 @@ void PerformWipe(FTexture* startimg, FTexture* endimg, int wipe_type, bool stops
{
// wipe update
uint64_t wipestart, nowtime, diff;
double diff_frac;
bool done;

GSnd->SetSfxPaused(true, 1);
Expand All @@ -438,20 +534,34 @@ void PerformWipe(FTexture* startimg, FTexture* endimg, int wipe_type, bool stops

do
{
do
if (wiper->Interpolatable() && !cl_capfps)
{
I_WaitVBL(2);
nowtime = I_msTime();
diff = (nowtime - wipestart) * 40 / 1000; // Using 35 here feels too slow.
} while (diff < 1);
wipestart = nowtime;
twod->Begin(screen->GetWidth(), screen->GetHeight());
done = wiper->Run(1);
if (overlaydrawer) overlaydrawer();
twod->End();
screen->Update();
twod->OnFrameDone();

diff_frac = (nowtime - wipestart) * 40. / 1000.; // Using 35 here feels too slow.
wipestart = nowtime;
twod->Begin(screen->GetWidth(), screen->GetHeight());
done = wiper->RunInterpolated(diff_frac);
if (overlaydrawer) overlaydrawer();
twod->End();
screen->Update();
twod->OnFrameDone();
}
else
{
do
{
I_WaitVBL(2);
nowtime = I_msTime();
diff = (nowtime - wipestart) * 40 / 1000; // Using 35 here feels too slow.
} while (diff < 1);
wipestart = nowtime;
twod->Begin(screen->GetWidth(), screen->GetHeight());
done = wiper->Run(1);
if (overlaydrawer) overlaydrawer();
twod->End();
screen->Update();
twod->OnFrameDone();
}
} while (!done);
delete wiper;
I_FreezeTime(false);
Expand Down
7 changes: 2 additions & 5 deletions source/common/audio/music/i_music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
#include "s_music.h"
#include "filereadermusicinterface.h"

using namespace FileSys;


void I_InitSoundFonts();

EXTERN_CVAR (Int, snd_samplerate)
Expand Down Expand Up @@ -188,7 +185,7 @@ static void SetupGenMidi()

static void SetupWgOpn()
{
int lump = fileSystem.CheckNumForFullName("xg.wopn");
int lump = fileSystem.FindFile("xg.wopn");
if (lump < 0)
{
return;
Expand Down Expand Up @@ -313,7 +310,7 @@ static ZMusic_MidiSource GetMIDISource(const char *fn)
if (src.Compare("*") == 0) src = mus_playing.name;

auto lump = fileSystem.CheckNumForName(src.GetChars(), ns_music);
if (lump < 0) lump = fileSystem.CheckNumForFullName(src.GetChars());
if (lump < 0) lump = fileSystem.FindFile(src.GetChars());
if (lump < 0)
{
Printf("Cannot find MIDI lump %s.\n", src.GetChars());
Expand Down
8 changes: 4 additions & 4 deletions source/common/audio/music/i_soundfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ FileReader FPatchSetReader::OpenFile(const char *name)

FLumpPatchSetReader::FLumpPatchSetReader(const char *filename)
{
mLumpIndex = fileSystem.CheckNumForFullName(filename);
mLumpIndex = fileSystem.FindFile(filename);

mBasePath = filename;
FixPathSeperator(mBasePath);
Expand All @@ -314,9 +314,9 @@ FileReader FLumpPatchSetReader::OpenMainConfigFile()
FileReader FLumpPatchSetReader::OpenFile(const char *name)
{
FString path;
if (IsAbsPath(name)) return FileReader(); // no absolute paths in the lump directory.
if (IsAbsPath(name)) return FileReader(); // no absolute paths in the virtual file system.
path = mBasePath + name;
auto index = fileSystem.CheckNumForFullName(path.GetChars());
auto index = fileSystem.FindFile(path.GetChars());
if (index < 0) return FileReader();
return fileSystem.ReopenFileReader(index);
}
Expand Down Expand Up @@ -472,7 +472,7 @@ FSoundFontReader *FSoundFontManager::OpenSoundFont(const char *const name, int a
// To avoid clashes this will only be done if the name has the '.cfg' extension.
// Sound fonts cannot be loaded this way.
const char *p = name + strlen(name) - 4;
if (p > name && !stricmp(p, ".cfg") && fileSystem.CheckNumForFullName(name) >= 0)
if (p > name && !stricmp(p, ".cfg") && fileSystem.FindFile(name) >= 0)
{
return new FLumpPatchSetReader(name);
}
Expand Down
4 changes: 2 additions & 2 deletions source/common/audio/music/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static FileReader OpenMusic(const char* musicname)
{
int lumpnum;
lumpnum = mus_cb.FindMusic(musicname);
if (lumpnum == -1) lumpnum = fileSystem.CheckNumForName(musicname, FileSys::ns_music);
if (lumpnum == -1) lumpnum = fileSystem.CheckNumForName(musicname, ns_music);
if (lumpnum == -1)
{
Printf("Music \"%s\" not found\n", musicname);
Expand Down Expand Up @@ -143,7 +143,7 @@ bool MusicExists(const char* music_name)
{
int lumpnum;
lumpnum = mus_cb.FindMusic(music_name);
if (lumpnum == -1) lumpnum = fileSystem.CheckNumForName(music_name, FileSys::ns_music);
if (lumpnum == -1) lumpnum = fileSystem.CheckNumForName(music_name, ns_music);
if (lumpnum != -1 && fileSystem.FileLength(lumpnum) != 0)
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion source/common/audio/sound/s_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum
{
DEFAULT_PITCH = 128,
};
static FRandom pr_soundpitch ("SoundPitch");
static FCRandom pr_soundpitch ("SoundPitch");
SoundEngine* soundEngine;

//==========================================================================
Expand Down
10 changes: 5 additions & 5 deletions source/common/console/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,15 +730,15 @@ void ReadBindings(int lump, bool override)

void C_SetDefaultKeys(const char* baseconfig)
{
auto lump = fileSystem.CheckNumForFullName("engine/commonbinds.txt");
auto lump = fileSystem.FindFile("engine/commonbinds.txt");
if (lump >= 0)
{
// Bail out if a mod tries to override this. Main game resources are allowed to do this, though.
auto fileno2 = fileSystem.GetFileContainer(lump);
if (fileno2 > fileSystem.GetMaxIwadNum())
if (fileno2 > fileSystem.GetMaxBaseNum())
{
I_FatalError("File %s is overriding core lump %s.",
fileSystem.GetResourceFileFullName(fileno2), "engine/commonbinds.txt");
fileSystem.GetContainerFullName(fileno2), "engine/commonbinds.txt");
}

ReadBindings(lump, true);
Expand All @@ -748,7 +748,7 @@ void C_SetDefaultKeys(const char* baseconfig)
while ((lump = fileSystem.FindLumpFullName(baseconfig, &lastlump)) != -1)
{
// Read this only from the main game resources.
if (fileSystem.GetFileContainer(lump) <= fileSystem.GetMaxIwadNum())
if (fileSystem.GetFileContainer(lump) <= fileSystem.GetMaxBaseNum())
ReadBindings(lump, true);
}

Expand All @@ -758,7 +758,7 @@ void C_SetDefaultKeys(const char* baseconfig)
// [SW] - We need to check to see the origin of the DEFBINDS... if it
// Comes from an IWAD/IPK3/IPK7 allow it to override the users settings...
// If it comes from a user mod however, don't.
if (fileSystem.GetFileContainer(lump) > fileSystem.GetMaxIwadNum())
if (fileSystem.GetFileContainer(lump) > fileSystem.GetMaxBaseNum())
ReadBindings(lump, false);
else
ReadBindings(lump, true);
Expand Down
Loading

1 comment on commit 5eaa53d

@markanini
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Causes any game to crash for me on start, resolved by using a build of 51ebaf9

Please sign in to comment.