From 39be28a99703ffa302f5f8029c558b301947b8ef Mon Sep 17 00:00:00 2001 From: _Redstone_c_ <2824517378@qq.com> Date: Sun, 3 Jan 2021 17:28:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20FKCPWrap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 Log 乱码 允许直接获取 KCPCB 添加 DebugName 区分不同 KCP 对象 --- Source/ThirdParty/KCP/Private/KCPWrap.cpp | 27 +++++++++++++++++++++-- Source/ThirdParty/KCP/Public/KCPWrap.h | 12 +++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Source/ThirdParty/KCP/Private/KCPWrap.cpp b/Source/ThirdParty/KCP/Private/KCPWrap.cpp index 2b7d74f..520b236 100644 --- a/Source/ThirdParty/KCP/Private/KCPWrap.cpp +++ b/Source/ThirdParty/KCP/Private/KCPWrap.cpp @@ -13,22 +13,35 @@ namespace FKCPFuncWrap void Writelog(const char* log, ikcpcb* kcp, void* user) { - UE_LOG(LogKCP, Log, TEXT("[%i]: %s"), kcp->conv, log); + FKCPWrap* KCPWrap = (FKCPWrap*)user; + UE_LOG(LogKCP, Log, TEXT("%s: %s"), *KCPWrap->GetDebugName(), ANSI_TO_TCHAR(log)); } } FKCPWrap::FKCPWrap(uint32 Conv) + : KCPPtr(ikcp_create(Conv, this)) + , DebugName(FString::Printf(TEXT("[%i]"), Conv)) { - KCPPtr = ikcp_create(Conv, this); KCPPtr->output = &FKCPFuncWrap::Output; KCPPtr->writelog = &FKCPFuncWrap::Writelog; } +FKCPWrap::FKCPWrap(uint32 Conv, const FString & InDebugName) + : FKCPWrap(Conv) +{ + DebugName = InDebugName; +} + FKCPWrap::~FKCPWrap() { ikcp_release(KCPPtr); } +ikcpcb & FKCPWrap::GetKCPCB() +{ + return *KCPPtr; +} + int FKCPWrap::Recv(uint8 * Data, int32 Count) { return ikcp_recv(KCPPtr, (char*)Data, Count); @@ -93,3 +106,13 @@ int FKCPWrap::SetTurboMode() { return SetNoDelay(1, 10, 2, 1); } + +void FKCPWrap::SetDebugName(const FString & InDebugName) +{ + DebugName = InDebugName; +} + +const FString & FKCPWrap::GetDebugName() const +{ + return DebugName; +} diff --git a/Source/ThirdParty/KCP/Public/KCPWrap.h b/Source/ThirdParty/KCP/Public/KCPWrap.h index 9f0e5c9..30d92fb 100644 --- a/Source/ThirdParty/KCP/Public/KCPWrap.h +++ b/Source/ThirdParty/KCP/Public/KCPWrap.h @@ -9,8 +9,12 @@ public: FKCPWrap(uint32 Conv); + FKCPWrap(uint32 Conv, const FString& InDebugName); + ~FKCPWrap(); + ikcpcb& GetKCPCB(); + int Recv(uint8* Data, int32 Count); int Send(const uint8* Data, int32 Count); @@ -37,10 +41,16 @@ public: int SetTurboMode(); - TFunction OutputFunc; + TFunction OutputFunc; + + void SetDebugName(const FString& InDebugName); + + const FString& GetDebugName() const; private: ikcpcb* KCPPtr; + FString DebugName; + };