| 329 | } |
| 330 | |
| 331 | void Level::HandleCollisions(CollisionPtrMap& col_map, SceneGraph& scenegraph) { |
| 332 | exit_call_queue.clear(); |
| 333 | enter_call_queue.clear(); |
| 334 | |
| 335 | // Convert old collision ids into pointers |
| 336 | { |
| 337 | PROFILER_ZONE(g_profiler_ctx, "A"); |
| 338 | old_col_ptr_map.clear(); |
| 339 | { |
| 340 | CollisionMap& map = old_col_map_; |
| 341 | for (auto& iter : map) { |
| 342 | int id = iter.first; |
| 343 | Object* obj_a_ptr = scenegraph.GetObjectFromID(id); |
| 344 | if (obj_a_ptr) { |
| 345 | CollisionSet& set = iter.second; |
| 346 | for (int id : set) { |
| 347 | Object* obj_b_ptr = scenegraph.GetObjectFromID(id); |
| 348 | if (obj_b_ptr) { |
| 349 | old_col_ptr_map[obj_a_ptr].insert(obj_b_ptr); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | { |
| 358 | PROFILER_ZONE(g_profiler_ctx, "B"); |
| 359 | // Check for collisions that used to be happening, and are now gone |
| 360 | CollisionPtrMap::iterator oci = old_col_ptr_map.begin(); |
| 361 | for (; oci != old_col_ptr_map.end(); ++oci) { |
| 362 | CollisionPtrMap::iterator ci = col_map.find(oci->first); |
| 363 | Object* obj_a = (Object*)oci->first; |
| 364 | CollisionPtrSet::iterator oci2 = oci->second.begin(); |
| 365 | for (; oci2 != oci->second.end(); ++oci2) { |
| 366 | Object* obj_b = (Object*)(*oci2); |
| 367 | bool not_found = false; |
| 368 | if (ci == col_map.end()) { |
| 369 | not_found = true; |
| 370 | } else { |
| 371 | CollisionPtrSet::iterator ci2 = ci->second.find(*oci2); |
| 372 | if (ci2 == ci->second.end()) { |
| 373 | not_found = true; |
| 374 | } |
| 375 | } |
| 376 | if (!not_found) { |
| 377 | continue; |
| 378 | } |
| 379 | Object* temp_obj_a = obj_a; |
| 380 | if (obj_b->GetType() == _hotspot_object) { |
| 381 | std::swap(temp_obj_a, obj_b); |
| 382 | } |
| 383 | if (temp_obj_a->GetType() == _hotspot_object && obj_b->GetType() == _movement_object) { |
| 384 | Hotspot* hotspot = (Hotspot*)temp_obj_a; |
| 385 | MovementObject* mo = (MovementObject*)obj_b; |
| 386 | |
| 387 | exit_call_queue.push_back(std::pair<Hotspot*, MovementObject*>(hotspot, mo)); |
| 388 | } |
no test coverage detected