A
Amfy
Гость
Гость
Бешеный перебор машин на основе foreach от Траккера (Триггера)
Переделал под машины: Caypen
В самый верх мода:
new forveh_vehicles[MAX_VEHICLES];
new forveh_count = 0;
#if !defined IsValidVehicle
native IsValidVehicle(vehicleid);
#endif
#define forveh(%0) for(new ouf, %0=forveh_vehicles[ouf]; ouf<forveh_count; %0=forveh_vehicles[++ouf])
stock Forveh_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
{
new vehid = CreateVehicle(modelid, x, y, z,angle, color1, color2, respawn_delay);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_CreateVehicle
#undef CreateVehicle
#else
#define _ALS_CreateVehicle
#endif
#define CreateVehicle Forveh_CreateVehicle
stock Forveh_AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
new vehid = AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_AddStaticVehicle
#undef AddStaticVehicle
#else
#define _ALS_AddStaticVehicle
#endif
#define AddStaticVehicle Forveh_AddStaticVehicle
stock Forveh_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay)
{
new vehid = AddStaticVehicleEx(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2,respawn_delay);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_AddStaticVehicleEx
#undef AddStaticVehicleEx
#else
#define _ALS_AddStaticVehicleEx
#endif
#define AddStaticVehicleEx Forveh_AddStaticVehicleEx
stock Forveh_DestroyVehicle(vehicleid)
{
if(!IsValidVehicle(vehicleid)) return 0;
for(new i=0;i<forveh_count;i++)
{
if(forveh_vehicles==vehicleid)
{
forveh_vehicles=forveh_vehicles[--forveh_count];
break;
}
}
return DestroyVehicle(vehicleid);
}
#if defined _ALS_DestroyVehicle
#undef DestroyVehicle
#else
#define _ALS_DestroyVehicle
#endif
#define DestroyVehicle Forveh_DestroyVehicle
Пример:
forveh(i)
{
Действие(i);
}
Таким образом, мы перебираем только те машины, которые были созданы, а те, которые удалены, пропускаем даже не интерпретируя.
За основу взят метод Траккера для игроков.
[09:47:37] Тестируем дедовский метод перебора машин
[09:47:37] 125 машин создали
[09:47:37] 50-74 ID машин уничтожены
[09:47:37] Стартуем глобальный цикл 1000000 раз
[09:58:05] тест дедовского метода перебора машин ЗАВЕРШЕН. время: 628328 ms.
[09:58:05]
[09:58:05] Тестируем forveh машин
[09:58:05] 125 машин создали
[09:58:05] 50-74 ID машин уничтожены
[09:58:05] Стартуем глобальный цикл 1000000 раз
[09:58:29] тест forveh машин ЗАВЕРШЕН. время: 23553 ms.
Почти в 27 раз быстрее.
Был создан цикл на 1000000 раз в нутри которого был цикл машин через forveh а в первом же тесте через дедовский метод.
Переделал под машины: Caypen
В самый верх мода:
new forveh_vehicles[MAX_VEHICLES];
new forveh_count = 0;
#if !defined IsValidVehicle
native IsValidVehicle(vehicleid);
#endif
#define forveh(%0) for(new ouf, %0=forveh_vehicles[ouf]; ouf<forveh_count; %0=forveh_vehicles[++ouf])
stock Forveh_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
{
new vehid = CreateVehicle(modelid, x, y, z,angle, color1, color2, respawn_delay);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_CreateVehicle
#undef CreateVehicle
#else
#define _ALS_CreateVehicle
#endif
#define CreateVehicle Forveh_CreateVehicle
stock Forveh_AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
new vehid = AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_AddStaticVehicle
#undef AddStaticVehicle
#else
#define _ALS_AddStaticVehicle
#endif
#define AddStaticVehicle Forveh_AddStaticVehicle
stock Forveh_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay)
{
new vehid = AddStaticVehicleEx(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2,respawn_delay);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_AddStaticVehicleEx
#undef AddStaticVehicleEx
#else
#define _ALS_AddStaticVehicleEx
#endif
#define AddStaticVehicleEx Forveh_AddStaticVehicleEx
stock Forveh_DestroyVehicle(vehicleid)
{
if(!IsValidVehicle(vehicleid)) return 0;
for(new i=0;i<forveh_count;i++)
{
if(forveh_vehicles==vehicleid)
{
forveh_vehicles=forveh_vehicles[--forveh_count];
break;
}
}
return DestroyVehicle(vehicleid);
}
#if defined _ALS_DestroyVehicle
#undef DestroyVehicle
#else
#define _ALS_DestroyVehicle
#endif
#define DestroyVehicle Forveh_DestroyVehicle
Пример:
forveh(i)
{
Действие(i);
}
Таким образом, мы перебираем только те машины, которые были созданы, а те, которые удалены, пропускаем даже не интерпретируя.
За основу взят метод Траккера для игроков.
[09:47:37] Тестируем дедовский метод перебора машин
[09:47:37] 125 машин создали
[09:47:37] 50-74 ID машин уничтожены
[09:47:37] Стартуем глобальный цикл 1000000 раз
[09:58:05] тест дедовского метода перебора машин ЗАВЕРШЕН. время: 628328 ms.
[09:58:05]
[09:58:05] Тестируем forveh машин
[09:58:05] 125 машин создали
[09:58:05] 50-74 ID машин уничтожены
[09:58:05] Стартуем глобальный цикл 1000000 раз
[09:58:29] тест forveh машин ЗАВЕРШЕН. время: 23553 ms.
Почти в 27 раз быстрее.
Был создан цикл на 1000000 раз в нутри которого был цикл машин через forveh а в первом же тесте через дедовский метод.
Последнее редактирование: