2019-05-10 05:17:29 +00:00
|
|
|
#pragma once
|
2022-06-11 09:02:27 +00:00
|
|
|
#include "Platform.h"
|
2019-05-10 05:17:29 +00:00
|
|
|
|
|
|
|
// Utility class mostly for when certain inputs need singleton callback handlers
|
|
|
|
template<typename T> class Static {
|
|
|
|
public:
|
|
|
|
static T* instance() {
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static T* s_instance;
|
|
|
|
};
|
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
template<typename T> struct StaticTaskRegistration : public Platform::TaskRegistration {
|
|
|
|
StaticTaskRegistration() : Platform::TaskRegistration(Static<T>::instance()) {
|
|
|
|
Platform::registerTask(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AutoTaskRegistration : public Platform::TaskRegistration {
|
|
|
|
explicit AutoTaskRegistration(Task* task) : Platform::TaskRegistration(task) {
|
|
|
|
Platform::registerTask(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-10 05:17:29 +00:00
|
|
|
#define NAMED_STATIC_ALLOC(Cls, StaticName) static Cls _staticAlloc__ ## StaticName;\
|
|
|
|
template<> Cls* Static<Cls>::s_instance=&_staticAlloc__ ## StaticName;
|
|
|
|
|
|
|
|
#define STATIC_ALLOC(Cls) NAMED_STATIC_ALLOC(Cls, Cls)
|
2022-06-11 09:02:27 +00:00
|
|
|
|
|
|
|
#define NAMED_STATIC_TASK(Cls, StaticName) static StaticTaskRegistration<Cls> _staticTask_ ## StaticName;
|
|
|
|
#define STATIC_TASK(Cls) NAMED_STATIC_TASK(Cls, Cls)
|
|
|
|
|
|
|
|
#define REGISTER_TASK(TaskName) static AutoTaskRegistration _autoTask__ ## TaskName(&TaskName);
|