AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   halflife_time - fakemeta (https://forums.alliedmods.net/showthread.php?t=75455)

anakin_cstrike 08-05-2008 23:08

halflife_time - fakemeta
 
Hi:)
Engine way:
PHP Code:

new Float:Time halflife_time(); 

Fakemeta way:
:|

Exolent[jNr] 08-05-2008 23:20

Re: halflife_time - fakemeta
 
Wrong section. Moved.

Also, this is the equivalent.

Code:

get_gametime()

danielkza 08-05-2008 23:24

Re: halflife_time - fakemeta
 
new Float:fNow
global_get(glb_time,fnow)

anakin_cstrike 08-05-2008 23:46

Re: halflife_time - fakemeta
 
Thanks.

jim_yang 08-05-2008 23:50

Re: halflife_time - fakemeta
 
get_gametime() from core is slightly faster than glb from fakemeta

danielkza 08-06-2008 12:59

Re: halflife_time - fakemeta
 
Quote:

Originally Posted by jim_yang (Post 665299)
get_gametime() from core is slightly faster than glb from fakemeta

Why do you say that? Any facts or just intuition?

Arkshine 08-06-2008 13:10

Re: halflife_time - fakemeta
 
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; }

Lee 08-06-2008 18:22

Re: halflife_time - fakemeta
 
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.

danielkza 08-06-2008 21:25

Re: halflife_time - fakemeta
 
Quote:

Originally Posted by Lee (Post 665662)
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.

XxAvalanchexX 08-06-2008 21:32

Re: halflife_time - fakemeta
 
That's awfully political of you, Lee.


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

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