Raised This Month: $51 Target: $400
 12% 

[STK] CvarToColor


Post New Thread Reply   
 
Thread Tools Display Modes
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 06-26-2009 , 09:31   Re: CvarToColor( )
Reply With Quote #11

Quote:
Originally Posted by arkshine View Post
It doesn't anwser to the question to know the advantage of the hex notation instead of classic but well known integer. ( more friendly for a tuto )
Cuz it's so much cooler... -_-'

I don't even see a reason for the function. What's wrong with clamp(num, 0, 0xFF); / clamp(num, 0, 255); ?

Last edited by [ --<-@ ] Black Rose; 06-26-2009 at 09:33.
[ --<-@ ] Black Rose is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-26-2009 , 11:30   Re: CvarToColor( )
Reply With Quote #12

Quote:
Originally Posted by Superiority View Post
What's wrong with clamp(num, 0, 0xFF); / clamp(num, 0, 255); ?
clamp is a native, so it's faster if you don't use it.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 06-26-2009 , 12:33   Re: CvarToColor( )
Reply With Quote #13

... You earned 0.01 seconds by using an ugly stock. You are teh win. Here's your nobelnothing price.

Prove it.

Hey... let's just rewrite the whole AMXX in one mm plugin without any custom plugins. That would speed things up.

Last edited by [ --<-@ ] Black Rose; 06-26-2009 at 12:35.
[ --<-@ ] Black Rose is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-26-2009 , 12:55   Re: CvarToColor( )
Reply With Quote #14

code
PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_plugin("clamp profile""0.1""stupok")
    
    new 
iValue 256
    
    
// pawn native function clamp
    
for( new 010000000i++ )
    {
        
clampiValue0255 )
    }
    
    
// extra function clamp
    
for( new 010000000i++ )
    {
        
clamp_byteiValue )
    }
    
    
server_cmd("exit")
}

stock clamp_byteiByte )
{
    if( 
iByte )
    {
        return 
0
    
}
    else if( 
iByte 0xFF )
    {
        return 
0xFF
    
}
    return 
iByte

3 profiles
Code:
date: Fri Jun 26 11:49:29 2009 map: de_dust2
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                  register_plugin |          1 | 0.000002 / 0.000002 / 0.000002
   n |                            clamp |   10000000 | 0.613344 / 0.000000 / 0.000227
   n |                       server_cmd |          1 | 0.000003 / 0.000003 / 0.000003
   p |                      plugin_init |          1 | 1.542432 / 1.542432 / 1.542432
   f |                       clamp_byte |   10000000 | 0.725329 / 0.000000 / 0.000520
0 natives, 0 public callbacks, 1 function calls were not executed.

date: Fri Jun 26 11:49:41 2009 map: de_dust2
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                  register_plugin |          1 | 0.000001 / 0.000001 / 0.000001
   n |                            clamp |   10000000 | 0.613077 / 0.000000 / 0.000226
   n |                       server_cmd |          1 | 0.000003 / 0.000003 / 0.000003
   p |                      plugin_init |          1 | 1.546259 / 1.546259 / 1.546259
   f |                       clamp_byte |   10000000 | 0.726270 / 0.000000 / 0.000585
0 natives, 0 public callbacks, 1 function calls were not executed.

date: Fri Jun 26 11:49:54 2009 map: de_dust2
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                  register_plugin |          1 | 0.000002 / 0.000002 / 0.000002
   n |                            clamp |   10000000 | 0.614865 / 0.000000 / 0.000599
   n |                       server_cmd |          1 | 0.000003 / 0.000003 / 0.000003
   p |                      plugin_init |          1 | 1.538301 / 1.538301 / 1.538301
   f |                       clamp_byte |   10000000 | 0.738247 / 0.000000 / 0.000571
0 natives, 0 public callbacks, 1 function calls were not executed.
clamp() average time: 0.613762 seconds
clamp_byte() average time: 0.729948 seconds

In this test, clamp() is faster than clamp_byte(), on average, by: 0.116186 seconds
__________________
stupok is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-26-2009 , 13:13   Re: CvarToColor( )
Reply With Quote #15

I was going to do it because I was sure that the difference would be unsignificant. Though I did not thought clamp() would be slightly more faster.
__________________
Arkshine is offline
DA
Veteran Member
Join Date: Nov 2005
Location: Germany/Münster
Old 06-26-2009 , 13:17   Re: CvarToColor( )
Reply With Quote #16

Plugin looks well. Do you think it's possible to add Hex colorcode?
Most programmer use Hexcode instead of decimal colorcode.
__________________
DA is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 06-26-2009 , 13:22   Re: CvarToColor( )
Reply With Quote #17

Here's a simple decimal to binary/hex converter.
itoa works with any radix. atoi works only with Hex and Binary.
PHP Code:
#define Hex  16
#define Binary 2
 
new map[] = "0123456789abcdefghijklmnopqrstuvwxyz"
 
stock itoa(valout[], lenradix) {
 
 for ( new 
len val && ; --ival /= radix )
  
out[len-i-1] = map[val radix];
 
 
reverse(out);
}
 
stock reverse(string[]) {
 
 new 
len strlen(string);
 new 
temp;
 
 for ( new 
len i++ ) {
  
temp string[i];
  
string[i] = string[len-i-1];
  
string[len-i-1] = temp;
 }
}
 
#define ctod(%0) ('0' <= %0 <= '9' ? %0 - '0' : 'A' <= %0 <= 'Z' ? %0 -'A' + 10 : 'a' <= %0 <= 'z' ? %0 -'a' + 10 : 0)
 
stock atoi(hexstring[], radix) {
 
 new 
radix_resultfirsttime falselen strlen(hexstring);
 
 switch ( 
radix ) {
  case 
16 radix_ 4;
  case 
radix_ 1;
  default : 
radix_ 0;
 }
 
 for ( new 
len i++ ) {
 
  if ( ! 
firsttime )
   
result <<= radix_;
 
  
result += ctod(hexstring[i]);
 
  
firsttime false;
 }
 
 return 
result;


Last edited by [ --<-@ ] Black Rose; 06-28-2009 at 07:01.
[ --<-@ ] Black Rose is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-26-2009 , 14:27   Re: CvarToColor( )
Reply With Quote #18

If the purpose is to convert Hex value to RGB or RGB to Hex, it doesn't work as expected.
__________________
Arkshine is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 06-26-2009 , 17:11   Re: CvarToColor( )
Reply With Quote #19

It sure as hell does.

And you can't pass a string like "255 255 255" you have to split them.
[ --<-@ ] Black Rose is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-26-2009 , 17:23   Re: CvarToColor( )
Reply With Quote #20

Quote:
Originally Posted by stupok View Post
clamp() average time: 0.613762 seconds
clamp_byte() average time: 0.729948 seconds

In this test, clamp() is faster than clamp_byte(), on average, by: 0.116186 seconds
Wooaaa, can't belive it
With some values clamp is lower, but you are right, stock is useless.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



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

Forum Jump


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


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