💿🐜 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.

84 lines
2.2 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_SCENE_COLLECTION_HPP
  20. #define ANTKEEPER_SCENE_COLLECTION_HPP
  21. #include <list>
  22. #include <unordered_map>
  23. namespace scene {
  24. class object_base;
  25. /**
  26. * Collection of scene objects.
  27. */
  28. class collection
  29. {
  30. public:
  31. /**
  32. * Adds an object to the collection.
  33. *
  34. * @param object Object to add.
  35. */
  36. void add_object(object_base* object);
  37. /**
  38. * Removes an object from the collection.
  39. *
  40. * @param object Object to remove.
  41. */
  42. void remove_object(object_base* object);
  43. /// Removes all objects from the collection.
  44. void remove_objects();
  45. /// Updates the tweens of all objects in the collection.
  46. void update_tweens();
  47. /// Returns a list of all objects in the collection.
  48. const std::list<object_base*>* get_objects() const;
  49. /**
  50. * Returns a list of all objects in the collection with the specified type ID.
  51. *
  52. * @param type_id Scene object type ID.
  53. * @return List of scene objects with the specified type ID.
  54. */
  55. const std::list<object_base*>* get_objects(std::size_t type_id) const;
  56. private:
  57. std::list<object_base*> objects;
  58. mutable std::unordered_map<std::size_t, std::list<object_base*>> object_map;
  59. };
  60. inline const std::list<object_base*>* collection::get_objects() const
  61. {
  62. return &objects;
  63. }
  64. inline const std::list<object_base*>* collection::get_objects(std::size_t type_id) const
  65. {
  66. return &object_map[type_id];
  67. }
  68. } // namespace scene
  69. #endif // ANTKEEPER_SCENE_COLLECTION_HPP