I'm trying to set up an expandable game framework, but ran into a rather important issue here: how do I store a function pointer in an entity skill?
I want to optionally have three functions that can be called by a player movement script, and each function is determined by the type of character or game mode. The simplest way to handle this is with a function pointer. However, the following code does not work:
// Function pointer defined
var bipedFunctionPtr(ENTITY* ent);
// This exists
void playerCamera(ENTITY* ent)
{
...
}
// in function main:
player.bpd_postoutput_func = playerCamera;
// in player update loop:
if(ent.bpd_postoutput_func)
{
bipedFunctionPtr = ent.bpd_postoutput_func;
bipedFunctionPtr(ent);
}
Evidently, function pointers won't cast to a VAR and back again. Trying to use handles and ptr_for_handle doesn't work either - same result, crash in player loop. Any ideas how to handle (ha, ha) this issue?