BsCoreObjectCore.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. protected:
  21. friend class CoreObjectManager;
  22. friend class CoreObject;
  23. /**
  24. * @brief Called on the core thread when the object is first created.
  25. */
  26. virtual void initialize() { }
  27. /**
  28. * @brief Called on the core thread just before the object is destroyed.
  29. */
  30. virtual void destroy() { }
  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. virtual CoreSyncData syncFromCore(FrameAlloc* allocator) { return CoreSyncData(); }
  36. /**
  37. * @brief Update internal data from provided memory buffer that
  38. * was populated with data from the sim thread.
  39. */
  40. virtual void syncToCore(const CoreSyncData& data) { }
  41. /**
  42. * @brief Marks the core data as dirty. This causes the syncFromCore()
  43. * method to trigger the next time objects are synced between core and sim threads.
  44. *
  45. * @param flags Optional flags in case you want to signal that only part of the
  46. * internal data is dirty. syncFromCore() will be called regardless
  47. * and it's up to the implementation to read the flags value if needed.
  48. */
  49. void markCoreDirty(UINT32 flags = 0xFFFFFFFF) { mCoreDirtyFlags = flags; }
  50. /**
  51. * @brief Marks the core data as clean. Normally called right after syncFromCore()
  52. * has been called.
  53. */
  54. void markCoreClean() { mCoreDirtyFlags = 0; }
  55. /**
  56. * @brief Checks is the core dirty flag set. This is used by external systems
  57. * to know when internal data has changed and sim thread potentially needs to be notified.
  58. */
  59. bool isCoreDirty() const { return mCoreDirtyFlags != 0; }
  60. UINT32 mCoreDirtyFlags;
  61. };
  62. }