AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] ColorLib (https://forums.alliedmods.net/showthread.php?t=320842)

c0rp3n 01-12-2020 04:12

[INC] ColorLib
 
ColorLib is built as a replacement for Colors, it uses a a less naive approach to formatting messages to improve the performance of C* functions.

Why?
The reason for this is that Colors and More Colors both make heavy use of many ReplaceString operations each one looping through the buffer being formatted, whereas this could be avoided by writing a single pass formatter as used here and was done for ColorVariables.
And to why replace ColorVariables? it also adds extra overhead with forwards and allowing for more "dynamic" colors, which isnt always needed.

So ColorLib was created.

Performance:
ColorLib is currently twice over twice as fast as MultiColors when using CPrintToChat, further and improved benchmarks will be availible at the GitHub Repository

Example:
Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <colorlib>

public void OnPluginStart()
{
    RegConsoleCmd("sm_colorlib", Command_ColorLib);
}

public Action Command_ColorLib(int client, int args)
{
    CPrintToChat(client, "CPrintToChat - {darkblue}%s - {darkred}%s", "Test", "Test");
    CPrintToChatAll("CPrintToChatAll - {darkblue}%s - {darkred}%s", "Test", "Test");
    CPrintToChatEx(client, client, "CPrintToChatEx - {darkblue}%s - {darkred}%s", "Test", "Test");
    CPrintToChatAllEx(client, "CPrintToChatAllEx - {darkblue}%s - {darkred}%s", "Test", "Test");

    CReplyToCommand(client, "CReplyToCommand - {darkblue}%s - {darkred}%s", "Test", "Test");
    CReplyToCommandEx(client, client, "CReplyToCommandEx - {darkblue}%s - {darkred}%s", "Test", "Test");

    CPrintToServer("CPrintToServer - {darkblue}%s - {darkred}%s", "Test", "Test");
}

More info and download at the GitHub Repository

404UserNotFound 01-13-2020 13:03

Re: [INC] ColorLib
 
Think I'll add support for this to my ST3 syntax highlighting. Very nice stuff.

Scag 01-13-2020 23:30

Re: [INC] ColorLib
 
This is awesome, thanks for this.

c0rp3n 01-15-2020 12:57

Re: [INC] ColorLib
 
Thanks, I'd originally planned this as an extension, but spent too much time fighting with AMBuild, so that has been delayed till I either stop hating it or I wait uppon the Rust bindings.


I shall be improving color customisation by making the color generator configurable without touching code with a config file.

Maxximou5 01-15-2020 13:42

Re: [INC] ColorLib
 
Thanks for this! I'm going to be using this in the next version of my Deathmatch plugin.

Bara 01-17-2020 20:11

Re: [INC] ColorLib
 
:bacon!:

Will already used in TTT (release soon). :up:

Ilusion9 01-23-2020 10:26

Re: [INC] ColorLib
 
Already using in my plugins.
Clean code, good job.

Scag 01-23-2020 21:47

Re: [INC] ColorLib
 
Hey I'm running into some chaos when using the inc.

https://imgur.com/66hdoXA.png

The stuff ->
PHP Code:

#include <colorlib>

public void OnPluginStart()
{
    
char strAnnounce[256];
    
strcopy(strAnnouncesizeof(strAnnounce), "You can set your {red}Boss Difficulty{default} by typing {red}/difficulty{default}.");
    
CPrintToChatAll("{olive][VSH 2]{default} %s"strAnnounce);


Using latest download from the GitHub, SM1.10 compiler if that matters at all.

hmmmmm 01-23-2020 22:53

Re: [INC] ColorLib
 
"{olive][VSH 2]{default} %s"

You're missing a closing brace for olive. Should be:
"{olive}[VSH 2]{default} %s"

Scag 01-25-2020 16:37

Re: [INC] ColorLib
 
Quote:

Originally Posted by hmmmmm (Post 2681409)
"{olive][VSH 2]{default} %s"

You're missing a closing brace for olive. Should be:
"{olive}[VSH 2]{default} %s"

(╯ ͡° ͜ʖ ͡°)╯︵ /(.□ . \)

I made a small reproduction plugin and fat-fingered that.

With fixed code:
Spoiler


Provides this output:

Ilusion9 02-06-2020 06:35

Re: [INC] ColorLib
 
It seems there's an error with CSayText2 function:

PHP Code:

Exception reportedInvalid field "params" for message "CCSUsrMsg_SayText2" 

You should use: UserMessageToProtobuf() function (see multicolors) instead of view_as<Protobuf>

c0rp3n 02-09-2020 07:55

Re: [INC] ColorLib
 
Quote:

Originally Posted by Ilusion9 (Post 2682911)
It seems there's an error with CSayText2 function:

PHP Code:

Exception reportedInvalid field "params" for message "CCSUsrMsg_SayText2" 

You should use: UserMessageToProtobuf() function (see multicolors) instead of view_as<Protobuf>


Thanks for the report, this is now fixed on the git, as well as another issue from Bara where the 'z' flag wasnt working for CPrintToChatAdmins, there is also an example GitHub workflow for building the color_map.inc in your actions.

TheDS1337 02-10-2020 14:43

Re: [INC] ColorLib
 
If you write %t to include translations it won't work, it only works with %T, I hope you add support for %t if plausible.

Ilusion9 02-11-2020 11:21

Re: [INC] ColorLib
 
Quote:

Originally Posted by TheDS1337 (Post 2683324)
If you write %t to include translations it won't work, it only works with %T, I hope you add support for %t if plausible.

What function? CPrintToChat?
I see there's SetGlobalTransTarget, that should do it for %t.

Ilusion9 02-20-2020 13:21

Re: [INC] ColorLib
 
CRemoveTags doesn't work well for me. If there's no tags, the first index is removed (ex: for my name "Ilusion" appears "lusion"). Maybe use a buffer and construct again the message like in CFormat function?

c0rp3n 02-21-2020 05:04

Re: [INC] ColorLib
 
Yeah I've gone though and fixed the issue, was to do with me checking if the index's are the same and skipping copying values, this has now been sorted along with adding a new function to remove color escape codes from a message `CRemoveColors`.
Also there was an additional bug fix for CSayText2 where I was calling SetString on the proto buffer instead of AddString for the params. This was why you had the error before, didnt notice it as rarely use CPrintToChatEx in code, I have gone back to using view_as<ProtoBuff> for now as the check done by UserMessageToProtobuf is already done in _CL_SupportsProtoBuf.

Ilusion9 02-21-2020 06:51

Re: [INC] ColorLib
 
Have you thought about checking if the color is valid? If not, keep the tag.
Something like:

PHP Code:

bool _CL_ColorMap(char color[16], char &hexColor)
{




c0rp3n 02-22-2020 08:30

Re: [INC] ColorLib
 
Made the change to keep bad / incorrect color tags, but just using 0 or well null, `CPrintToChat(client, "{bad tag here}Hello {green}World");` will remove green but `bad tag here` would stay.


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

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