main.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // #include <libxml/parser.h>
  2. #include "eruta.h"
  3. #include "state.h"
  4. #include "react.h"
  5. #include "image.h"
  6. #include "tile.h"
  7. #include "tilepane.h"
  8. #include "tilemap.h"
  9. #include "tileio.h"
  10. #include "sound.h"
  11. #include "silut.h"
  12. #include "fifi.h"
  13. #include "ui.h"
  14. #include "hatab.h"
  15. /* #include "beo.h" */
  16. #include "assert.h"
  17. #include "str.h"
  18. #include "sprite.h"
  19. #include "alps.h"
  20. #include "store.h"
  21. #include "scegra.h"
  22. #include "callrb.h"
  23. #include "zori.h"
  24. #include "zori_console.h"
  25. #define SCREEN_W 640
  26. #define SCREEN_H 480
  27. ALLEGRO_FONT* font;
  28. ALLEGRO_TRANSFORM identity;
  29. ALLEGRO_BITMAP* buffer;
  30. ALLEGRO_BITMAP* texture;
  31. ALLEGRO_COLOR solid_white;
  32. /** For some reason, onlt wav music plays?
  33. It seems there is a bug in init_dynlib() in the ogg driver but only
  34. if Allegro is compiled in the default RelWithDbg mode.
  35. ***/
  36. /* Testing function for al_get_standard_path */
  37. void puts_standard_path(int path, char * name) {
  38. ALLEGRO_PATH * testpath;
  39. testpath = al_get_standard_path(path);
  40. puts(name);
  41. puts(al_path_cstr(testpath, ALLEGRO_NATIVE_PATH_SEP));
  42. al_destroy_path(testpath);
  43. }
  44. /* Low level keys, not handled by the script. */
  45. React * main_react_key_down(React * self, ALLEGRO_KEYBOARD_EVENT * event) {
  46. State * state = state_get();
  47. /*
  48. Point f = bevec0();
  49. Camera * camera = NULL;
  50. if (!state) return NULL;
  51. camera = state_camera(state);
  52. if (!camera) return NULL;
  53. */
  54. switch(event->keycode) {
  55. /* Console control */
  56. case ALLEGRO_KEY_F1:
  57. case ALLEGRO_KEY_F3:
  58. /* Toggle the console here. */
  59. zori_console_active_(state_console(state), !zori_console_active(state_console(state)));
  60. break;
  61. case ALLEGRO_KEY_F2:
  62. /* Hide the console. */
  63. zori_console_active_(state_console(state), FALSE);
  64. break;
  65. case ALLEGRO_KEY_F5:
  66. /* Reload main script (and hence all other scripts that it loads) on F5 */
  67. rh_load_main();
  68. callrb_on_reload();
  69. break;
  70. /* Emergency exit keys. */
  71. case ALLEGRO_KEY_F12:
  72. case ALLEGRO_KEY_ESCAPE:
  73. state_done(state);
  74. return self;
  75. break;
  76. /* Otherwise it's up to the script. */
  77. default:
  78. return NULL;
  79. break;
  80. }
  81. return self;
  82. }
  83. /* Low level key releases not handled by the script. */
  84. React * main_react_key_up(React * self, ALLEGRO_KEYBOARD_EVENT * event) {
  85. Point f = bevec0();
  86. State * state = (State *) self->data;
  87. Camera * camera = NULL;
  88. if (!state) return NULL;
  89. camera = state_camera(state);
  90. if (!camera) return NULL;
  91. switch(event->keycode) {
  92. default:
  93. return NULL;
  94. break;
  95. }
  96. return self;
  97. }
  98. /* The real main loop of the Eruta engine. Most of the work happens in state.c,
  99. * and the main.rb script, though. */
  100. int real_main(void) {
  101. Image * border = NULL;
  102. Image * sheet = NULL;
  103. Tileset * tileset = NULL;
  104. Tile * tile = NULL;
  105. State * state = NULL;
  106. Camera * camera = NULL;
  107. Tilepane * tilepane = NULL;
  108. Tilemap * map = NULL;
  109. Thing * actor = NULL;
  110. Tracker * tracker = NULL;
  111. Tracker * maptracker = NULL;
  112. Sprite * sprite = NULL;
  113. SpriteState * spritestate = NULL;
  114. AlpsShower shower;
  115. int actor_id = -1;
  116. int sprite_id = -1;
  117. int npc1_id = -1;
  118. int npc2_id = -1;
  119. React react;
  120. ALLEGRO_COLOR myblack = {0.0, 0.0, 0.0, 1.0};
  121. state = state_alloc();
  122. state_set(state);
  123. if((!(state)) || (!state_init(state, FALSE))) {
  124. perror(state_errmsg(state));
  125. return 1;
  126. }
  127. alpsshower_init(&shower, state_camera(state), 100, 1.0, bevec(10.0, 10000.0));
  128. /* Initializes the reactor, the game state is it's data. */
  129. react_initempty(&react, state);
  130. react.keyboard_key_up = main_react_key_up;
  131. react.keyboard_key_down = main_react_key_down;
  132. puts_standard_path(ALLEGRO_EXENAME_PATH, "ALLEGRO_EXENAME_PATH:");
  133. camera = state_camera(state);
  134. /* Finally initialize ruby and call the ruby startup function. */
  135. rh_load_main();
  136. callrb_on_start();
  137. /* Main game loop, controlled by the State object. */
  138. while(state_busy(state)) {
  139. Point spritenow = bevec(100, 120);
  140. react_poll(&react, state);
  141. alpsshower_update(&shower, state_frametime(state));
  142. state_update(state);
  143. state_draw(state);
  144. /* alpsshower_draw(&shower, camera); */
  145. state_flip_display(state);
  146. }
  147. state_done(state);
  148. state_free(state);
  149. return 0;
  150. }
  151. int main(int argc, char* argv[]) {
  152. int res; // init xml parser
  153. // LIBXML_TEST_VERSION
  154. (void) argc, (void) argv;
  155. res = real_main();
  156. // cleanup xml parser
  157. // xmlCleanupParser();
  158. return res;
  159. }