[Include] BTXT - Fast and Easy Text Processor
#1

This time I want to introduce you an include, where you can use normal text inputs as commands which will be performed faster than using strcmp checks in OnPlayerText.

I've created this include because my heart bleeds if some peoples starts to script text string checks in OnPlayerText by using strcmp checks.
Example: http://pastebin.com/3sMRVaMY

Anyways this include is very easy to use, is not case sensitive, is very fast and can detect strings for params array.

How to use this include?
It's quite easy to use. (Idea from ZCMD)
You can use

pawn Код:
TXT:hello(playerid, params[])
or
pawn Код:
TEXT:hello(playerid, params[])
or (not recommend)
pawn Код:
forward txt_hello(playerid, params[]);
public txt_hello(playerid, params[])
//...
Код:
TXT:hello(playerid, params[])
Callback start:
Код:
TXT:
Text string:
Код:
hello
Player ID
Код:
playerid
Params string:
Код:
params[]
Example:
pawn Код:
TXT:test(playerid, params[])
{
    new str[128];
    format(str, 128, "You have wrote 'test' with following params: '%s'", params);
    SendClientMessage(playerid, 0xFF0000FF, str);
    return 0;
}
Even you can use the sscanf include/plugin (from ******) to parse strings to variables from params array.
https://sampforum.blast.hk/showthread.php?tid=120356


About returning values in txt_
If the callback exists, so returning 0 will deny executing TXT_OnPlayerText (muting) otherwise TXT_OnPlayerText will be also called!


Benchmark Tests
Results (Looping 10000 times through):

Код:
BTXT without params: 60-65 ms
BTXT with params (large params string): 252-263 ms

strcmp methode without params: 19037 ms
strcmp methode with params (same large params string as in BTXT check): 108984 ms
As we can see that my include is still faster than using strcmp checks in OnPlayerText.

Benchmark scripts:

http://solidfiles.com/d/8fc89eca14/

IF you find any another text processors, so please reply on this topic!

Credits:
  • Idea from ZCMD include (ZeeX)
  • Hooking methode by ******
  • Myself for creating this include
Downloads:

Download btxt.inc from Solidfiles
Download btxt.inc from Pastebin

Regards: BigETI
Reply
#2

nice
Reply
#3

Nice on!
Reply
#4

Looks cool, benchmark it with zcmd and ycmd please.
Reply
#5

Thanks

Quote:
Originally Posted by FireCat
Посмотреть сообщение
Looks cool, benchmark it with zcmd and ycmd please.
It has nothing to do with command processors..
Reply
#6

hah nice work dude
You have useful includes
Reply
#7

Thanks, I appreciate it System64
Reply
#8

This doesn't even work?

TIMING FOR STRCMP:
Код:
TIME: 1059 BOOYAKA: 1000000
TIMING FOR BTXT:
Booyaka is zero, which means the whole function wasn't even called.
Код:
TIME: 44 BOOYAKA: 0
Here's my testing script:
pawn Код:
#include <a_samp>
new booyakabooyaka;

#include <btxt>
TEXT:hello(playerid, params[])
{
    booyakabooyaka++;
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}


/*public OnPlayerText(playerid, text[])
{
    if(!strcmp("hello", text, true))
    {
        booyakabooyaka++;
    }
    return 1;
}*/



main()
{
    print("\n----------------------------------");
    print("  Bare Script\n");
    print("----------------------------------\n");
    return 1;
}

public OnGameModeInit()
{
    new check1 = GetTickCount();

    for(new i; i < 1000000; i++)
    {
        OnPlayerText(0, "hello");
    }

    new check2 = GetTickCount();

    printf("TIME: %d BOOYAKA: %d", check2-check1, booyakabooyaka);
    return 1;
}
Reply
#9

Quote:
Originally Posted by Finn
Посмотреть сообщение
This doesn't even work?

TIMING FOR STRCMP:
Код:
[20:21:02] TIME: 1059 BOOYAKA: 1000000
TIMING FOR BTXT:
Booyaka is zero, which means the whole function wasn't even called.
Код:
[20:22:36] TIME: 44 BOOYAKA: 0
Here's my testing script:
pawn Код:
#include <a_samp>
new booyakabooyaka;

#include <btxt>
TEXT:hello(playerid, params[])
{
    booyakabooyaka++;
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}


/*public OnPlayerText(playerid, text[])
{
    if(!strcmp("hello", text, true))
    {
        booyakabooyaka++;
    }
    return 1;
}*/



main()
{
    print("\n----------------------------------");
    print("  Bare Script\n");
    print("----------------------------------\n");
    return 1;
}

public OnGameModeInit()
{
    new check1 = GetTickCount();

    for(new i; i < 1000000; i++)
    {
        OnPlayerText(0, "hello");
    }

    new check2 = GetTickCount();

    printf("TIME: %d BOOYAKA: %d", check2-check1, booyakabooyaka);
    return 1;
}
You are doing it wrong. You can't use
pawn Код:
OnPlayerText(0, "hello");
as function.

Use
pawn Код:
CallLocalFunction("OnPlayerText", "ds", 0, "hello");
instead.

Anyways you are free to use my benchmark scripts which are downloadable from a file hoster and are posted in the main post.

Quote:
Originally Posted by Kerlan
Посмотреть сообщение
:/ video??
Of?
Reply
#10

Quote:
Originally Posted by BigETI
Посмотреть сообщение
Thanks



It has nothing to do with command processors..
Lol my fail. Sorry
Reply
#11

Quote:
Originally Posted by BigETI
View Post
You are doing it wrong. You can't use
Code:
OnPlayerText(0, "hello");
as function.

Use
Code:
CallLocalFunction("OnPlayerText", "ds", 0, "hello");
instead.

Anyways you are free to use my benchmark scripts which are downloadable from a file hoster and are posted in the main post.
Okay, yeah it worked now and seems to be slower than simply having strcmp:

BTXT:
Code:
TIME: 6709 BOOYAKA: 1000000
strcmp:
Code:
TIME: 1665 BOOYAKA: 1000000
Reply
#12

Quote:
Originally Posted by Finn
View Post
Okay, yeah it worked now and seems to be slower than simply having strcmp:

BTXT:
Code:
TIME: 6709 BOOYAKA: 1000000
strcmp:
Code:
TIME: 1665 BOOYAKA: 1000000
It is not about ONE check, it is about a BUNCH OF text checks.
Reply
#13

Pretty nice idea, could you put the benchmark test on pastebin too please?
Reply
#14

Good job keep it up
Reply
#15

Quote:
Originally Posted by KoczkaHUN
View Post
It is not about ONE check, it is about a BUNCH OF text checks.
I had 1 million checks, how much more does it need?
Reply
#16

That is why I think making more command processors is useless, since there are many and very good and fast ones, which can't be beated according to the speed (well, it can, but not really.. easy).

ZCMD and y_cmds is simply the best ones, which will never be replaced. That's why I think this include was a waste of your time. However, nice try and nicely done.
Reply
#17

Quote:
Originally Posted by Biesmen
View Post
That is why I think making more command processors is useless, since there are many and very good and fast ones, which can't be beated according to the speed (well, it can, but not really.. easy).

ZCMD and y_cmds is simply the best ones, which will never be replaced. That's why I think this include was a waste of your time. However, nice try and nicely done.
do you know what you are talking about?
You talk about command processor and this include is not command processor
Reply
#18

Quote:
Originally Posted by Finn
View Post
I had 1 million checks, how much more does it need?
He means that you need lots of different texts, for it to be faster.
For example,
if you have one command, then strcmp would be faster than zcmd!
Reply
#19

Quote:
Originally Posted by TheArcher
View Post
Pretty nice idea, could you put the benchmark test on pastebin too please?
Pastebin does not accept the size of my benchmark scripts.
So you're free to download it from solidfiles.
Quote:
Originally Posted by Biesmen
View Post
That is why I think making more command processors is useless, since there are many and very good and fast ones, which can't be beated according to the speed (well, it can, but not really.. easy).

ZCMD and y_cmds is simply the best ones, which will never be replaced. That's why I think this include was a waste of your time. However, nice try and nicely done.
So learn reading the topic. This include has nothing to do with commands.

Quote:
Originally Posted by Finn
View Post
Okay, yeah it worked now and seems to be slower than simply having strcmp:

BTXT:
Code:
TIME: 6709 BOOYAKA: 1000000
strcmp:
Code:
TIME: 1665 BOOYAKA: 1000000
You have probably done something wrong.
Show me your benchmark script.
Reply
#20

Quote:
Originally Posted by wups
View Post
He means that you need lots of different texts, for it to be faster.
For example,
if you have one command, then strcmp would be faster than zcmd!
Edit: Andre is right (post below)

You are right, when I tried the same with 10 texts ("hello0".."hello9"), the timings were almost the same:

strcmp:
Code:
TIME: 70570 BOOYAKA: 10000000
BTXT:
Code:
TIME: 69182 BOOYAKA: 10000000
--

Quote:
Originally Posted by BigETI
View Post
You have probably done something wrong.
Show me your benchmark script.
It's in the first page, I already posted it, but here it is again:
Code:
#include <a_samp>
new booyakabooyaka;

#include <btxt>
TEXT:hello0(playerid, params[])
{
    booyakabooyaka++;
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

/*public OnPlayerText(playerid, text[])
{
    if(!strcmp("hello0", text, true))
    {
        booyakabooyaka++;
    }
    return 1;
}*/


main()
{
    print("\n----------------------------------");
    print("  Bare Script\n");
    print("----------------------------------\n");
    return 1;
}

public OnGameModeInit()
{
    new check1 = GetTickCount();
	
    for(new i; i < 1000000; i++)
    {
        CallLocalFunction("OnPlayerText", "ds", 0, "hello0");
    }

    new check2 = GetTickCount();

    printf("TIME: %d BOOYAKA: %d", check2-check1, booyakabooyaka);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)