06.05.2015, 13:31
Considering that a player will at max open the hood every few minutes in average, the MAX_VEHICLES loop will be much more economic after all. Iterators might sound fast, but they will eat up a lot of RAM (as pointed out before), and depending on how youre realizing them they are really slow. Removing a vehicle from the iterator means finding its index first, and then shifting the index of all following vehicles (though the pointer relocation method is a good way for array shifting). And as there might be dozens of vehicles streaming in and out each streaming tick for each player this would cause a huge amount of extra work for the server, even if noone opens a hood.
Iterators are only useful for "slow data", like player joins or vehicle creations, but not for data that changes thousands of times every second.
A bitset actually would have little to no advantages compared to the common loop
Iterators are only useful for "slow data", like player joins or vehicle creations, but not for data that changes thousands of times every second.
Quote:
From C++, I can think of std::bitset, which would very much be your friend in such situation. For 200 players, having a bitset for 2000 vehicles would take up 400000 bits or 48 kilobytes, which is far less.
|
pawn Код:
// Common attempt
for (new i = 0; i < MAX_VEHICLES; i++) {
if (!IsVehicleStreamedIn(i, playerid)) continue;
}
// Bitset (some pawn/c++ pseudo mixup)
for (new i = 0; i < MAX_VEHICLES; i++) {
if (!bitset_playervehicles[playerid].test(i)) continue;
}