CreateDynamic3DTextLabel drops fps by 20 frames?
#1

Ok so I changed something in my script and when I walk up to the point it makes my fps drop by 20 frames, Heres the code.

pawn Код:
for(new h = 0; h < sizeof(Businesses); h++)
                {
                    if(GetPlayerVirtualWorld(i) == 0)
                    {
                        if(strcmp(Businesses[h][bOwner], "Nobody", true) == 0)
                        {
                            if(Businesses[h][bPrice] == -1)
                            {
                                format(string, sizeof(string), "Business %d (%s) Unavailable.", h, Businesses[h][bName]);
                                CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            }
                            else
                            {
                                format(string, sizeof(string), "Business %d (%s) Available to buy for %d (/buybusiness).", h, Businesses[h][bName], Businesses[h][bPrice]);
                                CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            }
                        }
                        else
                        {
                            format(string, sizeof(string), "Business %d (%s) Owner: %s. Press ~k~~PED_DUCK~  to enter", h, Businesses[h][bName], Businesses[h][bOwner]);
                            CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                        }
                    }
Could someone if they can tell me why the fps drops a bunch.
Reply
#2

Can you show the outer loop* as well? It looks like you're creating a couple hundred labels in the same place.

* Judging by this:
pawn Код:
GetPlayerVirtualWorld(i)
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Can you show the outer loop* as well? It looks like you're creating a couple hundred labels in the same place.

* Judging by this:
pawn Код:
GetPlayerVirtualWorld(i)
Didn't get what you meant by outer loop so heres the whole public variable :P
pawn Код:
public PickupMessages()
{
    new string[128], Float: playX, Float: playY, Float: playZ;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerInRangeOfPoint(i, 9, playX, playY, playZ))
        {
            if(IsPlayerConnectedEx(i) && IsPlayerSpawned(i))
            {
                if(IsPlayerInRangeOfPoint(i, 5, ArrestPosX, ArrestPosY, ArrestPosZ))
                {
                    GameTextForPlayer(i, "~r~Arrest ~w~Location", 3500, 3);
                }
                if(IsPlayerInRangeOfPoint(i, 5, 691.1537, -1275.7965, 13.5604))
                {
                    GameTextForPlayer(i, "~y~V.I.P~w~ Club.", 3500, 3);
                }
                if(IsPlayerInRangeOfPoint(i, 2, 1158.1835, -1437.5432, 15.7981))
                {
                    GameTextForPlayer(i, "~b~/~w~Buy.", 3500, 3);
                }
               
                for(new h = 0; h < sizeof(Businesses); h++)
                {
                    if(GetPlayerVirtualWorld(i) == 0)
                    {
                        if(strcmp(Businesses[h][bOwner], "Nobody", true) == 0)
                        {
                            if(Businesses[h][bPrice] == -1)
                            {
                                format(string, sizeof(string), "Business %d (%s) Unavailable.", h, Businesses[h][bName]);
                                CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            }
                            else
                            {
                                format(string, sizeof(string), "Business %d (%s) Available to buy for %d (/buybusiness).", h, Businesses[h][bName], Businesses[h][bPrice]);
                                CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            }
                        }
                        else
                        {
                            format(string, sizeof(string), "Business %d (%s) Owner: %s. Press ~k~~PED_DUCK~  to enter", h, Businesses[h][bName], Businesses[h][bOwner]);
                            CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                        }
                    }
                }
                for(new h = 0; h < sizeof(Houses); h++)
                {
                    if(GetPlayerVirtualWorld(i) == 0)
                    {
                        if(strcmp(Houses[h][hOwner], "Nobody", true) == 0)
                        {
                            if(Houses[h][HousePrice] == -1)
                            {
                                format(string, sizeof(string), "House %d Unavailable.", h, Houses[h][HousePrice]);
                                CreateDynamic3DTextLabel(string, YELLOW, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            }
                            else
                            {
                                format(string, sizeof(string), "House %d Available to buy for %d (/buyhouse).", h, Houses[h][HousePrice]);
                                CreateDynamic3DTextLabel(string, YELLOW, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            }
                        }
                        else
                        {
                            format(string, sizeof(string), "House %d Owner: %s. Press ~k~~PED_DUCK~ to enter", h, Houses[h][hOwner]);
                            CreateDynamic3DTextLabel(string, YELLOW, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                        }
                    }
                }
                for(new h = 0; h < sizeof(Jobs); h++)
                {
                    if(IsPlayerInRangeOfPoint(i, 5, Jobs[h][JobJoinPosX], Jobs[h][JobJoinPosY], Jobs[h][JobJoinPosZ]))
                    {
                        if(GetPlayerVirtualWorld(i) == Jobs[h][JobJoinPosWorld] && GetPlayerInterior(i) == Jobs[h][JobJoinPosInterior])
                        {
                            format(string, sizeof(string), "~w~Job ~y~%s ~w~ ~n~ /joinjob", Jobs[h][JobName]);
                            GameTextForPlayer(i, string, 3500, 3);
                        }
                    }
                    if(IsPlayerInRangeOfPoint(i, 5, Jobs[h][JobMiscLocationOneX], Jobs[h][JobMiscLocationOneY], Jobs[h][JobMiscLocationOneZ]))
                    {
                        if(GetPlayerVirtualWorld(i) == Jobs[h][JobMiscLocationOneWorld] && GetPlayerInterior(i) == Jobs[h][JobMiscLocationOneInterior])
                        {
                            format(string, sizeof(string), "~w~ %s", Jobs[h][JobMiscLocationOneMessage]);
                            GameTextForPlayer(i, string, 3500, 3);
                        }
                    }
                    if(IsPlayerInRangeOfPoint(i, 5, Jobs[h][JobMiscLocationTwoX], Jobs[h][JobMiscLocationTwoY], Jobs[h][JobMiscLocationTwoZ]))
                    {
                        if(GetPlayerVirtualWorld(i) == Jobs[h][JobMiscLocationTwoWorld] && GetPlayerInterior(i) == Jobs[h][JobMiscLocationTwoInterior])
                        {
                            format(string, sizeof(string), "~w~ %s", Jobs[h][JobMiscLocationTwoMessage]);
                            GameTextForPlayer(i, string, 3500, 3);
                        }
                    }
                }

                for(new h = 0; h < sizeof(Groups); h++)
                {
                    if(GetPlayerVirtualWorld(i) == 0)
                    {
                        format(string, sizeof(string), "~w~Group %s's HQ. Press ~k~~PED_DUCK~ ~w~ to enter", Groups[h][GroupName]);
                        CreateDynamic3DTextLabel(string, YELLOW, Groups[h][HQExteriorX], Groups[h][HQExteriorY], Groups[h][HQExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                    }
                    if(IsPlayerInRangeOfPoint(i, 5, Groups[h][SafeX], Groups[h][SafeY], Groups[h][SafeZ]))
                    {
                       if(GetPlayerVirtualWorld(i) == Groups[h][SafeWorld])
                        {
                            format(string, sizeof(string), "~w~Group ~y~%s's ~w~ Safe.", Groups[h][GroupName]);
                            GameTextForPlayer(i, string, 3500, 3);
                        }
                    }
                }
            }
        }
    }
    return 1;
}
Reply
#4

Vince would be correct. It seems like you're creating 500 labels at a single position. After creating the label, you need to stop the loop. To do that, add this: break;
Reply
#5

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Vince would be correct. It seems like you're creating 500 labels at a single position. After creating the label, you need to stop the loop. To do that, add this: break;
Now the label doesn't appear.
Heres the code.
pawn Код:
for(new h = 0; h < sizeof(Businesses); h++)
                {
                    if(GetPlayerVirtualWorld(i) == 0)
                    {
                        if(strcmp(Businesses[h][bOwner], "Nobody", true) == 0)
                        {
                            if(Businesses[h][bPrice] == -1)
                            {
                                format(string, sizeof(string), "Business %d (%s) Unavailable.", h, Businesses[h][bName]);
                                CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                                break;
                            }
                            else
                            {
                                format(string, sizeof(string), "Business %d (%s) Available to buy for %d (/buybusiness).", h, Businesses[h][bName], Businesses[h][bPrice]);
                                CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                                break;
                            }
                        }
                        else
                        {
                            format(string, sizeof(string), "Business %d (%s) Owner: %s. Press ~k~~PED_DUCK~  to enter", h, Businesses[h][bName], Businesses[h][bOwner]);
                            CreateDynamic3DTextLabel(string, YELLOW, Businesses[h][bExteriorX], Businesses[h][bExteriorY], Businesses[h][bExteriorZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 5.0);
                            break;
                        }  
                    }
                }
Reply
#6

Oh, my apologies!

Call "break;" after the "IsPlayerInRangeOfPoint" brace closes. So...

pawn Код:
}
      break;
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Oh, my apologies!

Call "break;" after the "IsPlayerInRangeOfPoint" brace closes. So...

pawn Код:
}
      break;
    }
    return 1;
}
Thanks for the help.
Reply
#8

I have a few tips for you about the structure of your business system and your loop.

1) The Businesses[h][bOwner] array contains a string in all cases. When no-body owns the business, it has "Nobody" stored in it. Instead, you could revert to using something simpler, for example store "*" as the business owner name (if you have no unique ID system in place for managing user accounts on your server). This will have 2 benefits: faster string setting (in theory) and faster comparison.
Currently you stick to using the strcmp (string comparison) function for "Nobody", while you could easily just do
pawn Код:
if(Businesses[h][bOwner][0] == '*')
... to see if the house is unowned.

2) Refrain from having the loop run code which is not vital for the loop functioning itself. An example is your virtual world getting call. This can be run either (sizeof(Businesses)) times for each player or just one time for each player. You decide which is better.

3) Good practice would be to have easier functions evaluated first. For example, if you're going to call code in this sequence:
a) IsPlayerInRangeOfPoint
b) IsPlayerConnectedEx
c) IsPlayerSpawned
... and the result of IsPlayerInRangeOfPoint does not affect the function calls b) and c), you will be better of calling functions that execute less code, before those which require more computing. Position comparison is a somewhat complex process considering the complexity of your loop.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)