Raised This Month: $ Target: $400
 0% 

halflife_time - fakemeta


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands       
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 08-05-2008 , 23:08   halflife_time - fakemeta
Reply With Quote #1

Hi
Engine way:
PHP Code:
new Float:Time halflife_time(); 
Fakemeta way:
__________________

anakin_cstrike is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-05-2008 , 23:20   Re: halflife_time - fakemeta
Reply With Quote #2

Wrong section. Moved.

Also, this is the equivalent.

Code:
get_gametime()
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-05-2008 , 23:24   Re: halflife_time - fakemeta
Reply With Quote #3

new Float:fNow
global_get(glb_time,fnow)
danielkza is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 08-05-2008 , 23:46   Re: halflife_time - fakemeta
Reply With Quote #4

Thanks.
__________________

anakin_cstrike is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-05-2008 , 23:50   Re: halflife_time - fakemeta
Reply With Quote #5

get_gametime() from core is slightly faster than glb from fakemeta
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-06-2008 , 12:59   Re: halflife_time - fakemeta
Reply With Quote #6

Quote:
Originally Posted by jim_yang View Post
get_gametime() from core is slightly faster than glb from fakemeta
Why do you say that? Any facts or just intuition?
danielkza is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-06-2008 , 13:10   Re: halflife_time - fakemeta
Reply With Quote #7

I'm not a pro, when you see the source code for both native, get_gametime() returns directly the time ( I mean without any checks or others ) when global_get works differently and has more checks. So I can assume that get_gametime() would be a bit more faster.

Code:
static cell AMX_NATIVE_CALL get_gametime(AMX *amx, cell *params) {     REAL pFloat = (REAL)gpGlobals->time;     return amx_ftoc(pFloat); }

Code:
static cell AMX_NATIVE_CALL amx_glb(AMX *amx, cell *params) {     int iSwitch = params[1];     if (iSwitch <= glb_start_int || iSwitch >= glb_end_pchar)     {         MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global index: %d", iSwitch);         return 0;     }     int offset = g_glob_offset_table[iSwitch];     if (offset == -1)     {         MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global index: %d", iSwitch);         return 0;     }     enum     {         Ret_Int = (1<<0),         Ret_Float = (1<<1),         Ret_Vec = (1<<2),         Ret_Edict = (1<<3),         Ret_PChar = (1<<4)     };     union     {         int i;         float f;         const char *c;     } rets;     Vector vec;     int Valtype = 0;     if (iSwitch > glb_start_int && iSwitch < glb_end_int)     {         rets.i = *(int *)GET_OFFS(gpGlobals, offset);         Valtype = Ret_Int;     }     else if (iSwitch > glb_start_float && iSwitch < glb_end_float)     {         rets.f = *(float *)GET_OFFS(gpGlobals, offset);         Valtype = Ret_Float;     }     else if (iSwitch > glb_start_edict && iSwitch < glb_end_edict)     {         edict_t *e = *(edict_t **)GET_OFFS(gpGlobals, offset);         rets.i = ENTINDEX(e);         Valtype = Ret_Int | Ret_Edict;     }     else if (iSwitch > glb_start_vector && iSwitch < glb_end_vector)     {         vec = *(vec3_t *)GET_OFFS(gpGlobals, offset);         Valtype = Ret_Vec;     }     else if (iSwitch > glb_start_string && iSwitch < glb_end_string)     {         rets.c = STRING(*(string_t *)GET_OFFS(gpGlobals, offset));         Valtype = Ret_PChar;     }     else if (iSwitch > glb_start_pchar && iSwitch < glb_end_pchar)     {         rets.c = *(const char **)GET_OFFS(gpGlobals, offset);         Valtype = Ret_PChar;     }     size_t paramnum = params[0] / sizeof(cell) - 1;     if (paramnum == 0)     {         //return an int         if (Valtype & Ret_Int)         {             return rets.i;         } else {             MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");             return 0;         }     }     else if (paramnum == 1)     {         //return a byref float - usually         cell *addr = MF_GetAmxAddr(amx, params[2]);         if (Valtype == Ret_Float)         {             *addr = amx_ftoc(rets.f);         }         else if (Valtype == Ret_Vec)         {             addr[0] = amx_ftoc(vec.x);             addr[1] = amx_ftoc(vec.y);             addr[2] = amx_ftoc(vec.z);         } else {             MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");             return 0;         }         return 1;     }     else if (paramnum == 2)     {         cell size = *(MF_GetAmxAddr(amx, params[3]));         if (Valtype == Ret_PChar)         {             const char *str = rets.c;             if (!str)                 str = "";             return MF_SetAmxString(amx, params[2], str, size);         }         MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");     }     else if (paramnum == 3)     {         cell size = *(MF_GetAmxAddr(amx, params[4]));         if (Valtype == Ret_PChar)         {             cell *str = MF_GetAmxAddr(amx, params[2]);             return MF_SetAmxString(amx, params[3], STRING((int)*str), size);         }         MF_LogError(amx, AMX_ERR_NATIVE, "Invalid return type");     }     //if we got here, something happened     MF_LogError(amx, AMX_ERR_NATIVE, "Unknown global index or return combination %d", iSwitch);     return 0; }
__________________
Arkshine is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 08-06-2008 , 18:22   Re: halflife_time - fakemeta
Reply With Quote #8

Many fakemeta methods are slower. A lot of scripters were sold a lie by people who shouldn't have been giving advice on the matter. Have you ever seen sawce say that all legacy engine/fun code would be faster written with fakemeta? High level code can only be used well if you understand what has been abstracted. Read AMXX source code and remember that native calls aren't free.
__________________
No support via PM.

Last edited by Lee; 08-06-2008 at 18:24.
Lee is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-06-2008 , 21:25   Re: halflife_time - fakemeta
Reply With Quote #9

Quote:
Originally Posted by Lee View Post
Many fakemeta methods are slower. A lot of scripters were sold a lie by people who shouldn't have been giving advice on the matter. Have you ever seen sawce say that all legacy engine/fun code would be faster written with fakemeta? High level code can only be used well if you understand what has been abstracted. Read AMXX source code and remember that native calls aren't free.
Who said that fakemeta was faster? And it's not fair to compare a specialized function to a general one. global_get includes code for error checking and for all the types. It's obvious from the size of the code that core's way it's much faster. We were only listing the possible functions, and i happened to ask why somebody said that get_gametime was faster. And it was proved with code.

I agree that there's no need to convert old code to FM. But because it's much more powerful than engine,there's no reason,at least for me,to start new projects using engine. But that's just me.
danielkza is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 08-06-2008 , 21:32   Re: halflife_time - fakemeta
Reply With Quote #10

That's awfully political of you, Lee.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX 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 05:29.


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