mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
This represents a major code restructuring. The dot-based and scanline-based renderers are now split into two separate core libraries, asnes and bsnes. For now at least, these are -internal- names. I'm not entirely decided on how I'm going to handle releasing these two separate builds. Regardless, the folders need names. asnes has had all of the processor subfolders collapsed back into their parent folders. In other words, ppu's functions were moved into ppu/sppu, and then ppu was deleted, and then ppu/sppu became the new ppu. Repeat this for the cpu, smp and dsp and there you go. asnes/dsp also removed the DSP_STATE_MACHINE option. This was done for the sake of consistency with the rest of the core. asnes' debugger mode is currently extremely broken, but I will be fixing it in time. And for now, bsnes has kept the processor abstraction layer. I may keep it around, not sure yet. It doesn't hurt speed or anything, so I'm not too worried about making a decision right away. I may throw snesfilter, snesreader and supergameboy into this folder, just to have everything in one place. The alternate GUI forks are definitely going in there as dotnet, cocoa and python. Compiled output goes to the out/ folder now, to prevent conflicts with a file and folder named bsnes, for instance.
90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
#ifndef NALL_FUNCTION_HPP
|
|
#define NALL_FUNCTION_HPP
|
|
|
|
#include <functional>
|
|
#include <type_traits>
|
|
|
|
namespace nall {
|
|
template<typename T> class function;
|
|
|
|
template<typename R, typename... P>
|
|
class function<R (P...)> {
|
|
private:
|
|
struct base1 { virtual void func1(P...) {} };
|
|
struct base2 { virtual void func2(P...) {} };
|
|
struct derived : base1, virtual base2 {};
|
|
|
|
struct data_t {
|
|
R (*callback)(const data_t&, P...);
|
|
union {
|
|
R (*callback_global)(P...);
|
|
struct {
|
|
R (derived::*callback_member)(P...);
|
|
void *object;
|
|
};
|
|
};
|
|
} data;
|
|
|
|
static R callback_global(const data_t &data, P... p) {
|
|
return data.callback_global(p...);
|
|
}
|
|
|
|
template<typename C>
|
|
static R callback_member(const data_t &data, P... p) {
|
|
return (((C*)data.object)->*((R (C::*&)(P...))data.callback_member))(p...);
|
|
}
|
|
|
|
public:
|
|
R operator()(P... p) const { return data.callback(data, p...); }
|
|
operator bool() const { return data.callback; }
|
|
void reset() { data.callback = 0; }
|
|
|
|
function& operator=(const function &source) { memcpy(&data, &source.data, sizeof(data_t)); return *this; }
|
|
function(const function &source) { operator=(source); }
|
|
|
|
//no pointer
|
|
function() {
|
|
data.callback = 0;
|
|
}
|
|
|
|
//symbolic link pointer (nall/dl.hpp::sym, etc)
|
|
function(void *callback) {
|
|
data.callback = callback ? &callback_global : 0;
|
|
data.callback_global = (R (*)(P...))callback;
|
|
}
|
|
|
|
//global function pointer
|
|
function(R (*callback)(P...)) {
|
|
data.callback = &callback_global;
|
|
data.callback_global = callback;
|
|
}
|
|
|
|
//member function pointer
|
|
template<typename C>
|
|
function(R (C::*callback)(P...), C *object) {
|
|
static_assert(sizeof data.callback_member >= sizeof callback, "callback_member is too small");
|
|
data.callback = &callback_member<C>;
|
|
(R (C::*&)(P...))data.callback_member = callback;
|
|
data.object = object;
|
|
}
|
|
|
|
//const member function pointer
|
|
template<typename C>
|
|
function(R (C::*callback)(P...) const, C *object) {
|
|
static_assert(sizeof data.callback_member >= sizeof callback, "callback_member is too small");
|
|
data.callback = &callback_member<C>;
|
|
(R (C::*&)(P...))data.callback_member = (R (C::*&)(P...))callback;
|
|
data.object = object;
|
|
}
|
|
|
|
//lambda function pointer
|
|
template<typename T>
|
|
function(T callback) {
|
|
static_assert(std::is_same<R, typename std::result_of<T(P...)>::type>::value, "lambda mismatch");
|
|
data.callback = &callback_global;
|
|
data.callback_global = (R (*)(P...))callback;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|