From 6924a36c7c09719f0773f2e0477e91ee8013a849 Mon Sep 17 00:00:00 2001 From: DragonAura Date: Wed, 26 Apr 2023 18:54:19 +0800 Subject: [PATCH] fix(CAPI): :bug: add read message buffer --- CAPI/cpp/API/include/Communication.h | 1 + CAPI/cpp/API/include/logic.h | 6 +++--- CAPI/cpp/API/src/Communication.cpp | 3 ++- CAPI/cpp/API/src/logic.cpp | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index 2f75e43..7df447b 100644 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -52,6 +52,7 @@ private: std::unique_ptr THUAI6Stub; bool haveNewMessage = false; protobuf::MessageToClient message2Client; + protobuf::MessageToClient buffer2Client; std::mutex mtxMessage; std::condition_variable cvMessage; }; diff --git a/CAPI/cpp/API/include/logic.h b/CAPI/cpp/API/include/logic.h index 8eef2fc..5ca41ea 100644 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -148,9 +148,9 @@ private: void ProcessMessage(); // 将信息加载到buffer - void LoadBufferSelf(protobuf::MessageToClient message); - void LoadBufferCase(protobuf::MessageOfObj item); - void LoadBuffer(protobuf::MessageToClient message); + void LoadBufferSelf(const protobuf::MessageToClient& message); + void LoadBufferCase(const protobuf::MessageOfObj& item); + void LoadBuffer(const protobuf::MessageToClient& message); // 解锁AI线程 void UnBlockAI(); diff --git a/CAPI/cpp/API/src/Communication.cpp b/CAPI/cpp/API/src/Communication.cpp index 6bcf8d8..a4ccd3c 100644 --- a/CAPI/cpp/API/src/Communication.cpp +++ b/CAPI/cpp/API/src/Communication.cpp @@ -249,10 +249,11 @@ void Communication::AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, T grpc::ClientContext context; auto MessageReader = THUAI6Stub->AddPlayer(&context, playerMsg); - while (MessageReader->Read(&message2Client)) + while (MessageReader->Read(&buffer2Client)) { { std::lock_guard lock(mtxMessage); + message2Client = buffer2Client; haveNewMessage = true; } cvMessage.notify_one(); diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 51a6d73..c06eb09 100644 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -398,7 +398,7 @@ void Logic::ProcessMessage() std::thread(messageThread).detach(); } -void Logic::LoadBufferSelf(protobuf::MessageToClient message) +void Logic::LoadBufferSelf(const protobuf::MessageToClient& message) { if (playerType == THUAI6::PlayerType::StudentPlayer) { @@ -432,7 +432,7 @@ void Logic::LoadBufferSelf(protobuf::MessageToClient message) } } -void Logic::LoadBufferCase(protobuf::MessageOfObj item) +void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) { int32_t x, y, viewRange; if (playerType == THUAI6::PlayerType::StudentPlayer) @@ -593,7 +593,7 @@ void Logic::LoadBufferCase(protobuf::MessageOfObj item) } } -void Logic::LoadBuffer(protobuf::MessageToClient message) +void Logic::LoadBuffer(const protobuf::MessageToClient& message) { // 将消息读入到buffer中 {