main.c 4.6 KB

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