So I have been looking into using the background resource loading semantics in ResourceCache
, but I’ve ran into something I’d like to understand if there is a better solution for.
Lets say there are 10 objects that have subscribed to E_RESOURCEBACKGROUNDLOADED
, and each of these objects have requested different files to be loaded. In the event callback function, I’m having to write something like this:
void Tile::OnResourceLoaded(Urho3D::StsringHash eventType, Urho3D::VariantMap &eventData)
{
using namespace Urho3D;
using namespace Urho3D::ResourceBackgroundLoaded;
if ( eventData[ P_SUCCESS ].GetBool() )
{
auto resource = reinterpret_cast<Resource*>( eventDAta[ P_RESOURCE ].GetPtr() );
if ( resource->GetName().Compare( queuedResourceName ) == 0 )
{
// handle it here
}
}
}
Is there anyway to actually do it more along the lines of this:
void Tile::OnResourceLoaded(Urho3D::StsringHash eventType, Urho3D::VariantMap &eventData)
{
using namespace Urho3D;
using namespace Urho3D::ResourceBackgroundLoaded;
if ( eventData[ P_USERDATA ].GetPtr() == this && eventData[ P_SUCCESS ].GetBool() )
{
// do logic
}
}
I can certainly modify the source of the engine or re-implement this in a custom way, but before I go down either of those paths, I was curious if there was any sort of way of actually indicating that only a single recipient is interested in a specific event.