// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "Memory/Memory.h"
///
/// Engine objects flags used in various aspects but packed into a single flags container.
///
enum class ObjectFlags : uint32
{
None = 0,
WasMarkedToDelete = 1 << 0,
UseGameTimeForDelete = 1 << 1,
IsRegistered = 1 << 2,
IsManagedType = 1 << 3,
IsDuringPlay = 1 << 4,
IsCustomScriptingType = 1 << 5,
};
DECLARE_ENUM_OPERATORS(ObjectFlags);
///
/// Interface for Engine objects.
///
class FLAXENGINE_API Object
{
public:
///
/// The object flags.
///
ObjectFlags Flags = ObjectFlags::None;
public:
///
/// Finalizes an instance of the class.
///
virtual ~Object()
{
}
///
/// Gets the string representation of this object.
///
/// The string.
virtual String ToString() const = 0;
};
///
/// Interface for removable Engine objects.
///
class FLAXENGINE_API RemovableObject : public Object
{
public:
///
/// Virtual destructor but protected. Removable objects should be deleted using `DeleteObject` which supports deferred delete.
/// Note: it's unsafe to delete object using destructor it it has been marked for deferred delete.
///
virtual ~RemovableObject();
///
/// Deletes the object without queueing it to the ObjectsRemovalService.
///
void DeleteObjectNow();
///
/// Deletes the object.
///
/// The time to live (in seconds). Use zero to kill it now.
/// True if unscaled game time for the object life timeout, otherwise false to use absolute time.
void DeleteObject(float timeToLive = 0.0f, bool useGameTime = false);
///
/// Deletes the object. Called by the ObjectsRemovalService. Can be overriden to provide custom logic per object (cleanup, etc.).
///
virtual void OnDeleteObject()
{
Delete(this);
}
};