BsUtility.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. namespace bs
  6. {
  7. /** @addtogroup Utility-Core-Internal
  8. * @{
  9. */
  10. /** Contains information about a resource dependency, including the dependant resource and number of references to it. */
  11. struct ResourceDependency
  12. {
  13. ResourceDependency()
  14. :numReferences(0)
  15. { }
  16. HResource resource;
  17. UINT32 numReferences;
  18. };
  19. /** Static class containing various utility methods that do not fit anywhere else. */
  20. class BS_CORE_EXPORT Utility
  21. {
  22. public:
  23. /**
  24. * Finds all resources referenced by the specified object.
  25. *
  26. * @param[in] object Object to search for resource dependencies.
  27. * @param[in] recursive Determines whether or not child objects will also be searched (if the object has any
  28. * children).
  29. * @return A list of unique, non-null resources.
  30. */
  31. static Vector<ResourceDependency> findResourceDependencies(IReflectable& object, bool recursive = true);
  32. /**
  33. * Finds all components of a specific type on a scene object and any of its children.
  34. *
  35. * @param[in] object Object which to search for components. All children will be searched as well.
  36. * @param[in] typeId RTTI type ID of the component type to search for.
  37. * @return A list of all components of the specified type.
  38. */
  39. static Vector<HComponent> findComponents(const HSceneObject& object, UINT32 typeId);
  40. /** Calculates how deep in the scene object hierarchy is the provided object. Zero means root. */
  41. static UINT32 getSceneObjectDepth(const HSceneObject& so);
  42. private:
  43. /**
  44. * Helper method for for recursion when finding resource dependencies.
  45. *
  46. * @see findDependencies
  47. */
  48. static void findResourceDependenciesInternal(IReflectable& object, bool recursive, Map<String, ResourceDependency>& dependencies);
  49. /**
  50. * Checks if the specified type (or any of its derived classes) have any IReflectable pointer or value types as
  51. * their fields.
  52. */
  53. static bool hasReflectableChildren(RTTITypeBase* type);
  54. };
  55. /** @} */
  56. }