您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

155 行
4.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. //
  14. // The Entity class
  15. // ----------------
  16. // Entities are objects that can be ticked by the game loop and/or the render
  17. // loop. Entities are implemented as one or several linked lists. See the
  18. // Ticker class for the ticking logic and the linked list implementation.
  19. //
  20. #include <stdint.h>
  21. namespace lol
  22. {
  23. struct InitState
  24. {
  25. enum Value
  26. {
  27. Unknown,
  28. Error,
  29. NeedInitDraw,
  30. NeedInitGame,
  31. Ready,
  32. }
  33. m_value;
  34. inline InitState(Value v) : m_value(v) {}
  35. inline operator Value() { return m_value; }
  36. };
  37. class Entity
  38. {
  39. friend class Scene;
  40. friend class Ticker;
  41. friend class TickerData;
  42. friend class Dict;
  43. friend class Emcee;
  44. public:
  45. virtual std::string GetName() const;
  46. inline bool IsTicked() { return !!m_ref && !m_autorelease; }
  47. protected:
  48. Entity();
  49. virtual ~Entity();
  50. inline int IsDestroying() { return m_destroy; }
  51. virtual void InitGame();
  52. virtual void InitDraw();
  53. virtual void tick_game(float seconds);
  54. virtual void tick_draw(float seconds, class Scene &scene);
  55. enum
  56. {
  57. GAMEGROUP_BEGIN = 0, // must be the first element
  58. GAMEGROUP_INPUT, // input should be polled before everything else
  59. GAMEGROUP_IMGUI, // debug update needs to be called before the rest for init purposes
  60. GAMEGROUP_APP, // main application update
  61. GAMEGROUP_ENTITY, // default entity update
  62. // ----------------- // split entity update:
  63. GAMEGROUP_PLAYER, // player updates before AI to ensure player actions is prevalent
  64. GAMEGROUP_AI, // AI update
  65. GAMEGROUP_OTHER_0, // other misc updates here
  66. GAMEGROUP_OTHER_1, // (same)
  67. GAMEGROUP_OTHER_2, // (same)
  68. GAMEGROUP_OTHER_3, // (same)
  69. // ----------------- // primitives updates
  70. GAMEGROUP_MESH, // update Mesh/Animation to ensure correct sync with PLY/AI
  71. GAMEGROUP_FX, // update FX/other to ensure correct sync with WorldPos and Meshes
  72. GAMEGROUP_LIGHT, // update after FX because it could some
  73. GAMEGROUP_CAMERA, // update camera at the end of the frame, once everything is settled
  74. GAMEGROUP_STATS, // stats update
  75. GAMEGROUP_END // must be the last element
  76. }
  77. m_gamegroup;
  78. enum
  79. {
  80. DRAWGROUP_BEGIN = GAMEGROUP_END,
  81. DRAWGROUP_CAMERA, // update camera first for rendering
  82. DRAWGROUP_TEXTURE, // texture
  83. DRAWGROUP_LIGHT, //
  84. DRAWGROUP_WORLD, // other misc updates here
  85. DRAWGROUP_ENTITY, //
  86. DRAWGROUP_FX, //
  87. DRAWGROUP_OTHER_0, // other misc updates here
  88. DRAWGROUP_OTHER_1, // (same)
  89. DRAWGROUP_OTHER_2, // (same)
  90. DRAWGROUP_OTHER_3, // (same)
  91. DRAWGROUP_APP, // main application Draw
  92. DRAWGROUP_HUD,
  93. DRAWGROUP_IMGUI,
  94. DRAWGROUP_CAPTURE,
  95. DRAWGROUP_END, // must be the next-to-last element
  96. DRAWGROUP_NONE, // this group is for non draw-ticked
  97. }
  98. m_drawgroup;
  99. static int const ALLGROUP_END = DRAWGROUP_END;
  100. /* The initialisation state */
  101. InitState m_initstate;
  102. #if !LOL_BUILD_RELEASE
  103. enum
  104. {
  105. STATE_IDLE = 0,
  106. STATE_PRETICK_GAME,
  107. STATE_POSTTICK_GAME,
  108. STATE_PRETICK_DRAW,
  109. STATE_POSTTICK_DRAW,
  110. }
  111. m_tickstate;
  112. #endif
  113. // Emcee begin
  114. private:
  115. void SetState(uint32_t newstate);
  116. void SetStateWhenMatch(uint32_t newstate,
  117. Entity *other_entity, uint32_t other_state);
  118. virtual uint32_t OnStateChanged(uint32_t newstate)
  119. {
  120. return LOLm_state = newstate;
  121. }
  122. uint32_t LOLm_state;
  123. // Emcee end
  124. private:
  125. int m_ref, m_autorelease, m_destroy;
  126. uint64_t m_scene_mask = 0;
  127. };
  128. } /* namespace lol */