<commit_before>#include <babylon/particles/sub_emitter.h>

#include <nlohmann/json.hpp>

#include <babylon/meshes/abstract_mesh.h>
#include <babylon/meshes/mesh.h>
#include <babylon/particles/particle_system.h>

namespace BABYLON {

SubEmitter::SubEmitter(const ParticleSystemPtr& iParticleSystem)
    : particleSystem{iParticleSystem}
    , type{SubEmitterType::END}
    , inheritDirection{false}
    , inheritedVelocityAmount{0.f}
{
  // Create mesh as emitter to support rotation
  if (!std::holds_alternative<AbstractMeshPtr>(particleSystem->emitter)) {
    particleSystem->emitter
      = AbstractMesh::New("SubemitterSystemEmitter", particleSystem->getScene());
  }

  // Automatically dispose of subemitter when system is disposed
  particleSystem->onDisposeObservable.add([this](IParticleSystem* /*ps*/, EventState& /*es*/) {
    if (std::holds_alternative<AbstractMeshPtr>(particleSystem->emitter)) {
      std::get<AbstractMeshPtr>(particleSystem->emitter)->dispose();
    }
  });
}

SubEmitter::~SubEmitter() = default;

SubEmitterPtr SubEmitter::clone() const
{
  // Clone particle system<commit_msg>Prevent recursive dispose to break<commit_after>#include <babylon/particles/sub_emitter.h>

#include <nlohmann/json.hpp>

#include <babylon/meshes/abstract_mesh.h>
#include <babylon/meshes/mesh.h>
#include <babylon/particles/particle_system.h>

namespace BABYLON {

SubEmitter::SubEmitter(const ParticleSystemPtr& iParticleSystem)
    : particleSystem{iParticleSystem}
    , type{SubEmitterType::END}
    , inheritDirection{false}
    , inheritedVelocityAmount{0.f}
{
  // Create mesh as emitter to support rotation
  if (!std::holds_alternative<AbstractMeshPtr>(particleSystem->emitter)) {
    particleSystem->emitter
      = AbstractMesh::New("SubemitterSystemEmitter", particleSystem->getScene());
  }

  // Automatically dispose of subemitter when system is disposed
  particleSystem->onDisposeObservable.add([this](IParticleSystem* /*ps*/, EventState& /*es*/) {
    if (std::holds_alternative<AbstractMeshPtr>(particleSystem->emitter)) {
      // Prevent recursive dispose to break.
      const auto disposable   = std::get<AbstractMeshPtr>(particleSystem->emitter);
      particleSystem->emitter = Vector3::Zero();
      disposable->dispose();
    }
  });
}

SubEmitter::~SubEmitter() = default;

SubEmitterPtr SubEmitter::clone() const
{
  // Clone particle system
{'fraction_non_alphanumeric': 0.13050776332354175, 'fraction_numerical': 0.001258917331095258, 'mean_word_length': 5.357333333333333, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2002332', 'n_tokens_mistral': 756, 'n_tokens_neox': 724, 'n_words': 122}