RenderThread.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef RenderThread_H
  2. #define RenderThread_H
  3. #include <functional>
  4. #include "Critical.h"
  5. #include "Thread.h"
  6. namespace Framework
  7. {
  8. class Screen; //! Screen.h
  9. class Timer; //! Timer.h
  10. class Image; //! Image.h
  11. //! A thread that manages a screen. It calls the render() and
  12. //! tick() functions automatically
  13. class RenderTh : public Thread
  14. {
  15. private:
  16. bool stop;
  17. Screen* screen;
  18. Timer* timer;
  19. double renderTickTime;
  20. void* renderParameter;
  21. void* tickParameter;
  22. std::function<void(void*, void*, Image*)> renderFunktion;
  23. std::function<void(void*, void*, double)> tickFunktion;
  24. bool pause;
  25. ReadWriteLock rwLock;
  26. int maxFps;
  27. bool quiet;
  28. public:
  29. //! Constructor
  30. DLLEXPORT RenderTh();
  31. //! Destructor
  32. DLLEXPORT ~RenderTh();
  33. //! returns a lock for reading the object.
  34. DLLEXPORT Lock& readLock();
  35. //! returns a lock for writing the object.
  36. DLLEXPORT Lock& writeLock();
  37. //! Sets the screen object to be managed
  38. //! \param screen The screen
  39. DLLEXPORT void setScreen(Screen* screen);
  40. //! The function that is automatically executed in a new thread
  41. DLLEXPORT void thread() override;
  42. //! Starts the render thread
  43. DLLEXPORT void beginn();
  44. //! Stops the render thread
  45. DLLEXPORT void terminate();
  46. //! if true, then nothing will be printed to std::cout
  47. DLLEXPORT void setQuiet(bool quiet);
  48. //! Sets the maximum frames per second
  49. //! \param fps Maximum frames per second
  50. DLLEXPORT void setMaxFps(int fps);
  51. //! Pauses the render thread
  52. //! \param p 1 if the thread should be paused
  53. DLLEXPORT void setPause(bool p);
  54. //! Sets the callback function that is always called before drawing
  55. //! \param rF The callback function
  56. DLLEXPORT void setRenderFunktion(
  57. std::function<void(void*, void*, Image*)> rF);
  58. //! Sets the callback function that is always called before updating
  59. //! all objects \param tF The callback function
  60. DLLEXPORT void setTickFunktion(
  61. std::function<void(void*, void*, double)> tF);
  62. //! Sets the parameter of the callback function that is always called
  63. //! before drawing \param p The parameter
  64. DLLEXPORT void setRenderFunktionParameter(void* p);
  65. //! Sets the parameter of the callback function that is always called
  66. //! before updating all objects
  67. DLLEXPORT void setTickFunktionParameter(void* p);
  68. //! Returns the screen managed by this thread
  69. DLLEXPORT Screen* getScreen() const;
  70. //! Returns the screen without increased reference counter managed
  71. //! by this thread
  72. DLLEXPORT Screen* zScreen() const;
  73. //! Returns the time with which the tick() function of the screen
  74. //! was last called
  75. DLLEXPORT double getRenderTickZeit() const;
  76. };
  77. } // namespace Framework
  78. #endif