Faster alternative to format()?
#1

Is there one? Using format() in a 2000 iteration vehicle loop makes the loop take about 5 seconds! Without it it takes mere miliseconds :/

Even filling the function with tonnes of functions (GetVehiclePos + IsPlayerInRangeOfPoint etc.) doesn't slow it down really at all, but format is taking the piss..
Reply
#2

Do you really need to use format for each car in less then second?

And what you want to formate, try to narrow, like use formate only for Streamed in cars or for cars in 0 Interior or so, just to avoid from blank loop with 2k format();
Reply
#3

I was just messing about, I don't need it tbh. I was just wondering A. why it's so slow and B. if there's a faster alternative.
Reply
#4

Need to improvise.
like you can do

new PlayerInEvent[MAX_PLAYERS];

In some event command
Loop for i
if(IsPlayerInEventCar(i,car)) { PlayerInEvent[i] = 1; }


Later elsewhere

Loop for i
if(PlayerInEvent[i] == 1) { SendClient(i,-1," you are in event"); }


or


new PlayerInEvent[10]; //As not whole server can be in the same event aka arena orso.

In some event command
Loop for i
if(IsPlayerInEventCar(i,car)) { Loop for B PlayerInEvent[b] = i; }


Later elsewhere

Loop for i
SendClient(PlayerInEvent[i],-1," you are in event");


Hope you got what I mean, like make slots for certain things, not always you have to loop through all cars or players, or like some faction cars can load apples example, you dont need to use Apples[MAX_VEHICLES]; but just Apples[Faction cars count];
Reply
#5

I use foreach. I don't WANT to do format for 2000 vehicles. I did it as a TEST. I want to know if there are alternatives that DON'T LAG.
Reply
#6

Go with strcat
Reply
#7

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
Go with strcat
strcat does not support arguments - he wants to fill the string with information like position
Reply
#8

Quote:
Originally Posted by Kwashiorkor
Посмотреть сообщение
strcat does not support arguments - he wants to fill the string with information like position
That's the problem with not being open minded. It's pretty easy to make strcat work exactly like format, the code is just longer.
Reply
#9

strcat concatenates two strings - might you post an example to use it with floats or integers?
Reply
#10

Quote:
Originally Posted by Kwashiorkor
Посмотреть сообщение
strcat concatenates two strings - might you post an example to use it with floats or integers?
You simply use valstr.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)