Skip to content

Commit

Permalink
Merge branch 'stenzek:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager authored Dec 12, 2024
2 parents 390e796 + 5eac1e4 commit ef7d4f3
Show file tree
Hide file tree
Showing 86 changed files with 3,285 additions and 2,574 deletions.
279 changes: 33 additions & 246 deletions data/resources/gamedb.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scripts/packaging/arch/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ package() {
install -Dm755 scripts/packaging/duckstation-qt "${pkgdir}/usr/bin/duckstation-qt"

# install desktop file and icon
install -Dm644 scripts/${_desktopname}.desktop "${pkgdir}/usr/share/applications/${_desktopname}.desktop"
install -Dm644 scripts/${_desktopname}.png "${pkgdir}/usr/share/icons/hicolor/512x512/apps/${_desktopname}.png"
install -Dm644 scripts/packaging/${_desktopname}.desktop "${pkgdir}/usr/share/applications/${_desktopname}.desktop"
install -Dm644 scripts/packaging/${_desktopname}.png "${pkgdir}/usr/share/icons/hicolor/512x512/apps/${_desktopname}.png"

# install license
install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
Expand Down
4 changes: 2 additions & 2 deletions scripts/packaging/fedora/duckstation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ ninja -C build %{?_smp_mflags}
rm -fr %{buildroot}
ninja -C build install
install -Dm755 scripts/packaging/duckstation-qt %{buildroot}/usr/bin/duckstation-qt
install -Dm644 scripts/org.duckstation.DuckStation.png %{buildroot}/usr/share/icons/hicolor/512x512/apps/org.duckstation.DuckStation.png
install -Dm644 scripts/org.duckstation.DuckStation.desktop %{buildroot}/usr/share/applications/org.duckstation.DuckStation.desktop
install -Dm644 scripts/packaging/org.duckstation.DuckStation.png %{buildroot}/usr/share/icons/hicolor/512x512/apps/org.duckstation.DuckStation.png
install -Dm644 scripts/packaging/org.duckstation.DuckStation.desktop %{buildroot}/usr/share/applications/org.duckstation.DuckStation.desktop

%files
%license LICENSE
Expand Down
56 changes: 56 additions & 0 deletions src/common-tests/rectangle_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,59 @@ TEST(Rectangle, RelationalOperators)
ASSERT_FALSE(r1.eq(r2));
}

TEST(Rectangle, ValidRectangles)
{
static constexpr GSVector4i cases[] = {
GSVector4i::cxpr(1, 2, 3, 4),
GSVector4i::cxpr(-5, -10, -1, -2),
GSVector4i::cxpr(0, 0, 1, 1),
GSVector4i::cxpr(100, 200, 300, 400),
GSVector4i::cxpr(-1000, -2000, 500, 600),
GSVector4i::cxpr(5, 10, 6, 12),
GSVector4i::cxpr(-10, -20, -5, -15),
GSVector4i::cxpr(-5, 0, 5, 10),
GSVector4i::cxpr(-100, -200, 100, 200),
GSVector4i::cxpr(-1, -2, 0, 1),
};

for (GSVector4i tcase : cases)
{
ASSERT_TRUE(tcase.rvalid());
ASSERT_FALSE(tcase.rempty());
}
}

TEST(Rectangle, InvalidRectangles)
{
static constexpr GSVector4i cases[] = {
// left < right but not top < bottom
GSVector4i::cxpr(1, 4, 3, 2),
GSVector4i::cxpr(-5, -2, -1, -10),
GSVector4i::cxpr(0, 1, 1, 0),
GSVector4i::cxpr(100, 400, 300, 200),
GSVector4i::cxpr(-1000, 600, 500, -2000),
GSVector4i::cxpr(5, 12, 6, 10),
GSVector4i::cxpr(-10, -15, -5, -20),
GSVector4i::cxpr(-5, 10, 5, 0),
GSVector4i::cxpr(-100, 200, 100, -200),
GSVector4i::cxpr(-1, 1, 0, -2),

// not left < right but top < bottom
GSVector4i::cxpr(3, 2, 1, 4),
GSVector4i::cxpr(-1, -10, -5, -2),
GSVector4i::cxpr(1, 0, 0, 1),
GSVector4i::cxpr(300, 200, 100, 400),
GSVector4i::cxpr(500, -2000, -1000, 600),
GSVector4i::cxpr(6, 10, 5, 12),
GSVector4i::cxpr(-5, -20, -10, -15),
GSVector4i::cxpr(5, 0, -5, 10),
GSVector4i::cxpr(100, -200, -100, 200),
GSVector4i::cxpr(0, -2, -1, 1),
};

for (GSVector4i tcase : cases)
{
ASSERT_FALSE(tcase.rvalid());
ASSERT_TRUE(tcase.rempty());
}
}
81 changes: 44 additions & 37 deletions src/common/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@

