05.05.2015, 08:56
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?
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?