Skip to content

Commit

Permalink
Backend update from GZDoom.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Oct 9, 2024
1 parent 27dc590 commit 6757fa6
Show file tree
Hide file tree
Showing 124 changed files with 1,536 additions and 504 deletions.
Binary file removed bin/windows/zmusic/arm64/zmusiclite.dll
Binary file not shown.
5 changes: 3 additions & 2 deletions bin/windows/zmusic/include/zmusic.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ typedef enum EIntConfigKey_
zmusic_mod_autochip_scan_threshold,

zmusic_snd_streambuffersize,

zmusic_snd_mididevice,
zmusic_snd_outputrate,
zmusic_mod_preferredplayer,

NUM_ZMUSIC_INT_CONFIGS
} EIntConfigKey;
Expand Down Expand Up @@ -226,7 +227,7 @@ typedef struct ZMusicCallbacks_
{
// Callbacks the client can install to capture messages from the backends
// or to provide sound font data.

void (*MessageFunc)(int severity, const char* msg);
// The message callbacks are optional, without them the output goes to stdout.

Expand Down
1 change: 1 addition & 0 deletions libraries/ZVulkan/src/glslang/glslang/Include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <list>
#include <map>
#include <set>
Expand Down
3 changes: 3 additions & 0 deletions libraries/ZWidget/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ include_directories(include include/zwidget src)
if(WIN32)
set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_WIN32_SOURCES})
add_definitions(-DUNICODE -D_UNICODE)
if(MINGW)
add_definitions(-DMINGW)
endif()
elseif(APPLE)
set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_COCOA_SOURCES})
set(ZWIDGET_LIBS ${CMAKE_DL_LIBS} -ldl)
Expand Down
2 changes: 2 additions & 0 deletions libraries/ZWidget/src/widgets/lineedit/lineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ LineEdit::LineEdit(Widget* parent) : Widget(parent)

LineEdit::~LineEdit()
{
delete timer;
delete scroll_timer;
}

bool LineEdit::IsReadOnly() const
Expand Down
25 changes: 23 additions & 2 deletions libraries/ZWidget/src/window/win32/win32window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
#define RIDEV_INPUTSINK (0x100)
#endif

#ifdef MINGW
// MinGW's library doesn't contain a thunk for DwmDefWindowProc, so we need to create our own

BOOL DwmDefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult )
{
typedef BOOL(* dwmdwp)(HWND, UINT, WPARAM, LPARAM, LRESULT* );
BOOL result(FALSE);
HMODULE module = LoadLibrary( _T( "dwmapi.dll" ) );
if( module ) {
dwmdwp proc = reinterpret_cast<dwmdwp>( GetProcAddress( module, "DwmDefWindowProc" ) );
if( proc ) {
result = proc( hWnd, msg, wParam, lParam, plResult );
}
FreeLibrary(module);
}
return result;
}

#endif

static std::string from_utf16(const std::wstring& str)
{
if (str.empty()) return {};
Expand Down Expand Up @@ -61,7 +81,7 @@ Win32Window::Win32Window(DisplayWindowHost* windowHost) : WindowHost(windowHost)
Windows.push_front(this);
WindowsIterator = Windows.begin();

WNDCLASSEX classdesc = {};
WNDCLASSEXW classdesc = {};
classdesc.cbSize = sizeof(WNDCLASSEX);
classdesc.hInstance = GetModuleHandle(0);
classdesc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
Expand All @@ -74,7 +94,7 @@ Win32Window::Win32Window(DisplayWindowHost* windowHost) : WindowHost(windowHost)
// WS_CAPTION shows the caption (yay! actually a flag that does what it says it does!)
// WS_SYSMENU shows the min/max/close buttons
// WS_THICKFRAME makes the window resizable
CreateWindowEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, L"ZWidgetWindow", L"", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this);
CreateWindowExW(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, L"ZWidgetWindow", L"", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this);

