| 302 | } |
| 303 | |
| 304 | void Renderer::GetVisibleRooms(short from, short to, Vector4 viewPort, bool water, int count, bool onlyRooms, RenderView& renderView) |
| 305 | { |
| 306 | // FIXME: This is an urgent hack to fix stack overflow crashes. |
| 307 | // See https://github.com/MontyTRC89/TombEngine/issues/947 for details. |
| 308 | // NOTE by MontyTRC: I'd keep this as a failsafe solution for 0.00000001% of cases we could have problems |
| 309 | |
| 310 | int stackSize = (int)_visitedRoomsStack.size(); |
| 311 | int stackMinIndex = std::max(0, int(stackSize - 5)); |
| 312 | |
| 313 | for (int i = stackSize - 1; i >= stackMinIndex; i--) |
| 314 | { |
| 315 | if (_visitedRoomsStack[i] == to) |
| 316 | { |
| 317 | TENLog("Circle detected in room " + std::to_string(to), LogLevel::Warning, LogConfig::Debug); |
| 318 | return; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static constexpr int MAX_SEARCH_DEPTH = 64; |
| 323 | if (_rooms[to].Visited && count > MAX_SEARCH_DEPTH) |
| 324 | { |
| 325 | TENLog( |
| 326 | "Maximum room collection depth of " + std::to_string(MAX_SEARCH_DEPTH) + " was reached with room " + std::to_string(to), |
| 327 | LogLevel::Warning, LogConfig::Debug); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | _visitedRoomsStack.push_back(to); |
| 332 | |
| 333 | _numGetVisibleRoomsCalls++; |
| 334 | |
| 335 | auto* room = &_rooms[to]; |
| 336 | |
| 337 | if (!room->Visited) |
| 338 | { |
| 339 | room->Visited = true; |
| 340 | |
| 341 | renderView.RoomsToDraw.push_back(room); |
| 342 | |
| 343 | CollectLightsForRoom(to, renderView); |
| 344 | CollectDecalsForRoom(to, renderView); |
| 345 | |
| 346 | if (!onlyRooms) |
| 347 | { |
| 348 | CollectItems(to, renderView); |
| 349 | CollectStatics(to, renderView); |
| 350 | CollectEffects(to); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | room->ViewPort.x = std::min(room->ViewPort.x, viewPort.x); |
| 355 | room->ViewPort.y = std::min(room->ViewPort.y, viewPort.y); |
| 356 | room->ViewPort.z = std::max(room->ViewPort.z, viewPort.z); |
| 357 | room->ViewPort.w = std::max(room->ViewPort.w, viewPort.w); |
| 358 | |
| 359 | Vector4 clipPort; |
| 360 | for (int i = 0; i < room->Doors.size(); i++) |
| 361 | { |