--- nono/vm/event.h 2026/04/29 17:05:50 1.1.1.12 +++ nono/vm/event.h 2026/04/29 17:06:00 1.1.1.13 @@ -12,8 +12,10 @@ #include "device.h" -// コールバック関数の型 -#define ToEventCallback(f) static_cast(f) +template +EventCallback_t ToEventCallback(T f) { + return static_cast(f); +} // イベント @@ -34,14 +36,21 @@ class Event return active; } + Device *GetOwner() const noexcept { return dev; } + EventCallback_t GetCallback() const noexcept { return func; } + // 以下はイベントを呼び出す側がセットする + // コールバック関数をセットする。 + template + void SetCallback(void (T::*func_)(Event *)) { + func = static_cast(func_); + } + // イベントを起こすまでの仮想時刻での相対時間 [nsec] // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。 uint64 time {}; - Device *dev {}; // デバイス - EventCallback_t func {}; // コールバック関数 int code {}; // コールバック関数への引数 const std::string GetName() const { return name; } void SetName(const std::string& val); @@ -54,6 +63,9 @@ class Event uint64 last_count {}; // (表示用)前回表示したときの count private: + Device *dev {}; // デバイス + EventCallback_t func {}; // コールバック関数 + // イベント名(表示用) // '\0' 含まず25文字まで。デバイス名も必要なら含めること。 std::string name {}; @@ -92,6 +104,6 @@ class EventManager : public Object std::vector all {}; }; -static inline EventManager* GetEventManager() { +inline EventManager* GetEventManager() { return Object::GetObject(OBJ_EVENT_MANAGER); }