💿🐜 Antkeeper source code https://antkeeper.com
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.

78 lines
2.6 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_ENTITY_SYSTEM_RENDER_HPP
  20. #define ANTKEEPER_ENTITY_SYSTEM_RENDER_HPP
  21. #include "entity/systems/updatable.hpp"
  22. #include "scene/collection.hpp"
  23. #include "scene/model-instance.hpp"
  24. #include "scene/light.hpp"
  25. #include "entity/components/model.hpp"
  26. #include "entity/components/light.hpp"
  27. #include "entity/id.hpp"
  28. #include "render/renderer.hpp"
  29. #include <unordered_map>
  30. #include <vector>
  31. namespace entity {
  32. namespace system {
  33. class render: public updatable
  34. {
  35. public:
  36. render(entity::registry& registry);
  37. virtual void update(double t, double dt);
  38. void draw(double alpha);
  39. void add_layer(scene::collection* layer);
  40. void remove_layers();
  41. void set_renderer(::render::renderer* renderer);
  42. scene::model_instance* get_model_instance(entity::id entity_id);
  43. scene::light* get_light(entity::id entity_id);
  44. private:
  45. void update_model_and_materials(entity::id entity_id, entity::component::model& model);
  46. void update_light(entity::id entity_id, entity::component::light& component);
  47. void on_model_construct(entity::registry& registry, entity::id entity_id, entity::component::model& model);
  48. void on_model_replace(entity::registry& registry, entity::id entity_id, entity::component::model& model);
  49. void on_model_destroy(entity::registry& registry, entity::id entity_id);
  50. void on_light_construct(entity::registry& registry, entity::id entity_id, entity::component::light& light);
  51. void on_light_replace(entity::registry& registry, entity::id entity_id, entity::component::light& light);
  52. void on_light_destroy(entity::registry& registry, entity::id entity_id);
  53. double t;
  54. double dt;
  55. ::render::renderer* renderer;
  56. std::vector<scene::collection*> layers;
  57. std::unordered_map<entity::id, scene::model_instance*> model_instances;
  58. std::unordered_map<entity::id, scene::light*> lights;
  59. };
  60. } // namespace system
  61. } // namespace entity
  62. #endif // ANTKEEPER_ENTITY_SYSTEM_RENDER_HPP