| 2875 | } |
| 2876 | |
| 2877 | void DeleteNode(HScene scene, HNode node, bool delete_headless_pfx) |
| 2878 | { |
| 2879 | InternalNode* n = GetNode(scene, node); |
| 2880 | |
| 2881 | FreeNodeMemory(scene, n); |
| 2882 | |
| 2883 | // Stop (or destroy) any living particle instances started on this node |
| 2884 | uint32_t count = scene->m_AliveParticlefxs.Size(); |
| 2885 | uint32_t i = 0; |
| 2886 | if (n->m_Node.m_NodeType == NODE_TYPE_PARTICLEFX) |
| 2887 | { |
| 2888 | while (i < count) |
| 2889 | { |
| 2890 | ParticlefxComponent* c = &scene->m_AliveParticlefxs[i]; |
| 2891 | if (node == c->m_Node) |
| 2892 | { |
| 2893 | if (delete_headless_pfx) |
| 2894 | { |
| 2895 | InternalNode* comp_n = GetNode(scene, c->m_Node); |
| 2896 | dmParticle::DestroyInstance(scene->m_ParticlefxContext, comp_n->m_Node.m_ParticleInstance); |
| 2897 | n->m_Node.m_ParticleInstance = dmParticle::INVALID_INSTANCE; |
| 2898 | scene->m_AliveParticlefxs.EraseSwap(i); |
| 2899 | --count; |
| 2900 | } |
| 2901 | else |
| 2902 | { |
| 2903 | dmParticle::StopInstance(scene->m_ParticlefxContext, c->m_Instance, false); |
| 2904 | n->m_Node.m_HasHeadlessPfx = 1; |
| 2905 | ++i; |
| 2906 | } |
| 2907 | } |
| 2908 | else |
| 2909 | { |
| 2910 | ++i; |
| 2911 | } |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | // Delete children first |
| 2916 | uint16_t child_index = n->m_ChildHead; |
| 2917 | while (child_index != INVALID_INDEX) |
| 2918 | { |
| 2919 | InternalNode* child = &scene->m_Nodes[child_index & 0xffff]; |
| 2920 | child_index = child->m_NextIndex; |
| 2921 | DeleteNode(scene, GetNodeHandle(child), delete_headless_pfx); |
| 2922 | } |
| 2923 | |
| 2924 | dmArray<Animation> *animations = &scene->m_Animations; |
| 2925 | uint32_t n_anims = animations->Size(); |
| 2926 | for (uint32_t i = 0; i < n_anims; ++i) |
| 2927 | { |
| 2928 | Animation* anim = &(*animations)[i]; |
| 2929 | |
| 2930 | if (anim->m_Node == node) |
| 2931 | { |
| 2932 | CompleteAnimation(scene, anim, false); |
| 2933 | RemoveAnimation(*animations, i); |
| 2934 | i--; |