From 6ffc421cbee50d831b82ca79d5602f9e8825e6a0 Mon Sep 17 00:00:00 2001 From: DragonAura Date: Fri, 21 Apr 2023 22:16:16 +0800 Subject: [PATCH 1/6] fix(CAPI): :bug: fix wrong print format --- CAPI/cpp/API/src/DebugAPI.cpp | 16 ++++++++-------- CAPI/python/PyAPI/DebugAPI.py | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index fdb9a5d..8aa3165 100644 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -645,7 +645,7 @@ void StudentDebugAPI::PrintStudent() const { for (const auto& student : logic.GetStudents()) { - logger->info("\n******Student Info******"); + logger->info("******Student Info******"); logger->info("playerID={}, GUID={}, x={}, y={}", student->playerID, student->guid, student->x, student->y); logger->info("speed={}, view range={}, place={}, radius={}", student->speed, student->viewRange, THUAI6::placeTypeDict[student->place], student->radius); std::string skillTime = ""; @@ -670,7 +670,7 @@ void TrickerDebugAPI::PrintStudent() const { for (const auto& student : logic.GetStudents()) { - logger->info("\n******Student Info******"); + logger->info("******Student Info******"); logger->info("playerID={}, GUID={}, x={}, y={}", student->playerID, student->guid, student->x, student->y); logger->info("speed={}, view range={}, place={}, radius={}", student->speed, student->viewRange, THUAI6::placeTypeDict[student->place], student->radius); std::string skillTime = ""; @@ -695,7 +695,7 @@ void StudentDebugAPI::PrintTricker() const { for (const auto& tricker : logic.GetTrickers()) { - logger->info("\n******Tricker Info******"); + logger->info("******Tricker Info******"); logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y); logger->info("speed={}, view range={}, place={}, radius={}", tricker->speed, tricker->viewRange, THUAI6::placeTypeDict[tricker->place], tricker->radius); std::string skillTime = ""; @@ -719,7 +719,7 @@ void TrickerDebugAPI::PrintTricker() const { for (auto tricker : logic.GetTrickers()) { - logger->info("\n******Tricker Info******"); + logger->info("******Tricker Info******"); logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y); logger->info("speed={}, view range={}, place={}, radius={}", tricker->speed, tricker->viewRange, THUAI6::placeTypeDict[tricker->place], tricker->radius); std::string skillTime = ""; @@ -743,7 +743,7 @@ void StudentDebugAPI::PrintProp() const { for (auto prop : logic.GetProps()) { - logger->info("\n******Prop Info******"); + logger->info("******Prop Info******"); logger->info("GUID={}, x={}, y={}, place={}, facing direction={}", prop->guid, prop->x, prop->y, THUAI6::placeTypeDict[prop->place], prop->facingDirection); logger->info("*********************\n"); } @@ -753,7 +753,7 @@ void TrickerDebugAPI::PrintProp() const { for (auto prop : logic.GetProps()) { - logger->info("\n******Prop Info******"); + logger->info("******Prop Info******"); logger->info("GUID={}, x={}, y={}, place={}, facing direction={}", prop->guid, prop->x, prop->y, THUAI6::placeTypeDict[prop->place], prop->facingDirection); logger->info("*********************\n"); } @@ -762,7 +762,7 @@ void TrickerDebugAPI::PrintProp() const void StudentDebugAPI::PrintSelfInfo() const { auto student = logic.StudentGetSelfInfo(); - logger->info("\n******Self Info******"); + logger->info("******Self Info******"); logger->info("playerID={}, GUID={}, x={}, y={}", student->playerID, student->guid, student->x, student->y); logger->info("speed={}, view range={}, place={}, radius={}", student->speed, student->viewRange, THUAI6::placeTypeDict[student->place], student->radius); std::string skillTime = ""; @@ -785,7 +785,7 @@ void StudentDebugAPI::PrintSelfInfo() const void TrickerDebugAPI::PrintSelfInfo() const { auto tricker = logic.TrickerGetSelfInfo(); - logger->info("\n******Self Info******"); + logger->info("******Self Info******"); logger->info("playerID={}, GUID={}, x={}, y={}", tricker->playerID, tricker->guid, tricker->x, tricker->y); logger->info("speed={}, view range={}, place={}, radius={}", tricker->speed, tricker->viewRange, THUAI6::placeTypeDict[tricker->place], tricker->radius); std::string skillTime = ""; diff --git a/CAPI/python/PyAPI/DebugAPI.py b/CAPI/python/PyAPI/DebugAPI.py index 17deaa7..a784026 100644 --- a/CAPI/python/PyAPI/DebugAPI.py +++ b/CAPI/python/PyAPI/DebugAPI.py @@ -311,7 +311,7 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): def PrintStudent(self) -> None: for student in self.__logic.GetStudents(): - self.__logger.info("\n******Student Info******") + self.__logger.info("******Student Info******") self.__logger.info( f"playerID={student.playerID}, GUID={student.guid}, x={student.x}, y={student.y}") self.__logger.info( @@ -335,7 +335,7 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): def PrintTricker(self) -> None: for tricker in self.__logic.GetTrickers(): - self.__logger.info("\n******Tricker Info******") + self.__logger.info("******Tricker Info******") self.__logger.info( f"playerID={tricker.playerID}, GUID={tricker.guid}, x={tricker.x}, y={tricker.y}") self.__logger.info( @@ -364,7 +364,7 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): def PrintSelfInfo(self) -> None: student = cast(THUAI6.Student, self.__logic.GetSelfInfo()) - self.__logger.info("\n******Student Info******") + self.__logger.info("******Student Info******") self.__logger.info( f"playerID={student.playerID}, GUID={student.guid}, x={student.x}, y={student.y}") self.__logger.info( @@ -763,7 +763,7 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer): def PrintStudent(self) -> None: for student in self.__logic.GetStudents(): - self.__logger.info("\n******Student Info******") + self.__logger.info("******Student Info******") self.__logger.info( f"playerID={student.playerID}, GUID={student.guid}, x={student.x}, y={student.y}") self.__logger.info( @@ -787,7 +787,7 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer): def PrintTricker(self) -> None: for tricker in self.__logic.GetTrickers(): - self.__logger.info("\n******Tricker Info******") + self.__logger.info("******Tricker Info******") self.__logger.info( f"playerID={tricker.playerID}, GUID={tricker.guid}, x={tricker.x}, y={tricker.y}") self.__logger.info( @@ -816,7 +816,7 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer): def PrintSelfInfo(self) -> None: tricker = cast(THUAI6.Tricker, self.__logic.GetSelfInfo()) - self.__logger.info("\n******Tricker Info******") + self.__logger.info("******Tricker Info******") self.__logger.info( f"playerID={tricker.playerID}, GUID={tricker.guid}, x={tricker.x}, y={tricker.y}") self.__logger.info( From 2dbe6c9308007f198d3eff4c9c9000d4c4f3765e Mon Sep 17 00:00:00 2001 From: DragonAura Date: Sat, 22 Apr 2023 00:59:06 +0800 Subject: [PATCH 2/6] fix(CAPI): :bug: fix missing lock --- CAPI/cpp/API/src/logic.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 40c5b24..bea812c 100644 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -436,14 +436,14 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) switch (Proto2THUAI6::messageOfObjDict[item.message_of_obj_case()]) { case THUAI6::MessageOfObj::PropMessage: - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.prop_message().x(), item.prop_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.prop_message().x(), item.prop_message().y(), bufferState->gameMap)) { bufferState->props.push_back(Proto2THUAI6::Protobuf2THUAI6Prop(item.prop_message())); logger->debug("Add Prop!"); } break; case THUAI6::MessageOfObj::BulletMessage: - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.prop_message().x(), item.prop_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.prop_message().x(), item.prop_message().y(), bufferState->gameMap)) { bufferState->bullets.push_back(Proto2THUAI6::Protobuf2THUAI6Bullet(item.bullet_message())); logger->debug("Add Bullet!"); @@ -451,7 +451,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) break; case THUAI6::MessageOfObj::ClassroomMessage: { - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.classroom_message().x(), item.classroom_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.classroom_message().x(), item.classroom_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.classroom_message().x()), AssistFunction::GridToCell(item.classroom_message().y())); if (bufferState->mapInfo->classRoomState.count(pos) == 0) @@ -469,7 +469,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::ChestMessage: { - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.chest_message().x(), item.chest_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.chest_message().x(), item.chest_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.chest_message().x()), AssistFunction::GridToCell(item.chest_message().y())); if (bufferState->mapInfo->chestState.count(pos) == 0) @@ -487,7 +487,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::DoorMessage: { - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.door_message().x(), item.door_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.door_message().x(), item.door_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.door_message().x()), AssistFunction::GridToCell(item.door_message().y())); if (bufferState->mapInfo->doorState.count(pos) == 0) @@ -507,7 +507,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::HiddenGateMessage: { - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.hidden_gate_message().x(), item.hidden_gate_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.hidden_gate_message().x(), item.hidden_gate_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.hidden_gate_message().x()), AssistFunction::GridToCell(item.hidden_gate_message().y())); if (bufferState->mapInfo->hiddenGateState.count(pos) == 0) @@ -525,7 +525,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::GateMessage: { - if (!AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.gate_message().x(), item.gate_message().y(), currentState->gameMap)) + if (!AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.gate_message().x(), item.gate_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.gate_message().x()), AssistFunction::GridToCell(item.gate_message().y())); if (bufferState->mapInfo->gateState.count(pos) == 0) @@ -591,7 +591,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) switch (Proto2THUAI6::messageOfObjDict[item.message_of_obj_case()]) { case THUAI6::MessageOfObj::PropMessage: - if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.prop_message().x(), item.prop_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.prop_message().x(), item.prop_message().y(), bufferState->gameMap)) { bufferState->props.push_back(Proto2THUAI6::Protobuf2THUAI6Prop(item.prop_message())); logger->debug("Add Prop!"); @@ -606,7 +606,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) break; case THUAI6::MessageOfObj::ClassroomMessage: { - if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.classroom_message().x(), item.classroom_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.classroom_message().x(), item.classroom_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.classroom_message().x()), AssistFunction::GridToCell(item.classroom_message().y())); if (bufferState->mapInfo->classRoomState.count(pos) == 0) @@ -624,7 +624,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::ChestMessage: { - if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.chest_message().x(), item.chest_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.chest_message().x(), item.chest_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.chest_message().x()), AssistFunction::GridToCell(item.chest_message().y())); if (bufferState->mapInfo->chestState.count(pos) == 0) @@ -642,7 +642,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::DoorMessage: { - if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.door_message().x(), item.door_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.door_message().x(), item.door_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.door_message().x()), AssistFunction::GridToCell(item.door_message().y())); if (bufferState->mapInfo->doorState.count(pos) == 0) @@ -662,7 +662,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::HiddenGateMessage: { - if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.hidden_gate_message().x(), item.hidden_gate_message().y(), currentState->gameMap)) + if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.hidden_gate_message().x(), item.hidden_gate_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.hidden_gate_message().x()), AssistFunction::GridToCell(item.hidden_gate_message().y())); if (bufferState->mapInfo->hiddenGateState.count(pos) == 0) @@ -680,7 +680,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } case THUAI6::MessageOfObj::GateMessage: { - if (!AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.gate_message().x(), item.gate_message().y(), currentState->gameMap)) + if (!AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.gate_message().x(), item.gate_message().y(), bufferState->gameMap)) { auto pos = std::make_pair(AssistFunction::GridToCell(item.gate_message().x()), AssistFunction::GridToCell(item.gate_message().y())); if (bufferState->mapInfo->gateState.count(pos) == 0) @@ -760,10 +760,13 @@ void Logic::Update() noexcept // 缓冲区被更新之后才可以使用 cvBuffer.wait(lock, [this]() { return bufferUpdated; }); - - std::swap(currentState, bufferState); + { + std::lock_guard stateLock(mtxState); + std::swap(currentState, bufferState); + counterState = counterBuffer; + } bufferUpdated = false; - counterState = counterBuffer; + logger->info("Update State!"); } } From 5e6dbe7e76236c139083465013c065eea4bcda00 Mon Sep 17 00:00:00 2001 From: DragonAura Date: Sat, 22 Apr 2023 01:08:09 +0800 Subject: [PATCH 3/6] fix(CAPI): :bug: fix assign and py lock missing --- CAPI/cpp/API/src/logic.cpp | 12 ++++-------- CAPI/python/PyAPI/logic.py | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index bea812c..41aa142 100644 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -27,8 +27,7 @@ Logic::Logic(THUAI6::PlayerType type, int64_t ID, THUAI6::TrickerType tricker, T std::vector> Logic::GetTrickers() const { std::lock_guard lock(mtxState); - std::vector> temp; - temp.assign(currentState->trickers.begin(), currentState->trickers.end()); + std::vector> temp(currentState->trickers.begin(), currentState->trickers.end()); logger->debug("Called GetTrickers"); return temp; } @@ -36,8 +35,7 @@ std::vector> Logic::GetTrickers() const std::vector> Logic::GetStudents() const { std::unique_lock lock(mtxState); - std::vector> temp; - temp.assign(currentState->students.begin(), currentState->students.end()); + std::vector> temp(currentState->students.begin(), currentState->students.end()); logger->debug("Called GetStudents"); return temp; } @@ -45,8 +43,7 @@ std::vector> Logic::GetStudents() const std::vector> Logic::GetProps() const { std::unique_lock lock(mtxState); - std::vector> temp; - temp.assign(currentState->props.begin(), currentState->props.end()); + std::vector> temp(currentState->props.begin(), currentState->props.end()); logger->debug("Called GetProps"); return temp; } @@ -54,8 +51,7 @@ std::vector> Logic::GetProps() const std::vector> Logic::GetBullets() const { std::unique_lock lock(mtxState); - std::vector> temp; - temp.assign(currentState->bullets.begin(), currentState->bullets.end()); + std::vector> temp(currentState->bullets.begin(), currentState->bullets.end()); logger->debug("Called GetBullets"); return temp; } diff --git a/CAPI/python/PyAPI/logic.py b/CAPI/python/PyAPI/logic.py index c258f6d..9e81b1e 100644 --- a/CAPI/python/PyAPI/logic.py +++ b/CAPI/python/PyAPI/logic.py @@ -552,9 +552,10 @@ class Logic(ILogic): if not Setting.asynchronous(): with self.__cvBuffer: self.__cvBuffer.wait_for(lambda: self.__bufferUpdated) - self.__bufferState, self.__currentState = self.__currentState, self.__bufferState + with self.__mtxState: + self.__bufferState, self.__currentState = self.__currentState, self.__bufferState + self.__counterState = self.__counterBuffer self.__bufferUpdated = False - self.__counterState = self.__counterBuffer self.__logger.info("Update state!") def __Wait(self) -> None: From 478649d022327837933a0582b4bbe1d01e7cdf75 Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Sat, 22 Apr 2023 01:47:26 +0800 Subject: [PATCH 4/6] =?UTF-8?q?docs:=20:memo:=20edit=20CAPI=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/CAPI接口(cpp).md | 2 +- docs/CAPI接口(python).md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CAPI接口(cpp).md b/docs/CAPI接口(cpp).md index d855b7c..01fc608 100644 --- a/docs/CAPI接口(cpp).md +++ b/docs/CAPI接口(cpp).md @@ -45,7 +45,7 @@ - `std::pair GetMessage()`:按照消息发送顺序获取来自队友的信息,第一个参数为发送该消息的PlayerID。 #### 查询可视范围内的信息 - - `std::vector> GetStudents() const` :返回所有可视学生的信息。 + - `std::vector> GetStudents() const` :对于学生,返回所有学生的信息;对于捣蛋鬼,返回可视学生的信息。 - `std::vector> GetTrickers() const` :返回所有可视捣蛋鬼的信息。 - `std::vector> GetProps() const` :返回所有可视道具的信息。 - `std::vector> GetBullets() const` :返回所有可视子弹(攻击)的信息。 diff --git a/docs/CAPI接口(python).md b/docs/CAPI接口(python).md index 1f3315b..d121660 100644 --- a/docs/CAPI接口(python).md +++ b/docs/CAPI接口(python).md @@ -57,7 +57,7 @@ #### 查询可视范围内的信息 - - `std::vector> GetStudents() const` :返回所有可视学生的信息。 + - `std::vector> GetStudents() const` :对于学生,返回所有学生的信息;对于捣蛋鬼,返回可视学生的信息。 - `std::vector> GetTrickers() const` :返回所有可视捣蛋鬼的信息。 - `std::vector> GetProps() const` :返回所有可视道具的信息。 - `std::vector> GetBullets() const` :返回所有可视子弹(攻击)的信息。 From f900c96ce44f83ed1d26de90761daef5751e642c Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Sat, 22 Apr 2023 18:15:34 +0800 Subject: [PATCH 5/6] refactor: :zap: Try to fix the problem about Moving --- logic/GameEngine/CollisionChecker.cs | 15 +++++---------- logic/Preparation/Utility/XY.cs | 6 +++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/logic/GameEngine/CollisionChecker.cs b/logic/GameEngine/CollisionChecker.cs index c147c20..179ce30 100644 --- a/logic/GameEngine/CollisionChecker.cs +++ b/logic/GameEngine/CollisionChecker.cs @@ -123,12 +123,9 @@ namespace GameEngine /// 最大可能的移动距离 public double FindMax(IMoveable obj, XY nextPos, XY moveVec) { - double maxLen = (double)uint.MaxValue; - double tmpMax = maxLen; // 暂存最大值 + double tmpMax = uint.MaxValue; // 暂存最大值 - // 先找只考虑墙的最大距离 - // double maxOnlyConsiderWall = FindMaxOnlyConsiderWall(obj, moveVec); - double maxDistance = maxLen; + double maxDistance = uint.MaxValue; foreach (var listWithLock in lists) { var lst = listWithLock.Item1; @@ -159,13 +156,13 @@ namespace GameEngine { double tmp = mod - obj.Radius - listObj.Radius; // 计算能走的最长距离,好像这么算有一点误差? - tmp = tmp / Math.Cos(Math.Atan2(orgDeltaY, orgDeltaX) - moveVec.Angle()); - if (tmp < 0 || tmp > uint.MaxValue || tmp == double.NaN) + tmp = ((int)(tmp*1000 / Math.Cos(Math.Atan2(orgDeltaY, orgDeltaX) - moveVec.Angle()))); + if (tmp < 0 || tmp > uint.MaxValue || double.IsNaN(tmp)) { tmpMax = uint.MaxValue; } else - tmpMax = tmp; + tmpMax = tmp/1000.0; } break; } @@ -207,11 +204,9 @@ namespace GameEngine } finally { - // maxLen = Math.Min(maxOnlyConsiderWall, maxDistance); //最大可能距离的最小值 listLock.ExitReadLock(); } } - // return maxLen; return maxDistance; } diff --git a/logic/Preparation/Utility/XY.cs b/logic/Preparation/Utility/XY.cs index 6749526..9b70661 100644 --- a/logic/Preparation/Utility/XY.cs +++ b/logic/Preparation/Utility/XY.cs @@ -64,7 +64,11 @@ namespace Preparation.Utility } public static double Distance(XY p1, XY p2) { - return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y))); + long c = (((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)))*1000000; + long t = c/2+1; + while (t*t>c||(t+1)*(t+1) Date: Sat, 22 Apr 2023 18:20:59 +0800 Subject: [PATCH 6/6] style: :art: Format --- logic/GameEngine/CollisionChecker.cs | 4 ++-- logic/Preparation/Utility/XY.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/logic/GameEngine/CollisionChecker.cs b/logic/GameEngine/CollisionChecker.cs index 179ce30..0d1d3ea 100644 --- a/logic/GameEngine/CollisionChecker.cs +++ b/logic/GameEngine/CollisionChecker.cs @@ -156,13 +156,13 @@ namespace GameEngine { double tmp = mod - obj.Radius - listObj.Radius; // 计算能走的最长距离,好像这么算有一点误差? - tmp = ((int)(tmp*1000 / Math.Cos(Math.Atan2(orgDeltaY, orgDeltaX) - moveVec.Angle()))); + tmp = ((int)(tmp * 1000 / Math.Cos(Math.Atan2(orgDeltaY, orgDeltaX) - moveVec.Angle()))); if (tmp < 0 || tmp > uint.MaxValue || double.IsNaN(tmp)) { tmpMax = uint.MaxValue; } else - tmpMax = tmp/1000.0; + tmpMax = tmp / 1000.0; } break; } diff --git a/logic/Preparation/Utility/XY.cs b/logic/Preparation/Utility/XY.cs index 9b70661..3798bb5 100644 --- a/logic/Preparation/Utility/XY.cs +++ b/logic/Preparation/Utility/XY.cs @@ -64,11 +64,11 @@ namespace Preparation.Utility } public static double Distance(XY p1, XY p2) { - long c = (((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)))*1000000; - long t = c/2+1; - while (t*t>c||(t+1)*(t+1) c || (t + 1) * (t + 1) < c) + t = (c / t + t) / 2; + return (double)t / 1000.0; } public double Length() {