@@ -494,7 +494,7 @@ namespace CPointViewControlHandler
494494{
495495 struct ViewControl
496496 {
497- CUtlVector <CHandle<CCSPlayerPawn>> m_players;
497+ std::vector <CHandle<CCSPlayerPawn>> m_players;
498498 std::string m_viewTarget;
499499 std::string m_name;
500500 };
@@ -590,22 +590,24 @@ namespace CPointViewControlHandler
590590
591591 for (auto & [vk, vc] : s_repository)
592592 {
593- if (const auto index = vc.m_players .Find (handle); index > -1 )
593+ const auto iterator = std::find (vc.m_players .begin (), vc.m_players .end (), handle);
594+ if (iterator != vc.m_players .end ())
594595 {
595596 if (vk == static_cast <uint>(key))
596597 {
597598 Warning (" PointViewControl %s was enabled twice in a row! player: %s\n " , vc.m_name .c_str (), pController->GetPlayerName ().c_str ());
598599 return false ;
599600 }
600601
601- vc.m_players .Remove (index );
602+ vc.m_players .erase (iterator );
602603 UpdatePlayerState (pPawn, INVALID_HANDLE , false , RESET_FOV );
603604 Warning (" PointViewControl %s already enabled for %s\n " , vc.m_name .c_str (), pController->GetPlayerName ().c_str ());
604605 break ;
605606 }
606607 }
607608
608- return it->second .m_players .AddToTail (handle) >= 0 ;
609+ it->second .m_players .push_back (handle);
610+ return true ;
609611 }
610612 bool OnDisable (CPointViewControl* pEntity, CBaseEntity* pActivator)
611613 {
@@ -632,7 +634,14 @@ namespace CPointViewControlHandler
632634
633635 UpdatePlayerState (pPawn, INVALID_HANDLE , false , RESET_FOV );
634636
635- return it->second .m_players .FindAndRemove (handle);
637+ auto & vecPlayers = it->second .m_players ;
638+ auto iterator = std::find (vecPlayers.begin (), vecPlayers.end (), handle);
639+
640+ if (iterator == vecPlayers.end ())
641+ return false ;
642+
643+ vecPlayers.erase (iterator);
644+ return true ;
636645 }
637646 bool OnEnableAll (CPointViewControl* pEntity)
638647 {
@@ -655,17 +664,19 @@ namespace CPointViewControlHandler
655664
656665 for (auto & [vk, vc] : s_repository)
657666 {
658- if (const auto index = vc.m_players .Find (handle); index > -1 )
667+ auto iterator = std::find (vc.m_players .begin (), vc.m_players .end (), handle);
668+
669+ if (iterator != vc.m_players .end ())
659670 {
660- vc.m_players .Remove (index );
671+ vc.m_players .erase (iterator );
661672 if (vk == static_cast <uint>(key))
662673 continue ;
663674 UpdatePlayerState (pPawn, INVALID_HANDLE , false , RESET_FOV );
664675 Warning (" PointViewControl %s already enabled for %s\n " , vc.m_name .c_str (), pController->GetPlayerName ().c_str ());
665676 }
666677 }
667678
668- it->second .m_players .AddToTail (handle);
679+ it->second .m_players .push_back (handle);
669680 }
670681
671682 return true ;
@@ -677,15 +688,11 @@ namespace CPointViewControlHandler
677688 if (it == s_repository.end ())
678689 return false ;
679690
680- FOR_EACH_VEC (it->second .m_players , i)
681- {
682- const auto & handle = it->second .m_players .Element (i);
683-
684- if (const auto player = handle.Get ())
691+ for (auto hPawn : it->second .m_players )
692+ if (CCSPlayerPawn* player = hPawn.Get ())
685693 UpdatePlayerState (player, INVALID_HANDLE , false , RESET_FOV );
686- }
687694
688- it->second .m_players .Purge ();
695+ it->second .m_players .clear ();
689696
690697 return true ;
691698 }
@@ -698,13 +705,9 @@ namespace CPointViewControlHandler
698705 const auto entity = CHandle<CPointViewControl>(it->first ).Get ();
699706 if (!entity)
700707 {
701- FOR_EACH_VEC (it->second .m_players , i)
702- {
703- const auto & handle = it->second .m_players .Element (i);
704-
705- if (const auto player = handle.Get ())
708+ for (auto hPawn : it->second .m_players )
709+ if (CCSPlayerPawn* player = hPawn.Get ())
706710 UpdatePlayerState (player, INVALID_HANDLE , false , RESET_FOV );
707- }
708711
709712 it = s_repository.erase (it);
710713 }
@@ -725,68 +728,58 @@ namespace CPointViewControlHandler
725728 continue ;
726729 }
727730
728- if (vc.m_players .Count () == 0 )
731+ if (vc.m_players .empty () )
729732 continue ;
730733
731734 const auto pTarget = entity->GetTargetCameraEntity ();
732735 if (!pTarget)
733736 {
734- FOR_EACH_VEC (vc.m_players , i)
735- {
736- const auto & handle = vc.m_players .Element (i);
737-
738- if (const auto player = handle.Get ())
737+ for (auto hPawn : vc.m_players )
738+ if (CCSPlayerPawn* player = hPawn.Get ())
739739 UpdatePlayerState (player, INVALID_HANDLE , false , RESET_FOV );
740- }
741- vc.m_players .Purge ();
740+ vc.m_players .clear ();
742741 continue ;
743742 }
744743
745- FOR_EACH_VEC ( vc.m_players , i )
744+ for ( auto iterator = vc.m_players . begin (); iterator != vc. m_players . end (); )
746745 {
747- const auto & handle = vc. m_players . Element (i) ;
748- const auto player = handle .Get ();
746+ auto hPawn = *iterator ;
747+ CCSPlayerPawn* player = hPawn .Get ();
749748 if (!player)
750749 {
751- vc.m_players .Remove (i-- );
750+ iterator = vc.m_players .erase (iterator );
752751 continue ;
753752 }
754753 if (!player->IsAlive ())
755754 {
756755 UpdatePlayerState (player, INVALID_HANDLE , false , RESET_FOV );
757- vc.m_players .Remove (i-- );
756+ iterator = vc.m_players .erase (iterator );
758757 continue ;
759758 }
760759
761760 UpdatePlayerState (player, pTarget->GetHandle (), entity->HasFrozen (), entity->HasFOV () ? entity->GetFOV () : INVALID_FOV , entity->HasDisarm ());
761+ iterator++;
762762 }
763763 }
764764 }
765765 bool IsViewControl (CCSPlayerPawn* pPawn)
766766 {
767- const auto handle = pPawn->GetHandle ().ToInt ();
768767 for (const auto & [vk, vc] : s_repository)
769768 {
770- FOR_EACH_VEC (vc.m_players , i)
771- {
772- if (vc.m_players .Element (i).ToInt () == handle)
769+ for (auto hPawn : vc.m_players )
770+ if (hPawn == pPawn->GetHandle ())
773771 return true ;
774- }
775772 }
776773 return false ;
777774 }
778775 void Shutdown ()
779776 {
780777 for (auto & [vk, vc] : s_repository)
781778 {
782- FOR_EACH_VEC (vc.m_players , i)
783- {
784- const auto & handle = vc.m_players .Element (i);
785-
786- if (const auto player = handle.Get ())
779+ for (auto hPawn : vc.m_players )
780+ if (CCSPlayerPawn* player = hPawn.Get ())
787781 UpdatePlayerState (player, INVALID_HANDLE , false , RESET_FOV );
788- }
789- vc.m_players .Purge ();
782+ vc.m_players .clear ();
790783 }
791784 s_repository.clear ();
792785 }
0 commit comments