// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "../ContentLoadTask.h"
#include "Engine/Content/Asset.h"
#include "Engine/Content/AssetReference.h"
#include "Engine/Content/WeakAssetReference.h"
#include "Engine/Profiler/ProfilerCPU.h"
///
/// Asset loading task object.
///
class LoadAssetTask : public ContentLoadTask
{
private:
WeakAssetReference _asset;
public:
///
/// Initializes a new instance of the class.
///
/// The asset to load.
LoadAssetTask(Asset* asset)
: ContentLoadTask(Type::LoadAsset)
, _asset(asset)
{
}
public:
///
/// Gets the asset.
///
/// The asset.
FORCE_INLINE Asset* GetAsset() const
{
return _asset.Get();
}
public:
// [ContentLoadTask]
bool HasReference(Object* obj) const override
{
return obj == _asset;
}
protected:
// [ContentLoadTask]
Result run() override
{
PROFILE_CPU();
AssetReference ref = _asset.Get();
if (ref == nullptr)
return Result::MissingReferences;
// Call loading
if (ref->onLoad(this))
return Result::AssetLoadError;
return Result::Ok;
}
void OnEnd() override
{
_asset = nullptr;
// Base
ContentLoadTask::OnEnd();
}
};