entry_point.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include <stdio.h>
  2. #include "core/Renderer.h"
  3. #include "RootActor.h"
  4. #include "DebugActor.h"
  5. #include "example.h"
  6. using namespace oxygine;
  7. Renderer renderer;
  8. Rect viewport;
  9. int mainloop()
  10. {
  11. //update our rootActor
  12. //Actor::update would be called also for children
  13. RootActor::instance->update();
  14. Color clear(33, 33, 33, 255);
  15. //start rendering and clear viewport
  16. renderer.begin(0, viewport, &clear);
  17. //begin rendering from RootActor.
  18. RootActor::instance->render(renderer);
  19. //rendering done
  20. renderer.end();
  21. //update internal components
  22. //all input events would be passed to RootActor::instance.handleEvent
  23. //if done is true then User requests quit from app.
  24. bool done = core::update();
  25. return done ? 1 : 0;
  26. }
  27. //it is application entry point
  28. void run()
  29. {
  30. //initialize oxygine's internal stuff
  31. core::init();
  32. //create RootActor. RootActor is a root node
  33. RootActor::instance = new RootActor();
  34. Point size = core::getDisplaySize();
  35. //initialize it
  36. //first argument is real display size of device.
  37. //second is your "virtual" preferred size. You could change it to any size you need
  38. //VirtualWidth and VirtualHeight are defined in example.h
  39. RootActor::instance->init(size,
  40. Point(VirtualWidth, VirtualHeight));
  41. //DebugActor is a helper node it shows FPS and memory usage
  42. DebugActor::initialize();
  43. //create and add new DebugActor to root actor as child
  44. RootActor::instance->addChild(new DebugActor());
  45. //it is view and projection matrix initialization stuff
  46. Matrix view = makeViewMatrix(size.x, size.y); //Returns View matrix where Left Top corner is (0,0), and right bottom is (w,h)
  47. viewport = Rect(0, 0, size.x, size.y);
  48. Matrix proj;
  49. //initialize projection matrix
  50. Matrix::orthoLH(proj, (float)size.x, (float)size.y, 0, 1);
  51. //initialize Renderer
  52. //Renderer is class helper for rendering primitives and batching them
  53. //Renderer is lightweight class you could create it many of times
  54. //for example if you need to render something into RenderTarget (FBO)
  55. renderer.setDriver(IVideoDriver::instance);
  56. renderer.setViewTransform(view);
  57. renderer.setProjTransform(proj);
  58. //initialize this example stuff. check example.cpp
  59. example_init();
  60. bool done = false;
  61. //here is main game loop
  62. while (1)
  63. {
  64. int done = mainloop();
  65. if (done)
  66. break;
  67. }
  68. //so user closed application
  69. //lets dump all created objects into Output
  70. //all created and not freed resources would be displayed
  71. ObjectBase::dumpCreatedObjects();
  72. //lets cleanup everything right now and call ObjectBase::dumpObjects() again
  73. //we need to free all allocated resources and delete all created actors
  74. //yes, actor is smart pointer and actually you don't need it remove by hands
  75. //but now we want delete it forcedly
  76. //check example.cpp
  77. example_destroy();
  78. renderer.cleanup();
  79. /**releases all internal components and RootActor*/
  80. core::release();
  81. //dump list should be empty now
  82. //we deleted everything and could be sure that there aren't any memory leaks
  83. ObjectBase::dumpCreatedObjects();
  84. //end
  85. }
  86. #ifdef __S3E__
  87. int main(int argc, char* argv[])
  88. {
  89. run();
  90. return 0;
  91. }
  92. #endif
  93. #ifdef OXYGINE_SDL
  94. extern "C"
  95. {
  96. int SDL_main(int argc, char* argv[])
  97. {
  98. run();
  99. return 0;
  100. }
  101. };
  102. #endif
  103. #ifdef __FLASHPLAYER__
  104. int main(int argc, char* argv[])
  105. {
  106. printf("test\n");
  107. run();
  108. return 0;
  109. }
  110. #endif