Skip to content

Commit

Permalink
- Backend update from Raze
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Apr 19, 2021
1 parent 55ce051 commit ba146ed
Show file tree
Hide file tree
Showing 43 changed files with 473 additions and 168 deletions.
32 changes: 24 additions & 8 deletions src/common/2d/v_2ddrawer.cpp
Expand Up @@ -189,8 +189,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, PushTriangle, Shape2D_PushTriangle)
//
//==========================================================================

int F2DDrawer::AddCommand(const RenderCommand *data)
int F2DDrawer::AddCommand(RenderCommand *data)
{
data->mScreenFade = screenFade;
if (mData.Size() > 0 && data->isCompatible(mData.Last()))
{
// Merge with the last command.
Expand Down Expand Up @@ -738,12 +739,12 @@ void F2DDrawer::AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
//
//==========================================================================

void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2)
void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, const unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2)
{
RenderCommand dg;
int method = 0;

if (!img->isValid()) return;
if (!img || !img->isValid()) return;

dg.mType = DrawTypeTriangles;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth() - 1 || clipy2 < GetHeight() - 1)
Expand All @@ -769,14 +770,28 @@ void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigne
Set(ptr, vt[i].X, vt[i].Y, 0.f, vt[i].Z, vt[i].W, color);
ptr++;
}

dg.mIndexIndex = mIndices.Size();
mIndices.Reserve(idxcount);
for (size_t i = 0; i < idxcount; i++)

if (idxcount > 0)
{
mIndices.Reserve(idxcount);
for (size_t i = 0; i < idxcount; i++)
{
mIndices[dg.mIndexIndex + i] = ind[i] + dg.mVertIndex;
}
dg.mIndexCount = (int)idxcount;
}
else
{
mIndices[dg.mIndexIndex + i] = ind[i] + dg.mVertIndex;
// If we have no index buffer, treat this as an unindexed list of triangles.
mIndices.Reserve(vtcount);
for (size_t i = 0; i < vtcount; i++)
{
mIndices[dg.mIndexIndex + i] = i + dg.mVertIndex;
}
dg.mIndexCount = (int)vtcount;

}
dg.mIndexCount = (int)idxcount;
AddCommand(&dg);
}

Expand Down Expand Up @@ -941,6 +956,7 @@ void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, F
{
// Only needed by Raze's fullscreen blends because they are being calculated late when half of the 2D content has already been submitted,
// This ensures they are below the HUD, not above it.
dg.mScreenFade = screenFade;
mData.Insert(0, dg);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/common/2d/v_2ddrawer.h
Expand Up @@ -118,6 +118,7 @@ class F2DDrawer
ETexMode mDrawMode;
uint8_t mLightLevel;
uint8_t mFlags;
float mScreenFade;

bool useTransform;
DMatrix3x3 transform;
Expand Down Expand Up @@ -149,6 +150,7 @@ class F2DDrawer
mLightLevel == other.mLightLevel &&
mColor1.d == other.mColor1.d &&
useTransform == other.useTransform &&
mScreenFade == other.mScreenFade &&
(
!useTransform ||
(
Expand All @@ -172,7 +174,7 @@ class F2DDrawer
int fullscreenautoaspect = 3;
int cliptop = -1, clipleft = -1, clipwidth = -1, clipheight = -1;

int AddCommand(const RenderCommand *data);
int AddCommand(RenderCommand *data);
void AddIndices(int firstvert, int count, ...);
private:
void AddIndices(int firstvert, TArray<int> &v);
Expand All @@ -187,7 +189,7 @@ class F2DDrawer
void AddPoly(FGameTexture *texture, FVector2 *points, int npoints,
double originx, double originy, double scalex, double scaley,
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double lightlevel, uint32_t *indices, size_t indexcount);
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2);
void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, const unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2);
void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex,
int clipx1, int clipy1, int clipx2, int clipy2);
void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin = false, double flatscale = 1.0, PalEntry color = 0xffffffff, ERenderStyle rs = STYLE_Normal);
Expand Down
27 changes: 24 additions & 3 deletions src/common/audio/music/music.cpp
Expand Up @@ -82,8 +82,11 @@ static MusicCallbacks mus_cb = { nullptr, DefaultOpenMusic };

// PUBLIC DATA DEFINITIONS -------------------------------------------------
EXTERN_CVAR(Int, snd_mididevice)
EXTERN_CVAR(Float, mod_dumb_mastervolume)
EXTERN_CVAR(Float, fluid_gain)

