Merge branch 'master' into mac

This commit is contained in:
Wojtek Figat
2022-01-09 19:15:15 +01:00
94 changed files with 1726 additions and 499 deletions

View File

@@ -11,6 +11,9 @@
#include "Engine/Serialization/FileWriteStream.h"
#include "Engine/Serialization/MemoryWriteStream.h"
#include "Engine/Debug/Exceptions/Exceptions.h"
#if USE_EDITOR
#include "Engine/Core/Collections/Array.h"
#endif
#include <iostream>
#define LOG_ENABLE_FILE (!PLATFORM_SWITCH)

View File

@@ -1,25 +0,0 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#include "Object.h"
#include "ObjectsRemovalService.h"
RemovableObject::~RemovableObject()
{
#if BUILD_DEBUG
// Prevent removing object that is still reverenced by the removal service
ASSERT(!ObjectsRemovalService::IsInPool(this));
#endif
}
void RemovableObject::DeleteObjectNow()
{
ObjectsRemovalService::Dereference(this);
OnDeleteObject();
}
void RemovableObject::DeleteObject(float timeToLive, bool useGameTime)
{
// Add to deferred remove (or just update timeout but don't remove object here)
ObjectsRemovalService::Add(this, timeToLive, useGameTime);
}

View File

@@ -37,30 +37,13 @@ public:
/// <summary>
/// Finalizes an instance of the <see cref="Object"/> class.
/// </summary>
virtual ~Object()
{
}
virtual ~Object();
/// <summary>
/// Gets the string representation of this object.
/// </summary>
/// <returns>The string.</returns>
virtual String ToString() const = 0;
};
/// <summary>
/// Interface for removable Engine objects.
/// </summary>
/// <seealso cref="Object" />
class FLAXENGINE_API RemovableObject : public Object
{
public:
/// <summary>
/// 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.
/// </summary>
virtual ~RemovableObject();
/// <summary>
/// Deletes the object without queueing it to the ObjectsRemovalService.
@@ -68,7 +51,7 @@ public:
void DeleteObjectNow();
/// <summary>
/// Deletes the object.
/// Deletes the object (deferred).
/// </summary>
/// <param name="timeToLive">The time to live (in seconds). Use zero to kill it now.</param>
/// <param name="useGameTime">True if unscaled game time for the object life timeout, otherwise false to use absolute time.</param>
@@ -82,3 +65,6 @@ public:
Delete(this);
}
};
// [Deprecated on 5.01.2022, expires on 5.01.2024]
typedef Object RemovableObject;

View File

@@ -16,8 +16,8 @@ namespace ObjectsRemovalServiceImpl
CriticalSection NewItemsLocker;
DateTime LastUpdate;
float LastUpdateGameTime;
Dictionary<RemovableObject*, float> Pool(8192);
Dictionary<RemovableObject*, float> NewItemsPool(2048);
Dictionary<Object*, float> Pool(8192);
Dictionary<Object*, float> NewItemsPool(2048);
}
using namespace ObjectsRemovalServiceImpl;
@@ -38,7 +38,7 @@ public:
ObjectsRemovalServiceService ObjectsRemovalServiceServiceInstance;
bool ObjectsRemovalService::IsInPool(RemovableObject* obj)
bool ObjectsRemovalService::IsInPool(Object* obj)
{
if (!IsReady)
return false;
@@ -67,7 +67,7 @@ bool ObjectsRemovalService::HasNewItemsForFlush()
return result;
}
void ObjectsRemovalService::Dereference(RemovableObject* obj)
void ObjectsRemovalService::Dereference(Object* obj)
{
if (!IsReady)
return;
@@ -81,7 +81,7 @@ void ObjectsRemovalService::Dereference(RemovableObject* obj)
PoolLocker.Unlock();
}
void ObjectsRemovalService::Add(RemovableObject* obj, float timeToLive, bool useGameTime)
void ObjectsRemovalService::Add(Object* obj, float timeToLive, bool useGameTime)
{
ScopeLock lock(NewItemsLocker);
@@ -213,3 +213,24 @@ void ObjectsRemovalServiceService::Dispose()
IsReady = false;
}
Object::~Object()
{
#if BUILD_DEBUG
// Prevent removing object that is still reverenced by the removal service
ASSERT(!ObjectsRemovalService::IsInPool(this));
#endif
}
void Object::DeleteObjectNow()
{
ObjectsRemovalService::Dereference(this);
OnDeleteObject();
}
void Object::DeleteObject(float timeToLive, bool useGameTime)
{
// Add to deferred remove (or just update timeout but don't remove object here)
ObjectsRemovalService::Add(this, timeToLive, useGameTime);
}

View File

@@ -16,7 +16,7 @@ public:
/// </summary>
/// <param name="obj">The object.</param>
/// <returns>True if object has been registered in the pool for the removing, otherwise false.</returns>
static bool IsInPool(RemovableObject* obj);
static bool IsInPool(Object* obj);
/// <summary>
/// Determines whether any object has been registered to be removed from pool (requests are flushed on Flush call).
@@ -28,7 +28,7 @@ public:
/// Removes the specified object from the dead pool (clears the reference to it).
/// </summary>
/// <param name="obj">The object.</param>
static void Dereference(RemovableObject* obj);
static void Dereference(Object* obj);
/// <summary>
/// Adds the specified object to the dead pool.
@@ -36,7 +36,7 @@ public:
/// <param name="obj">The object.</param>
/// <param name="timeToLive">The time to live (in seconds).</param>
/// <param name="useGameTime">True if unscaled game time for the object life timeout, otherwise false to use absolute time.</param>
static void Add(RemovableObject* obj, float timeToLive = 1.0f, bool useGameTime = false);
static void Add(Object* obj, float timeToLive = 1.0f, bool useGameTime = false);
/// <summary>
/// Flushes the objects pool removing objects marked to remove now (with negative or zero time to live).

View File

@@ -337,6 +337,8 @@ public:
void ReserveSpace(int32 length)
{
ASSERT(length >= 0);
if (length == _length)
return;
Platform::Free(_data);
if (length != 0)
{