Is there better way of adding components?
#1

Hello, I have this code, I'm worried cuz profiler Zeex's says 74% Self Time...
Here is code:
Код:
public OnVehicleSpawn(vehicleid)
{
	VehProtection(vehicleid);
	for(new i = 0; i < sizeof(VehicleInfo); i++)
	{
		new vFile[50];
        format(vFile, sizeof(vFile), AUTO_FILE, i);
		if(fexist(vFile))
		{
			if(vehicleid == VehicleInfo[i][vID])
			{
				for(new id = 1; id <= 17; id++)
				{
					if(VehicleInfo[i][vMod][id]!=0) { AddVehicleComponent(vehicleid, VehicleInfo[i][vMod][id]); }
				}
				if(VehicleInfo[i][vMod][0]>=0) { ChangeVehiclePaintjob(vehicleid, VehicleInfo[i][vMod][0]); }
			}
		}
	}
	return 1;
}
Reply
#2

Sure it does, you check for all available vehicle info for every single spawned vehicle
VehProtection can be also the reason, but who knows? You have not described how VehProtection, vFile, AUTO_FILE, VehicleInfo looks like.
Reply
#3

I removed vehprotect cuz its very old gamemode, I'm doing bugfix + opt ...
Reply
#4

The most resource intensive thing here is for sure the fexist() part. It solely depends on the disk speed which may vary at times.
I'm certain it doesn't need to check the file on every spawn, you could save that in the array as well. Especially when looping.

Furthermore you can use break; when the vehicle is found, that reduces the length of the loop.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)