Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

155 строки
4.3 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 Scene class
  13. // ---------------
  14. //
  15. #include <stdint.h>
  16. #include "tileset.h"
  17. #include "light.h"
  18. #include "camera.h"
  19. #include "mesh/mesh.h"
  20. #define LOL_MAX_LIGHT_COUNT 8
  21. namespace lol
  22. {
  23. class SceneData;
  24. //-----------------------------------------------------------------------------
  25. class PrimitiveSource
  26. {
  27. friend class Scene;
  28. public:
  29. PrimitiveSource() { }
  30. virtual ~PrimitiveSource() { }
  31. virtual void Render(Scene& scene) { }
  32. private:
  33. };
  34. class PrimitiveRenderer
  35. {
  36. friend class Scene;
  37. public:
  38. PrimitiveRenderer() { }
  39. virtual ~PrimitiveRenderer() { }
  40. virtual void Render(PrimitiveSource* primitive) const { UNUSED(primitive); }
  41. private:
  42. };
  43. //-----------------------------------------------------------------------------
  44. //-----------------------------------------------------------------------------
  45. class Scene
  46. {
  47. friend class Video;
  48. private:
  49. static array<Scene*> g_scenes;
  50. Scene(ivec2 size);
  51. ~Scene();
  52. public:
  53. static void AddNew(ivec2 size);
  54. private: //Private because I don't know if we should have it
  55. static void DestroyScene(Scene* scene);
  56. private:
  57. static void DestroyAll();
  58. public:
  59. static ptrdiff_t GetCount();
  60. static bool IsReady(ptrdiff_t index = 0);
  61. static Scene& GetScene(ptrdiff_t index = 0);
  62. public:
  63. //TODO: don't like the name
  64. void Link(Entity* entity);
  65. bool IsRelevant(Entity* entity);
  66. public:
  67. Camera* GetCamera(int cam_idx = -1);
  68. int PushCamera(Camera *cam);
  69. void PopCamera(Camera *cam);
  70. void SetTileCam(int cam_idx);
  71. void Reset();
  72. /* New scenegraph */
  73. void AddPrimitive(PrimitiveSource* primitive);
  74. /* === Primitive source stuff === */
  75. /* Returns the number of primitive source set to the given entity */
  76. ptrdiff_t HasPrimitiveSource(Entity* entity);
  77. /* Add a primitive sources linked to the given entity
  78. * Returns the slot number */
  79. ptrdiff_t AddPrimitiveSource(Entity* entity, PrimitiveSource* source);
  80. /* Update the primitive source at index linked to the given entity
  81. * Deletes the old one
  82. * The slot is kept even if source == nullptr */
  83. void SetPrimitiveSource(ptrdiff_t index, Entity* entity, PrimitiveSource* source);
  84. /* Remove primitive source at index set to the given entity */
  85. void ReleasePrimitiveSource(ptrdiff_t index, Entity* entity);
  86. /* Remove all primitive source set to the given entity */
  87. void ReleaseAllPrimitiveSource(Entity* entity);
  88. /* === Primitive renderer stuff === */
  89. /* Returns the number of primitive renderer set to the given entity */
  90. ptrdiff_t HasPrimitiveRenderer(Entity* entity);
  91. /* Add a primitive renderer linked to the given entity
  92. * Returns the slot number */
  93. ptrdiff_t AddPrimitiveRenderer(Entity* entity, PrimitiveRenderer* renderer);
  94. /* Update the primitive renderer linked to the given entity
  95. * Deletes the old one
  96. * Will assert if renderer == nullptr */
  97. void SetPrimitiveRenderer(ptrdiff_t index, Entity* entity, PrimitiveRenderer* renderer);
  98. /* Remove primitive renderer at index set to the given entity */
  99. void ReleasePrimitiveRenderer(ptrdiff_t index, Entity* entity);
  100. /* Remove all primitive renderer set to the given entity */
  101. void ReleaseAllPrimitiveRenderer(Entity* entity);
  102. /* FIXME: this should be deprecated -- it doesn't really match
  103. * the architecture we want to build */
  104. void AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale, float angle);
  105. public:
  106. void SetLineTime(float new_time = -1.f);
  107. void SetLineMask(int new_mask = 0xFFFFFFFF);
  108. void SetLineSegmentSize(float new_segment_size = 100000.f);
  109. void SetLineColor(vec4 new_color = vec4(1.f));
  110. float GetLineSegmentSize();
  111. vec4 GetLineColor();
  112. void AddLine(vec3 a, vec3 b, vec4 color);
  113. void AddLight(Light *light);
  114. array<Light *> const &GetLights();
  115. void RenderPrimitives();
  116. void RenderTiles();
  117. void RenderLines(float seconds);
  118. private:
  119. SceneData *data;
  120. };
  121. } /* namespace lol */