/*
RAWINPUTDEVICE rid;
Expand Down Expand Up @@ -387,6 +407,7 @@ void Win32Window::PresentBitmap(int width, int height, const uint32_t* pixels)
LRESULT Win32Window::OnWindowMessage(UINT msg, WPARAM wparam, LPARAM lparam)
{
LPARAM result = 0;

if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result))
return result;

Expand Down
2 changes: 1 addition & 1 deletion libraries/ZWidget/src/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "window/window.h"
#include <stdexcept>

#ifdef WIN32
#ifdef _WIN32

#include "win32/win32window.h"

Expand Down
1 change: 1 addition & 0 deletions libraries/bzip2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ add_library( bz2 STATIC
decompress.c
huffman.c
randtable.c )
link_libraries("-static")
target_link_libraries( bz2 )
4 changes: 4 additions & 0 deletions source/common/2d/v_2ddrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ void DShape2D::OnDestroy() {

void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
{
// bail if shape is null (shouldn't happen but it might)
if (!shape)
ThrowAbortException(X_OTHER, "shape is null");

// [MK] bail out if vertex/coord array sizes are mismatched
if ( shape->mVertices.Size() != shape->mCoords.Size() )
ThrowAbortException(X_OTHER, "Mismatch in vertex/coord count: %u != %u", shape->mVertices.Size(), shape->mCoords.Size());
Expand Down
4 changes: 2 additions & 2 deletions source/common/2d/v_drawtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void DrawText(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
{
return;
}
const char *txt = (parms.localize && string[0] == '$') ? GStrings(&string[1]) : string;
const char *txt = (parms.localize && string[0] == '$') ? GStrings.GetString(&string[1]) : string;
DrawTextCommon(drawer, font, normalcolor, x, y, (const uint8_t*)string, parms);
}

Expand Down Expand Up @@ -419,7 +419,7 @@ void DrawText(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double
{
return;
}
const char *txt = (parms.localize && string[0] == '$') ? GStrings(&string[1]) : string.GetChars();
const char *txt = (parms.localize && string[0] == '$') ? GStrings.GetString(&string[1]) : string.GetChars();
DrawTextCommon(drawer, font, normalcolor, x, y, (uint8_t*)txt, parms);
}

Expand Down
27 changes: 27 additions & 0 deletions source/common/audio/music/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ float relative_volume = 1.f;
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
MusicVolumeMap MusicVolumes;
MidiDeviceMap MidiDevices;
TMap<int, int> ModPlayers;

static int DefaultFindMusic(const char* fn)
{
Expand All @@ -93,6 +94,7 @@ EXTERN_CVAR(Float, fluid_gain)

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.
CVAR(Int, mod_preferred_player, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)// toggle between libXMP and Dumb. Unlike other sound CVARs this is not directly mapped to ZMusic's config.

// CODE --------------------------------------------------------------------

Expand Down Expand Up @@ -130,6 +132,24 @@ static FileReader OpenMusic(const char* musicname)
return reader;
}

bool MusicExists(const char* music_name)
{
if (music_name == nullptr)
return false;

if (FileExists(music_name))
return true;
else
{
int lumpnum;
lumpnum = mus_cb.FindMusic(music_name);
if (lumpnum == -1) lumpnum = fileSystem.CheckNumForName(music_name, FileSys::ns_music);
if (lumpnum != -1 && fileSystem.FileLength(lumpnum) != 0)
return true;
}
return false;
}

void S_SetMusicCallbacks(MusicCallbacks* cb)
{
mus_cb = *cb;
Expand Down Expand Up @@ -751,6 +771,7 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
{
int lumpnum = mus_cb.FindMusic(musicname);
MidiDeviceSetting* devp = MidiDevices.CheckKey(lumpnum);
int* mplay = ModPlayers.CheckKey(lumpnum);

auto volp = MusicVolumes.CheckKey(lumpnum);
if (volp)
Expand All @@ -763,6 +784,12 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
CheckReplayGain(musicname, devp ? (EMidiDevice)devp->device : MDEV_DEFAULT, devp ? devp->args.GetChars() : "");
}
auto mreader = GetMusicReader(reader); // this passes the file reader to the newly created wrapper.
int mod_player = mplay? *mplay : *mod_preferred_player;
int scratch;

// This config var is only effective when opening a music stream so there's no need for active synchronization. Setting it here is sufficient.
// Ideally this should have been a parameter to ZMusic_OpenSong, but that would have necessitated an API break.
ChangeMusicSettingInt(zmusic_mod_preferredplayer, mus_playing.handle, mod_player, &scratch);
mus_playing.handle = ZMusic_OpenSong(mreader, devp ? (EMidiDevice)devp->device : MDEV_DEFAULT, devp ? devp->args.GetChars() : "");
if (mus_playing.handle == nullptr)
{
Expand Down
4 changes: 4 additions & 0 deletions source/common/audio/music/s_music.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ bool S_StartMusic (const char *music_name);
// Start music using <music_name>, and set whether looping
bool S_ChangeMusic (const char *music_name, int order=0, bool looping=true, bool force=false);

// Check if <music_name> exists
bool MusicExists(const char* music_name);

void S_RestartMusic ();
void S_MIDIDeviceChanged(int newdev);

Expand All @@ -71,6 +74,7 @@ struct MidiDeviceSetting
typedef TMap<int, MidiDeviceSetting> MidiDeviceMap;
typedef TMap<int, float> MusicVolumeMap;

extern TMap<int, int> ModPlayers;
extern MidiDeviceMap MidiDevices;
extern MusicVolumeMap MusicVolumes;
extern MusicCallbacks mus_cb;
Expand Down
6 changes: 6 additions & 0 deletions source/common/audio/sound/oalsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ OpenALSoundRenderer::OpenALSoundRenderer()
ALC.EXT_disconnect = !!alcIsExtensionPresent(Device, "ALC_EXT_disconnect");
ALC.SOFT_HRTF = !!alcIsExtensionPresent(Device, "ALC_SOFT_HRTF");
ALC.SOFT_pause_device = !!alcIsExtensionPresent(Device, "ALC_SOFT_pause_device");
ALC.SOFT_output_limiter = !!alcIsExtensionPresent(Device, "ALC_SOFT_output_limiter");

const ALCchar *current = NULL;
if(alcIsExtensionPresent(Device, "ALC_ENUMERATE_ALL_EXT"))
Expand Down Expand Up @@ -634,6 +635,11 @@ OpenALSoundRenderer::OpenALSoundRenderer()
else
attribs.Push(ALC_DONT_CARE_SOFT);
}
if(ALC.SOFT_output_limiter)
{
attribs.Push(ALC_OUTPUT_LIMITER_SOFT);
attribs.Push(ALC_TRUE);
}
// Other attribs..?
attribs.Push(0);

Expand Down
4 changes: 2 additions & 2 deletions source/common/console/c_enginecmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CCMD (print)
Printf ("print <name>: Print a string from the string table\n");
return;
}
const char *str = GStrings[argv[1]];
const char *str = GStrings.CheckString(argv[1]);
if (str == NULL)
{
Printf ("%s unknown\n", argv[1]);
Expand Down Expand Up @@ -304,7 +304,7 @@ CCMD(printlocalized)
return;
}
}
Printf("%s\n", GStrings(argv[1]));
Printf("%s\n", GStrings.GetString(argv[1]));
}

}
Expand Down
11 changes: 9 additions & 2 deletions source/common/engine/i_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
#include "startupinfo.h"
#include "c_cvars.h"
#include "gstrings.h"
#include "version.h"

static_assert(sizeof(void*) == 8, "32 builds are not supported");
static_assert(sizeof(void*) == 8,
"Only LP64/LLP64 builds are officially supported. "
"Please do not attempt to build for other platforms; "
"even if the program succeeds in a MAP01 smoke test, "
"there are e.g. known visual artifacts "
"<https://forum.zdoom.org/viewtopic.php?f=7&t=75673> "
"that lead to a bad user experience.");

// Some global engine variables taken out of the backend code.
FStartupScreen* StartWindow;
Expand All @@ -23,7 +30,7 @@ bool pauseext;

FStartupInfo GameStartupInfo;

CVAR(Bool, queryiwad, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, queryiwad, QUERYIWADDEFAULT, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(String, defaultiwad, "", CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, vid_fps, false, 0)

Expand Down
1 change: 0 additions & 1 deletion source/common/engine/i_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct SystemCallbacks
FString(*GetPlayerName)(int i);
bool (*DispatchEvent)(event_t* ev);
bool (*CheckGame)(const char* nm);
int (*GetGender)();
void (*MenuClosed)();
bool (*CheckMenudefOption)(const char* opt);
void (*ConsoleToggled)(int state);
Expand Down
4 changes: 2 additions & 2 deletions source/common/engine/i_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,11 +903,11 @@ bool JoinGame (int i)
static int PrivateNetOf(in_addr in)
{
int addr = ntohl(in.s_addr);
if ((addr & 0xFFFF0000) == 0xC0A80000) // 192.168.0.0
if ((addr & 0xFFFF0000) == 0xC0A80000) // 192.168.0.0
{
return 0xC0A80000;
}
else if ((addr & 0xFFF00000) == 0xAC100000) // 172.16.0.0
else if ((addr & 0xFFFF0000) >= 0xAC100000 && (addr & 0xFFFF0000) <= 0xAC1F0000) // 172.16.0.0 - 172.31.0.0
{
return 0xAC100000;
}
Expand Down
30 changes: 25 additions & 5 deletions source/common/engine/m_joy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,38 +120,52 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy)
{
return false;
}

assert(GameConfig);

value = GameConfig->GetValueForKey("Enabled");
if (value != NULL)
if (value)
{
joy->SetEnabled((bool)atoi(value));
}

if(joy->AllowsEnabledInBackground())
{
value = GameConfig->GetValueForKey("EnabledInBackground");
if (value)
{
joy->SetEnabledInBackground((bool)atoi(value));
}
}

value = GameConfig->GetValueForKey("Sensitivity");
if (value != NULL)
if (value)
{
joy->SetSensitivity((float)atof(value));
}

numaxes = joy->GetNumAxes();
for (int i = 0; i < numaxes; ++i)
{
axislen = mysnprintf(key, countof(key), "Axis%u", i);

mysnprintf(key + axislen, countof(key) - axislen, "deadzone");
value = GameConfig->GetValueForKey(key);
if (value != NULL)
if (value)
{
joy->SetAxisDeadZone(i, (float)atof(value));
}

mysnprintf(key + axislen, countof(key) - axislen, "scale");
value = GameConfig->GetValueForKey(key);
if (value != NULL)
if (value)
{
joy->SetAxisScale(i, (float)atof(value));
}

mysnprintf(key + axislen, countof(key) - axislen, "map");
value = GameConfig->GetValueForKey(key);
if (value != NULL)
if (value)
{
EJoyAxis gameaxis = (EJoyAxis)atoi(value);
if (gameaxis < JOYAXIS_None || gameaxis >= NUM_JOYAXIS)
Expand Down Expand Up @@ -185,6 +199,12 @@ void M_SaveJoystickConfig(IJoystickConfig *joy)
{
GameConfig->SetValueForKey("Enabled", "0");
}

if (!joy->AllowsEnabledInBackground() && joy->GetEnabledInBackground())
{
GameConfig->SetValueForKey("EnabledInBackground", "1");
}

if (!joy->IsSensitivityDefault())
{
mysnprintf(value, countof(value), "%g", joy->GetSensitivity());
Expand Down
4 changes: 4 additions & 0 deletions source/common/engine/m_joy.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ struct IJoystickConfig
virtual bool GetEnabled() = 0;
virtual void SetEnabled(bool enabled) = 0;

virtual bool AllowsEnabledInBackground() = 0;
virtual bool GetEnabledInBackground() = 0;
virtual void SetEnabledInBackground(bool enabled) = 0;

// Used by the saver to not save properties that are at their defaults.
virtual bool IsSensitivityDefault() = 0;
virtual bool IsAxisDeadZoneDefault(int axis) = 0;
Expand Down
Loading

0 comments on commit 6757fa6

Please sign in to comment.