Skip to content
Shangzhi Huang edited this page Nov 17, 2017 · 6 revisions

The CNPLRuntimeState holds an CNPLMessageQueue, which is implemented by boost::circular_buffer.

We call the CNPLRuntimeState::Run() method to enter a loop:

int NPL::CNPLRuntimeState::Run()
{
	NPLMessage_ptr msg;
	int nRes = 0;
	while (nRes != -1)
	{
		m_input_queue.wait_and_pop(msg);
		nRes = ProcessMsg(msg);
	}
	// ...
	return 0;
}

In this loop, we process each message in the NPLMessageQueue one time. If the NPLMessageQueue is empty, we wait for incoming messages.

Processing Messages

Currently, the ProcessMsg method handles 5 types of message:

  1. Activating files
  2. Loading files (without activation)
  3. Reset
  4. Exit
  5. Tick

Activating Files

The CNPLRuntimeState holds a map m_neuron_files which maps file names to CNeuronFileStates. Each neuron file that is activated will have a CNeuronFileState structure kept.

pFileState = CNPLRuntimeState::GetNeuronFileState(msg->m_filename); not create if not exist
if !pFileState 
    CNPLRuntimeState::LoadFile_any(msg->m_filename);
        CNPLScriptingState::LoadFile(msg->m_filename);
            CNPLScriptingState::GetNPLCodeFromFile(pFile, pBuffer);
    pFileState = CNPLRuntimeState::GetNeuronFileState(msg->m_filename); create if not exist
if pFileState
    if (pFileState->IsProcessing() || pFileState->IsPreemptive()) 
        if pFileState->IsEmpty()
            m_active_neuron_files.push_back(pFileState);
    else
        CNPLRuntimeState::ActivateFile_any(msg->m_filename, msg->m_code);
            CNPLRuntimeState::ActivateFile(msg->m_filename)
        pFileState->Tick(m_nFrameMoveCount);

Clone this wiki locally