Thursday, 28.03.2024, 12:55
Приветствую Вас Гость
Register | Login | RSS
Jedi Academy Server Security
[ New messages · Users · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum » JASS » English forum » Just Curious about ENT_FROM_NUM.... macros
Just Curious about ENT_FROM_NUM.... macros
WEAPON_XDate: Tuesday, 26.06.2012, 03:19 | Message # 1
Group: User
Messages: 12
Reputation: 0
Status: Offline
In jassapi we have this helpful and flexible macros

#define ENT_FROM_NUM(index) ((gentity_t*)((byte*)g_gents + g_gentsize * (index)))
#define NUM_FROM_ENT(ent) ((int)((byte*)(ent) - (byte*)g_gents) / g_gentsize)

In my case, I am specifically targeting a mod, for which I have the correct entity structures in my header and therefore don't really benefit from the flexible macros.

Is there some difference between using the macro and using &g_gents[num] or ent-g_gents.
Am I right to think that the latter simply bypass multiplication and division and is therefore (very slightly) preferable in my case?
 
BufferOverflowDate: Tuesday, 26.06.2012, 13:36 | Message # 2
Group: Developer
Messages: 47
Reputation: 0
Status: Offline
ent-g_gents isn't exactly ent-g_gents, compiler interprets it as ((int)ent-(int)g_gents)/sizeof(gentity_t). So, you won't get any optimization, the only difference will be that sizeof(gentity_t) is constant. Yet, ENT_FROM_NUM is slower than &g_gents[num] coz this will be assembled that way:
mov edi, g_gents
mov ecx, num
lea eax, [edi+ecx*sizeof(gentity_t)]
Multiplication by g_gentsize not works the same way coz it isn't const
 
Forum » JASS » English forum » Just Curious about ENT_FROM_NUM.... macros
  • Page 1 of 1
  • 1
Search: