Example #1
0
csp::WorkResult::Enum csp::Process::Evaluate( Host& host, int numArgs )
{
	if( LuaThread().Status() != lua::Return::YIELD && LuaThread().Status() != lua::Return::OK )
		return WorkResult::FINISH;

	if( m_operation )
	{
		WorkResult::Enum result = m_operation->IsFinished()
			? WorkResult::FINISH
			: m_operation->Evaluate( host );

		if( result == WorkResult::FINISH )
		{
			lua::LuaStack luaStack = m_luaThread.GetStack();
			numArgs = m_operation->PushResults( luaStack );
			DeleteOperation( host );
		}
		else
			return WorkResult::YIELD;
	}
	
	WorkResult::Enum result = Resume( numArgs );
	
	if ( result == WorkResult::YIELD && m_operation )
		host.PushEvalStep( *this );
	else if ( result == WorkResult::FINISH && m_parentProcess )
	{
		if( host.GetTopProcess() != m_parentProcess )
			host.PushEvalStep( *m_parentProcess );
	}

	return result;
}
Example #2
0
void csp::OpAlt::SelectTimeProcessToTrigger( Host& host )
{
	CORE_ASSERT( m_pCaseTriggered == NULL );

	CspTime_t time = host.Time();

	for( int i = 0; i < m_numCases; ++i )
	{
		AltCase& altCase = m_cases[ i ];
		if( m_pNilCase == &altCase )
			continue;

		if( altCase.m_pChannel == NULL && altCase.m_time <= time )
		{
			if( m_pCaseTriggered )
			{
				if( altCase.m_time < m_pCaseTriggered->m_time )
					m_pCaseTriggered = &altCase;
			}
			else
				m_pCaseTriggered = &altCase;
		}
	}

	if( m_pCaseTriggered )
	{
		m_argumentsMoved = true;
		DetachChannels();

		host.PushEvalStep( ThisProcess() );
	}
}
Example #3
0
bool csp::OpAlt::SelectChannelProcessToTrigger( Host& host )
{
	CORE_ASSERT( m_pCaseTriggered == NULL );

	bool allCasesClosed = true;

	for( int i = 0; i < m_numCases; ++i )
	{
		AltCase& altCase = m_cases[ i ];
		if( m_pNilCase == &altCase )
		{
			m_pCaseTriggered = m_pNilCase;
			allCasesClosed = false;

			m_argumentsMoved = true;
			DetachChannels();

			host.PushEvalStep( ThisProcess() );
			break;
		}

		Channel* pChannel = altCase.m_pChannel;
		if( pChannel || altCase.m_time >= 0.0f )
			allCasesClosed = false;

		if( pChannel && pChannel->OutAttached() )
		{
			ChannelAttachmentOut_i& out = pChannel->OutAttachment();
			out.Communicate( host, ThisProcess() );
			break;
		}
	}

	return allCasesClosed;
}
Example #4
0
void csp::Process::Work( Host& host, CspTime_t dt )
{
	if( m_operation == NULL )
		return;

	WorkResult::Enum result = m_operation->Work( host, dt );
	
	if( result == WorkResult::FINISH )
	{
		m_operation->SetFinished( true );
		CORE_ASSERT( m_luaThread.Status() == lua::Return::YIELD );
		host.PushEvalStep( *this );
	}
}