diff --git a/Source/Engine/Core/Delegate.h b/Source/Engine/Core/Delegate.h index bd448165f..57d685031 100644 --- a/Source/Engine/Core/Delegate.h +++ b/Source/Engine/Core/Delegate.h @@ -405,6 +405,59 @@ public: } } + /// + /// Binds a static function (if not binded yet). + /// + template + void BindUnique() + { + FunctionType f; + f.template Bind(); + BindUnique(f); + } + + /// + /// Binds a member function (if not binded yet). + /// + /// The object instance. + template + void BindUnique(T* callee) + { + FunctionType f; + f.template Bind(callee); + BindUnique(f); + } + + /// + /// Binds a function (if not binded yet). + /// + /// The method. + void BindUnique(Signature method) + { + FunctionType f(method); + BindUnique(f); + } + + /// + /// Binds a function (if not binded yet). + /// + /// The function to bind. + void BindUnique(const FunctionType& f) + { + const intptr size = Platform::AtomicRead(&_size); + FunctionType* bindings = (FunctionType*)Platform::AtomicRead(&_ptr); + if (bindings) + { + // Skip if already binded + for (intptr i = 0; i < size; i++) + { + if (Platform::AtomicRead((intptr volatile*)&bindings[i]._callee) == (intptr)f._callee && Platform::AtomicRead((intptr volatile*)&bindings[i]._function) == (intptr)f._function) + return; + } + } + Bind(f); + } + /// /// Unbinds a static function. ///