void CParticleEditor::play(CWorkspaceNode &node)
{
	if (isRunning(&node)) return;
	// NB : node must be stopped, no check is done
	nlassert(node.isLoaded());
	// if node not started, start it
	node.memorizeState();
	// enable the system to take the right date from the scene	
	node.getPSModel()->enableAutoGetEllapsedTime(true);
	node.getPSPointer()->setSystemDate(0.f);
	node.getPSPointer()->reactivateSound();
	node.getPSModel()->activateEmitters(true);
	if (node.getPSPointer()->getAutoCountFlag())
	{
		if (node.getResetAutoCountFlag())
		{
			// reset particle size arrays
			node.getPSPointer()->matchArraySize();
		}
		resetAutoCount(&node, false);
	}		
	
	// Set speed playback particle system
	node.getPSModel()->setEllapsedTimeRatio(_Speed);
}
void CParticleEditor::stop(CWorkspaceNode &node)
{
	if (!isRunning(&node)) return;
	nlassert(node.isLoaded());
	node.restoreState();
	node.getPSModel()->enableAutoGetEllapsedTime(false);
	node.getPSModel()->setEllapsedTime(0.f);
	node.getPSModel()->activateEmitters(true);
	node.getPSPointer()->stopSound();
}
bool CParticleEditor::checkHasLoop(CWorkspaceNode &node)
{
	nlassert(node.isLoaded());
	if (!node.getPSPointer()->hasLoop()) return false;
	return true;	
}
void CParticleEditor::update()
{
	if (!_ActiveNode) return;
	if (_PW == NULL) return;

	NL3D::CParticleSystem *currPS = _ActiveNode->getPSPointer();
	
	// compute BBox
	if (_DisplayBBox)
	{
		if (_AutoUpdateBBox)
		{
			NLMISC::CAABBox currBBox;
			currPS->forceComputeBBox(currBBox);
			if (_EmptyBBox)
			{
				_EmptyBBox = false;
				_CurrBBox = currBBox;
			}
			else
			{
				_CurrBBox = NLMISC::CAABBox::computeAABBoxUnion(currBBox, _CurrBBox);
			}
			currPS->setPrecomputedBBox(_CurrBBox);
		}
	}
		
	// auto repeat feature
	if (_AutoRepeat)
	{
		if (isRunning())
		{
			bool allFXFinished = true;
			bool fxStarted = false;
			TPWNodeItr itr = _PlayingNodes.begin();
			while(itr != _PlayingNodes.end())
			{
				CWorkspaceNode *node = (*itr);
				if (node->isLoaded())
				{
					if (isRunning(node))
					{
						fxStarted = true;
						if (node->getPSPointer()->getSystemDate() <= node->getPSPointer()->evalDuration())
						{
							allFXFinished = false;
							break;
						}
						else 
						{
							if (node->getPSPointer()->getCurrNumParticles() != 0)
							{
								allFXFinished = false;
								break;
							}
						}
					}
				}
				itr++;
			}
			if (fxStarted && allFXFinished)
				restartAllFX();
		}
	}

	// draw PSmodel
	TPWNodeItr itr = _PW->getNodeList().begin();
	while(itr != _PW->getNodeList().end())
	{
		CWorkspaceNode *node = (*itr);
		if (node->isLoaded())
		{
			if (node  == _ActiveNode)
				node->getPSModel()->enableDisplayTools(!isRunning(node) || _DisplayHelpers);
			else
				node->getPSModel()->enableDisplayTools(false);

			// hide / show the node
			if (_State == State::RunningMultiple || _State == State::PausedMultiple)
			{
				if (isRunning(node))
					node->getPSModel()->show();
				else
					node->getPSModel()->hide();
			}
			else
			{
				if (node == _ActiveNode)
					node->getPSModel()->show();
				else
					node->getPSModel()->hide();
			}
		}
		itr++;
	}
}