#include "assert.h"
#include "crash_handler.h"

#include <cstdio>
#include <cstdlib>
#include <mutex>

#if defined(_WIN32)
#ifdef _WIN32

#include "windows_headers.h"
#include <intrin.h>
#include <tlhelp32.h>
#endif

#include <mutex>

#ifdef __clang__
#pragma clang diagnostic ignored "-Winvalid-noreturn"
#endif

static std::mutex s_AssertFailedMutex;

static inline void FreezeThreads(void** ppHandle)
static HANDLE FreezeThreads()
{
#if defined(_WIN32)
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
Expand All @@ -43,17 +44,12 @@ static inline void FreezeThreads(void** ppHandle)
}
}

*ppHandle = (void*)hSnapshot;
#else
*ppHandle = nullptr;
#endif
return hSnapshot;
}

static inline void ResumeThreads(void* pHandle)
static void ResumeThreads(HANDLE hSnapshot)
{
#if defined(_WIN32)
HANDLE hSnapshot = (HANDLE)pHandle;
if (pHandle != INVALID_HANDLE_VALUE)
if (hSnapshot != INVALID_HANDLE_VALUE)
{
THREADENTRY32 threadEntry;
if (Thread32First(hSnapshot, &threadEntry))
Expand All @@ -73,21 +69,42 @@ static inline void ResumeThreads(void* pHandle)
}
CloseHandle(hSnapshot);
}
}

#else

#ifdef __ANDROID__
// Define as a weak symbol for ancient devices that don't have it.
extern "C" __attribute__((weak)) void android_set_abort_message(const char*);
#endif
}

void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char* szFile, unsigned uLine)
[[noreturn]] ALWAYS_INLINE static void AbortWithMessage(const char* szMsg)
{
std::lock_guard<std::mutex> guard(s_AssertFailedMutex);
#ifndef __ANDROID__
std::fputs(szMsg, stderr);
CrashHandler::WriteDumpForCaller();
std::fputs("Aborting application.\n", stderr);
std::fflush(stderr);
std::abort();
#else
if (&android_set_abort_message)
android_set_abort_message(szMsg);

void* pHandle;
FreezeThreads(&pHandle);
std::abort();
#endif
}

#endif // _WIN32

void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char* szFile, unsigned uLine)
{
char szMsg[512];
std::snprintf(szMsg, sizeof(szMsg), "%s in function %s (%s:%u)\n", szMessage, szFunction, szFile, uLine);

#if defined(_WIN32)
std::unique_lock lock(s_AssertFailedMutex);
HANDLE pHandle = FreezeThreads();

SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), szMsg, static_cast<DWORD>(std::strlen(szMsg)), NULL, NULL);
OutputDebugStringA(szMsg);
Expand All @@ -107,28 +124,22 @@ void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char*
CrashHandler::WriteDumpForCaller();
TerminateProcess(GetCurrentProcess(), 0xBAADC0DE);
}
#else
std::fputs(szMsg, stderr);
CrashHandler::WriteDumpForCaller();
std::fputs("Aborting application.\n", stderr);
std::fflush(stderr);
std::abort();
#endif

ResumeThreads(pHandle);
#else
AbortWithMessage(szMsg);
#endif
}

[[noreturn]] void Y_OnPanicReached(const char* szMessage, const char* szFunction, const char* szFile, unsigned uLine)
{
std::lock_guard<std::mutex> guard(s_AssertFailedMutex);

void* pHandle;
FreezeThreads(&pHandle);

char szMsg[512];
std::snprintf(szMsg, sizeof(szMsg), "%s in function %s (%s:%u)\n", szMessage, szFunction, szFile, uLine);

#if defined(_WIN32)
std::unique_lock guard(s_AssertFailedMutex);
HANDLE pHandle = FreezeThreads();

SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), szMsg, static_cast<DWORD>(std::strlen(szMsg)), NULL, NULL);
OutputDebugStringA(szMsg);
Expand All @@ -145,13 +156,9 @@ void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char*
CrashHandler::WriteDumpForCaller();

