BsCoreThreadAccessor.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRenderAPI.h"
  4. #include "BsCommandQueue.h"
  5. #include "BsAsyncOp.h"
  6. #include "BsViewport.h"
  7. #include "BsColor.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Contains some base functionality used for CoreThreadAccessor.
  12. *
  13. * @see CoreThreadAccesor
  14. */
  15. class BS_CORE_EXPORT CoreThreadAccessorBase
  16. {
  17. public:
  18. CoreThreadAccessorBase(CommandQueueBase* commandQueue);
  19. virtual ~CoreThreadAccessorBase();
  20. /**
  21. * @brief Queues a new generic command that will be added to the command queue.
  22. */
  23. AsyncOp queueReturnCommand(std::function<void(AsyncOp&)> commandCallback);
  24. /**
  25. * @brief Queues a new generic command that will be added to the command queue.
  26. */
  27. void queueCommand(std::function<void()> commandCallback);
  28. /**
  29. * @brief Makes all the currently queued commands available to the core thread. They will be executed
  30. * as soon as the core thread is ready. All queued commands are removed from the accessor.
  31. */
  32. void submitToCoreThread(bool blockUntilComplete = false);
  33. /**
  34. * @brief Cancels all commands in the queue.
  35. */
  36. void cancelAll();
  37. private:
  38. CommandQueueBase* mCommandQueue;
  39. };
  40. /**
  41. * @brief Core thread accessor allows you to schedule core commands outside of the core thread. Provides a set of common
  42. * methods you may want to execute on the core thread, as well as a general command queuing methods.
  43. *
  44. * @note Queued commands are only executed after the call to submitToCoreThread, in the order they were submitted.
  45. */
  46. template <class CommandQueueSyncPolicy = CommandQueueNoSync>
  47. class BS_CORE_EXPORT CoreThreadAccessor : public CoreThreadAccessorBase
  48. {
  49. public:
  50. /**
  51. * @brief Constructor.
  52. *
  53. * @param threadId Identifier for the thread that created the accessor.
  54. */
  55. CoreThreadAccessor(BS_THREAD_ID_TYPE threadId)
  56. :CoreThreadAccessorBase(bs_new<CommandQueue<CommandQueueSyncPolicy>>(threadId))
  57. {
  58. }
  59. };
  60. }