//-------- Begin of function Remote::process_specific_msg ---------// // // Pre-process a specific message type. // void Remote::process_specific_msg(DWORD msgId) { if( !process_queue_flag ) // avoid sys.yield() return; int loopCount=0; disable_poll_msg(); RemoteQueue &rq = receive_queue[0]; RemoteQueueTraverse rqt(rq); if( !rq.validate_queue() ) err.run( "Queue corrupted, Remote::process_specific_msg()" ); for( rqt.traverse_set_start(); !rqt.traverse_finish(); rqt.traverse_next() ) { err_when( ++loopCount > 1000 ); RemoteMsg* remoteMsgPtr = rqt.get_remote_msg(); if( remoteMsgPtr->id == msgId ) { remoteMsgPtr->process_msg(); remoteMsgPtr->id = 0; } } enable_poll_msg(); }
// ------- begin of function RemoteQueue::validate_queue -------// int RemoteQueue::validate_queue(int start) { int loopCount = 0; RemoteQueueTraverse rqt(*this, start); for( rqt.traverse_set_start(start); !rqt.traverse_finish(); rqt.traverse_next() ) { RemoteMsg *remoteMsgPtr = rqt.get_remote_msg(); if( remoteMsgPtr->id ) { if( remoteMsgPtr->id<FIRST_REMOTE_MSG_ID || remoteMsgPtr->id>LAST_REMOTE_MSG_ID ) return 0; } err_when( ++loopCount > 200 ); } return 1; }
//-------- Begin of function Remote::process_receive_queue ---------// // // Process messages in the receive queue. // void Remote::process_receive_queue() { if( !process_queue_flag ) // avoid sys.yield() return; int processFlag; int loopCount=0; disable_poll_msg(); RemoteQueue &rq = receive_queue[0]; RemoteQueueTraverse rqt(rq); if( !rq.validate_queue() ) err.run( "Queue corrupted, Remote::process_receive_queue()" ); //---- if not started yet, process the message without handling the message sequence ----// if( !power.enable_flag ) { for( rqt.traverse_set_start(); !rqt.traverse_finish(); rqt.traverse_next() ) { err_when( ++loopCount > 1000 ); RemoteMsg* remoteMsgPtr = rqt.get_remote_msg(); remoteMsgPtr->process_msg(); } } else //--------- process in the order of nation recno --------// { LOG_BEGIN; for( int nationRecno=1 ; nationRecno<=nation_array.size() ; ++nationRecno ) { if( nation_array.is_deleted(nationRecno) || nation_array[nationRecno]->nation_type==NATION_AI ) continue; nation_processing = nationRecno; processFlag=0; //-------- scan through the message queue --------// loopCount = 0; for( rqt.traverse_set_start(); !rqt.traverse_finish(); rqt.traverse_next() ) { err_when( ++loopCount > 1000 ); RemoteMsg* remoteMsgPtr = rqt.get_remote_msg(); //--- check if this message indicates the start of a new message queue ---// if( remoteMsgPtr->id == MSG_QUEUE_HEADER ) { short msgNation = *(short *)(&remoteMsgPtr->data_buf[sizeof(DWORD)]); //--- if this is the message queue of the nation we should process now ----// if(msgNation==nationRecno ) // struct of data_buf: <DWORD> frameCount + <short> nationRecno { processFlag = 1; } else //--- if this is a message queue that should be processed now ---// { if( processFlag ) //--- if we were previously processing the right queue, now the processing is complete by this point ---// break; // message on next nation is met, stop this nation } } else if( remoteMsgPtr->id == MSG_QUEUE_TRAILER ) { short msgNation = *(short *)remoteMsgPtr->data_buf; //--- if this is the message queue of the nation we should process now ----// if(msgNation==nationRecno ) // struct of data_buf:<short> nationRecno break; // end of that nation } else { //--- if this is the message queue of the nation we should process now ----// if( processFlag ) { #if defined(ENABLE_LOG) String logStr("begin process remote message id:"); logStr += (long) remoteMsgPtr->id; logStr += " of nation "; logStr += nation_processing; LOG_MSG(logStr); #endif remoteMsgPtr->process_msg(); LOG_MSG("end process remote message"); LOG_MSG(m.get_random_seed()); } } } nation_processing = 0; } LOG_END; } //---------- clear receive_queue[0] and shift from next queue ------// rq.clear(); int n; for( n = 1; n < RECEIVE_QUEUE_BACKUP; ++n) { receive_queue[n-1].swap(receive_queue[n]); receive_frame_count[n-1] = receive_frame_count[n]; } receive_frame_count[n-1]++; enable_poll_msg(); }