diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-08 10:42:34 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-08 10:42:34 +0800 |
| commit | 7d1380bc7be97eb75c64e66af1619d7aa36cf35d (patch) | |
| tree | 97900ae09d056716b96092a0252c1bfa1bae2075 /objects/room.lua | |
| parent | b58031ff993c2032600c753beb8d9e808bfae385 (diff) | |
perf: use limited loops to connect rooms
Diffstat (limited to 'objects/room.lua')
| -rw-r--r-- | objects/room.lua | 16 |
1 files changed, 12 insertions, 4 deletions
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 |
