AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [TUT] SourcePawn Scripting - Tips, Basics to Advanced (https://forums.alliedmods.net/showthread.php?t=321089)

Dragokas 03-28-2022 09:19

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
strcopy has less logic, should be faster.
Also, if you need stringbuilder functionality, use strCat; it doesn't re-create string buffer unlike Format.

plug344 03-29-2022 04:41

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
Thank you very much,

the various "handle.method" of the new syntax seems to be just the wrapper of the old syntax, is there a difference in their speed? Such as "ClearArray (ArrayList)" and "ArrayList.Clear()", etc.

Psyk0tik 03-29-2022 07:21

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
You can use either-or. The speed is irrelevant. It’s more a matter of preference rather than which one is slightly faster.

If you’re really curious about it, you can use the profiler. Pre-optimizing your plugin is a waste of time. Unless you’re actually experiencing performance issues with your plugin, don’t worry so much about choosing the fastest method/function for every part of your code. You may end up sacrificing readability, maintainability, and simplicity for a negligible difference in speed.

Optimizing Plugins (SourceMod Scripting)

Silvers 03-29-2022 10:47

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
For something like this optimizing is negligible but I wouldn't advise against optimizing especially if the plugin will be made publicly available. Many public ones have huge performance hits due to bad practices and some servers running many plugins will feel the degradation in performance due to certain unoptimized plugins.

iaNanaNana 04-13-2022 03:50

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
I have a question: int i[N][33] or ArrayList i[33] Which is better? The before cause too many plugin file size after compiled

Marttt 04-13-2022 15:00

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
"Which is better" most of the time depends on the situation and the use case.
You should share an example and mention the "before" and "after" sizes as well.

iaNanaNana 04-15-2022 09:03

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
Quote:

Originally Posted by Marttt (Post 2776700)
"Which is better" most of the time depends on the situation and the use case.
You should share an example and mention the "before" and "after" sizes as well.

PHP Code:

int iConfig[100][MAXPLAYERS]

public 
OnClientPutInServer(a)
{
    
iConfig[0][a] = 1
}

public 
OnClientDisconnect(a)
{
    
iConfig[0][a] = 0


or
PHP Code:

ArrayList hConfig[MAXPLAYERS]

public 
OnClientPutInServer(a)
{
    
ArrayList hConfig[a] = new ArrayList(1,100)
    
hConfig[a].Set(01)
}

public 
OnClientDisconnect(a)
{
    
delete hConfig[a]


I wanna use to store clients configures when in game, reset values or delete ArrayList when disconenct.

Silvers 04-15-2022 09:30

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
Should be: MAXPLAYERS+1 not just MAXPLAYERS

Dragokas 04-15-2022 11:13

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
iaNanaNana, you don't need array of lists, it is already an "array" of blocks.
Also, alloc/release handles is a heavy operation.
See:
PHP Code:

ArrayList     hConfig;

public 
void OnPluginStart()
{
    
hConfig = new ArrayList(ByteCountToCells(4), MAXPLAYERS+1); // 4 bytes (int or float)
    
    // or
    // hConfig = new ArrayList(ByteCountToCells(4));
    // hConfig.Resize(MAXPLAYERS+1);
}

public 
void OnClientPutInServer(int client)
{
    
hConfig.Set(client10); // write 1 at block 0
}

public 
void OnClientDisconnect(int client)
{
    
hConfig.Set(client00); // write 0 at block 0


or write multiple values, e.g. int + float using different arraylist's blocks:
PHP Code:

ArrayList    hList;

public 
void OnPluginStart()
{
    
hList = new ArrayList(ByteCountToCells(8)); // 8 bytes (int + float)
}

public 
Action SomeCommand(int clientint argc)
{
    
int countattacker;
    
float hpfPercent[MAXPLAYERS+1] = ......
    
    for( 
int i 1<= MaxClientsi++ )
    {
        if( 
SomeCondition )
        {
            
hList.Resize(count 1);
            
hList.Set(cntfPercent[i], 0);     // block 0 - float (e.g. % HP)
            
hList.Set(cnti1);                // block 1 - int (client index)
            
++ count;
        }
    }

    
hList.Sort(Sort_DescendingSort_Float);
    
    for( 
int i 0hList.Lengthi++ )
    {
        
attacker al.Get(i1); // read block 1
        
hp al.Get(i0);         // read block 0
    
}
    
// ...


But, for simple tasks the simple arrays is much more faster.

sorallll 04-16-2022 00:21

Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
 
I would like to ask, how to calculate the number of bytes occupied by the string in IntToString, FloatToString


All times are GMT -4. The time now is 22:27.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.