From 7d1380bc7be97eb75c64e66af1619d7aa36cf35d Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sat, 8 Mar 2025 10:42:34 +0800 Subject: perf: use limited loops to connect rooms --- objects/room.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'objects/room.lua') diff --git a/objects/room.lua b/objects/room.lua index 1d2bfa2..23ab73e 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -156,10 +156,18 @@ function Room:connect(anotherRoom, way) local dd1 = self:getDoorlessDirections() local dd2 = anotherRoom:getDoorlessDirections() - repeat - directions[1] = utils.any(dd1) - directions[2] = OppositeDirection[directions[1]] - until utils.contains(dd2, directions[2]) + for _, dir1 in ipairs(dd1) do + local dir2 = OppositeDirection[dir1] + if (utils.contains(dd2, dir2)) then + directions = { dir1, dir2 } + break + end + end + if directions == {} or not utils.contains(dd2, directions[2]) then return false end + -- repeat + -- directions[1] = utils.any(dd1) + -- directions[2] = OppositeDirection[directions[1]] + -- until utils.contains(dd2, directions[2]) end if not directions then return false end -- cgit v1.2.3