[Include] Command Processor [Faster Than I-ZCMD!]
#1

Command Processor

Description

This include forwards in-game command input to hard-coded functions, at a fast speed.

Benchmarks with I-ZCMD (5 consecutive tests):

Код:
This Include: 513 | 10/11/2016
This Include: 522 | 10/11/2016
This Include: 512 | 10/11/2016
This Include: 508 | 10/11/2016
This Include: 513 | 10/11/2016

I-ZCMD: 1,111 | 10/08/2016
I-ZCMD: 1,106 | 10/08/2016
I-ZCMD: 1,105 | 10/08/2016
I-ZCMD: 1,118 | 10/08/2016
I-ZCMD: 1,115 | 10/08/2016
Exclusive benchmarks with Pawn.CMD, as Pawn.CMD's commands are truncated to 24 characters and this include's commands are truncated to 27 characters (5 consecutive tests):

Код:
With Callbacks:

This Include: 568 | 10/11/2016
This Include: 571 | 10/11/2016
This Include: 571 | 10/11/2016
This Include: 570 | 10/11/2016
This Include: 569 | 10/11/2016

Pawn.CMD: 1,434 | 10/10/2016
Pawn.CMD: 1,443 | 10/10/2016
Pawn.CMD: 1,432 | 10/10/2016
Pawn.CMD: 1,450 | 10/10/2016
Pawn.CMD: 1,449 | 10/10/2016

Without Callbacks:

This Include: 533 | 10/11/2016
This Include: 531 | 10/11/2016
This Include: 528 | 10/11/2016
This Include: 533 | 10/11/2016
This Include: 532 | 10/11/2016

Pawn.CMD: 484 | 10/10/2016
Pawn.CMD: 497 | 10/10/2016
Pawn.CMD: 484 | 10/10/2016
Pawn.CMD: 487 | 10/10/2016
Pawn.CMD: 491 | 10/10/2016
Old benchmarks of this include in comparison with Pawn.CMD as it updates:

Код:
With Callbacks:

This Include: 659 | 10/10/2016
This Include: 658 | 10/10/2016
This Include: 663 | 10/10/2016
This Include: 661 | 10/10/2016
This Include: 664 | 10/10/2016

Without Callbacks:

This Include: 624 | 10/10/2016
This Include: 626 | 10/10/2016
This Include: 623 | 10/10/2016
This Include: 623 | 10/10/2016
This Include: 624 | 10/10/2016
Old benchmarks of this include as it updates (Code: This Include | I-ZCMD):

Код:
This Include: 613 | 10/10/2016
This Include: 610 | 10/10/2016
This Include: 613 | 10/10/2016
This Include: 617 | 10/10/2016
This Include: 612 | 10/10/2016

This Include: 841 | 10/10/2016
This Include: 848 | 10/10/2016
This Include: 843 | 10/10/2016
This Include: 846 | 10/10/2016
This Include: 850 | 10/10/2016

This Include: 866 | 10/09/2016
This Include: 861 | 10/09/2016
This Include: 864 | 10/09/2016
This Include: 865 | 10/09/2016
This Include: 863 | 10/09/2016

This Include: 882 | 10/08/2016
This Include: 893 | 10/08/2016
This Include: 878 | 10/08/2016
This Include: 883 | 10/08/2016
This Include: 892 | 10/08/2016
Code used to benchmark this include and I-ZCMD (just note the changes in the arguments of OnPlayerCommandPerformed):

