ドキュメントに基づく 2 つのアプローチがあり、どちらも疎結合を助長する一般的な C++ パターンです。
1.) リスナーのアプローチ。このアプローチでは、クラス (ObjectManager と呼ばれるとしましょう) も「ある」、つまり TimeListener から継承されます。これは、このフレームワークがあなたに望んでいる方法のようです。純粋仮想基底クラス「TimeListener」を見てください。
2.) コールバック アプローチ。これは「game::Schedule」への 2 回目の呼び出しです:
http://gameplay3d.github.io/GamePlay/api/classgameplay_1_1_game.html#a3b8adb5a096f735bfcfec801f02ea0da
これはスクリプト関数を取ります。私はこのフレームワークに詳しくないので、あまりコメントできません。必要な署名に一致する関数へのポインターを渡す必要があります。
全体として、私は次のようなことをします:
class ObjectManager: public TimeListener
{
public:
void OnTimeEvent(long timeDiff, void* cookie)
{
// timeDiff is difference between game time and current time
// cookie is the data you passed into the event. it could be a pointer to anything.
// Cast appropriately. remember, it is completely optional! you can pass
// nullptr!
MyOtherObject* other = static_cast<MyOtherObject>(cookie);
// ...
// handle the event and do the other stuff I wanted to do on a timer.
}
// my other business logic and all other good stuff this class does.
private:
// data, other private things.
}
....
これで、イベントをスケジュールする場合、リスナーで呼び出されるようにスケジュールできます。
ObjectManager myObjectManager; // example only, stack variable. would be invalid.
// Schedule an event to be invoked on the instance noted, with a context of MyOtherObject, in 100 milliseconds.
gameplay::Game::schedule(100.0, &myObjectManager, new MyOtherObject());
スケジュールを呼び出す「ゲーム」オブジェクトへのポインターが必要かどうかを確認するには、ドキュメントを読む必要があります。その場合は、"game->Schedule(..)" のようになります。