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

[INC] ESF UTIL


Post New Thread Reply   
 
Thread Tools Display Modes
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 04-09-2009 , 09:52   Re: [INC] ESF UTIL
Reply With Quote #11

that is hip_hop_x stock not mine , thanks for help.. will update soon

@ Spunky - good idea i will try something
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 04-09-2009 , 22:49   Re: [INC] ESF UTIL
Reply With Quote #12

get_user_team() already works, I just want it to return 1 for Good, 2 for Evil, or 0/-1 for FFA. get_user_team() only returns 9 for the team ID.

Code:
stock esf_get_team(id) {     new szTeamName[6]     get_user_team(id, szTeamName, 5)     if (equal(szTeamName, "Good"))         return 1     else if (equal(szTeamName, "Evil"))         return 2     else         return 0 }

Also, use stocks instead of macros. With a macro, a new stack allocation is made for each use of the macro, cluttering up DAT and using precious resources.

Last edited by Spunky; 04-09-2009 at 23:02.
Spunky is offline
Send a message via AIM to Spunky
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-10-2009 , 10:48   Re: [INC] ESF UTIL
Reply With Quote #13

Quote:
Originally Posted by Spunky View Post
Also, use stocks instead of macros. With a macro, a new stack allocation is made for each use of the macro, cluttering up DAT and using precious resources.
Macros are replaced at compile, so there is no reason not to use them (at least from what I understand of it).
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 04-10-2009 , 11:12   Re: [INC] ESF UTIL
Reply With Quote #14

Quote:
Originally Posted by YamiKaitou View Post
Macros are replaced at compile, so there is no reason not to use them (at least from what I understand of it).
Yes.

Quote:
each use of the macro
There isn't "each use of macro". A macro is a rule for text replacement applied before compiling. A way of avoid a function call.
__________________
joaquimandrade is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 04-10-2009 , 11:32   Re: [INC] ESF UTIL
Reply With Quote #15

@ Spunky thanks for idea and stock.. i will update this inc asap
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 04-10-2009 , 12:16   Re: [INC] ESF UTIL
Reply With Quote #16

Quote:
Originally Posted by Spunky View Post
get_user_team() already works, I just want it to return 1 for Good, 2 for Evil, or 0/-1 for FFA. get_user_team() only returns 9 for the team ID.

PHP Code:
stock esf_get_team(id
{     
    new 
szTeamName[6]     
    
get_user_team(idszTeamName5)      

if (
equal(szTeamName"Good"))         
    return 
1      

else if (equal(szTeamName"Evil"))        
    return 
2      

else        
    return 


Will get_user_team always return 9? If it does not and returns unique numbers you could just remap it - returning 1 if get_user_team is 9, 2 if it is 8 (or whatever).

If this does not apply I would use this instead of full string comparison (assuming that those are unique):

PHP Code:
stock esf_get_team(id
{     
    new 
szTeamName[2]     
    
get_user_team(idszTeamName1)      

if( 
szTeamName[0] == 'G' )         
    return 
1      

else if( szTeamName[0] == 'E' )        
    return 
2      

else        
    return 


__________________
In Flames we trust!
Nextra is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 04-10-2009 , 12:28   Re: [INC] ESF UTIL
Reply With Quote #17

updated the INC... look at my esf_get_team
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 04-10-2009 , 13:50   Re: [INC] ESF UTIL
Reply With Quote #18

Nice. Of course a switch is the next step of what I did. Should've come up with that by myself
__________________
In Flames we trust!
Nextra is offline
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 04-10-2009 , 21:10   Re: [INC] ESF UTIL
Reply With Quote #19

Quote:
Originally Posted by YamiKaitou View Post
Macros are replaced at compile, so there is no reason not to use them (at least from what I understand of it).
Yeah, but look at this quote from BAILOPAN's dev log:

Quote:
Originally Posted by BAILOPAN
We noticed that the DAT section is not optimized. You can repeat a string a 800 times and the DAT section will have an entry for each repetition. The solution?

Code:
//BAD #define COMMON_STRING   "Gaben" //GOOD new COMMON_STRING[] = "Gaben"

This way, DAT will only have one reference. Furthermore, it might even be faster because in the case of non-const the compiler won’t have to copy it into the heap first. In many cases you know it will never be modified, and the native declaration simply forgot a ‘const’ keyword.
Another example:

Code:
//BAD stock GetWeaponName(id, name[], max) {    if (id==0)       copy(name, max, "weapon_none")    else if (id==1)       copy(name, max, "weapon_gaben")    //.... } //GOOD new g_WeaponNames[] = {      "weapon_none", //0     "weapon_gaben", //1 }

A lookup table is near-instantaneous execution. The compiler simply has to add an integer to a base memory offset. Calling a function is expensive — branch prediction, cache misses, more instructions can add up very quickly. If you’re using the function very often, it’s a good idea to take the time to make these trivial and worth-while optimizations. You can do lookup tables in Small for anything which inputs an integer and outputs any other data type, as long as the set of inputs has fixed limits. It is okay to build the lookup table at runtime, as long as you don’t need to do it often (or building it often outweighs the cost of computing entries totally dynamically).
Greenberet told me about this and I was shocked at how unoptimized the Pawn compiler is.
Spunky is offline
Send a message via AIM to Spunky
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-10-2009 , 21:12   Re: [INC] ESF UTIL
Reply With Quote #20

I thought it's for strings only. So I shall not use const even if I'm not planing changing my variable?
__________________

Last edited by hleV; 04-10-2009 at 21:14.
hleV 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 13:17.


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