mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-12-23 08:38:52 -05:00
e56af6a7a3
* Redesign hooks mechanism * Use reference instead of copy
51 lines
976 B
C++
51 lines
976 B
C++
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <functional>
|
|
|
|
#include "UltraController.h"
|
|
|
|
#define DEFINE_HOOK(name, type) struct name { typedef std::function<type> fn; }
|
|
|
|
namespace ModInternal {
|
|
|
|
template <typename H>
|
|
struct RegisteredHooks {
|
|
inline static std::vector<typename H::fn> functions;
|
|
};
|
|
|
|
template <typename H>
|
|
void RegisterHook(typename H::fn h) {
|
|
RegisteredHooks<H>::functions.push_back(h);
|
|
}
|
|
|
|
template <typename H, typename... Args>
|
|
void ExecuteHooks(Args&&... args) {
|
|
for (auto& fn : RegisteredHooks<H>::functions) {
|
|
fn(std::forward<Args>(args)...);
|
|
}
|
|
}
|
|
|
|
DEFINE_HOOK(ControllerRead, void(OSContPad* cont_pad));
|
|
|
|
DEFINE_HOOK(AudioInit, void());
|
|
|
|
DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture));
|
|
|
|
DEFINE_HOOK(GfxInit, void());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
void ModInternal_ExecuteAudioInitHooks();
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|