// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Threading/Task.h"
#include "Engine/Core/Types/String.h"
class Asset;
class LoadingThread;
///
/// Describes content loading task object.
///
class ContentLoadTask : public Task
{
friend LoadingThread;
public:
///
/// Describes work type
///
DECLARE_ENUM_3(Type, Custom, LoadAsset, LoadAssetData);
///
/// Describes work result value
///
DECLARE_ENUM_5(Result, Ok, AssetLoadError, MissingReferences, LoadDataError, TaskFailed);
private:
///
/// Task type
///
Type _type;
protected:
///
/// Initializes a new instance of the class.
///
/// The task type.
ContentLoadTask(const Type type)
: _type(type)
{
}
public:
///
/// Gets a task type.
///
/// The type.
FORCE_INLINE Type GetType() const
{
return _type;
}
public:
///
/// Checks if async task is loading given asset resource
///
/// Target asset to check
/// True if is loading that asset, otherwise false
bool IsLoading(Asset* asset) const
{
return _type == Type::LoadAsset && HasReference((Object*)asset);
}
protected:
virtual Result run() = 0;
public:
// [Task]
String ToString() const override
{
return String::Format(TEXT("Content Load Task {0} ({1})"),
ToString(GetType()),
::ToString(GetState())
);
}
protected:
// [Task]
void Enqueue() override;
bool Run() override;
};