You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

135 lines
2.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. //
  11. // The Entity class
  12. // ---------------
  13. // Entities are objects that can be ticked by the game loop and/or the render
  14. // loop. Entities are implemented as one or several linked lists. See the
  15. // Ticker class for the ticking logic and the linked list implementation.
  16. //
  17. #if !defined __LOL_ENTITY_H__
  18. #define __LOL_ENTITY_H__
  19. #include <stdint.h>
  20. namespace lol
  21. {
  22. struct InitState
  23. {
  24. enum Value
  25. {
  26. Unknown,
  27. Error,
  28. NeedInitDraw,
  29. NeedInitGame,
  30. Ready,
  31. }
  32. m_value;
  33. inline InitState(Value v) : m_value(v) {}
  34. inline operator Value() { return m_value; }
  35. };
  36. class Entity
  37. {
  38. friend class Ticker;
  39. friend class TickerData;
  40. friend class Dict;
  41. friend class Emcee;
  42. public:
  43. virtual char const *GetName();
  44. inline bool IsTicked() { return !!m_ref && !m_autorelease; }
  45. protected:
  46. Entity();
  47. virtual ~Entity();
  48. inline int IsDestroying() { return m_destroy; }
  49. virtual void InitGame();
  50. virtual void InitDraw();
  51. virtual void TickGame(float seconds);
  52. virtual void TickDraw(float seconds);
  53. enum
  54. {
  55. GAMEGROUP_BEFORE = 0,
  56. GAMEGROUP_DEFAULT,
  57. GAMEGROUP_AFTER,
  58. GAMEGROUP_AFTER_0,
  59. GAMEGROUP_AFTER_1,
  60. // Must be the last element
  61. GAMEGROUP_END
  62. }
  63. m_gamegroup;
  64. enum
  65. {
  66. DRAWGROUP_BEFORE = GAMEGROUP_END,
  67. DRAWGROUP_LIGHT,
  68. DRAWGROUP_CAMERA,
  69. DRAWGROUP_DEFAULT,
  70. DRAWGROUP_AFTER,
  71. DRAWGROUP_AFTER_0,
  72. DRAWGROUP_AFTER_1,
  73. DRAWGROUP_HUD,
  74. DRAWGROUP_CAPTURE,
  75. // Must be the last element
  76. DRAWGROUP_END
  77. }
  78. m_drawgroup;
  79. static int const GAMEGROUP_BEGIN = 0;
  80. static int const DRAWGROUP_BEGIN = GAMEGROUP_END;
  81. static int const ALLGROUP_END = DRAWGROUP_END;
  82. /* The initialisation state */
  83. InitState m_initstate;
  84. #if !LOL_BUILD_RELEASE
  85. enum
  86. {
  87. STATE_IDLE = 0,
  88. STATE_PRETICK_GAME,
  89. STATE_POSTTICK_GAME,
  90. STATE_PRETICK_DRAW,
  91. STATE_POSTTICK_DRAW,
  92. }
  93. m_tickstate;
  94. #endif
  95. // Emcee begin
  96. private:
  97. void SetState(uint32_t newstate);
  98. void SetStateWhenMatch(uint32_t newstate,
  99. Entity *other_entity, uint32_t other_state);
  100. virtual uint32_t OnStateChanged(uint32_t newstate)
  101. {
  102. return LOLm_state = newstate;
  103. }
  104. uint32_t LOLm_state;
  105. // Emcee end
  106. private:
  107. int m_ref, m_autorelease, m_destroy;
  108. };
  109. } /* namespace lol */
  110. #endif // __LOL_ENTITY_H__