RE: [GD-General] Overhead of RTTI
Brought to you by:
vexxed72
|
From: Cruise <cr...@ca...> - 2002-12-24 14:08:13
|
>The easy, if rather messy and special-cased way, is to have a=
whole load of
>functions like this all the way down the hierarchy:
>
>virtual D3DTexture *MyCoolClass::GetD3DTexture ( void )
>{
>=A0=A0=A0=A0// I'm not a D3DTexture you fool.
>=A0=A0=A0=A0return NULL;
>}
>
>
>....but then for the D3DTexture class it's
>
>virtual D3DTexture *D3DTexture::GetD3DTexture ( void )
>{
>=A0=A0=A0=A0return this;
>}
>
>
>Now sure, this pollutes your namespace with lots of=
GetMyFunkyClassName()
>calls, but if that's all you need to do, it's robust and pretty=
easy to
>understand, and doesn't require any RTTI support.
>
>
>Tom Forsyth - Muckyfoot bloke and Microsoft MVP.
>
>This email is the product of your deranged imagination,
>and does not in any way imply existence of the author.
>
This obviously can be restricted to only the classes that you=
need to get the specific class pointer for.
Half-Life used this method within it's game entity hierarchy, but=
restricted it to only two classes/functions:
MyMonsterPointer() and MySquadMonsterPointer()
which did exactly as Tom described above for CBaseMonster and=
CBaseSquadMonster respectively.
If you have a reasonably flat hierarchy, and this functionality=
is only required for a few classes, then it's not too ugly, and=
is probably about as fast/efficient/safe as you could get this=
sort of thing.
[ cruise / casual-tempest.net / transference.org ]
|