TerminateProcess(GetCurrentProcess(), 0xBAADC0DE);
#else
std::fputs(szMsg, stderr);
CrashHandler::WriteDumpForCaller();
std::fputs("Aborting application.\n", stderr);
std::fflush(stderr);
std::abort();
#endif

ResumeThreads(pHandle);
#else
AbortWithMessage(szMsg);
#endif
}
28 changes: 16 additions & 12 deletions src/common/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@ void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char*
[[noreturn]] void Y_OnPanicReached(const char* szMessage, const char* szFunction, const char* szFile, unsigned uLine);

#define Assert(expr) \
if (!(expr)) \
do \
{ \
Y_OnAssertFailed("Assertion failed: '" #expr "'", __FUNCTION__, __FILE__, __LINE__); \
}
if (!(expr)) \
Y_OnAssertFailed("Assertion failed: '" #expr "'", __FUNCTION__, __FILE__, __LINE__); \
} while (0)
#define AssertMsg(expr, msg) \
if (!(expr)) \
do \
{ \
Y_OnAssertFailed("Assertion failed: '" msg "'", __FUNCTION__, __FILE__, __LINE__); \
}
if (!(expr)) \
Y_OnAssertFailed("Assertion failed: '" msg "'", __FUNCTION__, __FILE__, __LINE__); \
} while (0)

#if defined(_DEBUG) || defined(_DEVEL)
#define DebugAssert(expr) \
if (!(expr)) \
do \
{ \
Y_OnAssertFailed("Debug assertion failed: '" #expr "'", __FUNCTION__, __FILE__, __LINE__); \
}
if (!(expr)) \
Y_OnAssertFailed("Debug assertion failed: '" #expr "'", __FUNCTION__, __FILE__, __LINE__); \
} while (0)
#define DebugAssertMsg(expr, msg) \
if (!(expr)) \
do \
{ \
Y_OnAssertFailed("Debug assertion failed: '" msg "'", __FUNCTION__, __FILE__, __LINE__); \
}
if (!(expr)) \
Y_OnAssertFailed("Debug assertion failed: '" msg "'", __FUNCTION__, __FILE__, __LINE__); \
} while (0)
#else
#define DebugAssert(expr)
#define DebugAssertMsg(expr, msg)
Expand Down
2 changes: 1 addition & 1 deletion src/common/crash_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void CrashHandler::WriteDumpForCaller()
LogCallstack(0, nullptr);
}

#else
#elif !defined(__ANDROID__)

bool CrashHandler::Install(CleanupHandler cleanup_handler)
{
Expand Down
6 changes: 5 additions & 1 deletion src/common/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,10 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
return false;
}

#endif

#ifdef HAS_POSIX_FILE_LOCK

static bool SetLock(int fd, bool lock, bool block, Error* error)
{
// We want to lock the whole file.
Expand All @@ -2814,7 +2818,7 @@ static bool SetLock(int fd, bool lock, bool block, Error* error)
bool res;
for (;;)
{
res = (lockf(fd, lock ? (block ? F_TLOCK : F_LOCK) : F_ULOCK, 0) == 0);
res = (lockf(fd, lock ? (block ? F_LOCK : F_TLOCK) : F_ULOCK, 0) == 0);
if (!res && errno == EINTR)
continue;
else
Expand Down
8 changes: 7 additions & 1 deletion src/common/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ bool CommitAtomicRenamedFile(AtomicRenamedFile& file, Error* error);
void DiscardAtomicRenamedFile(AtomicRenamedFile& file);

/// Abstracts a POSIX file lock.
#ifndef _WIN32
#if !defined(_WIN32) && !defined(__ANDROID__)
#define HAS_POSIX_FILE_LOCK 1
#endif

#ifdef HAS_POSIX_FILE_LOCK

class POSIXLock
{
public:
Expand All @@ -175,6 +180,7 @@ class POSIXLock
private:
int m_fd;
};

#endif

std::optional<DynamicHeapArray<u8>> ReadBinaryFile(const char* path, Error* error = nullptr);
Expand Down
Loading

0 comments on commit ef7d4f3

Please sign in to comment.