|
|
@@ -23,10 +23,8 @@ namespace BansheeEngine
|
|
|
*/
|
|
|
enum Flags
|
|
|
{
|
|
|
- CGO_INITIALIZED = 0x01, /**< Object has been fully initialized and may be used. */
|
|
|
- CGO_INIT_ON_CORE_THREAD = 0x02, /**< Object requires initialization on core thread. */
|
|
|
- CGO_SCHEDULED_FOR_INIT = 0x04, /**< Object has been scheduled for initialization but core thread has not completed it yet. */
|
|
|
- CGO_SCHEDULED_FOR_DELETE = 0x08 /**< Object has been scheduled for deletion but core thread has not completed it yet. */
|
|
|
+ CGO_DESTROYED = 0x01, /**< Object has been destroyed and shouldn't be used. */
|
|
|
+ CGO_INIT_ON_CORE_THREAD = 0x02 /**< Object requires initialization on core thread. */
|
|
|
};
|
|
|
|
|
|
public:
|
|
|
@@ -62,13 +60,9 @@ namespace BansheeEngine
|
|
|
virtual void initialize();
|
|
|
|
|
|
/**
|
|
|
- * @brief Returns true if the object has been properly initialized. You are not
|
|
|
- * allowed to call any methods on the resource until you are sure resource is initialized.
|
|
|
- *
|
|
|
- * @note Normally CPU objects are initialized on creation and this will never be false, and GPU
|
|
|
- * objects are initialized when the core thread processes them.
|
|
|
+ * @brief Returns true if the object has been destroyed. Destroyed object should not be used.
|
|
|
*/
|
|
|
- bool isInitialized() const { return (mFlags & CGO_INITIALIZED) != 0; }
|
|
|
+ bool isDestroyed() const { return (mFlags & CGO_DESTROYED) != 0; }
|
|
|
|
|
|
/**
|
|
|
* @brief Blocks the current thread until the resource is fully initialized.
|
|
|
@@ -94,20 +88,12 @@ namespace BansheeEngine
|
|
|
* @brief Internal method. Schedules the object to be destroyed, and then deleted.
|
|
|
*/
|
|
|
template<class T, class MemAlloc>
|
|
|
- static void _deleteDelayed(CoreObject* obj)
|
|
|
+ static void _delete(CoreObject* obj)
|
|
|
{
|
|
|
- _deleteDelayedInternal(obj);
|
|
|
-
|
|
|
- if(obj->isInitialized())
|
|
|
- {
|
|
|
- std::shared_ptr<CoreObject> thisPtr(obj);
|
|
|
- obj->_setThisPtr(thisPtr);
|
|
|
+ if (!obj->isDestroyed())
|
|
|
obj->destroy();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- bs_delete<MemAlloc, T>((T*)obj);
|
|
|
- }
|
|
|
+
|
|
|
+ bs_delete<MemAlloc, T>((T*)obj);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -132,29 +118,6 @@ namespace BansheeEngine
|
|
|
void syncToCore(CoreAccessor& accessor);
|
|
|
|
|
|
protected:
|
|
|
- /**
|
|
|
- * @brief Frees all of the internal resources. All derived classes that have something to free
|
|
|
- * should do it here instead of their destructor. All derived classes need to call this base method when they're done.
|
|
|
- *
|
|
|
- * @note For objects with "CGO_INIT_ON_CORE_THREAD" flag this is scheduled to be executed on the core thread,
|
|
|
- * so normally you want to destroy all GPU specific resources here.
|
|
|
- */
|
|
|
- virtual void destroyCore();
|
|
|
-
|
|
|
- /**
|
|
|
- * @brief Initializes all the internal resources of this object. Needs to be called before doing
|
|
|
- * any operations with the object. All derived classes also need to call this base method.
|
|
|
- *
|
|
|
- * @note For objects with "CGO_INIT_ON_CORE_THREAD" flag this is scheduled to be executed on the core thread,
|
|
|
- * so normally you want to initialize all GPU specific resources here.
|
|
|
- */
|
|
|
- virtual void initializeCore();
|
|
|
-
|
|
|
- /**
|
|
|
- * @brief Performs some internal checks when an object is being deleted.
|
|
|
- */
|
|
|
- static void _deleteDelayedInternal(CoreObject* obj);
|
|
|
-
|
|
|
/**
|
|
|
* @brief Queues a command to be executed on the core thread, without a return value.
|
|
|
*
|
|
|
@@ -162,7 +125,7 @@ namespace BansheeEngine
|
|
|
* make sure the object is not deleted before the command executes. Can be null if the
|
|
|
* function is static or global.
|
|
|
*/
|
|
|
- static void queueGpuCommand(std::shared_ptr<CoreObject>& obj, std::function<void()> func);
|
|
|
+ static void queueGpuCommand(const SPtr<CoreObjectCore>& obj, std::function<void()> func);
|
|
|
|
|
|
/**
|
|
|
* @brief Queues a command to be executed on the core thread, with a return value in the form of AsyncOp.
|
|
|
@@ -173,15 +136,10 @@ namespace BansheeEngine
|
|
|
* make sure the object is not deleted before the command executes. Can be null if the
|
|
|
* function is static or global.
|
|
|
*/
|
|
|
- static AsyncOp queueReturnGpuCommand(std::shared_ptr<CoreObject>& obj, std::function<void(AsyncOp&)> func);
|
|
|
+ static AsyncOp queueReturnGpuCommand(const SPtr<CoreObjectCore>& obj, std::function<void(AsyncOp&)> func);
|
|
|
|
|
|
- bool isScheduledToBeInitialized() const { return (mFlags & CGO_SCHEDULED_FOR_INIT) != 0; }
|
|
|
- bool isScheduledToBeDeleted() const { return (mFlags & CGO_SCHEDULED_FOR_DELETE) != 0; }
|
|
|
bool requiresInitOnCoreThread() const { return (mFlags & CGO_INIT_ON_CORE_THREAD) != 0; }
|
|
|
-
|
|
|
- void setIsInitialized(bool initialized) { mFlags = initialized ? mFlags | CGO_INITIALIZED : mFlags & ~CGO_INITIALIZED; }
|
|
|
- void setScheduledToBeInitialized(bool scheduled) { mFlags = scheduled ? mFlags | CGO_SCHEDULED_FOR_INIT : mFlags & ~CGO_SCHEDULED_FOR_INIT; }
|
|
|
- void setScheduledToBeDeleted(bool scheduled) { mFlags = scheduled ? mFlags | CGO_SCHEDULED_FOR_DELETE : mFlags & ~CGO_SCHEDULED_FOR_DELETE; }
|
|
|
+ void setIsDestroyed(bool destroyed) { mFlags = destroyed ? mFlags | CGO_DESTROYED : mFlags & ~CGO_DESTROYED; }
|
|
|
private:
|
|
|
friend class CoreObjectManager;
|
|
|
|
|
|
@@ -190,14 +148,11 @@ namespace BansheeEngine
|
|
|
UINT64 mInternalID; // ID == 0 is not a valid ID
|
|
|
std::weak_ptr<CoreObject> mThis;
|
|
|
|
|
|
- BS_STATIC_THREAD_SYNCHRONISER(mCoreGpuObjectLoadedCondition)
|
|
|
- BS_STATIC_MUTEX(mCoreGpuObjectLoadedMutex)
|
|
|
-
|
|
|
/**
|
|
|
* @brief Queues object initialization command on the core thread. The command is added to the
|
|
|
* primary core thread queue and will be executed as soon as the core thread is ready.
|
|
|
*/
|
|
|
- static void queueInitializeGpuCommand(std::shared_ptr<CoreObject>& obj);
|
|
|
+ static void queueInitializeGpuCommand(const SPtr<CoreObjectCore>& obj);
|
|
|
|
|
|
/**
|
|
|
* @brief Queues object destruction command on the core thread. The command is added to the
|
|
|
@@ -206,17 +161,17 @@ namespace BansheeEngine
|
|
|
*
|
|
|
* @note It is up to the caller to ensure no other accessors attempt to use this object.
|
|
|
*/
|
|
|
- static void queueDestroyGpuCommand(std::shared_ptr<CoreObject>& obj);
|
|
|
+ static void queueDestroyGpuCommand(const SPtr<CoreObjectCore>& obj);
|
|
|
|
|
|
/**
|
|
|
* @brief Helper wrapper method used for queuing commands with no return value on the core thread.
|
|
|
*/
|
|
|
- static void executeGpuCommand(std::shared_ptr<CoreObject> obj, std::function<void()> func);
|
|
|
+ static void executeGpuCommand(const SPtr<CoreObjectCore>& obj, std::function<void()> func);
|
|
|
|
|
|
/**
|
|
|
* @brief Helper wrapper method used for queuing commands with a return value on the core thread.
|
|
|
*/
|
|
|
- static void executeReturnGpuCommand(std::shared_ptr<CoreObject> obj, std::function<void(AsyncOp&)> func, AsyncOp& op);
|
|
|
+ static void executeReturnGpuCommand(const SPtr<CoreObjectCore>& obj, std::function<void(AsyncOp&)> func, AsyncOp& op);
|
|
|
|
|
|
protected:
|
|
|
/************************************************************************/
|
|
|
@@ -289,7 +244,7 @@ namespace BansheeEngine
|
|
|
std::shared_ptr<Type> bs_core_ptr(Args &&...args)
|
|
|
{
|
|
|
return std::shared_ptr<Type>(bs_new<Type, MainAlloc>(std::forward<Args>(args)...),
|
|
|
- &CoreObject::_deleteDelayed<Type, MainAlloc>, StdAlloc<Type, PtrDataAlloc>());
|
|
|
+ &CoreObject::_delete<Type, MainAlloc>, StdAlloc<Type, PtrDataAlloc>());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -302,7 +257,7 @@ namespace BansheeEngine
|
|
|
std::shared_ptr<Type> bs_core_ptr(Args &&...args)
|
|
|
{
|
|
|
return std::shared_ptr<Type>(bs_new<Type, MainAlloc>(std::forward<Args>(args)...),
|
|
|
- &CoreObject::_deleteDelayed<Type, MainAlloc>, StdAlloc<Type, GenAlloc>());
|
|
|
+ &CoreObject::_delete<Type, MainAlloc>, StdAlloc<Type, GenAlloc>());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -315,7 +270,7 @@ namespace BansheeEngine
|
|
|
std::shared_ptr<Type> bs_core_ptr(Args &&...args)
|
|
|
{
|
|
|
return std::shared_ptr<Type>(bs_new<Type, GenAlloc>(std::forward<Args>(args)...),
|
|
|
- &CoreObject::_deleteDelayed<Type, GenAlloc>, StdAlloc<Type, GenAlloc>());
|
|
|
+ &CoreObject::_delete<Type, GenAlloc>, StdAlloc<Type, GenAlloc>());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -327,7 +282,7 @@ namespace BansheeEngine
|
|
|
template<class Type, class MainAlloc>
|
|
|
std::shared_ptr<Type> bs_core_ptr(Type* data)
|
|
|
{
|
|
|
- return std::shared_ptr<Type>(data, &CoreObject::_deleteDelayed<Type, MainAlloc>, StdAlloc<Type, GenAlloc>());
|
|
|
+ return std::shared_ptr<Type>(data, &CoreObject::_delete<Type, MainAlloc>, StdAlloc<Type, GenAlloc>());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -339,6 +294,6 @@ namespace BansheeEngine
|
|
|
template<class Type, class MainAlloc, class PtrDataAlloc>
|
|
|
std::shared_ptr<Type> bs_core_ptr(Type* data)
|
|
|
{
|
|
|
- return std::shared_ptr<Type>(data, &CoreObject::_deleteDelayed<Type, MainAlloc>, StdAlloc<Type, PtrDataAlloc>());
|
|
|
+ return std::shared_ptr<Type>(data, &CoreObject::_delete<Type, MainAlloc>, StdAlloc<Type, PtrDataAlloc>());
|
|
|
}
|
|
|
}
|