main.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include <cstdio>
  2. #include <cstdarg>
  3. #include <os.h>
  4. #include "Timers.h"
  5. #include "Graphics.h"
  6. #include "Pixel.h"
  7. #include "Map.h"
  8. #include "Camera.h"
  9. #include "Text.h"
  10. #include "misc.h"
  11. #include "sprites.h"
  12. #include "version.h"
  13. #include "Interrupts.h"
  14. using namespace WalrusRPG;
  15. using namespace WalrusRPG::Graphics;
  16. using namespace WalrusRPG::Graphics::Text;
  17. void print_debug_camera_data(const Camera &camera)
  18. {
  19. print_format(0, 8, "CAM : X : %d Y: %d", camera.get_x(), camera.get_y());
  20. }
  21. void print_debug_map_data(const Map &map)
  22. {
  23. print_format(0, 16, "MAP : W: %d, H:%d", map.get_width(), map.get_height());
  24. }
  25. void map_loop(unsigned x, unsigned y, Map &map)
  26. {
  27. // Free-running, no interrupts, divider = 1, 32 bit, wrapping
  28. WalrusRPG::Timers::mode(0, true, false, false, 1, true);
  29. WalrusRPG::Timers::load(0, 0);
  30. unsigned loop_time = 546; // 32768Hz/60ups
  31. unsigned loop_next = -loop_time;
  32. unsigned last_frame = 0;
  33. unsigned keep_running = 1;
  34. Camera camera((signed) x, (signed) y);
  35. // Tileset asdf(better_character, 9, 16);
  36. TileRenderer asdf(better_character, 9, 16);
  37. Entity test_char(115, 90, 9, 16, &asdf, 0);
  38. while (keep_running)
  39. {
  40. if (isKeyPressed(KEY_NSPIRE_ESC))
  41. keep_running = 0;
  42. camera.update(0);
  43. // Frameskip
  44. if (WalrusRPG::Timers::read(0) > loop_next)
  45. {
  46. Pixel pix(Green);
  47. // TODO?: Preset color macros/consts?
  48. buffer_fill(pix);
  49. map.render(camera, 1);
  50. test_char.render(camera, 1);
  51. print_format(0, 0, "WalrusRPG test build %s", git_version);
  52. print_debug_camera_data(camera);
  53. print_debug_map_data(map);
  54. unsigned frame_stamp = WalrusRPG::Timers::read(0);
  55. print_format(0, 240 - 8, "%u fps", 32768 / (last_frame - frame_stamp));
  56. last_frame = frame_stamp;
  57. buffer_swap_render();
  58. }
  59. // Frame limiting
  60. while (WalrusRPG::Timers::read(0) > loop_next)
  61. ;
  62. loop_next -= loop_time;
  63. }
  64. }
  65. int main(int argc, char *argv[])
  66. {
  67. UNUSED(argc);
  68. UNUSED(argv);
  69. buffer_allocate();
  70. WalrusRPG::Timers::init(0);
  71. WalrusRPG::Interrupts::init();
  72. uint16_t dungeonTest[] = {
  73. 21, 21, 1, 1, 1, 1, 21, 22, 21, 22, 21, 22, 21, 21, 1, 22, 21,
  74. 1, 22, 22, 22, 1, 21, 2, 3, 3, 3, 3, 3, 4, 21, 1, 22, 21,
  75. 22, 22, 21, 21, 21, 1, 22, 22, 22, 23, 108, 109, 109, 109, 24, 87, 4,
  76. 21, 21, 22, 5, 6, 6, 7, 1, 1, 22, 21, 21, 23, 66, 67, 108, 109,
  77. 24, 109, 25, 21, 22, 5, 132, 43, 43, 28, 1, 1, 21, 22, 1, 23, 25,
  78. 23, 109, 109, 108, 108, 25, 1, 1, 26, 42, 110, 48, 49, 22, 21, 1, 21,
  79. 21, 23, 87, 88, 109, 24, 109, 109, 25, 1, 1, 26, 43, 131, 6, 7, 21,
  80. 1, 22, 1, 21, 44, 67, 109, 24, 24, 24, 66, 46, 1, 22, 26, 27, 43,
  81. 42, 131, 7, 21, 22, 1, 22, 21, 44, 45, 45, 45, 45, 46, 1, 22, 1,
  82. 26, 27, 27, 43, 27, 28, 22, 21, 22, 21, 1, 21, 1, 22, 22, 21, 1,
  83. 21, 22, 1, 47, 48, 111, 42, 27, 28, 21, 21, 1, 21, 21, 22, 2, 3,
  84. 3, 4, 1, 2, 3, 4, 1, 5, 132, 27, 27, 28, 1, 1, 22, 1, 22,
  85. 21, 23, 24, 66, 46, 1, 23, 24, 25, 1, 26, 42, 42, 110, 49, 21, 22,
  86. 21, 22, 22, 2, 88, 24, 25, 2, 3, 88, 24, 87, 4, 26, 43, 110, 49,
  87. 21, 21, 1, 1, 1, 2, 88, 24, 24, 87, 88, 108, 24, 24, 109, 25, 47,
  88. 48, 49, 1, 22, 22, 21, 1, 21, 23, 24, 24, 24, 24, 24, 24, 24, 24,
  89. 24, 87, 4, 21, 21, 22, 22, 22, 22, 1, 21, 23, 24, 24, 109, 24, 24,
  90. 24, 24, 24, 108, 109, 25, 21, 21, 22, 22, 22, 22, 21, 21, 44, 45, 45,
  91. 67, 24, 24, 24, 66, 45, 45, 45, 46, 1, 22, 1, 22, 22, 22, 21, 22,
  92. 22, 22, 1, 44, 67, 108, 108, 25, 22, 22, 1, 22, 21, 22, 21, 21, 1,
  93. 21, 22, 1, 22, 22, 1, 22, 44, 45, 45, 46, 1, 1, 1, 1, 21, 21,
  94. 21, 21, 21, 21, 22, 21, 21, 21, 1, 21, 1, 22, 22, 22, 1, 21, 22,
  95. 21, 1, 1, 22, 21, 1, 1, 21, 1, 1, 21, 21, 21, 1, 22, 22, 1,
  96. 21, 22, 21, 22, 1, 22, 21, 21, 21,
  97. };
  98. uint16_t dungeonTest2[] = {
  99. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  101. 0, 0, 0, 0, 0, 52, 53, 54, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  102. 0, 0, 0, 0, 0, 73, 74, 75, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  103. 0, 0, 0, 0, 0, 157, 158, 140, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  104. 0, 0, 0, 0, 0, 178, 179, 161, 181, 0, 12, 14, 12, 14, 162, 163, 164, 0, 0, 0,
  105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 184, 185, 0, 0, 0,
  106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 166, 0, 0, 186, 0, 0,
  107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 167, 0, 0,
  108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110. 0, 0, 0, 0, 133, 134, 134, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111. 0, 0, 0, 0, 154, 155, 155, 71, 135, 39, 40, 41, 0, 0, 0, 0, 0, 0, 0, 0,
  112. 0, 0, 0, 0, 154, 155, 155, 155, 156, 60, 61, 62, 0, 0, 0, 0, 0, 0, 0, 0,
  113. 0, 0, 0, 0, 175, 176, 51, 155, 156, 81, 82, 83, 0, 0, 0, 0, 0, 0, 0, 0,
  114. 0, 0, 0, 0, 0, 0, 175, 176, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119. };
  120. Map map(20, 20, dungeonTest, dungeonTest2);
  121. tinystl::vector<Frame> stripe21;
  122. tinystl::vector<Frame> stripe22;
  123. stripe21.push_back({21, 23});
  124. stripe21.push_back({22, 31});
  125. stripe22.push_back({22, 37});
  126. stripe22.push_back({21, 41});
  127. map.anim.add_animation(21, {stripe21, true});
  128. map.anim.add_animation(22, {stripe22, true});
  129. map_loop(0, 0, map);
  130. WalrusRPG::Interrupts::off();
  131. WalrusRPG::Timers::restore(0);
  132. buffer_free();
  133. return 0;
  134. }