21.07.2011, 16:42
Quote:
WHAT? I think YOU need to look at what plugins are for and understand the difference between C++ and PAWN (and, more importantly, which is faster).
|
pawn versions
Код:
stock GetVehicleDriver(vehicleid) { for (new i; i<500; i++) { if (!IsPlayerConnected(i)) continue; if (GetPlayerState(i) != PLAYER_STATE_DRIVER) continue; if (GetPlayerVehicleID(i) == vehicleid) { return i; } } return -1; }
Код:
int GetVehicleDriver(int vehicleid) { if ((vehicleid == 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES)) return INVALID_PLAYER_ID; int i; for (i = 0; i < max_players; i++) { if (invoke->callNative(&PAWN::IsPlayerConnected, i) == false) // no connected player in slot? continue; if (invoke->callNative(&PAWN::GetPlayerState, i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle? int thisplayervehid; thisplayervehid = invoke->callNative(&PAWN::GetPlayerVehicleID, i); // todo: maybe use IsPlayerInVehicle instead. if (thisplayervehid == vehicleid) // found a connected driver in this car. return i; } return INVALID_PLAYER_ID; // found no driver. }
Код:
#define MAXTEST 500 new test1; test1 = GetTickCount(); for(new a; a < 500; ++a) { MPGetVehicleDriver(1); //returnit(a); } printf("# MPGetVehicleDriver %d", GetTickCount() - test1); new test2; test2 = GetTickCount(); for(new a; a < 500; ++a) { GetVehicleDriver(1); } printf("# GetVehicleDriver %d", GetTickCount() - test2);
****** and other experts - any idea why the c++ version is slower? i managed to track down to invoke->callNative function.. so whenever i call sa-mp natives via invoke that's significantly slower than doing it in pawn (pure math functions work faster tho), so this is unacceptable to me.. if calling samp natives via invoke makes the whole thing slower than in pawn, i should just stop this project - there is no other option.
Also, full source: http://code.******.com/p/samp-mp/sou...e/#svn%2Ftrunk