77 行
1.6 KiB

  1. //
  2. // Deus Hax (working title)
  3. // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
  4. //
  5. #if defined HAVE_CONFIG_H
  6. # include "config.h"
  7. #endif
  8. #include <cstdio>
  9. #include <cmath>
  10. #include <SDL.h>
  11. #include "sdlinput.h"
  12. #include "debugfps.h"
  13. #include "debugsprite.h"
  14. #include "debugrecord.h"
  15. #include "game.h"
  16. #include "ticker.h"
  17. #include "profiler.h"
  18. #include "video.h"
  19. static float const FPS = 30.0f;
  20. int main(int argc, char **argv)
  21. {
  22. /* Initialise SDL */
  23. if (SDL_Init(SDL_INIT_VIDEO) < 0)
  24. {
  25. fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
  26. return EXIT_FAILURE;
  27. }
  28. SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
  29. if (!video)
  30. {
  31. fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
  32. SDL_Quit();
  33. return EXIT_FAILURE;
  34. }
  35. SDL_WM_SetCaption("Map Test (SDL)", NULL);
  36. SDL_ShowCursor(0);
  37. SDL_WM_GrabInput(SDL_GRAB_ON);
  38. /* Initialise OpenGL */
  39. Video::Setup(video->w, video->h);
  40. /* Create a game */
  41. Game *game = new Game("maps/testmap.tmx");
  42. /* Register an input driver and some debug stuff */
  43. new SdlInput(game);
  44. new DebugFps();
  45. new DebugSprite(game);
  46. //new DebugRecord("lolengine.ogg");
  47. while (!game->Finished())
  48. {
  49. /* Tick the game */
  50. Ticker::TickGame();
  51. /* Clear the screen, tick the renderer, show the frame and
  52. * clamp to desired framerate. */
  53. Video::Clear();
  54. Ticker::TickRender();
  55. SDL_GL_SwapBuffers();
  56. Ticker::ClampFps(1000.0f / FPS);
  57. }
  58. SDL_Quit();
  59. return EXIT_SUCCESS;
  60. }