From 7de1d3058f166eead23c76a0721f5892f5cee29a Mon Sep 17 00:00:00 2001 From: bencie Date: Tue, 24 Sep 2024 21:33:54 +0200 Subject: [PATCH 1/9] Show skin name as tooltip in friendlist and serverinfo --- src/game/client/components/menus.h | 1 + src/game/client/components/menus_browser.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index c9797eb37ce..4595bd1eebb 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -417,6 +417,7 @@ class CMenus : public CComponent const void *ListItemId() const { return &m_aName; } const void *RemoveButtonId() const { return &m_FriendState; } const void *CommunityTooltipId() const { return &m_IsPlayer; } + const void *SkinTooltipId() const { return &m_aSkin; } bool operator<(const CFriendItem &Other) const { diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 9188cff7276..5cbb81ad760 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1325,6 +1325,8 @@ void CMenus::RenderServerbrowserInfoScoreboard(CUIRect View, const CServerInfo * CRenderTools::GetRenderTeeOffsetToRenderedTee(pIdleState, &TeeInfo, OffsetToMid); const vec2 TeeRenderPos = vec2(Skin.x + TeeInfo.m_Size / 2.0f, Skin.y + Skin.h / 2.0f + OffsetToMid.y); RenderTools()->RenderTee(pIdleState, &TeeInfo, CurrentClient.m_Afk ? EMOTE_BLINK : EMOTE_NORMAL, vec2(1.0f, 0.0f), TeeRenderPos); + Ui()->DoButtonLogic(&CurrentClient.m_aSkin, 0, &Skin); + GameClient()->m_Tooltips.DoToolTip(&CurrentClient.m_aSkin, &Skin, CurrentClient.m_aSkin); } // name @@ -1493,8 +1495,9 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) if(s_ScrollRegion.RectClipped(Rect)) continue; - const bool Inside = Ui()->HotItem() == Friend.ListItemId() || Ui()->HotItem() == Friend.RemoveButtonId() || Ui()->HotItem() == Friend.CommunityTooltipId(); + const bool Inside = Ui()->HotItem() == Friend.ListItemId() || Ui()->HotItem() == Friend.RemoveButtonId() || Ui()->HotItem() == Friend.CommunityTooltipId() || Ui()->HotItem() == Friend.SkinTooltipId(); int ButtonResult = Ui()->DoButtonLogic(Friend.ListItemId(), 0, &Rect); + if(Friend.ServerInfo()) { GameClient()->m_Tooltips.DoToolTip(Friend.ListItemId(), &Rect, Localize("Click to select server. Double click to join your friend.")); @@ -1525,6 +1528,8 @@ void CMenus::RenderServerbrowserFriends(CUIRect View) CRenderTools::GetRenderTeeOffsetToRenderedTee(pIdleState, &TeeInfo, OffsetToMid); const vec2 TeeRenderPos = vec2(Skin.x + Skin.w / 2.0f, Skin.y + Skin.h * 0.55f + OffsetToMid.y); RenderTools()->RenderTee(pIdleState, &TeeInfo, Friend.IsAfk() ? EMOTE_BLINK : EMOTE_NORMAL, vec2(1.0f, 0.0f), TeeRenderPos); + Ui()->DoButtonLogic(Friend.SkinTooltipId(), 0, &Skin); + GameClient()->m_Tooltips.DoToolTip(Friend.SkinTooltipId(), &Skin, Friend.Skin()); } Rect.HSplitTop(11.0f, &NameLabel, &ClanLabel); From 36c3656883f92d9c9c27e4cb0f573ff644f945c4 Mon Sep 17 00:00:00 2001 From: bencie Date: Wed, 25 Sep 2024 18:19:45 +0200 Subject: [PATCH 2/9] Make cl_show_direction change alpha with cl_show_others_alpha --- src/game/client/components/nameplates.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/nameplates.cpp b/src/game/client/components/nameplates.cpp index b5ec8a65d05..59366afe516 100644 --- a/src/game/client/components/nameplates.cpp +++ b/src/game/client/components/nameplates.cpp @@ -60,7 +60,10 @@ void CNamePlates::RenderNameplate(vec2 Position, const CNetObj_PlayerInfo *pPlay Jump = Character.m_Cur.m_Jumped & 1; } - Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + if(OtherTeam && !ForceAlpha) + Graphics()->SetColor(1.0f, 1.0f, 1.0f, g_Config.m_ClShowOthersAlpha / 100.0f); + else + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); const float ShowDirectionImgSize = 22.0f; YOffset -= ShowDirectionImgSize; From 2dcbd5ecbb665bdebd6a9b52a02025ef4b323bd6 Mon Sep 17 00:00:00 2001 From: furo Date: Thu, 26 Sep 2024 00:09:41 +0200 Subject: [PATCH 3/9] Don't reset zoom on team switch --- src/game/client/gameclient.cpp | 5 +---- src/game/client/gameclient.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index bbeddef4528..b1d701552e2 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -2513,14 +2513,11 @@ void CGameClient::CClientData::CSixup::Reset() } } -void CGameClient::SendSwitchTeam(int Team) +void CGameClient::SendSwitchTeam(int Team) const { CNetMsg_Cl_SetTeam Msg; Msg.m_Team = Team; Client()->SendPackMsgActive(&Msg, MSGFLAG_VITAL); - - if(Team != TEAM_SPECTATORS) - m_Camera.OnReset(); } void CGameClient::SendStartInfo7(bool Dummy) const diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index d385bfd791d..11fd32f27ba 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -554,7 +554,7 @@ class CGameClient : public IGameClient // actions // TODO: move these - void SendSwitchTeam(int Team); + void SendSwitchTeam(int Team) const; void SendStartInfo7(bool Dummy) const; void SendSkinChange7(bool Dummy); // Returns true if the requested skin change got applied by the server From 7180ef1ec175aaaee0de48226e0836999c1357fe Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 27 Sep 2024 12:02:53 +0800 Subject: [PATCH 4/9] Fix glew CI error ``` [1/322] Building C object CMakeFiles/glew.dir/src/engine/external/glew/glew.c.o FAILED: CMakeFiles/glew.dir/src/engine/external/glew/glew.c.o /usr/bin/cc -DGLEW_STATIC -I/home/runner/work/ddnet/ddnet/src/engine/external/glew -g -fdiagnostics-color=always -fstack-protector-strong -fno-exceptions -fsigned-char -Wno-implicit-function-declaration -MD -MT CMakeFiles/glew.dir/src/engine/external/glew/glew.c.o -MF CMakeFiles/glew.dir/src/engine/external/glew/glew.c.o.d -o CMakeFiles/glew.dir/src/engine/external/glew/glew.c.o -c /home/runner/work/ddnet/ddnet/src/engine/external/glew/glew.c In file included from /home/runner/work/ddnet/ddnet/src/engine/external/glew/glew.c:34: /home/runner/work/ddnet/ddnet/src/engine/external/glew/GL/glew.h:1205:14: fatal error: GL/glu.h: No such file or directory 1205 | # include | ^~~~~~~~~~ compilation terminated. [2/322] Building C object CMakeFiles/wavpack.dir/src/engine/external/wavpack/float.c.o ``` --- .github/workflows/build.yml | 2 +- .github/workflows/clang-sanitizer.yml | 2 +- .github/workflows/clang-tidy.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/style.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26aabc669b3..29f0b6bda5d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,7 +51,7 @@ jobs: sudo apt-get update -y # mount: /var/lib/grub/esp: special device /dev/disk/by-id/scsi-... does not exist. # sudo apt-get upgrade -y - sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libvulkan-dev glslang-tools spirv-tools libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libpng-dev valgrind gcovr -y + sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libvulkan-dev glslang-tools spirv-tools libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libpng-dev valgrind gcovr libglew-dev -y - name: Prepare Linux (non-fancy) if: ${{ contains(matrix.os, 'ubuntu') && !matrix.fancy }} diff --git a/.github/workflows/clang-sanitizer.yml b/.github/workflows/clang-sanitizer.yml index 56421ca4dc3..b08b3f31d67 100644 --- a/.github/workflows/clang-sanitizer.yml +++ b/.github/workflows/clang-sanitizer.yml @@ -21,7 +21,7 @@ jobs: - name: Prepare linux run: | sudo apt-get update -y - sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libvulkan-dev glslang-tools spirv-tools -y + sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libvulkan-dev glslang-tools spirv-tools libglew-dev -y - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - name: Build with ASan and UBSan diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index b37a40c395d..29caf4ec93b 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -21,7 +21,7 @@ jobs: - name: Install clang-tidy run: | sudo apt-get update -y - sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev clang-tidy libvulkan-dev glslang-tools spirv-tools -y + sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev clang-tidy libvulkan-dev glslang-tools spirv-tools libglew-dev -y - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 16f0720b621..9e4df7bdb7e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -40,7 +40,7 @@ jobs: if: matrix.language == 'cpp' run: | sudo apt-get update -y - sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libmariadb-dev libwebsockets-dev libvulkan-dev glslang-tools spirv-tools -y + sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libmariadb-dev libwebsockets-dev libvulkan-dev glslang-tools spirv-tools libglew-dev -y # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 5b5b811c311..93c9e9022ff 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -20,7 +20,7 @@ jobs: - name: Prepare run: | sudo apt-get update -y - sudo apt-get install clang-format imagemagick ddnet-tools shellcheck pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev python3-clang libvulkan-dev glslang-tools spirv-tools -y + sudo apt-get install clang-format imagemagick ddnet-tools shellcheck pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev python3-clang libvulkan-dev glslang-tools spirv-tools libglew-dev -y rustup default stable pip3 install pylint wget -O ~/.local/bin/shfmt https://github.com/mvdan/sh/releases/download/v3.8.0/shfmt_v3.8.0_linux_amd64 From b18073a5cdd590f4338cd75068cf0b5918ec738a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 2 Jan 2024 21:43:57 +0100 Subject: [PATCH 5/9] Minor improvement of I/O functions documentation --- src/base/system.h | 117 +++++++++++++++++++++++++++++++--------------- src/base/types.h | 5 ++ 2 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/base/system.h b/src/base/system.h index de2de0346c2..3245ac16169 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -219,12 +219,42 @@ bool mem_has_null(const void *block, size_t size); */ enum { + /** + * Open file for reading. + * + * @see io_open + */ IOFLAG_READ = 1, + /** + * Open file for writing. + * + * @see io_open + */ IOFLAG_WRITE = 2, + /** + * Open file for appending at the end. + * + * @see io_open + */ IOFLAG_APPEND = 4, + /** + * Start seeking from the beginning of the file. + * + * @see io_seek + */ IOSEEK_START = 0, + /** + * Start seeking from the current position. + * + * @see io_seek + */ IOSEEK_CUR = 1, + /** + * Start seeking from the end of the file. + * + * @see io_seek + */ IOSEEK_END = 2, }; @@ -236,10 +266,9 @@ enum * @param File to open. * @param flags A set of IOFLAG flags. * - * @sa IOFLAG_READ, IOFLAG_WRITE, IOFLAG_APPEND. - * - * @return A handle to the file on success and 0 on failure. + * @see IOFLAG_READ, IOFLAG_WRITE, IOFLAG_APPEND. * + * @return A handle to the file on success, or `nullptr` on failure. */ IOHANDLE io_open(const char *filename, int flags); @@ -253,7 +282,6 @@ IOHANDLE io_open(const char *filename, int flags); * @param size Number of bytes to read from the file. * * @return Number of bytes read. - * */ unsigned io_read(IOHANDLE io, void *buffer, unsigned size); @@ -279,7 +307,7 @@ void io_read_all(IOHANDLE io, void **result, unsigned *result_len); * * @param io Handle to the file to read data from. * - * @return The file's remaining contents or null on failure. + * @return The file's remaining contents, or `nullptr` on failure. * * @remark Guarantees that there are no internal null bytes. * @remark Guarantees that result will contain zero-termination. @@ -300,7 +328,7 @@ char *io_read_all_str(IOHANDLE io); int io_skip(IOHANDLE io, int size); /** - * Writes data from a buffer to file. + * Writes data from a buffer to a file. * * @ingroup File-IO * @@ -313,13 +341,13 @@ int io_skip(IOHANDLE io, int size); unsigned io_write(IOHANDLE io, const void *buffer, unsigned size); /** - * Writes a platform dependent newline to file. + * Writes a platform dependent newline to a file. * * @ingroup File-IO * * @param io Handle to the file. * - * @return true on success, false on failure. + * @return `true` on success, `false` on failure. */ bool io_write_newline(IOHANDLE io); @@ -329,10 +357,10 @@ bool io_write_newline(IOHANDLE io); * @ingroup File-IO * * @param io Handle to the file. - * @param offset Offset from pos to stop. + * @param offset Offset from position to search. * @param origin Position to start searching from. * - * @return 0 on success. + * @return `0` on success. */ int io_seek(IOHANDLE io, int offset, int origin); @@ -343,18 +371,18 @@ int io_seek(IOHANDLE io, int offset, int origin); * * @param io Handle to the file. * - * @return The current position. @c -1L if an error occurred. + * @return The current position, or `-1` on failure. */ long int io_tell(IOHANDLE io); /** - * Gets the total length of the file. Resetting cursor to the beginning + * Gets the total length of the file. Resets cursor to the beginning. * * @ingroup File-IO * * @param io Handle to the file. * - * @return The total size. @c -1L if an error occurred. + * @return The total size, or `-1` on failure. */ long int io_length(IOHANDLE io); @@ -365,7 +393,7 @@ long int io_length(IOHANDLE io); * * @param io Handle to the file. * - * @return 0 on success. + * @return `0` on success. */ int io_close(IOHANDLE io); @@ -376,7 +404,7 @@ int io_close(IOHANDLE io); * * @param io Handle to the file. * - * @return 0 on success. + * @return `0` on success. */ int io_flush(IOHANDLE io); @@ -387,7 +415,7 @@ int io_flush(IOHANDLE io); * * @param io Handle to the file. * - * @return 0 on success. + * @return `0` on success. */ int io_sync(IOHANDLE io); @@ -398,34 +426,57 @@ int io_sync(IOHANDLE io); * * @param io Handle to the file. * - * @return nonzero on error, 0 otherwise. + * @return `0` on success, or non-`0` on error. */ int io_error(IOHANDLE io); /** * @ingroup File-IO - * @return An to the standard input. + * + * Returns a handle for the standard input. + * + * @return An @link IOHANDLE @endlink for the standard input. + * + * @remark The handle must not be closed. */ IOHANDLE io_stdin(); /** * @ingroup File-IO - * @return An to the standard output. + * + * Returns a handle for the standard output. + * + * @return An @link IOHANDLE @endlink for the standard output. + * + * @remark The handle must not be closed. */ IOHANDLE io_stdout(); /** * @ingroup File-IO - * @return An to the standard error. + * + * Returns a handle for the standard error. + * + * @return An @link IOHANDLE @endlink for the standard error. + * + * @remark The handle must not be closed. */ IOHANDLE io_stderr(); /** * @ingroup File-IO - * @return An to the current executable. + * + * Returns a handle for the current executable. + * + * @return An @link IOHANDLE @endlink for the current executable. */ IOHANDLE io_current_exe(); +/** + * Wrapper for asynchronously writing to an @link IOHANDLE @endlink. + * + * @ingroup File-IO + */ typedef struct ASYNCIO ASYNCIO; /** @@ -436,12 +487,11 @@ typedef struct ASYNCIO ASYNCIO; * @param io Handle to the file. * * @return The handle for asynchronous writing. - * */ ASYNCIO *aio_new(IOHANDLE io); /** - * Locks the ASYNCIO structure so it can't be written into by + * Locks the `ASYNCIO` structure so it can't be written into by * other threads. * * @ingroup File-IO @@ -451,7 +501,7 @@ ASYNCIO *aio_new(IOHANDLE io); void aio_lock(ASYNCIO *aio); /** - * Unlocks the ASYNCIO structure after finishing the contiguous + * Unlocks the `ASYNCIO` structure after finishing the contiguous * write. * * @ingroup File-IO @@ -477,12 +527,11 @@ void aio_write(ASYNCIO *aio, const void *buffer, unsigned size); * @ingroup File-IO * * @param aio Handle to the file. - * */ void aio_write_newline(ASYNCIO *aio); /** - * Queues a chunk of data for writing. The ASYNCIO struct must be + * Queues a chunk of data for writing. The `ASYNCIO` struct must be * locked using @link aio_lock @endlink first. * * @ingroup File-IO @@ -490,18 +539,16 @@ void aio_write_newline(ASYNCIO *aio); * @param aio Handle to the file. * @param buffer Pointer to the data that should be written. * @param size Number of bytes to write. - * */ void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size); /** - * Queues a newline for writing. The ASYNCIO struct must be locked + * Queues a newline for writing. The `ASYNCIO` struct must be locked * using @link aio_lock @endlink first. * * @ingroup File-IO * * @param aio Handle to the file. - * */ void aio_write_newline_unlocked(ASYNCIO *aio); @@ -509,16 +556,15 @@ void aio_write_newline_unlocked(ASYNCIO *aio); * Checks whether errors have occurred during the asynchronous * writing. * - * Call this function regularly to see if there are errors. Call - * this function after to see if the process of writing + * Call this function regularly to see if there are errors. Call this + * function after @link aio_wait @endlink to see if the process of writing * to the file succeeded. * * @ingroup File-IO * * @param aio Handle to the file. * - * @eturn 0 if no error occurred, and nonzero on error. - * + * @return `0` on success, or non-`0` on error. */ int aio_error(ASYNCIO *aio); @@ -528,7 +574,6 @@ int aio_error(ASYNCIO *aio); * @ingroup File-IO * * @param aio Handle to the file. - * */ void aio_close(ASYNCIO *aio); @@ -538,17 +583,15 @@ void aio_close(ASYNCIO *aio); * @ingroup File-IO * * @param aio Handle to the file. - * */ void aio_wait(ASYNCIO *aio); /** - * Frees the resources associated to the asynchronous file handle. + * Frees the resources associated with the asynchronous file handle. * * @ingroup File-IO * * @param aio Handle to the file. - * */ void aio_free(ASYNCIO *aio); diff --git a/src/base/types.h b/src/base/types.h index 13abeb0e8a8..b1d5af051c2 100644 --- a/src/base/types.h +++ b/src/base/types.h @@ -10,6 +10,11 @@ enum class TRISTATE ALL, }; +/** + * Handle for input/output files/streams. + * + * @ingroup File-IO + */ typedef void *IOHANDLE; typedef int (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user); From 1021fdf7ae26f08a03be73c137c8471a4ec00eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 15 Sep 2024 15:36:57 +0200 Subject: [PATCH 6/9] Consistently order I/O functions declarations and definitions --- src/base/system.cpp | 136 ++++++++++++++++++++++---------------------- src/base/system.h | 38 ++++++------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index b244163f9d6..f42341453c5 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -84,58 +84,6 @@ #include #endif -IOHANDLE io_stdin() -{ - return stdin; -} - -IOHANDLE io_stdout() -{ - return stdout; -} - -IOHANDLE io_stderr() -{ - return stderr; -} - -IOHANDLE io_current_exe() -{ - // From https://stackoverflow.com/a/1024937. -#if defined(CONF_FAMILY_WINDOWS) - wchar_t wide_path[IO_MAX_PATH_LENGTH]; - if(GetModuleFileNameW(NULL, wide_path, std::size(wide_path)) == 0 || GetLastError() != ERROR_SUCCESS) - { - return 0; - } - const std::optional path = windows_wide_to_utf8(wide_path); - return path.has_value() ? io_open(path.value().c_str(), IOFLAG_READ) : 0; -#elif defined(CONF_PLATFORM_MACOS) - char path[IO_MAX_PATH_LENGTH]; - uint32_t path_size = sizeof(path); - if(_NSGetExecutablePath(path, &path_size)) - { - return 0; - } - return io_open(path, IOFLAG_READ); -#else - static const char *NAMES[] = { - "/proc/self/exe", // Linux, Android - "/proc/curproc/exe", // NetBSD - "/proc/curproc/file", // DragonFly - }; - for(auto &name : NAMES) - { - IOHANDLE result = io_open(name, IOFLAG_READ); - if(result) - { - return result; - } - } - return 0; -#endif -} - static NETSTATS network_stats = {0}; #define VLEN 128 @@ -403,11 +351,6 @@ long int io_length(IOHANDLE io) return length; } -int io_error(IOHANDLE io) -{ - return ferror((FILE *)io); -} - unsigned io_write(IOHANDLE io, const void *buffer, unsigned size) { return fwrite(buffer, 1, size, (FILE *)io); @@ -445,6 +388,63 @@ int io_sync(IOHANDLE io) #endif } +int io_error(IOHANDLE io) +{ + return ferror((FILE *)io); +} + +IOHANDLE io_stdin() +{ + return stdin; +} + +IOHANDLE io_stdout() +{ + return stdout; +} + +IOHANDLE io_stderr() +{ + return stderr; +} + +IOHANDLE io_current_exe() +{ + // From https://stackoverflow.com/a/1024937. +#if defined(CONF_FAMILY_WINDOWS) + wchar_t wide_path[IO_MAX_PATH_LENGTH]; + if(GetModuleFileNameW(NULL, wide_path, std::size(wide_path)) == 0 || GetLastError() != ERROR_SUCCESS) + { + return 0; + } + const std::optional path = windows_wide_to_utf8(wide_path); + return path.has_value() ? io_open(path.value().c_str(), IOFLAG_READ) : 0; +#elif defined(CONF_PLATFORM_MACOS) + char path[IO_MAX_PATH_LENGTH]; + uint32_t path_size = sizeof(path); + if(_NSGetExecutablePath(path, &path_size)) + { + return 0; + } + return io_open(path, IOFLAG_READ); +#else + static const char *NAMES[] = { + "/proc/self/exe", // Linux, Android + "/proc/curproc/exe", // NetBSD + "/proc/curproc/file", // DragonFly + }; + for(auto &name : NAMES) + { + IOHANDLE result = io_open(name, IOFLAG_READ); + if(result) + { + return result; + } + } + return 0; +#endif +} + #define ASYNC_BUFSIZE (8 * 1024) #define ASYNC_LOCAL_BUFSIZE (64 * 1024) @@ -719,17 +719,6 @@ int aio_error(ASYNCIO *aio) return aio->error; } -void aio_free(ASYNCIO *aio) -{ - aio->lock.lock(); - if(aio->thread) - { - thread_detach(aio->thread); - aio->thread = 0; - } - aio_handle_free_and_unlock(aio); -} - void aio_close(ASYNCIO *aio) { { @@ -755,6 +744,17 @@ void aio_wait(ASYNCIO *aio) thread_wait(thread); } +void aio_free(ASYNCIO *aio) +{ + aio->lock.lock(); + if(aio->thread) + { + thread_detach(aio->thread); + aio->thread = 0; + } + aio_handle_free_and_unlock(aio); +} + struct THREAD_RUN { void (*threadfunc)(void *); diff --git a/src/base/system.h b/src/base/system.h index 3245ac16169..cf75ce3092a 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -328,63 +328,63 @@ char *io_read_all_str(IOHANDLE io); int io_skip(IOHANDLE io, int size); /** - * Writes data from a buffer to a file. + * Seeks to a specified offset in the file. * * @ingroup File-IO * * @param io Handle to the file. - * @param buffer Pointer to the data that should be written. - * @param size Number of bytes to write. + * @param offset Offset from position to search. + * @param origin Position to start searching from. * - * @return Number of bytes written. + * @return `0` on success. */ -unsigned io_write(IOHANDLE io, const void *buffer, unsigned size); +int io_seek(IOHANDLE io, int offset, int origin); /** - * Writes a platform dependent newline to a file. + * Gets the current position in the file. * * @ingroup File-IO * * @param io Handle to the file. * - * @return `true` on success, `false` on failure. + * @return The current position, or `-1` on failure. */ -bool io_write_newline(IOHANDLE io); +long int io_tell(IOHANDLE io); /** - * Seeks to a specified offset in the file. + * Gets the total length of the file. Resets cursor to the beginning. * * @ingroup File-IO * * @param io Handle to the file. - * @param offset Offset from position to search. - * @param origin Position to start searching from. * - * @return `0` on success. + * @return The total size, or `-1` on failure. */ -int io_seek(IOHANDLE io, int offset, int origin); +long int io_length(IOHANDLE io); /** - * Gets the current position in the file. + * Writes data from a buffer to a file. * * @ingroup File-IO * * @param io Handle to the file. + * @param buffer Pointer to the data that should be written. + * @param size Number of bytes to write. * - * @return The current position, or `-1` on failure. + * @return Number of bytes written. */ -long int io_tell(IOHANDLE io); +unsigned io_write(IOHANDLE io, const void *buffer, unsigned size); /** - * Gets the total length of the file. Resets cursor to the beginning. + * Writes a platform dependent newline to a file. * * @ingroup File-IO * * @param io Handle to the file. * - * @return The total size, or `-1` on failure. + * @return `true` on success, `false` on failure. */ -long int io_length(IOHANDLE io); +bool io_write_newline(IOHANDLE io); /** * Closes a file. From 2646de0a7a427711e12568e9086ff301af418e80 Mon Sep 17 00:00:00 2001 From: KebsCS Date: Fri, 27 Sep 2024 01:26:42 +0200 Subject: [PATCH 7/9] Fix SpectateClosest switching to random player --- src/game/client/components/spectator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/components/spectator.cpp b/src/game/client/components/spectator.cpp index f180022236d..1e29fccacb6 100644 --- a/src/game/client/components/spectator.cpp +++ b/src/game/client/components/spectator.cpp @@ -135,7 +135,7 @@ void CSpectator::ConSpectateClosest(IConsole::IResult *pResult, void *pUserData) int ClosestDistance = std::numeric_limits::max(); for(int i = 0; i < MAX_CLIENTS; i++) { - if(i == SpectatorId || !Snap.m_apPlayerInfos[i] || Snap.m_apPlayerInfos[i]->m_Team == TEAM_SPECTATORS || (SpectatorId == SPEC_FREEVIEW && i == Snap.m_LocalClientId)) + if(i == SpectatorId || !Snap.m_aCharacters[i].m_Active || !Snap.m_apPlayerInfos[i] || Snap.m_apPlayerInfos[i]->m_Team == TEAM_SPECTATORS || (SpectatorId == SPEC_FREEVIEW && i == Snap.m_LocalClientId)) continue; const CNetObj_Character &MaybeClosestCharacter = Snap.m_aCharacters[i].m_Cur; int Distance = distance(CurPosition, vec2(MaybeClosestCharacter.m_X, MaybeClosestCharacter.m_Y)); From f2ec87d4e0ef3f376e470f6357ee3d3ef9bce987 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 27 Sep 2024 11:16:34 +0800 Subject: [PATCH 8/9] Remove unused m_ClientId from score worker --- src/game/server/score.cpp | 1 - src/game/server/scoreworker.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/game/server/score.cpp b/src/game/server/score.cpp index ee7c2116761..222f0416ce7 100644 --- a/src/game/server/score.cpp +++ b/src/game/server/score.cpp @@ -373,7 +373,6 @@ void CScore::LoadTeam(const char *pCode, int ClientId) auto Tmp = std::make_unique(SaveResult); str_copy(Tmp->m_aCode, pCode, sizeof(Tmp->m_aCode)); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); - Tmp->m_ClientId = ClientId; str_copy(Tmp->m_aRequestingPlayer, Server()->ClientName(ClientId), sizeof(Tmp->m_aRequestingPlayer)); Tmp->m_NumPlayer = 0; for(int i = 0; i < MAX_CLIENTS; i++) diff --git a/src/game/server/scoreworker.h b/src/game/server/scoreworker.h index 9e38501e54c..4cbf26d36b8 100644 --- a/src/game/server/scoreworker.h +++ b/src/game/server/scoreworker.h @@ -214,7 +214,6 @@ struct CSqlTeamLoad : ISqlData char m_aCode[128]; char m_aMap[MAX_MAP_LENGTH]; char m_aRequestingPlayer[MAX_NAME_LENGTH]; - int m_ClientId; // struct holding all player names in the team or an empty string char m_aClientNames[MAX_CLIENTS][MAX_NAME_LENGTH]; int m_aClientId[MAX_CLIENTS]; From 82af70554242c2c7acf09045fd812612fb9e0bc2 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 27 Sep 2024 11:41:39 +0800 Subject: [PATCH 9/9] Cleanup sql worker request/result naming convention There are two interfaces for score worker data: There is ``ISqlResult`` and every class inheriting from it should have the suffix ``Result`` Then there is ``ISqlData`` and every class inheriting from it should have the suffix ``Data`` if it is data that should be written in an INSERT statement. Or ``Request`` if it is used to perform a read operation and will be used in a SELECT statament. The convention was mostly established alreay. In this commit the last three classes that broke this convention got fixed. --- src/game/server/score.cpp | 6 +++--- src/game/server/scoreworker.cpp | 6 +++--- src/game/server/scoreworker.h | 16 ++++++++-------- src/test/score.cpp | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/game/server/score.cpp b/src/game/server/score.cpp index ee7c2116761..6c4454c3fa0 100644 --- a/src/game/server/score.cpp +++ b/src/game/server/score.cpp @@ -112,7 +112,7 @@ void CScore::LoadBestTime() auto LoadBestTimeResult = std::make_shared(); m_pGameServer->m_pController->m_pLoadBestTimeResult = LoadBestTimeResult; - auto Tmp = std::make_unique(LoadBestTimeResult); + auto Tmp = std::make_unique(LoadBestTimeResult); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); m_pPool->Execute(CScoreWorker::LoadBestTime, std::move(Tmp), "load best time"); } @@ -308,7 +308,7 @@ void CScore::SaveTeam(int ClientId, const char *pCode, const char *pServer) return; pController->Teams().SetSaving(Team, SaveResult); - auto Tmp = std::make_unique(SaveResult); + auto Tmp = std::make_unique(SaveResult); str_copy(Tmp->m_aCode, pCode, sizeof(Tmp->m_aCode)); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); str_copy(Tmp->m_aServer, pServer, sizeof(Tmp->m_aServer)); @@ -370,7 +370,7 @@ void CScore::LoadTeam(const char *pCode, int ClientId) auto SaveResult = std::make_shared(ClientId); SaveResult->m_Status = CScoreSaveResult::LOAD_FAILED; pController->Teams().SetSaving(Team, SaveResult); - auto Tmp = std::make_unique(SaveResult); + auto Tmp = std::make_unique(SaveResult); str_copy(Tmp->m_aCode, pCode, sizeof(Tmp->m_aCode)); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); Tmp->m_ClientId = ClientId; diff --git a/src/game/server/scoreworker.cpp b/src/game/server/scoreworker.cpp index aa2b14314df..76d85f5a56d 100644 --- a/src/game/server/scoreworker.cpp +++ b/src/game/server/scoreworker.cpp @@ -101,7 +101,7 @@ bool CTeamrank::SamePlayers(const std::vector *pvSortedNames) bool CScoreWorker::LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize) { - const auto *pData = dynamic_cast(pGameData); + const auto *pData = dynamic_cast(pGameData); auto *pResult = dynamic_cast(pGameData->m_pResult.get()); char aBuf[512]; @@ -1568,7 +1568,7 @@ bool CScoreWorker::RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData bool CScoreWorker::SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize) { - const auto *pData = dynamic_cast(pGameData); + const auto *pData = dynamic_cast(pGameData); auto *pResult = dynamic_cast(pGameData->m_pResult.get()); if(w == Write::NORMAL_SUCCEEDED) @@ -1715,7 +1715,7 @@ bool CScoreWorker::LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData { if(w == Write::NORMAL_SUCCEEDED || w == Write::BACKUP_FIRST) return false; - const auto *pData = dynamic_cast(pGameData); + const auto *pData = dynamic_cast(pGameData); auto *pResult = dynamic_cast(pGameData->m_pResult.get()); pResult->m_Status = CScoreSaveResult::LOAD_FAILED; diff --git a/src/game/server/scoreworker.h b/src/game/server/scoreworker.h index 9e38501e54c..ae641fe2a32 100644 --- a/src/game/server/scoreworker.h +++ b/src/game/server/scoreworker.h @@ -72,9 +72,9 @@ struct CScoreLoadBestTimeResult : ISqlResult float m_CurrentRecord; }; -struct CSqlLoadBestTimeData : ISqlData +struct CSqlLoadBestTimeRequest : ISqlData { - CSqlLoadBestTimeData(std::shared_ptr pResult) : + CSqlLoadBestTimeRequest(std::shared_ptr pResult) : ISqlData(std::move(pResult)) { } @@ -188,13 +188,13 @@ struct CSqlTeamScoreData : ISqlData CUuid m_TeamrankUuid; }; -struct CSqlTeamSave : ISqlData +struct CSqlTeamSaveData : ISqlData { - CSqlTeamSave(std::shared_ptr pResult) : + CSqlTeamSaveData(std::shared_ptr pResult) : ISqlData(std::move(pResult)) { } - virtual ~CSqlTeamSave(){}; + virtual ~CSqlTeamSaveData(){}; char m_aClientName[MAX_NAME_LENGTH]; char m_aMap[MAX_MAP_LENGTH]; @@ -203,13 +203,13 @@ struct CSqlTeamSave : ISqlData char m_aServer[5]; }; -struct CSqlTeamLoad : ISqlData +struct CSqlTeamLoadRequest : ISqlData { - CSqlTeamLoad(std::shared_ptr pResult) : + CSqlTeamLoadRequest(std::shared_ptr pResult) : ISqlData(std::move(pResult)) { } - virtual ~CSqlTeamLoad(){}; + virtual ~CSqlTeamLoadRequest(){}; char m_aCode[128]; char m_aMap[MAX_MAP_LENGTH]; diff --git a/src/test/score.cpp b/src/test/score.cpp index c9c9e190ec9..4bd3dcdec6d 100644 --- a/src/test/score.cpp +++ b/src/test/score.cpp @@ -70,9 +70,9 @@ struct Score : public testing::TestWithParam void LoadBestTime() { - CSqlLoadBestTimeData loadBestTimeData(std::make_shared()); - str_copy(loadBestTimeData.m_aMap, "Kobra 3", sizeof(loadBestTimeData.m_aMap)); - ASSERT_FALSE(CScoreWorker::LoadBestTime(m_pConn, &loadBestTimeData, m_aError, sizeof(m_aError))) << m_aError; + CSqlLoadBestTimeRequest loadBestTimeReq(std::make_shared()); + str_copy(loadBestTimeReq.m_aMap, "Kobra 3", sizeof(loadBestTimeReq.m_aMap)); + ASSERT_FALSE(CScoreWorker::LoadBestTime(m_pConn, &loadBestTimeReq, m_aError, sizeof(m_aError))) << m_aError; } void InsertMap()