No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

engine.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* The MIT License
  2. *
  3. * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #include "engine.h"
  24. #include "platform.h"
  25. #include "graphics.h"
  26. #include "const.h"
  27. #include "input.h"
  28. Engine g_engine;
  29. Engine::Engine() :
  30. m_stopping(false),
  31. m_running(false),
  32. m_lastFrameTicks(0)
  33. {
  34. }
  35. Engine::~Engine()
  36. {
  37. }
  38. void Engine::init()
  39. {
  40. Platform::init();
  41. int width = 640;
  42. int height = 480;
  43. // create the window
  44. Platform::createWindow(width, height, 550, 450);
  45. Platform::setWindowTitle(APP_NAME);
  46. Platform::setVsync();
  47. // initialize graphics stuff
  48. g_graphics.init();
  49. // finally show the window
  50. onResize(width, height);
  51. Platform::showWindow();
  52. Platform::hideMouseCursor();
  53. }
  54. void Engine::terminate()
  55. {
  56. Platform::showMouseCursor();
  57. Platform::terminate();
  58. g_graphics.terminate();
  59. }
  60. void Engine::run()
  61. {
  62. unsigned long ticks;
  63. m_running = true;
  64. m_lastFrameTicks = Platform::getTicks();
  65. while(!m_stopping) {
  66. // fire platform events
  67. Platform::poll();
  68. // update
  69. ticks = Platform::getTicks();
  70. update(ticks - m_lastFrameTicks);
  71. m_lastFrameTicks = ticks;
  72. // render
  73. render();
  74. // swap buffers
  75. Platform::swapBuffers();
  76. }
  77. m_lastFrameTicks = 0;
  78. m_stopping = false;
  79. m_running = false;
  80. }
  81. void Engine::stop()
  82. {
  83. m_stopping = true;
  84. }
  85. void Engine::render()
  86. {
  87. g_graphics.beginRender();
  88. g_graphics.endRender();
  89. }
  90. void Engine::update(int elapsedTicks)
  91. {
  92. }
  93. void Engine::onClose()
  94. {
  95. stop();
  96. }
  97. void Engine::onResize(int width, int height)
  98. {
  99. }
  100. void Engine::onInputEvent(InputEvent *event)
  101. {
  102. }