eruta.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef ERUTA_H
  2. #define ERUTA_H
  3. /* Commonly used includes. */
  4. #include <math.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdint.h>
  8. #include <stdarg.h>
  9. #include <allegro5/allegro.h>
  10. #include <allegro5/allegro_font.h>
  11. #include <allegro5/allegro_ttf.h>
  12. #include <allegro5/allegro_image.h>
  13. #include <allegro5/allegro_primitives.h>
  14. #include <allegro5/allegro_audio.h>
  15. #include <allegro5/allegro_acodec.h>
  16. #include "bevec.h"
  17. /* Nogfx mode displays merely boxes. */
  18. // #define ERUTA_NOGFX_MODE
  19. /* Screen size wich will always be 640x480 (real or virtually). */
  20. #define SCREEN_W 640
  21. #define SCREEN_H 480
  22. /* Bitwise operations helpers. */
  23. #define BIT_ISFLAG(NUM, FLAG) ((NUM) & (FLAG))
  24. #define BIT_ISBIT(NUM, BIT) BIT_ISFLAG(NUM, (1 << BIT))
  25. #define BIT_SETFLAG(NUM, FLAG) ((NUM) | (FLAG))
  26. #define BIT_UNFLAG(NUM, FLAG) ((NUM) & (~(FLAG)))
  27. #define BIT_SETBIT(NUM, BIT) BIT_SETFLAG(NUM, (1 << BIT))
  28. #define BIT_UNBIT(NUM, BIT) BIT_UNFLAG(NUM, (1 << BIT))
  29. /* Clamping */
  30. #define CLAMP_MAX(SET, VALUE, MAX) do { \
  31. int value___ = (VALUE), max___ = (MAX); \
  32. (SET) = ((value___ > max___ ) ? (max___) : (value___)); \
  33. } while(0)
  34. /* */
  35. #ifndef TRUE
  36. #define TRUE (!0)
  37. #endif
  38. #ifndef FALSE
  39. #define FALSE (0)
  40. #endif
  41. /* Boolean type*/
  42. #ifndef BOOL
  43. #define BOOL int
  44. #endif
  45. /* String type */
  46. #ifndef STR
  47. #define STR ALLEGRO_USTR
  48. #endif
  49. /* Use the Bump vector as the Point type.
  50. Allegro also uses floats now for it's drawing. */
  51. typedef BeVec Point;
  52. /** Other shorthand types */
  53. typedef ALLEGRO_PATH Path;
  54. typedef ALLEGRO_EVENT Event;
  55. /* Wrapper macros */
  56. #define point(X, Y) bevec(X, Y);
  57. /* Some univerally useful function declarations. */
  58. /* Helper to convert paths to C strings */
  59. const char * fifi_path_cstr(Path * path);
  60. /* Helper for al_filename_exists with a Fifi path. */
  61. int fifi_path_exists(Path * path);
  62. /* Shorthand macros. */
  63. #define PATH_CSTR(PATH) (fifi_path_cstr(PATH))
  64. #define PATH_EXISTS(PATH) (fifi_path_exists(PATH))
  65. /*
  66. These macros can be used in the body of a function with ... args to
  67. map it to a functions with va_arg arguments as last. Use them like this:
  68. blah foo_va(bar last, va_args args);
  69. blah foo(bar last, ...) {
  70. VA_MAP_START(blah, last);
  71. VA_MAP_RESULT(foo_va(blag, VA_MAP_ARGS));
  72. VA_MAP_END();
  73. }
  74. */
  75. #define VA_MAP_START(TYPE, LAST) \
  76. va_list args___; \
  77. TYPE result___; \
  78. va_start(args___, LAST)
  79. #define VA_MAP_ARGS args___
  80. #define VA_MAP_RESULT(VALUE) do { \
  81. result___ = (VALUE); \
  82. } while (0)
  83. #define VA_MAP_END() \
  84. va_end(args___); \
  85. return result___
  86. /* Commonly used types and typedefs. */
  87. struct Program_;
  88. typedef struct Program_ Program;
  89. enum ProgramMode_ {
  90. // Negatieve modes are special.
  91. ProgramModeQuit = -2,
  92. ProgramModeNone = -1,
  93. ProgramModeIntro = 0,
  94. ProgramModeStart = 1,
  95. ProgramModePlay = 2,
  96. ProgramModeMenu = 3,
  97. ProgramModeEdit = 4,
  98. ProgramModeRes1 = 5,
  99. ProgramModeRes2 = 6,
  100. ProgramModeRes3 = 7,
  101. ProgramModeLast = 8,
  102. };
  103. typedef enum ProgramMode_ ProgramMode;
  104. /* Error or RESult. Zero if OK, negative if an error occurred. */
  105. enum Eres_ {
  106. ERES_OK = 0,
  107. ERES_NULL = -1,
  108. ERES_NOMEM = -2,
  109. ERES_NOFILE = -3,
  110. };
  111. typedef int ERES;
  112. #endif