CVAR(Bool, mus_calcgain, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song.

CVAR(Bool, mus_calcgain, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song.
CVAR(Bool, mus_usereplaygain, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // changing this will only take effect for the next song.
CUSTOM_CVAR(Float, mus_gainoffset, 0.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // for customizing the base volume
{
Expand All @@ -107,13 +110,18 @@ void S_SetMusicCallbacks(MusicCallbacks* cb)
//==========================================================================

static std::unique_ptr<SoundStream> musicStream;
static TArray<SoundStream*> customStreams;

SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata)
{
int flags = 0;
if (numchannels < 2) flags |= SoundStream::Mono;
auto stream = GSnd->CreateStream(cb, int(size), flags, samplerate, userdata);
if (stream) stream->Play(true, 1);
if (stream)
{
stream->Play(true, 1);
customStreams.Push(stream);
}
return stream;
}

Expand All @@ -122,11 +130,19 @@ void S_StopCustomStream(SoundStream *stream)
if (stream)
{
stream->Stop();
auto f = customStreams.Find(stream);
if (f < customStreams.Size()) customStreams.Delete(f);
delete stream;
}

}

void S_PauseAllCustomStreams(bool on)
{
for (auto s : customStreams)
{
s->SetPaused(on);
}
}

static TArray<int16_t> convert;
static bool FillStream(SoundStream* stream, void* buff, int len, void* userdata)
Expand Down Expand Up @@ -214,6 +230,9 @@ static bool S_StartMusicPlaying(ZMusic_MusicStream song, bool loop, float rel_vo
I_SetRelativeVolume(saved_relative_volume * factor);
}
ZMusic_Stop(song);
// make sure the volume modifiers update properly in case replay gain settings have changed.
fluid_gain.Callback();
mod_dumb_mastervolume.Callback();
if (!ZMusic_Start(song, subsong, loop))
{
return false;
Expand Down Expand Up @@ -488,6 +507,8 @@ static void CheckReplayGain(const char *musicname, EMidiDevice playertype, const
{
mus_playing.replayGain = 0.f;
mus_playing.replayGainFactor = dBToAmplitude(mus_gainoffset);
fluid_gain.Callback();
mod_dumb_mastervolume.Callback();
if (!mus_usereplaygain) return;

FileReader reader = mus_cb.OpenMusic(musicname);
Expand Down
22 changes: 20 additions & 2 deletions src/common/audio/music/music_config.cpp
Expand Up @@ -41,6 +41,7 @@
#include "version.h"
#include <zmusic.h>

EXTERN_CVAR(Bool, mus_usereplaygain)
//==========================================================================
//
// ADL Midi device
Expand Down Expand Up @@ -122,7 +123,16 @@ CUSTOM_CVAR(String, fluid_patchset, GAMENAMELOWERCASE, CVAR_ARCHIVE | CVAR_GLOBA

CUSTOM_CVAR(Float, fluid_gain, 0.5, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
{
FORWARD_CVAR(fluid_gain);
if (!mus_usereplaygain)
{
FORWARD_CVAR(fluid_gain);
}
else
{
// Replay gain will disable the user setting for consistency.
float newval;
ChangeMusicSetting(zmusic_fluid_gain, mus_playing.handle, 0.5f, & newval);
}
}

CUSTOM_CVAR(Bool, fluid_reverb, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
Expand Down Expand Up @@ -493,6 +503,14 @@ CUSTOM_CVAR(Int, mod_autochip_scan_threshold, 12, CVAR_ARCHIVE | CVAR_GLOBAL

CUSTOM_CVAR(Float, mod_dumb_mastervolume, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_VIRTUAL)
{
FORWARD_CVAR(mod_dumb_mastervolume);
if (!mus_usereplaygain)
{
FORWARD_CVAR(mod_dumb_mastervolume);
}
else
{
float newval;
ChangeMusicSetting(zmusic_mod_dumb_mastervolume, mus_playing.handle, 0.5f, &newval);
}
}

1 change: 1 addition & 0 deletions src/common/audio/music/s_music.h
Expand Up @@ -14,6 +14,7 @@ class SoundStream;
typedef bool(*StreamCallback)(SoundStream* stream, void* buff, int len, void* userdata);
SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata);
void S_StopCustomStream(SoundStream* stream);
void S_PauseAllCustomStreams(bool on);

struct MusicCallbacks
{
Expand Down
1 change: 1 addition & 0 deletions src/common/audio/sound/i_soundinternal.h
Expand Up @@ -31,6 +31,7 @@ enum EChanFlag
CHANF_OVERLAP = 8192, // [MK] Does not stop any sounds in the channel and instead plays over them.
CHANF_LOCAL = 16384, // only plays locally for the calling actor
CHANF_TRANSIENT = 32768, // Do not record in savegames - used for sounds that get restarted outside the sound system (e.g. ambients in SW and Blood)
CHANF_FORCE = 65536, // Start, even if sound is paused.
};

typedef TFlags<EChanFlag> EChanFlags;
Expand Down
2 changes: 1 addition & 1 deletion src/common/audio/sound/s_sound.cpp
Expand Up @@ -528,7 +528,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,

// sound is paused and a non-looped sound is being started.
// Such a sound would play right after unpausing which wouldn't sound right.
if (!(chanflags & CHANF_LOOP) && !(chanflags & (CHANF_UI|CHANF_NOPAUSE)) && SoundPaused)
if (!(chanflags & CHANF_LOOP) && !(chanflags & (CHANF_UI|CHANF_NOPAUSE|CHANF_FORCE)) && SoundPaused)
{
return NULL;
}
Expand Down
6 changes: 6 additions & 0 deletions src/common/console/c_bind.cpp
Expand Up @@ -696,6 +696,12 @@ void ReadBindings(int lump, bool override)
dest = &AutomapBindings;
sc.MustGetString();
}
else if (sc.Compare("unbind"))
{
sc.MustGetString();
dest->UnbindKey(sc.String);
continue;
}
key = GetConfigKeyFromName(sc.String);
sc.MustGetString();
dest->SetBind(key, sc.String, override);
Expand Down
15 changes: 9 additions & 6 deletions src/common/engine/d_event.cpp
Expand Up @@ -76,12 +76,15 @@ void D_ProcessEvents (void)
continue;
if (ev->type == EV_DeviceChange)
UpdateJoystickMenu(I_UpdateDeviceList());
if (gamestate == GS_INTRO)
continue;
if (C_Responder (ev))
continue; // console ate the event
if (M_Responder (ev))
continue; // menu ate the event

if (gamestate != GS_INTRO) // GS_INTRO blocks the UI.
{
if (C_Responder(ev))
continue; // console ate the event
if (M_Responder(ev))
continue; // menu ate the event
}

G_Responder (ev);
}
}
Expand Down
36 changes: 36 additions & 0 deletions src/common/engine/sc_man.cpp
Expand Up @@ -1287,6 +1287,42 @@ void FScanner::AddSymbol(const char* name, double value)
symbols.Insert(name, sym);
}

//==========================================================================
//
//
//
//==========================================================================

int FScanner::StartBraces(FScanner::SavedPos* braceend)
{
if (CheckString("{"))
{
auto here = SavePos();
SkipToEndOfBlock();
*braceend = SavePos();
RestorePos(here);
return 0;
}
else
{
ScriptError("'{' expected");
return -1;
}
}

//==========================================================================
//
//
//
//==========================================================================

bool FScanner::FoundEndBrace(FScanner::SavedPos& braceend)
{
auto here = SavePos();
return here.SavedScriptPtr >= braceend.SavedScriptPtr;
}


//==========================================================================
//
// a class that remembers a parser position
Expand Down
25 changes: 25 additions & 0 deletions src/common/engine/sc_man.h
Expand Up @@ -94,6 +94,8 @@ class FScanner
inline void AddSymbol(const char* name, uint32_t value) { return AddSymbol(name, uint64_t(value)); }
void AddSymbol(const char* name, double value);
void SkipToEndOfBlock();
int StartBraces(FScanner::SavedPos* braceend);
bool FoundEndBrace(FScanner::SavedPos& braceend);

static FString TokenName(int token, const char *string=NULL);

Expand All @@ -113,7 +115,30 @@ class FScanner
void MustGetNumber(bool evaluate = false);
bool CheckNumber(bool evaluate = false);

bool GetNumber(int& var, bool evaluate = false)
{
if (!GetNumber(evaluate)) return false;
var = Number;
return true;
}

bool GetString(FString& var)
{
if (!GetString()) return false;
var = String;
return true;
}

bool GetFloat(bool evaluate = false);

bool GetFloat(double& var, bool evaluate = false)
{
if (!GetFloat(evaluate)) return false;
var = Float;
return true;
}


void MustGetFloat(bool evaluate = false);
bool CheckFloat(bool evaluate = false);

Expand Down
1 change: 0 additions & 1 deletion src/common/engine/startupinfo.h
Expand Up @@ -13,7 +13,6 @@ struct FStartupInfo
int LoadLights = -1;
int LoadBrightmaps = -1;
int LoadWidescreen = -1;
int modern = 0;
enum
{
DefaultStartup,
Expand Down
2 changes: 1 addition & 1 deletion src/common/filesystem/file_7z.cpp
Expand Up @@ -293,7 +293,7 @@ bool F7ZFile::Open(bool quiet, LumpFilterInfo *filter)
lump_p->Owner = this;
lump_p->Flags = LUMPF_FULLPATH|LUMPF_COMPRESSED;
lump_p->Position = i;
lump_p->CheckEmbedded();
lump_p->CheckEmbedded(filter);
lump_p++;
}
// Resize the lump record array to its actual size
Expand Down

1 comment on commit ba146ed

@madame-rachelle
Copy link
Collaborator

Choose a reason for hiding this comment

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

This commit completely broke the software renderer, at least on Vulkan. When I flip to it, the game crashes now.

Please sign in to comment.