EVENT.H 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //*****************************************************************************
  19. //
  20. // EVENT.H
  21. //
  22. //*****************************************************************************
  23. #ifndef event_h
  24. #define event_h
  25. #include "grip.h"
  26. #include "list.h"
  27. #define HORIZONTAL 1
  28. #define VERTICAL 0
  29. #define EVENT_IGNORES 50 //This determines how many events
  30. //will fit on the ignore list. The
  31. //larger this value, the slower the
  32. //searches through the list will be.
  33. //Can be set to any value keeping
  34. //in mind memory and speed limitations
  35. #define EVENT_SPACING 16 //This value is used when generating
  36. //indexes into the event data. It
  37. //determines the spacing between
  38. //the coordinate associated with one
  39. //index and the coordinae associated
  40. //with the next index. By setting this
  41. //to a smaller value, you can cut down
  42. //on the number of compares required
  43. //to find events within a given
  44. //coordinate range, but at the same
  45. //time, you increase the size of the
  46. //index table. The size of the table
  47. //is given by EVENT_MAX_COORD divided
  48. //by this value.
  49. #define EVENT_MAX_COORD 4096 //This is the maximum value that
  50. //this module will encounter in
  51. //the event data. It can handle
  52. //higher values, but the search
  53. //times for any values above
  54. //this one will not have the benefit
  55. //of the index table, and hence
  56. //will be very slow
  57. //This value cannot exceed 32767
  58. #define EVENT_TRIGGER_TOP 32 //Top of trigger region
  59. #define EVENT_TRIGGER_BOTTOM 32 //Bottom of trigger region
  60. #define EVENT_TRIGGER_LEFT 32 //Left side of trigger region
  61. #define EVENT_TRIGGER_RIGHT 32 //Right side of trigger region
  62. #define EVENT_LEFT (short) 0x8000 //%1000000000000000
  63. #define EVENT_RIGHT (short) 0x4000 //%0100000000000000
  64. #define EVENT_UP 0x2000 //%0010000000000000
  65. #define EVENT_DOWN 0x1000 //%0001000000000000
  66. #define EVENT_DIR_MASK 0xf000 //%1111000000000000
  67. #define EVENT_INDEX_MAX 255
  68. #define EVENT_PERMANENT -1
  69. #define EVENT_TEMPORARY -2
  70. #define EVENT_NOT_IN_RANGE 10
  71. #define EVENT_ON_IGNORE_LIST 11
  72. void event_undefined(); //null event handler function
  73. typedef struct tag_EVENT
  74. {
  75. short sX; // From data file = x position
  76. short sY; // From data file = y position
  77. short sType; // From data file = application assigned id number
  78. short sFlags; // From data file = directional or optional trigger
  79. short sTimer; // Used when the event is on the ignore list
  80. short sIgnoreTimer; // Created & used in CEvent
  81. } EVENT;
  82. class CEvent
  83. {
  84. protected:
  85. short m_sScanYFrom;
  86. short m_sScanYTo;
  87. short m_sScanXFrom;
  88. short m_sScanXTo;
  89. short m_sEventTriggerMin;
  90. short m_sEventTriggerMax;
  91. short m_sEventConstMin;
  92. short m_sEventConstMax;
  93. short m_sDispOldX;
  94. short m_sDispOldY;
  95. short m_sOrientation;
  96. short m_sEventDir;
  97. EVENT* m_pEventData;
  98. static EVENT* m_pEventList; // Currently selected event set for this level
  99. static short m_aIndexList[EVENT_MAX_COORD/EVENT_SPACING];
  100. static CList m_IgnoreList;
  101. short SelectSet(short sEventSet);
  102. void TriggerInit(short sDispX, short sDispY);
  103. short Trigger(short sDispX, short sDispY);
  104. void CreateIndexes(short sOrientation);
  105. short Scan();
  106. short CallHandler(short sIndex);
  107. void DecrementTimers();
  108. inline void From_Bottom(short s)
  109. {
  110. m_sScanYFrom = s + GRIP_DISPLAY_H + EVENT_TRIGGER_BOTTOM + 1;
  111. }
  112. inline void To_Bottom(short s)
  113. {
  114. m_sScanYTo = s + GRIP_DISPLAY_H + EVENT_TRIGGER_BOTTOM;
  115. }
  116. inline void From_Top(short s)
  117. {
  118. m_sScanYFrom = max(0, s - EVENT_TRIGGER_TOP);
  119. }
  120. inline void To_Top(short s)
  121. {
  122. m_sScanYTo = max(0, s - (EVENT_TRIGGER_TOP + 1));
  123. }
  124. inline void From_Left(short s)
  125. {
  126. m_sScanXFrom = max(0, s - EVENT_TRIGGER_LEFT);
  127. }
  128. inline void To_Left(short s)
  129. {
  130. m_sScanXTo = max(0, s - (EVENT_TRIGGER_LEFT + 1));
  131. }
  132. inline void From_Right(short s)
  133. {
  134. m_sScanXFrom = s + GRIP_DISPLAY_W + EVENT_TRIGGER_RIGHT + 1;
  135. }
  136. inline void To_Right(short s)
  137. {
  138. m_sScanXTo = s + GRIP_DISPLAY_W + EVENT_TRIGGER_RIGHT;
  139. }
  140. public:
  141. // Default Constructor
  142. CEvent();
  143. // Destructor
  144. ~CEvent();
  145. // Reset - warm start the module
  146. void Reset();
  147. // Add Set
  148. short AddSet(short sSetNum);
  149. // Select Set
  150. short SelectSet();
  151. // TriggerInit - Call at start of level to trigger on-screen events
  152. void TriggerInit();
  153. // Trigger - Called every time a new event is "uncovered"
  154. void Trigger();
  155. // Ignore - Put event on the ignore list
  156. void Ignore(EVENT* pEvent);
  157. // Unignore - remove event from the ignore list
  158. void Unignore(EVENT* pEvent);
  159. // Search - search for event in selected event list
  160. EVENT* Search(short sEventNum);
  161. // SearchNext - search for next event of same type in the list
  162. EVENT* SearchNext(EVENT* pEvent);
  163. // SearchAll - search for event in all event lists
  164. short SearchAll(short sEventNum);
  165. };
  166. #endif //event_h