RenderThread.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Bildschirm; //! Screen.h
  9. class ZeitMesser; //! ZeitMesser.h
  10. class Bild; //! 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 stoppen;
  17. Bildschirm* bildschirm;
  18. ZeitMesser* zeit;
  19. double renderTickZeit;
  20. void* renderParameter;
  21. void* tickParameter;
  22. std::function<void(void*, void*, Bild*)> renderFunktion;
  23. std::function<void(void*, void*, double)> tickFunktion;
  24. bool pause;
  25. Critical cs;
  26. int maxFps;
  27. bool quiet;
  28. public:
  29. //! Constructor
  30. DLLEXPORT RenderTh();
  31. //! Destructor
  32. DLLEXPORT ~RenderTh();
  33. //! This is necessary if multiple threads use the object simultaneously.
  34. //! If lock() is called by two threads, the latter waits until the
  35. //! first has called unlock().
  36. DLLEXPORT void lock();
  37. //! This is necessary if multiple threads use the object simultaneously.
  38. //! If lock() is called by two threads, the latter waits until the
  39. //! first has called unlock().
  40. DLLEXPORT void unlock();
  41. //! Sets the screen object to be managed
  42. //! \param bildschirm The screen
  43. DLLEXPORT void setBildschirm(Bildschirm* bildschirm);
  44. //! The function that is automatically executed in a new thread
  45. DLLEXPORT void thread() override;
  46. //! Starts the render thread
  47. DLLEXPORT void beginn();
  48. //! Stops the render thread
  49. DLLEXPORT void beenden();
  50. //! if true, then nothing will be printed to std::cout
  51. DLLEXPORT void setQuiet(bool quiet);
  52. //! Sets the maximum frames per second
  53. //! \param fps Maximum frames per second
  54. DLLEXPORT void setMaxFps(int fps);
  55. //! Pauses the render thread
  56. //! \param p 1 if the thread should be paused
  57. DLLEXPORT void setPause(bool p);
  58. //! Sets the callback function that is always called before drawing
  59. //! \param rF The callback function
  60. DLLEXPORT void setRenderFunktion(
  61. std::function<void(void*, void*, Bild*)> rF);
  62. //! Sets the callback function that is always called before updating
  63. //! all objects \param tF The callback function
  64. DLLEXPORT void setTickFunktion(
  65. std::function<void(void*, void*, double)> tF);
  66. //! Sets the parameter of the callback function that is always called
  67. //! before drawing \param p The parameter
  68. DLLEXPORT void setRenderFunktionParameter(void* p);
  69. //! Sets the parameter of the callback function that is always called
  70. //! before updating all objects
  71. DLLEXPORT void setTickFunktionParameter(void* p);
  72. //! Returns the screen managed by this thread
  73. DLLEXPORT Bildschirm* getBildschirm() const;
  74. //! Returns the screen without increased reference counter managed
  75. //! by this thread
  76. DLLEXPORT Bildschirm* zBildschirm() const;
  77. //! Returns the time with which the tick() function of the screen
  78. //! was last called
  79. DLLEXPORT double getRenderTickZeit() const;
  80. };
  81. } // namespace Framework
  82. #endif