Efficient Vehicle Looping
#1

Let say I have scripted it so when you press KEY_WALK (LALT), the boot of a vehicle you are standing near opens.

To do this, I need to loop through all vehicles, get their position, get the offset for the boot, get the player’s position, then get the distance between the two and check if they are in range.

I’d like to discuss the most efficient method to do this. The way I see it, there are two options:

Option 1:
Loop through every vehicle and check if it is in range.

Option 2:
When a vehicle streams in for a player (OnVehicleStreamIn), add the vehicle ID to an iterator, then use that in the loop instead.

Option 2 would obviously make it more efficient when the button is pressed, but I want to look at the whole picture.

Is it more efficient to have frequent 2000-iteration loops, or to have constant iterator adding/removing as vehicles are streamed in and out? Think about if there were 100 players on the server; there would be constant vehicles streaming in and out – probably hundreds every few seconds.

I personally think option 2 (Iterator) is more efficient, as even if it is called frequently, it won’t stop the PAWN thread like the raw loop will.

Thoughts?
Reply


Messages In This Thread
Efficient Vehicle Looping - by MP2 - 05.05.2015, 08:56
Re: Efficient Vehicle Looping - by AIped - 05.05.2015, 09:08
Re: Efficient Vehicle Looping - by MicroD - 05.05.2015, 09:22
Re: Efficient Vehicle Looping - by Tamer - 05.05.2015, 09:43
Re: Efficient Vehicle Looping - by MP2 - 05.05.2015, 09:54
Re: Efficient Vehicle Looping - by Tamer - 05.05.2015, 10:00
Re: Efficient Vehicle Looping - by Misiur - 05.05.2015, 10:01
Re: Efficient Vehicle Looping - by Lordzy - 05.05.2015, 10:10
Re: Efficient Vehicle Looping - by MP2 - 05.05.2015, 10:29
Re: Efficient Vehicle Looping - by Konstantinos - 05.05.2015, 10:38
Re: Efficient Vehicle Looping - by MP2 - 05.05.2015, 10:51
Re: Efficient Vehicle Looping - by Kar - 05.05.2015, 21:28
Re: Efficient Vehicle Looping - by Emmet_ - 05.05.2015, 21:45
Re: Efficient Vehicle Looping - by Crayder - 05.05.2015, 21:59
Re: Efficient Vehicle Looping - by MP2 - 06.05.2015, 10:22
Re: Efficient Vehicle Looping - by AndreT - 06.05.2015, 11:51
Re: Efficient Vehicle Looping - by Mauzen - 06.05.2015, 13:31
Re: Efficient Vehicle Looping - by sammp - 06.05.2015, 14:57
Re: Efficient Vehicle Looping - by Tamer - 06.05.2015, 17:57
Re: Efficient Vehicle Looping - by AndreT - 06.05.2015, 19:31
Re: Efficient Vehicle Looping - by Marricio - 08.05.2015, 21:22
Re: Efficient Vehicle Looping - by Pottus - 09.05.2015, 01:39

Forum Jump:


Users browsing this thread: 1 Guest(s)