Admer456 / halflife-adm-legacy

Advanced Development Mod - technical overhaul for Half-Life

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rewrite keyvalue handling

Admer456 opened this issue · comments

commented

Keyvalue handling is not so nice in HL SDK, and while it's a bit faster to write in ADM, that brought a new "not so nice" thing.
Simply put, look at this: https://github.com/Admer456/halflife-ADM/blob/master/dlls/ADM/AdmGetSetKV.cpp
:(

Other than that, handling keyvalues in a manual fashion is fairly repetitive.

void SomeEntity::KeyValue( KeyValueData* pkvd )
{
   if ( KeyvalueToken( myKeyvalue ) )
   {
      KeyvalueToInt( myMember );
   }
   else
      KeyvaluesFromBase( CBaseEntity );
}

What should be done is a system similar to the save-restore system. Each entity class can have a static array of keyvalue elements, where keyvalue elements are basically pairs of strings and byte offsets. In implementation, they're a bit more than that, because you have to specify the data type too.

It'll eventually look something like this:

KeyValueElement MyEntity::keyValues[] =
{
   KV_Define( mykeyvalue, Int ),
   KV_DefineCustom( mykeyvalue2, Float );
};