Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
ParticleDeclaration.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Graphics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_PARTICLEDECLARATION_HPP
8 #define NAZARA_PARTICLEDECLARATION_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/ObjectLibrary.hpp>
12 #include <Nazara/Core/ObjectRef.hpp>
13 #include <Nazara/Core/RefCounted.hpp>
14 #include <Nazara/Core/Signal.hpp>
15 #include <Nazara/Graphics/Config.hpp>
16 #include <Nazara/Graphics/Enums.hpp>
17 #include <Nazara/Utility/Enums.hpp>
18 #include <array>
19 
20 namespace Nz
21 {
22  class ParticleDeclaration;
23 
24  using ParticleDeclarationConstRef = ObjectRef<const ParticleDeclaration>;
25  using ParticleDeclarationLibrary = ObjectLibrary<ParticleDeclaration>;
26  using ParticleDeclarationRef = ObjectRef<ParticleDeclaration>;
27 
28  class NAZARA_GRAPHICS_API ParticleDeclaration : public RefCounted
29  {
30  friend ParticleDeclarationLibrary;
31  friend class Graphics;
32 
33  public:
35  ParticleDeclaration(const ParticleDeclaration& declaration);
37 
38  void DisableComponent(ParticleComponent component);
39  void EnableComponent(ParticleComponent component, ComponentType type, std::size_t offset);
40 
41  void GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const;
42  std::size_t GetStride() const;
43 
44  void SetStride(unsigned int stride);
45 
46  ParticleDeclaration& operator=(const ParticleDeclaration& declaration);
47 
48  static ParticleDeclaration* Get(ParticleLayout layout);
49  static bool IsTypeSupported(ComponentType type);
50  template<typename... Args> static ParticleDeclarationRef New(Args&&... args);
51 
52  // Signals:
53  NazaraSignal(OnParticleDeclarationRelease, const ParticleDeclaration* /*particleDeclaration*/);
54 
55  private:
56  static bool Initialize();
57  static void Uninitialize();
58 
59  struct Component
60  {
61  ComponentType type;
62  bool enabled = false;
63  std::size_t offset;
64 
65  /*
66  ** -Lynix:
67  ** It would be also possible to precise the stride by an independant way, what I don't allow
68  ** to decomplexify the interface of something I consider useless.
69  ** If you think that could be useful, don't hesitate to make me aware !
70  */
71  };
72 
73  std::array<Component, ParticleComponent_Max + 1> m_components;
74  std::size_t m_stride;
75 
76  static std::array<ParticleDeclaration, ParticleLayout_Max + 1> s_declarations;
77  static ParticleDeclarationLibrary::LibraryMap s_library;
78  };
79 }
80 
81 #include <Nazara/Graphics/ParticleDeclaration.inl>
82 
83 #endif // NAZARA_PARTICLEDECLARATION_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents the module initializer of Graphics.
Definition: Graphics.hpp:15
Core class that represents a reference with a counter.
Definition: RefCounted.hpp:21
Core class that represents a reference to an object.
Definition: ObjectRef.hpp:18
Graphics class that represents the declaration of the particle, works like an ECS.
Definition: ParticleDeclaration.hpp:28