BsCoreObjectCore.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsAsyncOp.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Represents part of a CoreObject that is meant to be used specifically
  8. * on the core thread.
  9. *
  10. * @note Core thread only.
  11. *
  12. * Different CoreObject implementations should implement this class for their
  13. * own needs.
  14. */
  15. class BS_CORE_EXPORT CoreObjectCore
  16. {
  17. public:
  18. CoreObjectCore();
  19. virtual ~CoreObjectCore();
  20. /**
  21. * @brief Called on the core thread when the object is first created.
  22. */
  23. virtual void initialize() { }
  24. /**
  25. * @brief Called on the core thread just before the object is destroyed.
  26. */
  27. virtual void destroy();
  28. protected:
  29. friend class CoreObjectManager;
  30. friend class CoreObject;
  31. /**
  32. * @brief Copy internal dirty data to a memory buffer that will be used
  33. * for updating sim thread version of that data.
  34. *
  35. * @note This generally happens at the end of a core thread frame. Data is then passed
  36. * to the sim thread and will be available on the next sim thread frame.
  37. */
  38. virtual CoreSyncData syncFromCore(FrameAlloc* allocator) { return CoreSyncData(); }
  39. /**
  40. * @brief Update internal data from provided memory buffer that
  41. * was populated with data from the sim thread.
  42. *
  43. * @note This generally happens at the start of a core thread frame. Data used was
  44. * recorded on the previous sim thread frame.
  45. */
  46. virtual void syncToCore(const CoreSyncData& data) { }
  47. /**
  48. * @brief Marks the core data as dirty. This causes the syncFromCore()
  49. * method to trigger the next time objects are synced between core and sim threads.
  50. *
  51. * @param flags Optional flags in case you want to signal that only part of the
  52. * internal data is dirty. syncFromCore() will be called regardless
  53. * and it's up to the implementation to read the flags value if needed.
  54. */
  55. void markCoreDirty(UINT32 flags = 0xFFFFFFFF) { mCoreDirtyFlags = flags; }
  56. /**
  57. * @brief Marks the core data as clean. Normally called right after syncFromCore()
  58. * has been called.
  59. */
  60. void markCoreClean() { mCoreDirtyFlags = 0; }
  61. /**
  62. * @brief Checks is the core dirty flag set. This is used by external systems
  63. * to know when internal data has changed and sim thread potentially needs to be notified.
  64. */
  65. bool isCoreDirty() const { return mCoreDirtyFlags != 0; }
  66. UINT32 mCoreDirtyFlags;
  67. bool mIsDestroyed;
  68. };
  69. }