Window.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef CORE_WINDOW_H
  2. #define CORE_WINDOW_H
  3. void window(void);
  4. /*namespace Window {
  5. typedef bool (*ShouldRun)();
  6. typedef void (*Tick)();
  7. typedef void (*Render)(float);
  8. struct Options final {
  9. int majorVersion;
  10. int minorVersion;
  11. const IntVector2& size;
  12. bool fullscreen;
  13. bool es;
  14. bool vsync;
  15. const char* name;
  16. Options(int majorVersion, int minorVersion, const IntVector2& size,
  17. bool es, const char* name);
  18. };
  19. Error open(const Options& options);
  20. void close();
  21. float getTicksPerSecond();
  22. float getFramesPerSecond();
  23. void trapCursor();
  24. void freeCursor();
  25. bool isCursorTrapped();
  26. const IntVector2& getSize();
  27. bool hasSizeChanged();
  28. void show();
  29. bool shouldClose();
  30. Error startFrame(Clock::Nanos& n);
  31. void endFrame();
  32. Error tick();
  33. void postTick();
  34. template<ShouldRun SR, Tick T, Render R>
  35. Error run(Clock::Nanos nanosPerTick) {
  36. Clock::Nanos lag = 0;
  37. while(SR()) {
  38. Clock::Nanos passedTime = 0;
  39. Error e = startFrame(passedTime);
  40. if(e.has()) {
  41. return e;
  42. }
  43. lag += passedTime;
  44. while(lag >= nanosPerTick) {
  45. lag -= nanosPerTick;
  46. e = tick();
  47. if(e.has()) {
  48. return e;
  49. }
  50. T();
  51. postTick();
  52. }
  53. R(static_cast<float>(lag) / static_cast<float>(nanosPerTick));
  54. endFrame();
  55. }
  56. return Error();
  57. }
  58. namespace Input {
  59. void setLimit(int limit);
  60. void reset();
  61. void enable();
  62. void disable();
  63. bool isEnabled();
  64. void fill(const char* s);
  65. int getCursor();
  66. void setCursor(int index);
  67. const List<uint32>& getUnicode();
  68. template<int N>
  69. void toString(StringBuffer<N>& s) {
  70. for(uint32 c : getUnicode()) {
  71. s.appendUnicode(c);
  72. }
  73. }
  74. }
  75. namespace Controls {
  76. typedef StringBuffer<32> ButtonName;
  77. typedef int ButtonId;
  78. ButtonId add(const ButtonName& name);
  79. void bindKey(ButtonId id, int key);
  80. void bindGamepad(ButtonId id, int gamepadButton);
  81. void bindMouse(ButtonId id, int mouseButton);
  82. Vector2 getLastMousePosition();
  83. Vector2 getMousePosition();
  84. Vector2 getLeftGamepadAxis();
  85. Vector2 getRightGamepadAxis();
  86. float getLeftGamepadTrigger();
  87. float getRightGamepadTrigger();
  88. bool isDown(ButtonId id);
  89. int getDownTime(ButtonId id);
  90. bool wasReleased(ButtonId id);
  91. const ButtonName& getName(ButtonId id);
  92. }
  93. }*/
  94. #endif