PHP код:
// ** MAIN
main()
{
    new 
tick GetTickCount();
    for(new 
050000++)
    {
        
OnPlayerCommandText(0"/AaaaaaaaaaaaaaaAaaaaaaaaAa6 test");
        
OnPlayerCommandText(0"/AaaaaaaaaaaaaaaAaaaaaaaaAa6 test");
        
OnPlayerCommandText(0"/AaaaaaaaaaaaaaaAaaaaaaaaAa6 test");
    }
    
printf("%d"GetTickCount() - tick);
}
// ** CALLBACKS
public OnGameModeInit()
{
    return 
1;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerCommandPerformed(playeridcmd[], params[], success)
{
    
/*if(success)
    {
        print("success true");
    }
    else
    {
        print("success false");
    }*/
    
return 1;
}
// ** COMMANDS
CMD:aaaaaaaaaaaaaaaaaaaaaaaaaa6(playeridparams[])
{
    
//printf("%d %s", playerid, params);
    
return 1;

Code used to benchmark this include with Pawn.CMD:

PHP код:
// ** INCLUDES
#include <a_samp>
#include <sscanf2>
#include <command_processor>
// ** MAIN
main()
{
    print(
"Loaded \"command_processor_benchmark.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
    return 
1;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    new 
tick GetTickCount();
    for(new 
050000++)
    {
        
OnPlayerCommandText(playerid"/AaaaaaaaaaaaAaaaaaaaaAa6 test");
        
OnPlayerCommandText(playerid"/AaaaaaaaaaaaAaaaaaaaaAa6 test");
        
OnPlayerCommandText(playerid"/AaaaaaaaaaaaAaaaaaaaaAa6 test");
    }
    
printf("%d"GetTickCount() - tick);
    return 
1;
}
public 
OnPlayerCommandReceived(playeridcmd[], params[])
{
    return 
1;
}
public 
OnPlayerCommandPerformed(playeridcmd[], params[], success)
{
    
/*if(success)
    {
        print("success true");
    }
    else
    {
        print("success false");
    }*/
    
return 1;
}
// ** COMMANDS
command(aaaaaaaaaaaaaaaaaaaaaaa6playeridparams[])
{
    
//printf("%d %s", playerid, params);
    
return 1;

Code used to benchmark Pawn.CMD with this include (please note that PC_EmulateCommand does not fully execute if the player isn't connected):

PHP код:
// ** INCLUDES
#include <a_samp>
#include <Pawn.CMD>
// ** MAIN
main()
{
    print(
"Loaded \"command_processor_pawncmd_benchmark.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
    return 
1;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    new 
tick GetTickCount();
    for(new 
050000++)
    {
        
PC_EmulateCommand(playerid"/AaaaaaaaaaaaAaaaaaaaaAa6 test");
        
PC_EmulateCommand(playerid"/AaaaaaaaaaaaAaaaaaaaaAa6 test");
        
PC_EmulateCommand(playerid"/AaaaaaaaaaaaAaaaaaaaaAa6 test");
    }
    
printf("%d"GetTickCount() - tick);
    return 
1;
}
public 
OnPlayerCommandReceived(playeridcmd[], params[], flags
{
    return 
1;
}
public 
OnPlayerCommandPerformed(playeridcmd[], params[], resultflags)
{
    
/*if(result)
    {
        print("result true");
    }
    else
    {
        print("result false");
    }*/
    
return 1;
}
// ** COMMANDS
CMD:aaaaaaaaaaaaaaaaaaaaaaa6(playeridparams[])
{
    
//printf("%d %s", playerid, params);
    
return 1;

Callbacks:

Код:
forward OnPlayerCommandReceived(playerid, cmd[], params[]); - Please note that cmd does not include the slash "/".
forward OnPlayerCommandPerformed(playerid, cmd[], params[], success); - Please note that cmd does not include the slash "/".
Other:

Код:
- isnull macro will be defined by the include
The example script (command_processor_example.pwn) and the include (command_processor.inc) requires: Download

https://github.com/Kevin-Reinke/Command_Processor
Reply
#2

Nice one! I'll use it. I honestly don't really care what is fast and what isn't fast, I don't really make difference, but I still always download includes that are supposed to be the fastest so this one is nice. :P
Reply
#3

Why should anyone here download this one? there's no noticeable difference ingame
Reply
#4

Quote:
Originally Posted by XBrianX
Посмотреть сообщение
Why should anyone here download this one? there's no noticeable difference ingame
That's debatable.

Код:
ZCMD: 2,163
ZCMD: 2,147
ZCMD: 2,124
ZCMD: 2,160
ZCMD: 2,156
These benchmarks are done on commands/functions that have plain nothing. Adding stuff to commands will increase the time they take to execute. You may not see any significant difference in-game, but processes add up. So you could say it would benefit you, even at the tiniest bit.

Nonetheless, it doesn't hurt to speed things up a bit, nor would you get anything better out of things that are a bit slower. When needed however, you could choose functionality over speed. But it's always better to try to get the best of it, regardless.
Reply
#5

Congratulations! I'm going to use this.
Reply
#6

So the coding syntax for the command remains the same? Like for example I wanted to create a command with the syntax, CMD: or command( etc??

And what's new with this command processor compare to the other command processor (excluding the performance speed)?
Reply
#7

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
So the coding syntax for the command remains the same? Like for example I wanted to create a command with the syntax, CMD: or command( etc??

And what's new with this command processor compare to the other command processor (excluding the performance speed)?
Код:
#define CMD:%1(%2) forward cmd_%1(%2); public cmd_%1(%2)
#define COMMAND:%1(%2) forward cmd_%1(%2); public cmd_%1(%2)
Buen trabajo Sick, mientras mбs rбpido mejor, lo usarй.
Reply
#8

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
So the coding syntax for the command remains the same? Like for example I wanted to create a command with the syntax, CMD: or command( etc??

And what's new with this command processor compare to the other command processor (excluding the performance speed)?
OMG, I'M WONDERING THE SAME
please give us a quick answer, I'd like to switch to this asap
Reply
#9

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
So the coding syntax for the command remains the same? Like for example I wanted to create a command with the syntax, CMD: or command( etc??

And what's new with this command processor compare to the other command processor (excluding the performance speed)?
Yeah, the way you create commands is the same. The only thing new besides the performance boost is that the macro (which I just added - though, this is a different command processor from ZCMD) "cmd/command(mycommand, playerid, params[])" can also be defined without params "cmd/command(mycommand, playerid)" where in ZCMD this isn't possible.

Feel free to leave your suggestions, that's of course if you have any. Like a built-in command list?

--------------------

Thanks.
Reply
#10

Command flags, command array, ID's... That's all I'll suggest for now. If you really want to do more than IZCMD than you must add more than what IZCMD has.
Reply
#11

Doesn't this limit params? The reason why I never used something like this is because of that.
(Unless the text box is actually limited to 156 characters ('/' + 27 + space + 127))
Reply
#12

I was always wondering why nobody has used sscanf to split them so far and finally someone did!

@Stinged: You can only enter 128 characters so if a command has one letter like /a <text>, then 125 characters + 1 for NULL are enough for params.
Reply
#13

I have a question: how can I disable commands, like let's say I don't want players that are not logged in to use any commands. With ZCMD I could do it with OnPlayerCommandReceived, but I just found that this include doesn't have OnPlayerCommandReceived and I can't do it with OnPlayerCommandPerformed.
Reply
#14

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
I have a question: how can I disable commands, like let's say I don't want players that are not logged in to use any commands. With ZCMD I could do it with OnPlayerCommandReceived, but I just found that this include doesn't have OnPlayerCommandReceived and I can't do it with OnPlayerCommandPerformed.
For now you can add three lines at the top of it:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    #if defined OnPlayerCommandReceived
        if (!OnPlayerCommandReceived(playerid, cmdtext)) return 1;
    #endif
   
    ...
}
and an example:
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if (!gPlayer_LoggedIn[playerid]) return 0;
    return 1;
}
For certain commands, use strcmp + length parameter of it to compare only the command's name and ignore params.

Something last I forgot:
pawn Код:
#if defined OnPlayerCommandReceived
    forward OnPlayerCommandReceived(playerid, cmdtext[]);
#endif
@SickAttack: Add isnull macro too. What about the two callbacks to provide "cmd" and "params" parameters instead of "cmdtext"?
Reply
#15

I know more faster than that but good work.
Reply
#16

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
For now you can add three lines at the top of it:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    #if defined OnPlayerCommandReceived
        if (!OnPlayerCommandReceived(playerid, cmdtext)) return 1;
    #endif
   
    ...
}
and an example:
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if (!gPlayer_LoggedIn[playerid]) return 0;
    return 1;
}
For certain commands, use strcmp + length parameter of it to compare only the command's name and ignore params.

Something last I forgot:
pawn Код:
#if defined OnPlayerCommandReceived
    forward OnPlayerCommandReceived(playerid, cmdtext[]);
#endif
@SickAttack: Add isnull macro too. What about the two callbacks to provide "cmd" and "params" parameters instead of "cmdtext"?
Thanks.
Reply
#17

I updated the include. OnPlayerCommandReceived is now there (returning 0 in the callback will stop a command from executing), and here are the latest benchmarks as there has been some improvements (5 consecutive tests):

Код:
This Include: 866
This Include: 861
This Include: 864
This Include: 865
This Include: 863
Old benchmarks:

Код:
This Include: 882
This Include: 893
This Include: 878
This Include: 883
This Include: 892
Despite that, isnull macro has been added and OnPlayerCommandPerformed has new arguments:

Код:
forward OnPlayerCommandPerformed(playerid, cmd[], params[], success); - Please note that cmd does not include the slash "/".
This is OnPlayerCommandReceived's arguments:

Код:
forward OnPlayerCommandReceived(playerid, cmd[], params[]); - Please note that cmd does not include the slash "/".
Quote:
Originally Posted by Stinged
Посмотреть сообщение
Doesn't this limit params? The reason why I never used something like this is because of that.
(Unless the text box is actually limited to 156 characters ('/' + 27 + space + 127))
User input is limited to 128 characters.

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
I have a question: how can I disable commands, like let's say I don't want players that are not logged in to use any commands. With ZCMD I could do it with OnPlayerCommandReceived, but I just found that this include doesn't have OnPlayerCommandReceived and I can't do it with OnPlayerCommandPerformed.
Now you can, redownload the include.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
For now you can add three lines at the top of it:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    #if defined OnPlayerCommandReceived
        if (!OnPlayerCommandReceived(playerid, cmdtext)) return 1;
    #endif
   
    ...
}
and an example:
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if (!gPlayer_LoggedIn[playerid]) return 0;
    return 1;
}
For certain commands, use strcmp + length parameter of it to compare only the command's name and ignore params.

Something last I forgot:
pawn Код:
#if defined OnPlayerCommandReceived
    forward OnPlayerCommandReceived(playerid, cmdtext[]);
#endif
@SickAttack: Add isnull macro too. What about the two callbacks to provide "cmd" and "params" parameters instead of "cmdtext"?
All good now.

Quote:
Originally Posted by Eymeric69
Посмотреть сообщение
I know more faster than that but good work.
Plugins don't really count in this scenario. ** yeah, yeah, a bit contradictory ** But everyone uses SSCANF, so this is a good alternative.

-------------------------------

Thanks to everyone!
Reply
#18

Can you add a function to check if a command exists?
ex:
PHP код:
CommandExist(cmd[]); 
returns 1 if exist 0 if not, it would be useful to block the existing commands from being used by non registered / logged in users while they yet can use the unknow commands....

btw Good job.
Reply
#19

Quote:
Originally Posted by jlalt
Посмотреть сообщение
Can you add a function to check if a command exists?
ex:
PHP код:
CommandExist(cmd[]); 
returns 1 if exist 0 if not, it would be useful to block the existing commands from being used by non registered / logged in users while they yet can use the unknow commands....

btw Good job.
OnPlayerCommandReceived could help you achieve that, it will be called if a command that hasn't been performed yet exists. If you return 0 in the callback, the command will not proceed to execute. Take advantage of the cmd argument.

Please note that cmd does not include the slash "/".

I'm planning on adding a built-in command list, so that function will most like be introduced later on without you having to do anything with OnPlayerCommandReceived.
Reply
#20

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
OnPlayerCommandReceived could help you achieve that, it will be called if a command exists and will yet not perform. Take advantage of the cmd[] argument.

Please note that cmd[] does not include the slash "/".

I'm planning on adding a built-in command list, so that function will most like be introduced later on without you having to do anything with OnPlayerCommandReceived.
Nevermind.
didn't read your reply properly lol.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)