I am attempting to write a wrapper class for an Async Physics query function with a return type and many function parameters, some of which have default values. The wrapper class will help maintain an internal state of the async query, thread data, and other important meta-data, which makes it easier to use for engineers. Below is the function signature:
typedef std::function AsyncOverlapByObjectTypeFunction;
In my AsyncHelperFile.h, I have the following typedef and class:
typedef std::function<FTraceHandle( const FVector&, const FQuat&, const FCollisionObjectQueryParams&, const FCollisionShape&, const FCollisionQueryParams&, FOverlapDelegate*, uint32 )> AsyncOverlapByObjectTypeFunction;
/**
* Helper class for Async collisions
*/
class AsyncCollision_OverlapByObjectType
{
public:
AsyncCollision_OverlapByObjectType();
// Use this CTOR if there are multiple Worlds and you want to specify the world context.
// If no context is provided, then the StrayKiteAsyncCollision is used
explicit AsyncCollision_OverlapByObjectType( UWorld* const contextOverride );
~AsyncCollision_OverlapByObjectType();
FORCEINLINE const bool HasQueryPending() { return ( CurrentTraceHandle._Data.FrameNumber != StrayKiteAsyncCollision::InvalidFrameNumber ); }
FORCEINLINE FOverlapDelegate& GetOverlapDelegate() { return OverlapDelegate; }
FORCEINLINE FTraceHandle GetTraceHandle() const { return CurrentTraceHandle; }
void Reset();
private:
// Called from CTOR's
FORCEINLINE void SetOverlapQueryForWorldContext( UWorld* const worldContext )
{
CurrentWorldContext = CurrentWorldContext;
AsyncOverlapByObjectType = std::bind( &UWorld::AsyncOverlapByObjectType, worldContext, const FVector&, const FQuat&, const FCollisionObjectQueryParams&, const FCollisionShape&, const FCollisionQueryParams&, FOverlapDelegate*, uint32 );
}
AsyncOverlapByObjectTypeFunction AsyncOverlapByObjectType;
FOverlapDatum OverlapDatum;
FOverlapDelegate OverlapDelegate;
FTraceHandle CurrentTraceHandle;
TWeakObjectPtr<UWorld> CurrentWorldContext;
};
Since most of my C++ experience is Pre-C++11, I am not that familiar with std::function and std::bind. I am struggling to find good examples of how to use this pair together to bind a complex member function ptr with a return type.
The current compile error I am receiving is error C2059: syntax error: 'const on line 99, which is this snippet:
AsyncOverlapByObjectType = std::bind( &UWorld::AsyncOverlapByObjectType, worldContext, const FVector&, const FQuat&, const FCollisionObjectQueryParams&, const FCollisionShape&, const FCollisionQueryParams&, FOverlapDelegate*, uint32 );
What do I need to do to use these std library functions in conjunction together so that I may bind a std::function object to the UWorld::AsyncOverlapByObjectType function? Conceptually, am I missing a core concept here for their use? My current guess is it is not working due to how I am using std::bind. Does std::bind need dummy arguments for all the possible function parameters in UWorld::AsyncOverlapByObjectType? Any conceptual explanation of how these work together would be helpful.
Aucun commentaire:
Enregistrer un commentaire