SA-MP Forums

Go Back   SA-MP Forums > Non-English > Languages > Русский/Russian

Reply
 
Thread Tools Display Modes
Old 16/11/2017, 04:45 PM   #1311
ZiGGi
Banned
 
Join Date: Sep 2008
Location: Russia
Posts: 1,659
Reputation: 356
Default Re: Оптимизация кода

Quote:
Originally Posted by Sia View Post
У меня лагает мод + сервер. Я посоветовался с профессионалом, он сказал нужно сделать балансировку серверного стёка. Но как сделать не сказал, поэтому прошу помощи у вас
Quote:
Originally Posted by White_116 View Post
А ещё провести профилирование и выявить узкие места.
И провести аудит программного обеспечения.

А если серьёзно, то ставь profiler плагин и ищи самые медленные места твоего скрипта. А если твой сервер стоит на каком-нибудь бесплатном хостинге, то вывод очевиден.
ZiGGi is offline   Reply With Quote
Old 25/11/2019, 07:35 PM   #1312
bgAndroid
Little Clucker
 
bgAndroid's Avatar
 
Join Date: Apr 2019
Posts: 12
Reputation: 0
Default Re: Оптимизация кода

Как лучше всего оптимизировать данный код?

PHP Code:
cmd:lock(playerid)
{
    if (
GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
        new
            
vehicleid GetPlayerVehicleID(playerid);
        switch (
GetVehicleType(vehicleid)) {
            case 
VEHICLE_TYPE_BIKEVEHICLE_TYPE_TRAILERVEHICLE_TYPE_RC:
                return 
1;
        }
        if (
Vehicle[vehicleid][Doors] == false)
            
SetPlayerChatBubble(playerid"закрыл"COLOR_HELIOTROPE10.04000);
        else
            
SetPlayerChatBubble(playerid"открыл"COLOR_HELIOTROPE10.04000);
        
ToggleVehicleDoors(vehicleid);
        return 
1;
    }
    else if (
p_Vehicle_VehicleID[playerid] != INVALID_VEHICLE_ID && Vehicle[p_Vehicle_VehicleID[playerid]][Doors] == true) {
        new
            
Float:pl_pos_xFloat:pl_pos_yFloat:pl_pos_z;
        
GetVehiclePos(p_Vehicle_VehicleID[playerid], pl_pos_xpl_pos_ypl_pos_z);
        if (
IsPlayerInRangeOfPoint(playerid5.0pl_pos_xpl_pos_ypl_pos_z)) {
            
SetPlayerChatBubble(playerid"открыл"COLOR_HELIOTROPE10.04000);

            
ToggleVehicleDoors(p_Vehicle_VehicleID[playerid]);
            
p_Vehicle_VehicleID[playerid] = INVALID_VEHICLE_ID;
            return 
1;
        }
    }
    new 
vehicle1;
    new 
Float:a_last_distance 7.0Float:a_distance;
    new 
Float:a_pos_xFloat:a_pos_yFloat:a_pos_z;
    foreach (new 
p_Player_Vehicles[playerid]) {
        
GetVehiclePos(ia_pos_xa_pos_ya_pos_z);
        
a_distance GetPlayerDistanceFromPoint(playerida_pos_xa_pos_ya_pos_z);
        if (
floatcmp(a_distancea_last_distance) == -1) {
            
a_last_distance a_distance;
            
vehicle1i;
        }
    }

    
GetVehiclePos(vehicle1a_pos_xa_pos_ya_pos_z);
    if (
IsPlayerInRangeOfPoint(playerid10.0a_pos_xa_pos_ya_pos_z)) {
        if (
Vehicle[vehicle1][Doors] == false)
            
SetPlayerChatBubble(playerid"закрыл"COLOR_HELIOTROPE10.04000);
        else
            
SetPlayerChatBubble(playerid"открыл"COLOR_HELIOTROPE10.04000);
        
ToggleVehicleDoors(vehicle1);
    }
    else {
        
SendClientMessage(playerid, -1"Ты не за рулем");
    }
    return 
1;

__________________
Kalcor
1. Add https protocol
2. Fix the bug in SetObjectMaterialText when the transparency is set to materialcolor = 10FFFF00 (ARGB), but if you set "12 {ff0000}" the transparency disappears
3. Make saving the radio in the car, let's say the player turned it off, and re-entered the game, it will not play
4. Add parameters fontface and fontsize in Create3DTextLabel analog - (SetObjectMaterialText)
5. Add MoveTextDraw
6. Limit object - 2000
7. TogglePlayerHUD(playerid, component, bool:toggle); // component - 0 - Radar, 1 - Money, 2 - HealthBar, etc.
8. Return grass from gta sa in samp
bgAndroid is offline   Reply With Quote
Old 25/11/2019, 08:13 PM   #1313
eakwarp
High-roller
 
Join Date: Feb 2007
Posts: 1,912
Reputation: 131
Default Re: Оптимизация кода

Quote:
Originally Posted by bgAndroid View Post
Как лучше всего оптимизировать данный код?

PHP Code:
cmd:lock(playerid)
{
    if (
GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
        new
            
vehicleid GetPlayerVehicleID(playerid);
        switch (
GetVehicleType(vehicleid)) {
            case 
VEHICLE_TYPE_BIKEVEHICLE_TYPE_TRAILERVEHICLE_TYPE_RC:
                return 
1;
        }
        if (
Vehicle[vehicleid][Doors] == false)
            
SetPlayerChatBubble(playerid"закрыл"COLOR_HELIOTROPE10.04000);
        else
            
SetPlayerChatBubble(playerid"открыл"COLOR_HELIOTROPE10.04000);
        
ToggleVehicleDoors(vehicleid);
        return 
1;
    }
    else if (
p_Vehicle_VehicleID[playerid] != INVALID_VEHICLE_ID && Vehicle[p_Vehicle_VehicleID[playerid]][Doors] == true) {
        new
            
Float:pl_pos_xFloat:pl_pos_yFloat:pl_pos_z;
        
GetVehiclePos(p_Vehicle_VehicleID[playerid], pl_pos_xpl_pos_ypl_pos_z);
        if (
IsPlayerInRangeOfPoint(playerid5.0pl_pos_xpl_pos_ypl_pos_z)) {
            
SetPlayerChatBubble(playerid"открыл"COLOR_HELIOTROPE10.04000);

            
ToggleVehicleDoors(p_Vehicle_VehicleID[playerid]);
            
p_Vehicle_VehicleID[playerid] = INVALID_VEHICLE_ID;
            return 
1;
        }
    }
    new 
vehicle1;
    new 
Float:a_last_distance 7.0Float:a_distance;
    new 
Float:a_pos_xFloat:a_pos_yFloat:a_pos_z;
    foreach (new 
p_Player_Vehicles[playerid]) {
        
GetVehiclePos(ia_pos_xa_pos_ya_pos_z);
        
a_distance GetPlayerDistanceFromPoint(playerida_pos_xa_pos_ya_pos_z);
        if (
floatcmp(a_distancea_last_distance) == -1) {
            
a_last_distance a_distance;
            
vehicle1i;
        }
    }

    
GetVehiclePos(vehicle1a_pos_xa_pos_ya_pos_z);
    if (
IsPlayerInRangeOfPoint(playerid10.0a_pos_xa_pos_ya_pos_z)) {
        if (
Vehicle[vehicle1][Doors] == false)
            
SetPlayerChatBubble(playerid"закрыл"COLOR_HELIOTROPE10.04000);
        else
            
SetPlayerChatBubble(playerid"открыл"COLOR_HELIOTROPE10.04000);
        
ToggleVehicleDoors(vehicle1);
    }
    else {
        
SendClientMessage(playerid, -1"Ты не за рулем");
    }
    return 
1;

Зачем? Тут итак все нормально.
__________________
More than 10 years of development, more than 40 mb(sic! 1 kk lines+) of source code, more than a two hundred units and more than 35k revisions(upd. aug 2017). Valakas Roleplay - choose your role.

Как правило, то, что делаю я, лишь через годы начинают делать другие, но потом, обязательно мне ставят в укор, "ой, да это уже у всех есть"...



[Gamemode] Valakas Trucker Roleplay (Russian).
eakwarp is offline   Reply With Quote
Old 27/11/2019, 02:56 PM   #1314
OKStyle
High-roller
 
OKStyle's Avatar
 
Join Date: May 2008
Location: Russia, Orenburg Money: GTA$ 999,999,999
Posts: 3,125
Reputation: 142
Default Re: Оптимизация кода

Кроме читабельности.
__________________
O.K.Style™ Laboratory
Kalcor: "... it's makes the game look like it's not GTA. This mod is called San Andreas Multiplayer. It's not a custom game engine which you can script..."
OKStyle is offline   Reply With Quote
Old 28/11/2019, 07:07 AM   #1315
Argument
Big Clucker
 
Join Date: Jan 2015
Location: :/
Posts: 55
Reputation: 4
Default Re: Оптимизация кода

Quote:
Originally Posted by OKStyle View Post
Кроме читабельности.
Ваш вариант в студию.
__________________
SA-MP 0.4a is released!
Download: http://files.sa-mp.com/sa-mp-0.4a-install.exe
english is bad
Argument is offline   Reply With Quote
Old 28/11/2019, 01:57 PM   #1316
Jaaaar
Little Clucker
 
Join Date: Mar 2019
Posts: 19
Reputation: 0
Default Re: Оптимизация кода

Че у самперов за мода после new перенос делать? При этом скобку пишет на той же строке, что и условие лол, думаешь код быстрее работать станет? На своем проекте руки бы сломал за такое
Jaaaar is offline   Reply With Quote
Old 29/11/2019, 09:31 AM   #1317
bgAndroid
Little Clucker
 
bgAndroid's Avatar
 
Join Date: Apr 2019
Posts: 12
Reputation: 0
Default Re: Оптимизация кода

Quote:
Originally Posted by Jaaaar View Post
Че у самперов за мода после new перенос делать? При этом скобку пишет на той же строке, что и условие лол, думаешь код быстрее работать станет? На своем проекте руки бы сломал за такое
Какая разница как я код пишу? У каждого свой стиль..
__________________
Kalcor
1. Add https protocol
2. Fix the bug in SetObjectMaterialText when the transparency is set to materialcolor = 10FFFF00 (ARGB), but if you set "12 {ff0000}" the transparency disappears
3. Make saving the radio in the car, let's say the player turned it off, and re-entered the game, it will not play
4. Add parameters fontface and fontsize in Create3DTextLabel analog - (SetObjectMaterialText)
5. Add MoveTextDraw
6. Limit object - 2000
7. TogglePlayerHUD(playerid, component, bool:toggle); // component - 0 - Radar, 1 - Money, 2 - HealthBar, etc.
8. Return grass from gta sa in samp
bgAndroid is offline   Reply With Quote
Old 29/11/2019, 03:37 PM   #1318
OKStyle
High-roller
 
OKStyle's Avatar
 
Join Date: May 2008
Location: Russia, Orenburg Money: GTA$ 999,999,999
Posts: 3,125
Reputation: 142
Default Re: Оптимизация кода

Как-то так. Оптимизировал и сделал читабельным:

PHP Code:
cmd:lock(playerid)
{
    new 
vehicleidFloat:pl_pos_xFloat:pl_pos_yFloat:pl_pos_z;
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        
vehicleid GetPlayerVehicleID(playerid), vtype GetVehicleType(vehicleid);
        switch(
vtype)
        {
            case 
VEHICLE_TYPE_BIKEVEHICLE_TYPE_TRAILERVEHICLE_TYPE_RC: return 1;
            default:
            {
                if(
Vehicle[vehicleid][Doors] == falseSetPlayerChatBubble(playerid, !"закрыл"COLOR_HELIOTROPE10.04000);
                else 
SetPlayerChatBubble(playerid, !"открыл"COLOR_HELIOTROPE10.04000);
                
ToggleVehicleDoors(vehicleid);
                return 
1;
            }
        }
        
    }
    else if(
p_Vehicle_VehicleID[playerid] != INVALID_VEHICLE_ID && Vehicle[p_Vehicle_VehicleID[playerid]][Doors] == true)
    {
        
GetVehiclePos(p_Vehicle_VehicleID[playerid], pl_pos_xpl_pos_ypl_pos_z);
        if(
IsPlayerInRangeOfPoint(playerid5.0pl_pos_xpl_pos_ypl_pos_z))
        {
            
SetPlayerChatBubble(playerid, !"открыл"COLOR_HELIOTROPE10.04000);
            
ToggleVehicleDoors(p_Vehicle_VehicleID[playerid]);
            
p_Vehicle_VehicleID[playerid] = INVALID_VEHICLE_ID;
            return 
1;
        }
    }
    new 
Float:a_last_distance 7.0Float:a_distance;
    foreach (new 
p_Player_Vehicles[playerid])
    {
        
GetVehiclePos(ipl_pos_xpl_pos_ypl_pos_z);
        
a_distance GetPlayerDistanceFromPoint(playeridpl_pos_xpl_pos_ypl_pos_z);
        if(
floatcmp(a_distancea_last_distance) == -1)
        {
            
a_last_distance a_distance;
            
vehicleid i;
        }
    }
    
GetVehiclePos(vehicleidpl_pos_xpl_pos_ypl_pos_z);
    if(!
IsPlayerInRangeOfPoint(playerid10.0pl_pos_xpl_pos_ypl_pos_z)) return SendClientMessage(playerid, -1, !"Ты не рядом с авто");
    if(
Vehicle[vehicleid][Doors] == falseSetPlayerChatBubble(playerid, !"закрыл"COLOR_HELIOTROPE10.04000);
    else 
SetPlayerChatBubble(playerid, !"открыл"COLOR_HELIOTROPE10.04000);
    
ToggleVehicleDoors(vehicleid);
    return 
1;

__________________
O.K.Style™ Laboratory
Kalcor: "... it's makes the game look like it's not GTA. This mod is called San Andreas Multiplayer. It's not a custom game engine which you can script..."
OKStyle is offline   Reply With Quote
Old 29/04/2020, 06:42 AM   #1319
natovan
Little Clucker
 
natovan's Avatar
 
Join Date: Nov 2019
Posts: 31
Reputation: 0
Default Re: Оптимизация кода

30 - 40 миллисекунд за 500 сообщений игрока в общий чат это нормально?
natovan is offline   Reply With Quote
Old 02/05/2020, 05:21 AM   #1320
eakwarp
High-roller
 
Join Date: Feb 2007
Posts: 1,912
Reputation: 131
Default Re: Оптимизация кода

Quote:
Originally Posted by natovan View Post
30 - 40 миллисекунд за 500 сообщений игрока в общий чат это нормально?
Можно на русском?
__________________
More than 10 years of development, more than 40 mb(sic! 1 kk lines+) of source code, more than a two hundred units and more than 35k revisions(upd. aug 2017). Valakas Roleplay - choose your role.

Как правило, то, что делаю я, лишь через годы начинают делать другие, но потом, обязательно мне ставят в укор, "ой, да это уже у всех есть"...



[Gamemode] Valakas Trucker Roleplay (Russian).
eakwarp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 03:24 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.