Browse Source

fix(CAPI): 🐛 add read message buffer

tags/0.1.0
DragonAura 2 years ago
parent
commit
6924a36c7c
4 changed files with 9 additions and 7 deletions
  1. +1
    -0
      CAPI/cpp/API/include/Communication.h
  2. +3
    -3
      CAPI/cpp/API/include/logic.h
  3. +2
    -1
      CAPI/cpp/API/src/Communication.cpp
  4. +3
    -3
      CAPI/cpp/API/src/logic.cpp

+ 1
- 0
CAPI/cpp/API/include/Communication.h View File

@@ -52,6 +52,7 @@ private:
std::unique_ptr<protobuf::AvailableService::Stub> THUAI6Stub;
bool haveNewMessage = false;
protobuf::MessageToClient message2Client;
protobuf::MessageToClient buffer2Client;
std::mutex mtxMessage;
std::condition_variable cvMessage;
};


+ 3
- 3
CAPI/cpp/API/include/logic.h View File

@@ -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();


+ 2
- 1
CAPI/cpp/API/src/Communication.cpp View File

@@ -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<std::mutex> lock(mtxMessage);
message2Client = buffer2Client;
haveNewMessage = true;
}
cvMessage.notify_one();


+ 3
- 3
CAPI/cpp/API/src/logic.cpp View File

@@ -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中
{


Loading…
Cancel
Save