597 | | void Map::Update(const uint32 &t_diff) |
598 | | { |
599 | | // TODO: need have an active object list for every map |
600 | | |
601 | | /*resetMarkedCells(); |
602 | | |
| 597 | void Map::UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff) |
| 598 | { |
| 599 | CellPair standing_cell(Trinity::ComputeCellPair(x, y)); |
| 600 | |
| 601 | // Check for correctness of standing_cell, it also avoids problems with update_cell |
| 602 | if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) |
| 603 | return; |
| 604 | |
| 605 | // will this reduce the speed? |
| 612 | // the overloaded operators handle range checking |
| 613 | // so ther's no need for range checking inside the loop |
| 614 | CellPair begin_cell(standing_cell), end_cell(standing_cell); |
| 615 | begin_cell << 1; begin_cell -= 1; // upper left |
| 616 | end_cell >> 1; end_cell += 1; // lower right |
| 617 | |
| 618 | for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) |
| 619 | { |
| 620 | for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) |
| 621 | { |
| 622 | // marked cells are those that have been visited |
| 623 | // don't visit the same cell twice |
| 624 | uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x; |
| 625 | if(!isCellMarked(cell_id)) |
| 626 | { |
| 627 | markCell(cell_id); |
| 628 | CellPair pair(x,y); |
| 629 | Cell cell(pair); |
| 630 | cell.data.Part.reserved = CENTER_DISTRICT; |
| 631 | cell.SetNoCreate(); |
| 632 | CellLock<NullGuard> cell_lock(cell, pair); |
| 633 | cell_lock->Visit(cell_lock, grid_object_update, *this); |
| 634 | cell_lock->Visit(cell_lock, world_object_update, *this); |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | void Map::Update(const uint32 &t_diff) |
| 641 | { |
| 642 | resetMarkedCells(); |
| 643 | |
| 644 | // update cells around players |
612 | | if(!plr->IsInWorld()) |
613 | | continue; |
614 | | |
615 | | CellPair standing_cell(Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY())); |
616 | | |
617 | | // Check for correctness of standing_cell, it also avoids problems with update_cell |
618 | | if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) |
619 | | continue; |
620 | | |
621 | | // the overloaded operators handle range checking |
622 | | // so ther's no need for range checking inside the loop |
623 | | CellPair begin_cell(standing_cell), end_cell(standing_cell); |
624 | | begin_cell << 1; begin_cell -= 1; // upper left |
625 | | end_cell >> 1; end_cell += 1; // lower right |
626 | | |
627 | | for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) |
628 | | { |
629 | | for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) |
630 | | { |
631 | | // marked cells are those that have been visited |
632 | | // don't visit the same cell twice |
633 | | uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x; |
634 | | if(!isCellMarked(cell_id)) |
635 | | { |
636 | | markCell(cell_id); |
637 | | CellPair pair(x,y); |
638 | | Cell cell(pair); |
639 | | cell.data.Part.reserved = CENTER_DISTRICT; |
640 | | cell.SetNoCreate(); |
641 | | CellLock<NullGuard> cell_lock(cell, pair); |
642 | | cell_lock->Visit(cell_lock, grid_object_update, *this); |
643 | | cell_lock->Visit(cell_lock, world_object_update, *this); |
644 | | } |
645 | | } |
646 | | } |
647 | | }*/ |
| 648 | if(plr->IsInWorld()) |
| 649 | UpdateActiveCells(plr->GetPositionX(), plr->GetPositionY(), t_diff); |
| 650 | } |
| 651 | |
| 652 | // update cells around active objects |
| 653 | // clone the active object list, because update might remove from it |
| 654 | std::set<WorldObject *> activeObjects(i_activeObjects); |
| 655 | for(std::set<WorldObject *>::iterator iter = activeObjects.begin(); iter != activeObjects.end(); ++iter) |
| 656 | { |
| 657 | if((*iter)->IsInWorld()) |
| 658 | UpdateActiveCells((*iter)->GetPositionX(), (*iter)->GetPositionY(), t_diff); |
| 659 | } |
| 1521 | if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && |
| 1522 | (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) |
| 1523 | return true; |
| 1524 | } |
| 1525 | |
| 1526 | return false; |
| 1527 | } |
| 1528 | |
| 1529 | bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const |
| 1530 | { |
| 1531 | CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); |
| 1532 | CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); |
| 1533 | cell_min << 2; |
| 1534 | cell_min -= 2; |
| 1535 | cell_max >> 2; |
| 1536 | cell_max += 2; |
| 1537 | |
| 1538 | for(MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) |
| 1539 | { |
| 1540 | Player* plr = iter->getSource(); |
| 1541 | |
| 1542 | CellPair p = Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()); |
| 1543 | if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && |
| 1544 | (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) |
| 1545 | return true; |
| 1546 | } |
| 1547 | |
| 1548 | for(std::set<WorldObject*>::const_iterator itr = i_activeObjects.begin(); itr != i_activeObjects.end(); ++itr) |
| 1549 | { |
| 1550 | CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY()); |