Quasar
Moderator

Posts: 4484
Registered: 08-00 |
andrewj said:
I read most of it, but didn't find it educational. Mostly I wondered how this system would fit into the whole program, and what benefits it would bring.
As for this, here are some ways we're using it in EE already:
code:
// in E_ProcessDamageFactors...
MetaSetDouble(info->meta, E_ModFieldName("damagefactor", mod),
cfg_getfloat(sec, ITEM_TNG_DMGF_FACTOR));
// in P_DamageMobj:
double df = MetaGetDouble(target->info->meta,
E_ModFieldName("damagefactor", emod),
1.0);
damage = (int)(damage * df);
// in E_AddMetaState:
MetaAddObject(mi->meta, name, &newMetaState->parent, newMetaState,
METATYPE(metastate_t));
// in P_KillMobj:
if(mod->num > 0 && (state = E_StateForMod(target->info, "Death", mod)))
st = state->index;
So as you can see, our current application of the metatable is to extend mobjinfo with information that is generated at runtime, such as DECORATE states, damage factors, item drop types, etc. All of these things have the requirement that I store N of them and must be able to retrieve a particular one later one. They were previously being implemented as separate, private lists, and this was grossly inefficient in terms of the amount of code needed. Now they all share the same common structure.
This perhaps is the largest benefit of the metatable so far:
code:
// in E_CopyThing (used to implement mobjinfo inheritance):
MetaCopyTable(this_mi->meta, mobjinfo[pnum].meta);
This used to be a series of 4 or 5 deep separate deep list copy routine calls, all implemented in different modules using only subtly different algorithms and data structures.
|