Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

132 рядки
2.7 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. #pragma once
  11. //
  12. // The Entity class
  13. // ---------------
  14. // Entities are objects that can be ticked by the game loop and/or the render
  15. // loop. Entities are implemented as one or several linked lists. See the
  16. // Ticker class for the ticking logic and the linked list implementation.
  17. //
  18. #include <stdint.h>
  19. namespace lol
  20. {
  21. struct InitState
  22. {
  23. enum Value
  24. {
  25. Unknown,
  26. Error,
  27. NeedInitDraw,
  28. NeedInitGame,
  29. Ready,
  30. }
  31. m_value;
  32. inline InitState(Value v) : m_value(v) {}
  33. inline operator Value() { return m_value; }
  34. };
  35. class Entity
  36. {
  37. friend class Ticker;
  38. friend class TickerData;
  39. friend class Dict;
  40. friend class Emcee;
  41. public:
  42. virtual char const *GetName();
  43. inline bool IsTicked() { return !!m_ref && !m_autorelease; }
  44. protected:
  45. Entity();
  46. virtual ~Entity();
  47. inline int IsDestroying() { return m_destroy; }
  48. virtual void InitGame();
  49. virtual void InitDraw();
  50. virtual void TickGame(float seconds);
  51. virtual void TickDraw(float seconds, class Scene &scene);
  52. enum
  53. {
  54. GAMEGROUP_BEFORE = 0,
  55. GAMEGROUP_DEFAULT,
  56. GAMEGROUP_AFTER,
  57. GAMEGROUP_AFTER_0,
  58. GAMEGROUP_AFTER_1,
  59. // Must be the last element
  60. GAMEGROUP_END
  61. }
  62. m_gamegroup;
  63. enum
  64. {
  65. DRAWGROUP_BEFORE = GAMEGROUP_END,
  66. DRAWGROUP_LIGHT,
  67. DRAWGROUP_CAMERA,
  68. DRAWGROUP_DEFAULT,
  69. DRAWGROUP_AFTER,
  70. DRAWGROUP_AFTER_0,
  71. DRAWGROUP_AFTER_1,
  72. DRAWGROUP_HUD,
  73. DRAWGROUP_CAPTURE,
  74. // Must be the last element
  75. DRAWGROUP_END
  76. }
  77. m_drawgroup;
  78. static int const GAMEGROUP_BEGIN = 0;
  79. static int const DRAWGROUP_BEGIN = GAMEGROUP_END;
  80. static int const ALLGROUP_END = DRAWGROUP_END;
  81. /* The initialisation state */
  82. InitState m_initstate;
  83. #if !LOL_BUILD_RELEASE
  84. enum
  85. {
  86. STATE_IDLE = 0,
  87. STATE_PRETICK_GAME,
  88. STATE_POSTTICK_GAME,
  89. STATE_PRETICK_DRAW,
  90. STATE_POSTTICK_DRAW,
  91. }
  92. m_tickstate;
  93. #endif
  94. // Emcee begin
  95. private:
  96. void SetState(uint32_t newstate);
  97. void SetStateWhenMatch(uint32_t newstate,
  98. Entity *other_entity, uint32_t other_state);
  99. virtual uint32_t OnStateChanged(uint32_t newstate)
  100. {
  101. return LOLm_state = newstate;
  102. }
  103. uint32_t LOLm_state;
  104. // Emcee end
  105. private:
  106. int m_ref, m_autorelease, m_destroy;
  107. };
  108. } /* namespace lol */