| @@ -63,6 +63,8 @@ public: | |||
| virtual bool CarryHuman() = 0; | |||
| virtual bool ReleaseHuman() = 0; | |||
| virtual bool HangHuman() = 0; | |||
| virtual const std::vector<int64_t> GetPlayerGUIDs() const = 0; | |||
| }; | |||
| class IAPI | |||
| @@ -171,11 +173,9 @@ public: | |||
| } | |||
| void Play(IAI& ai) override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| [[nodiscard]] int GetFrameCount() const override; | |||
| [[nodiscard]] int GetFrameCount() const override | |||
| { | |||
| } | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override; | |||
| @@ -190,9 +190,7 @@ public: | |||
| [[nodiscard]] std::future<bool> HaveMessage() override; | |||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override; | |||
| std::future<bool> Wait() override | |||
| { | |||
| } | |||
| std::future<bool> Wait() override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override; | |||
| @@ -230,12 +228,9 @@ public: | |||
| } | |||
| void Play(IAI& ai) override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| [[nodiscard]] int GetFrameCount() const override | |||
| { | |||
| } | |||
| [[nodiscard]] int GetFrameCount() const override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override; | |||
| @@ -249,9 +244,7 @@ public: | |||
| [[nodiscard]] std::future<bool> HaveMessage() override; | |||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override; | |||
| std::future<bool> Wait() override | |||
| { | |||
| } | |||
| std::future<bool> Wait() override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override; | |||
| @@ -280,20 +273,13 @@ public: | |||
| logic(logic) | |||
| { | |||
| } | |||
| void StartTimer() override | |||
| { | |||
| } | |||
| void EndTimer() override | |||
| { | |||
| } | |||
| void StartTimer() override; | |||
| void EndTimer() override; | |||
| void Play(IAI& ai) override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| [[nodiscard]] int GetFrameCount() const override | |||
| { | |||
| } | |||
| [[nodiscard]] int GetFrameCount() const override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override; | |||
| @@ -307,9 +293,7 @@ public: | |||
| [[nodiscard]] std::future<bool> HaveMessage() override; | |||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override; | |||
| std::future<bool> Wait() override | |||
| { | |||
| } | |||
| std::future<bool> Wait() override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override; | |||
| @@ -329,6 +313,7 @@ public: | |||
| [[nodiscard]] virtual std::shared_ptr<const THUAI6::Human> GetSelfInfo() const override; | |||
| private: | |||
| std::chrono::system_clock::time_point StartPoint; | |||
| ILogic& logic; | |||
| }; | |||
| @@ -339,20 +324,13 @@ public: | |||
| logic(logic) | |||
| { | |||
| } | |||
| void StartTimer() override | |||
| { | |||
| } | |||
| void EndTimer() override | |||
| { | |||
| } | |||
| void StartTimer() override; | |||
| void EndTimer() override; | |||
| void Play(IAI& ai) override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| [[nodiscard]] int GetFrameCount() const override | |||
| { | |||
| } | |||
| [[nodiscard]] int GetFrameCount() const override; | |||
| std::future<bool> Move(int64_t timeInMilliseconds, double angleInRadian) override; | |||
| std::future<bool> MoveRight(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveUp(int64_t timeInMilliseconds) override; | |||
| std::future<bool> MoveLeft(int64_t timeInMilliseconds) override; | |||
| @@ -366,9 +344,7 @@ public: | |||
| [[nodiscard]] std::future<bool> HaveMessage() override; | |||
| [[nodiscard]] std::future<std::pair<int64_t, std::string>> GetMessage() override; | |||
| std::future<bool> Wait() override | |||
| { | |||
| } | |||
| std::future<bool> Wait() override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Human>> GetHuman() const override; | |||
| [[nodiscard]] std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButcher() const override; | |||
| @@ -387,6 +363,7 @@ public: | |||
| [[nodiscard]] std::shared_ptr<const THUAI6::Butcher> GetSelfInfo() const override; | |||
| private: | |||
| std::chrono::system_clock::time_point StartPoint; | |||
| ILogic& logic; | |||
| }; | |||
| @@ -43,10 +43,6 @@ private: | |||
| // GUID信息 | |||
| std::vector<int64_t> playerGUIDs; | |||
| // THUAI5中的通信组件可以完全被我们的stub取代,故无须再写 | |||
| std::unique_ptr<IAI> pAI; | |||
| std::unique_ptr<IGameTimer> timer; | |||
| std::thread tAI; // 用于运行AI的线程 | |||
| @@ -70,6 +66,8 @@ private: | |||
| int counterState = 0; | |||
| int counterBuffer = 0; | |||
| THUAI6::GameState gameState = THUAI6::GameState::NullGameState; | |||
| // 是否应该执行player() | |||
| std::atomic_bool AILoop = true; | |||
| @@ -84,8 +82,6 @@ private: | |||
| // 提供给API使用的函数 | |||
| // 获取服务器发来的消息 | |||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> GetButchers() const override; | |||
| std::vector<std::shared_ptr<const THUAI6::Human>> GetHumans() const override; | |||
| std::vector<std::shared_ptr<const THUAI6::Prop>> GetProps() const override; | |||
| @@ -121,6 +117,8 @@ private: | |||
| int GetCounter() const override; | |||
| const std::vector<int64_t> GetPlayerGUIDs() const override; | |||
| bool TryConnection(); | |||
| // THUAI5中的一系列用于处理信息的函数可能也不会再用 | |||
| @@ -8,6 +8,15 @@ | |||
| namespace THUAI6 | |||
| { | |||
| // 游戏状态 | |||
| enum class GameState : unsigned char | |||
| { | |||
| NullGameState = 0, | |||
| GameStart = 1, | |||
| GameRunning = 2, | |||
| GameEnd = 3, | |||
| }; | |||
| // 所有NullXXXType均为错误类型,其余为可能出现的正常类型 | |||
| // 位置标志 | |||
| @@ -85,6 +85,13 @@ namespace Proto2THUAI6 | |||
| {protobuf::HumanState::DEAD, THUAI6::HumanState::Dead}, | |||
| }; | |||
| inline std::map<protobuf::GameState, THUAI6::GameState> gameStateDict{ | |||
| {protobuf::GameState::NULL_GAME_STATE, THUAI6::GameState::NullGameState}, | |||
| {protobuf::GameState::GAME_START, THUAI6::GameState::GameStart}, | |||
| {protobuf::GameState::GAME_RUNNING, THUAI6::GameState::GameRunning}, | |||
| {protobuf::GameState::GAME_END, THUAI6::GameState::GameEnd}, | |||
| }; | |||
| // 用于将Protobuf中的类转换为THUAI6的类 | |||
| inline std::shared_ptr<THUAI6::Butcher> Protobuf2THUAI6Butcher(const protobuf::MessageOfButcher& butcherMsg) | |||
| { | |||
| @@ -2,6 +2,16 @@ | |||
| #include "API.h" | |||
| #define PI 3.14159265358979323846 | |||
| int HumanAPI::GetFrameCount() const | |||
| { | |||
| return logic.GetCounter(); | |||
| } | |||
| int ButcherAPI::GetFrameCount() const | |||
| { | |||
| return logic.GetCounter(); | |||
| } | |||
| std::future<bool> HumanAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | |||
| { | |||
| return std::async(std::launch::async, [&]() | |||
| @@ -126,6 +136,26 @@ std::future<std::pair<int64_t, std::string>> ButcherAPI::GetMessage() | |||
| { return logic.GetMessage(); }); | |||
| } | |||
| std::future<bool> HumanAPI::Wait() | |||
| { | |||
| if (logic.GetCounter() == -1) | |||
| return std::async(std::launch::async, [&]() | |||
| { return false; }); | |||
| else | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.WaitThread(); }); | |||
| } | |||
| std::future<bool> ButcherAPI::Wait() | |||
| { | |||
| if (logic.GetCounter() == -1) | |||
| return std::async(std::launch::async, [&]() | |||
| { return false; }); | |||
| else | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.WaitThread(); }); | |||
| } | |||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanAPI::GetButcher() const | |||
| { | |||
| return logic.GetButchers(); | |||
| @@ -178,36 +208,36 @@ std::vector<std::vector<THUAI6::PlaceType>> ButcherAPI::GetFullMap() const | |||
| const std::vector<int64_t> HumanAPI::GetPlayerGUIDs() const | |||
| { | |||
| // todo | |||
| return logic.GetPlayerGUIDs(); | |||
| } | |||
| const std::vector<int64_t> ButcherAPI::GetPlayerGUIDs() const | |||
| { | |||
| // todo | |||
| return logic.GetPlayerGUIDs(); | |||
| } | |||
| std::future<bool> HumanAPI::StartFixMachine() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.StartFixMachine(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.StartFixMachine(); }); | |||
| } | |||
| std::future<bool> HumanAPI::EndFixMachine() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.EndFixMachine(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.EndFixMachine(); }); | |||
| } | |||
| std::future<bool> HumanAPI::StartSaveHuman() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.StartSaveHuman(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.StartSaveHuman(); }); | |||
| } | |||
| std::future<bool> HumanAPI::EndSaveHuman() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.EndSaveHuman(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.EndSaveHuman(); }); | |||
| } | |||
| std::future<bool> HumanAPI::Escape() | |||
| @@ -2,6 +2,36 @@ | |||
| #include "API.h" | |||
| #define PI 3.14159265358979323846 | |||
| void HumanDebugAPI::StartTimer() | |||
| { | |||
| StartPoint = std::chrono::system_clock::now(); | |||
| std::time_t t = std::chrono::system_clock::to_time_t(StartPoint); | |||
| } | |||
| void ButcherDebugAPI::StartTimer() | |||
| { | |||
| StartPoint = std::chrono::system_clock::now(); | |||
| std::time_t t = std::chrono::system_clock::to_time_t(StartPoint); | |||
| } | |||
| void HumanDebugAPI::EndTimer() | |||
| { | |||
| } | |||
| void ButcherDebugAPI::EndTimer() | |||
| { | |||
| } | |||
| int HumanDebugAPI::GetFrameCount() const | |||
| { | |||
| return logic.GetCounter(); | |||
| } | |||
| int ButcherDebugAPI::GetFrameCount() const | |||
| { | |||
| return logic.GetCounter(); | |||
| } | |||
| std::future<bool> HumanDebugAPI::Move(int64_t timeInMilliseconds, double angleInRadian) | |||
| { | |||
| return std::async(std::launch::async, [&]() | |||
| @@ -126,6 +156,26 @@ std::future<std::pair<int64_t, std::string>> ButcherDebugAPI::GetMessage() | |||
| { return logic.GetMessage(); }); | |||
| } | |||
| std::future<bool> HumanDebugAPI::Wait() | |||
| { | |||
| if (logic.GetCounter() == -1) | |||
| return std::async(std::launch::async, [&]() | |||
| { return false; }); | |||
| else | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.WaitThread(); }); | |||
| } | |||
| std::future<bool> ButcherDebugAPI::Wait() | |||
| { | |||
| if (logic.GetCounter() == -1) | |||
| return std::async(std::launch::async, [&]() | |||
| { return false; }); | |||
| else | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.WaitThread(); }); | |||
| } | |||
| std::vector<std::shared_ptr<const THUAI6::Butcher>> HumanDebugAPI::GetButcher() const | |||
| { | |||
| return logic.GetButchers(); | |||
| @@ -178,36 +228,36 @@ std::vector<std::vector<THUAI6::PlaceType>> ButcherDebugAPI::GetFullMap() const | |||
| const std::vector<int64_t> HumanDebugAPI::GetPlayerGUIDs() const | |||
| { | |||
| // todo | |||
| return logic.GetPlayerGUIDs(); | |||
| } | |||
| const std::vector<int64_t> ButcherDebugAPI::GetPlayerGUIDs() const | |||
| { | |||
| // todo | |||
| return logic.GetPlayerGUIDs(); | |||
| } | |||
| std::future<bool> HumanDebugAPI::StartFixMachine() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.StartFixMachine(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.StartFixMachine(); }); | |||
| } | |||
| std::future<bool> HumanDebugAPI::EndFixMachine() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.EndFixMachine(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.EndFixMachine(); }); | |||
| } | |||
| std::future<bool> HumanDebugAPI::StartSaveHuman() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.StartSaveHuman(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.StartSaveHuman(); }); | |||
| } | |||
| std::future<bool> HumanDebugAPI::EndSaveHuman() | |||
| { | |||
| std::async(std::launch::async, [&]() | |||
| { return logic.EndSaveHuman(); }); | |||
| return std::async(std::launch::async, [&]() | |||
| { return logic.EndSaveHuman(); }); | |||
| } | |||
| std::future<bool> HumanDebugAPI::Escape() | |||
| @@ -158,13 +158,58 @@ void Logic::ProcessMessage() | |||
| { | |||
| std::cout << "Join Player!" << std::endl; | |||
| pComm->AddPlayer(playerID, playerType, humanType, butcherType); | |||
| while (true) | |||
| while (gameState != THUAI6::GameState::GameEnd) | |||
| { | |||
| if (pComm->HaveMessage2Client()) | |||
| { | |||
| std::cout << "Get Message!" << std::endl; | |||
| auto clientMsg = pComm->GetMessage2Client(); | |||
| LoadBuffer(clientMsg); | |||
| gameState = Proto2THUAI6::gameStateDict[clientMsg.game_state()]; | |||
| switch (gameState) | |||
| { | |||
| case THUAI6::GameState::GameStart: | |||
| std::cout << "Game Start!" << std::endl; | |||
| // 重新读取玩家的guid,guid确保人类在前屠夫在后 | |||
| playerGUIDs.clear(); | |||
| for (auto human : clientMsg.human_message()) | |||
| playerGUIDs.push_back(human.guid()); | |||
| for (auto butcher : clientMsg.butcher_message()) | |||
| playerGUIDs.push_back(butcher.guid()); | |||
| currentState->guids = playerGUIDs; | |||
| bufferState->guids = playerGUIDs; | |||
| LoadBuffer(clientMsg); | |||
| AILoop = true; | |||
| UnBlockAI(); | |||
| break; | |||
| case THUAI6::GameState::GameRunning: | |||
| // 重新读取玩家的guid,guid确保人类在前屠夫在后 | |||
| playerGUIDs.clear(); | |||
| for (auto human : clientMsg.human_message()) | |||
| playerGUIDs.push_back(human.guid()); | |||
| for (auto butcher : clientMsg.butcher_message()) | |||
| playerGUIDs.push_back(butcher.guid()); | |||
| currentState->guids = playerGUIDs; | |||
| bufferState->guids = playerGUIDs; | |||
| LoadBuffer(clientMsg); | |||
| break; | |||
| case THUAI6::GameState::GameEnd: | |||
| AILoop = false; | |||
| { | |||
| std::lock_guard<std::mutex> lock(mtxBuffer); | |||
| bufferUpdated = true; | |||
| counterBuffer = -1; | |||
| } | |||
| cvBuffer.notify_one(); | |||
| std::cout << "Game End!" << std::endl; | |||
| break; | |||
| default: | |||
| std::cerr << "Invalid GameState!" << std::endl; | |||
| } | |||
| } | |||
| } | |||
| }; | |||
| @@ -443,6 +488,12 @@ int Logic::GetCounter() const | |||
| return counterState; | |||
| } | |||
| const std::vector<int64_t> Logic::GetPlayerGUIDs() const | |||
| { | |||
| std::unique_lock<std::mutex> lock(mtxState); | |||
| return currentState->guids; | |||
| } | |||
| bool Logic::TryConnection() | |||
| { | |||
| std::cout << "Trying to connect to server..." << std::endl; | |||
| @@ -452,9 +503,6 @@ bool Logic::TryConnection() | |||
| void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port) | |||
| { | |||
| // 构造AI | |||
| pAI = createAI(); | |||
| // 建立与服务器之间通信的组件 | |||
| pComm = std::make_unique<Communication>(IP, port); | |||
| @@ -472,15 +520,24 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port) | |||
| cvAI.wait(lock, [this]() | |||
| { return AIStart; }); | |||
| } | |||
| std::cout << "AI Start!" << std::endl; | |||
| auto ai = createAI(); | |||
| ProcessMessage(); | |||
| while (AILoop) | |||
| { | |||
| Update(); | |||
| timer->StartTimer(); | |||
| timer->Play(*ai); | |||
| timer->EndTimer(); | |||
| if (asynchronous) | |||
| { | |||
| Wait(); | |||
| timer->StartTimer(); | |||
| timer->Play(*ai); | |||
| timer->EndTimer(); | |||
| } | |||
| else | |||
| { | |||
| Update(); | |||
| timer->StartTimer(); | |||
| timer->Play(*ai); | |||
| timer->EndTimer(); | |||
| } | |||
| } | |||
| }; | |||
| @@ -493,8 +550,8 @@ void Logic::Main(CreateAIFunc createAI, std::string IP, std::string port) | |||
| if (tAI.joinable()) | |||
| { | |||
| std::cout << "Join the AI thread." << std::endl; | |||
| AIStart = true; | |||
| cvAI.notify_one(); | |||
| // 首先开启处理消息的线程 | |||
| ProcessMessage(); | |||
| tAI.join(); | |||
| } | |||
| } | |||
| @@ -158,7 +158,7 @@ namespace protobuf | |||
| ::_pbi::ConstantInitialized | |||
| ) : | |||
| _impl_{ | |||
| /*decltype(_impl_.human_message_)*/ {}, /*decltype(_impl_.butcher_message_)*/ {}, /*decltype(_impl_.prop_message_)*/ {}, /*decltype(_impl_.map_message_)*/ nullptr, /*decltype(_impl_._cached_size_)*/ {}} | |||
| /*decltype(_impl_.human_message_)*/ {}, /*decltype(_impl_.butcher_message_)*/ {}, /*decltype(_impl_.prop_message_)*/ {}, /*decltype(_impl_.map_message_)*/ nullptr, /*decltype(_impl_.game_state_)*/ 0, /*decltype(_impl_._cached_size_)*/ {}} | |||
| { | |||
| } | |||
| struct MessageToClientDefaultTypeInternal | |||
| @@ -340,6 +340,7 @@ const uint32_t TableStruct_Message2Clients_2eproto::offsets[] PROTOBUF_SECTION_V | |||
| PROTOBUF_FIELD_OFFSET(::protobuf::MessageToClient, _impl_.butcher_message_), | |||
| PROTOBUF_FIELD_OFFSET(::protobuf::MessageToClient, _impl_.prop_message_), | |||
| PROTOBUF_FIELD_OFFSET(::protobuf::MessageToClient, _impl_.map_message_), | |||
| PROTOBUF_FIELD_OFFSET(::protobuf::MessageToClient, _impl_.game_state_), | |||
| ~0u, // no _has_bits_ | |||
| PROTOBUF_FIELD_OFFSET(::protobuf::MoveRes, _internal_metadata_), | |||
| ~0u, // no _extensions_ | |||
| @@ -374,9 +375,9 @@ static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protode | |||
| {68, -1, -1, sizeof(::protobuf::MessageOfMap_Row)}, | |||
| {75, -1, -1, sizeof(::protobuf::MessageOfMap)}, | |||
| {82, -1, -1, sizeof(::protobuf::MessageToClient)}, | |||
| {92, -1, -1, sizeof(::protobuf::MoveRes)}, | |||
| {101, -1, -1, sizeof(::protobuf::BoolRes)}, | |||
| {108, -1, -1, sizeof(::protobuf::MsgRes)}, | |||
| {93, -1, -1, sizeof(::protobuf::MoveRes)}, | |||
| {102, -1, -1, sizeof(::protobuf::BoolRes)}, | |||
| {109, -1, -1, sizeof(::protobuf::MsgRes)}, | |||
| }; | |||
| static const ::_pb::Message* const file_default_instances[] = { | |||
| @@ -423,18 +424,19 @@ const char descriptor_table_protodef_Message2Clients_2eproto[] PROTOBUF_SECTION_ | |||
| "\t\n\001y\030\003 \001(\005\022\030\n\020facing_direction\030\004 \001(\001\022\022\n\n" | |||
| "mapping_id\030\005 \001(\003\"`\n\014MessageOfMap\022\'\n\003row\030" | |||
| "\002 \003(\0132\032.protobuf.MessageOfMap.Row\032\'\n\003Row" | |||
| "\022 \n\003col\030\001 \003(\0162\023.protobuf.PlaceType\"\323\001\n\017M" | |||
| "\022 \n\003col\030\001 \003(\0162\023.protobuf.PlaceType\"\374\001\n\017M" | |||
| "essageToClient\022/\n\rhuman_message\030\001 \003(\0132\030." | |||
| "protobuf.MessageOfHuman\0223\n\017butcher_messa" | |||
| "ge\030\002 \003(\0132\032.protobuf.MessageOfButcher\022-\n\014" | |||
| "prop_message\030\003 \003(\0132\027.protobuf.MessageOfP" | |||
| "rop\022+\n\013map_message\030\004 \001(\0132\026.protobuf.Mess" | |||
| "ageOfMap\"J\n\007MoveRes\022\024\n\014actual_speed\030\001 \001(" | |||
| "\003\022\024\n\014actual_angle\030\002 \001(\001\022\023\n\013act_success\030\003" | |||
| " \001(\010\"\036\n\007BoolRes\022\023\n\013act_success\030\001 \001(\010\"P\n\006" | |||
| "MsgRes\022\024\n\014have_message\030\001 \001(\010\022\026\n\016from_pla" | |||
| "yer_id\030\002 \001(\003\022\030\n\020message_received\030\003 \001(\tb\006" | |||
| "proto3"; | |||
| "ageOfMap\022\'\n\ngame_state\030\005 \001(\0162\023.protobuf." | |||
| "GameState\"J\n\007MoveRes\022\024\n\014actual_speed\030\001 \001" | |||
| "(\003\022\024\n\014actual_angle\030\002 \001(\001\022\023\n\013act_success\030" | |||
| "\003 \001(\010\"\036\n\007BoolRes\022\023\n\013act_success\030\001 \001(\010\"P\n" | |||
| "\006MsgRes\022\024\n\014have_message\030\001 \001(\010\022\026\n\016from_pl" | |||
| "ayer_id\030\002 \001(\003\022\030\n\020message_received\030\003 \001(\tb" | |||
| "\006proto3"; | |||
| static const ::_pbi::DescriptorTable* const descriptor_table_Message2Clients_2eproto_deps[1] = { | |||
| &::descriptor_table_MessageType_2eproto, | |||
| }; | |||
| @@ -442,7 +444,7 @@ static ::_pbi::once_flag descriptor_table_Message2Clients_2eproto_once; | |||
| const ::_pbi::DescriptorTable descriptor_table_Message2Clients_2eproto = { | |||
| false, | |||
| false, | |||
| 1646, | |||
| 1687, | |||
| descriptor_table_protodef_Message2Clients_2eproto, | |||
| "Message2Clients.proto", | |||
| &descriptor_table_Message2Clients_2eproto_once, | |||
| @@ -3044,13 +3046,14 @@ namespace protobuf | |||
| MessageToClient* const _this = this; | |||
| (void)_this; | |||
| new (&_impl_) Impl_{ | |||
| decltype(_impl_.human_message_){from._impl_.human_message_}, decltype(_impl_.butcher_message_){from._impl_.butcher_message_}, decltype(_impl_.prop_message_){from._impl_.prop_message_}, decltype(_impl_.map_message_){nullptr}, /*decltype(_impl_._cached_size_)*/ {}}; | |||
| decltype(_impl_.human_message_){from._impl_.human_message_}, decltype(_impl_.butcher_message_){from._impl_.butcher_message_}, decltype(_impl_.prop_message_){from._impl_.prop_message_}, decltype(_impl_.map_message_){nullptr}, decltype(_impl_.game_state_){}, /*decltype(_impl_._cached_size_)*/ {}}; | |||
| _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); | |||
| if (from._internal_has_map_message()) | |||
| { | |||
| _this->_impl_.map_message_ = new ::protobuf::MessageOfMap(*from._impl_.map_message_); | |||
| } | |||
| _this->_impl_.game_state_ = from._impl_.game_state_; | |||
| // @@protoc_insertion_point(copy_constructor:protobuf.MessageToClient) | |||
| } | |||
| @@ -3061,7 +3064,7 @@ namespace protobuf | |||
| (void)arena; | |||
| (void)is_message_owned; | |||
| new (&_impl_) Impl_{ | |||
| decltype(_impl_.human_message_){arena}, decltype(_impl_.butcher_message_){arena}, decltype(_impl_.prop_message_){arena}, decltype(_impl_.map_message_){nullptr}, /*decltype(_impl_._cached_size_)*/ {}}; | |||
| decltype(_impl_.human_message_){arena}, decltype(_impl_.butcher_message_){arena}, decltype(_impl_.prop_message_){arena}, decltype(_impl_.map_message_){nullptr}, decltype(_impl_.game_state_){0}, /*decltype(_impl_._cached_size_)*/ {}}; | |||
| } | |||
| MessageToClient::~MessageToClient() | |||
| @@ -3105,6 +3108,7 @@ namespace protobuf | |||
| delete _impl_.map_message_; | |||
| } | |||
| _impl_.map_message_ = nullptr; | |||
| _impl_.game_state_ = 0; | |||
| _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); | |||
| } | |||
| @@ -3180,6 +3184,17 @@ namespace protobuf | |||
| else | |||
| goto handle_unusual; | |||
| continue; | |||
| // .protobuf.GameState game_state = 5; | |||
| case 5: | |||
| if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 40)) | |||
| { | |||
| uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); | |||
| CHK_(ptr); | |||
| _internal_set_game_state(static_cast<::protobuf::GameState>(val)); | |||
| } | |||
| else | |||
| goto handle_unusual; | |||
| continue; | |||
| default: | |||
| goto handle_unusual; | |||
| } // switch | |||
| @@ -3254,6 +3269,15 @@ namespace protobuf | |||
| InternalWriteMessage(4, _Internal::map_message(this), _Internal::map_message(this).GetCachedSize(), target, stream); | |||
| } | |||
| // .protobuf.GameState game_state = 5; | |||
| if (this->_internal_game_state() != 0) | |||
| { | |||
| target = stream->EnsureSpace(target); | |||
| target = ::_pbi::WireFormatLite::WriteEnumToArray( | |||
| 5, this->_internal_game_state(), target | |||
| ); | |||
| } | |||
| if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) | |||
| { | |||
| target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( | |||
| @@ -3306,6 +3330,13 @@ namespace protobuf | |||
| ); | |||
| } | |||
| // .protobuf.GameState game_state = 5; | |||
| if (this->_internal_game_state() != 0) | |||
| { | |||
| total_size += 1 + | |||
| ::_pbi::WireFormatLite::EnumSize(this->_internal_game_state()); | |||
| } | |||
| return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); | |||
| } | |||
| @@ -3335,6 +3366,10 @@ namespace protobuf | |||
| from._internal_map_message() | |||
| ); | |||
| } | |||
| if (from._internal_game_state() != 0) | |||
| { | |||
| _this->_internal_set_game_state(from._internal_game_state()); | |||
| } | |||
| _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); | |||
| } | |||
| @@ -3359,7 +3394,11 @@ namespace protobuf | |||
| _impl_.human_message_.InternalSwap(&other->_impl_.human_message_); | |||
| _impl_.butcher_message_.InternalSwap(&other->_impl_.butcher_message_); | |||
| _impl_.prop_message_.InternalSwap(&other->_impl_.prop_message_); | |||
| swap(_impl_.map_message_, other->_impl_.map_message_); | |||
| ::PROTOBUF_NAMESPACE_ID::internal::memswap< | |||
| PROTOBUF_FIELD_OFFSET(MessageToClient, _impl_.game_state_) + sizeof(MessageToClient::_impl_.game_state_) - PROTOBUF_FIELD_OFFSET(MessageToClient, _impl_.map_message_)>( | |||
| reinterpret_cast<char*>(&_impl_.map_message_), | |||
| reinterpret_cast<char*>(&other->_impl_.map_message_) | |||
| ); | |||
| } | |||
| ::PROTOBUF_NAMESPACE_ID::Metadata MessageToClient::GetMetadata() const | |||
| @@ -1951,6 +1951,7 @@ namespace protobuf | |||
| kButcherMessageFieldNumber = 2, | |||
| kPropMessageFieldNumber = 3, | |||
| kMapMessageFieldNumber = 4, | |||
| kGameStateFieldNumber = 5, | |||
| }; | |||
| // repeated .protobuf.MessageOfHuman human_message = 1; | |||
| int human_message_size() const; | |||
| @@ -2041,6 +2042,16 @@ namespace protobuf | |||
| ); | |||
| ::protobuf::MessageOfMap* unsafe_arena_release_map_message(); | |||
| // .protobuf.GameState game_state = 5; | |||
| void clear_game_state(); | |||
| ::protobuf::GameState game_state() const; | |||
| void set_game_state(::protobuf::GameState value); | |||
| private: | |||
| ::protobuf::GameState _internal_game_state() const; | |||
| void _internal_set_game_state(::protobuf::GameState value); | |||
| public: | |||
| // @@protoc_insertion_point(class_scope:protobuf.MessageToClient) | |||
| private: | |||
| @@ -2056,6 +2067,7 @@ namespace protobuf | |||
| ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<::protobuf::MessageOfButcher> butcher_message_; | |||
| ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<::protobuf::MessageOfProp> prop_message_; | |||
| ::protobuf::MessageOfMap* map_message_; | |||
| int game_state_; | |||
| mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; | |||
| }; | |||
| union | |||
| @@ -4208,6 +4220,30 @@ namespace protobuf | |||
| // @@protoc_insertion_point(field_set_allocated:protobuf.MessageToClient.map_message) | |||
| } | |||
| // .protobuf.GameState game_state = 5; | |||
| inline void MessageToClient::clear_game_state() | |||
| { | |||
| _impl_.game_state_ = 0; | |||
| } | |||
| inline ::protobuf::GameState MessageToClient::_internal_game_state() const | |||
| { | |||
| return static_cast<::protobuf::GameState>(_impl_.game_state_); | |||
| } | |||
| inline ::protobuf::GameState MessageToClient::game_state() const | |||
| { | |||
| // @@protoc_insertion_point(field_get:protobuf.MessageToClient.game_state) | |||
| return _internal_game_state(); | |||
| } | |||
| inline void MessageToClient::_internal_set_game_state(::protobuf::GameState value) | |||
| { | |||
| _impl_.game_state_ = value; | |||
| } | |||
| inline void MessageToClient::set_game_state(::protobuf::GameState value) | |||
| { | |||
| _internal_set_game_state(value); | |||
| // @@protoc_insertion_point(field_set:protobuf.MessageToClient.game_state) | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // MoveRes | |||
| @@ -23,7 +23,7 @@ namespace _pbi = _pb::internal; | |||
| namespace protobuf | |||
| { | |||
| } // namespace protobuf | |||
| static const ::_pb::EnumDescriptor* file_level_enum_descriptors_MessageType_2eproto[9]; | |||
| static const ::_pb::EnumDescriptor* file_level_enum_descriptors_MessageType_2eproto[10]; | |||
| static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_MessageType_2eproto = nullptr; | |||
| const uint32_t TableStruct_MessageType_2eproto::offsets[1] = {}; | |||
| static constexpr ::_pbi::MigrationSchema* schemas = nullptr; | |||
| @@ -51,12 +51,14 @@ const char descriptor_table_protodef_MessageType_2eproto[] PROTOBUF_SECTION_VARI | |||
| "\020\003\022\016\n\nHUMANTYPE4\020\004*l\n\013ButcherType\022\025\n\021NUL" | |||
| "L_BUTCHER_TYPE\020\000\022\020\n\014BUTCHERTYPE1\020\001\022\020\n\014BU" | |||
| "TCHERTYPE2\020\002\022\020\n\014BUTCHERTYPE3\020\003\022\020\n\014BUTCHE" | |||
| "RTYPE4\020\004b\006proto3"; | |||
| "RTYPE4\020\004*P\n\tGameState\022\023\n\017NULL_GAME_STATE" | |||
| "\020\000\022\016\n\nGAME_START\020\001\022\020\n\014GAME_RUNNING\020\002\022\014\n\010" | |||
| "GAME_END\020\003b\006proto3"; | |||
| static ::_pbi::once_flag descriptor_table_MessageType_2eproto_once; | |||
| const ::_pbi::DescriptorTable descriptor_table_MessageType_2eproto = { | |||
| false, | |||
| false, | |||
| 856, | |||
| 938, | |||
| descriptor_table_protodef_MessageType_2eproto, | |||
| "MessageType.proto", | |||
| &descriptor_table_MessageType_2eproto_once, | |||
| @@ -258,6 +260,25 @@ namespace protobuf | |||
| } | |||
| } | |||
| const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* GameState_descriptor() | |||
| { | |||
| ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_MessageType_2eproto); | |||
| return file_level_enum_descriptors_MessageType_2eproto[9]; | |||
| } | |||
| bool GameState_IsValid(int value) | |||
| { | |||
| switch (value) | |||
| { | |||
| case 0: | |||
| case 1: | |||
| case 2: | |||
| case 3: | |||
| return true; | |||
| default: | |||
| return false; | |||
| } | |||
| } | |||
| // @@protoc_insertion_point(namespace_scope) | |||
| } // namespace protobuf | |||
| PROTOBUF_NAMESPACE_OPEN | |||
| @@ -337,6 +337,37 @@ namespace protobuf | |||
| ButcherType_descriptor(), name, value | |||
| ); | |||
| } | |||
| enum GameState : int | |||
| { | |||
| NULL_GAME_STATE = 0, | |||
| GAME_START = 1, | |||
| GAME_RUNNING = 2, | |||
| GAME_END = 3, | |||
| GameState_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::min(), | |||
| GameState_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::max() | |||
| }; | |||
| bool GameState_IsValid(int value); | |||
| constexpr GameState GameState_MIN = NULL_GAME_STATE; | |||
| constexpr GameState GameState_MAX = GAME_END; | |||
| constexpr int GameState_ARRAYSIZE = GameState_MAX + 1; | |||
| const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* GameState_descriptor(); | |||
| template<typename T> | |||
| inline const std::string& GameState_Name(T enum_t_value) | |||
| { | |||
| static_assert(::std::is_same<T, GameState>::value || ::std::is_integral<T>::value, "Incorrect type passed to function GameState_Name."); | |||
| return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( | |||
| GameState_descriptor(), enum_t_value | |||
| ); | |||
| } | |||
| inline bool GameState_Parse( | |||
| ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, GameState* value | |||
| ) | |||
| { | |||
| return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<GameState>( | |||
| GameState_descriptor(), name, value | |||
| ); | |||
| } | |||
| // =================================================================== | |||
| // =================================================================== | |||
| @@ -438,6 +469,15 @@ inline const EnumDescriptor* GetEnumDescriptor<::protobuf::ButcherType>() | |||
| { | |||
| return ::protobuf::ButcherType_descriptor(); | |||
| } | |||
| template<> | |||
| struct is_proto_enum<::protobuf::GameState> : ::std::true_type | |||
| { | |||
| }; | |||
| template<> | |||
| inline const EnumDescriptor* GetEnumDescriptor<::protobuf::GameState>() | |||
| { | |||
| return ::protobuf::GameState_descriptor(); | |||
| } | |||
| PROTOBUF_NAMESPACE_CLOSE | |||
| @@ -79,6 +79,7 @@ message MessageToClient | |||
| repeated MessageOfButcher butcher_message = 2; // 是否真正repeated待定 | |||
| repeated MessageOfProp prop_message = 3; | |||
| MessageOfMap map_message = 4; | |||
| GameState game_state = 5; | |||
| } | |||
| message MoveRes // 如果打算设计撞墙保留平行速度分量,且需要返回值则可用这个(大概没啥用) | |||
| @@ -89,32 +89,11 @@ enum ButcherType | |||
| BUTCHERTYPE4 = 4; | |||
| } | |||
| // 取消了大包之后,MessageType的枚举是否有必要保留还有待商榷 | |||
| // enum MessageType | |||
| // { | |||
| // // 公共信息类型 | |||
| // Move = 0; | |||
| // PickProp = 1; | |||
| // UseProp = 2; | |||
| // UseSkill = 3; | |||
| // Map = 4; | |||
| // Send = 5; | |||
| // // 人类限定信息类型 | |||
| // FixMachine = 6; | |||
| // SaveHuman = 7; | |||
| // // 屠夫限定信息类型 | |||
| // Attack = 8; | |||
| // CarryHuman = 9; | |||
| // ReleaseHuman = 10; | |||
| // HangHuman = 11; | |||
| // // 游戏相关信息类型 | |||
| // AddPlayer = 12; | |||
| // InvalidPlayer = 13; | |||
| // ValidPlayer = 14; | |||
| // StartGame = 15; | |||
| // Gaming = 16; | |||
| // EndGame = 17; | |||
| // } | |||
| // 游戏进行状态 | |||
| enum GameState | |||
| { | |||
| NULL_GAME_STATE = 0; | |||
| GAME_START = 1; | |||
| GAME_RUNNING = 2; | |||
| GAME_END = 3; | |||
| } | |||
| @@ -18,7 +18,7 @@ | |||
| <PackageReference Include="Google.Protobuf.Tools" Version="3.21.9" /> | |||
| <PackageReference Include="Grpc" Version="2.46.5" /> | |||
| <PackageReference Include="Grpc.Core" Version="2.46.5" /> | |||
| <PackageReference Include="Grpc.Tools" Version="2.50.0"> | |||
| <PackageReference Include="Grpc.Tools" Version="2.51.0"> | |||
| <PrivateAssets>all</PrivateAssets> | |||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |||
| </PackageReference> | |||
| @@ -7,7 +7,7 @@ | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="FrameRateTask" Version="1.1.2" /> | |||
| <PackageReference Include="FrameRateTask" Version="1.2.0" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| @@ -8,11 +8,11 @@ | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="FrameRateTask" Version="1.1.2" /> | |||
| <PackageReference Include="FrameRateTask" Version="1.2.0" /> | |||
| <PackageReference Include="Google.Protobuf" Version="3.21.9" /> | |||
| <PackageReference Include="Grpc" Version="2.46.5" /> | |||
| <PackageReference Include="Grpc.Core" Version="2.46.5" /> | |||
| <PackageReference Include="Grpc.Tools" Version="2.50.0"> | |||
| <PackageReference Include="Grpc.Tools" Version="2.51.0"> | |||
| <PrivateAssets>all</PrivateAssets> | |||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |||
| </PackageReference> | |||