我正在使用一个 Timer 类,该类将 void* 作为可选参数传递给回调。我需要传递一个整数,但我的逻辑似乎并不顺利。
在 Event_PlayerSpawn() 我有一个 int* clientIndex 指向 int“客户端”的内存位置。我将它传递给 void* 参数,然后在回调中将其再次转换为 int*,然后取消引用它以获取值。我到底哪里错了?
ResultType PlayerSpawnTimer::OnTimer(ITimer *pTimer, void *pData)
{
int client = *((int*)pData);
ConquestPlayer *pPlayer = dynamic_cast<ConquestPlayer*>(CEntity::Instance(client));
Msg("Spawn Timer Called client = %d!\n", client);
if(pPlayer)
{
pPlayer->FindSpawnLocation();
}
return Pl_Continue;
}
void GameManager::Event_PlayerSpawn(IGameEvent *event)
{
int client = engine->IndexOfEdict(GetEdictOfUserID(event->GetInt("userid")));
int *clientIndex = &client;
// Add a 0.1 second delay then handle spawn location
timerPlayerSpawn = timersys->CreateTimer(&playerSpawnTimerCallback, 5.0, clientIndex, 0);
}