123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 |
- /*
- * Seven Kingdoms: Ancient Adversaries
- *
- * Copyright 1997,1998 Enlight Software Ltd.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- //Filename : OREMOTE2.CPP
- //Description : Object Remote - part 2
- #include <windows.h>
- #include <windowsx.h>
- #include <mmsystem.h>
- #define DEBUG_LOG_LOCAL 1
- #include <ALL.h>
- #include <OVGA.h>
- #include <OSTR.h>
- #include <OFONT.h>
- #include <OSYS.h>
- #include <OWORLD.h>
- #include <OPOWER.h>
- #include <ONATION.h>
- #include <OREMOTE.h>
- #include <OERRCTRL.h>
- #include <OLOG.h>
- //---------- Define static functions ----------//
- // static int validate_queue(char* queueBuf, int queuedSize);
- //-------- Begin of function Remote::new_msg ---------//
- //
- // Allocate a RemoteMsg with the specified data size.
- //
- // <short> msgId - id. of the message.
- // <int> dataSize - the data size of the RemoteMsg needed (size of RemoteMsg::data_buf)
- //
- // Data structure:
- //
- // <short> size of RemoteMsg + <RemoteMsg> RemoteMsg body
- // ^ ^
- // | Allocate starts here | return variable here to the client function
- //
- RemoteMsg* Remote::new_msg(int msgId, int dataSize)
- {
- int msgSize = sizeof(DWORD) + dataSize;
- // <DWORD> is for the message id.
- char* shortPtr;
- //--- use common_msg_buf, if the requested one is not bigger than common_msg_buf ---//
- int reqSize = sizeof(short) + msgSize;
- // <short> for length
- if(reqSize <= COMMON_MSG_BUF_SIZE )
- {
- shortPtr = common_msg_buf;
- }
- else //---- allocate a new RemoteMsg if the requested one is bigger than common_msg_buf ----//
- {
- shortPtr = (char *)mem_add( reqSize );
- }
- //---------- return RemoteMsg now -----------//
- *(short *)shortPtr = msgSize;
- shortPtr += sizeof(short);
- RemoteMsg* remoteMsgPtr = (RemoteMsg*) shortPtr;
- remoteMsgPtr->id = (DWORD) msgId;
- return remoteMsgPtr;
- }
- //--------- End of function Remote::new_msg ---------//
- //-------- Begin of function Remote::free_msg ---------//
- //
- // Free a RemoteMsg previously allocated by remote_msg().
- //
- // Data structure:
- //
- // <short> size of RemoteMsg + <RemoteMsg> RemoteMsg body
- // ^ ^
- // | Allocate starts here | return variable here to the client function
- //
- void Remote::free_msg(RemoteMsg* remoteMsgPtr)
- {
- char* memPtr = (char *)remoteMsgPtr - sizeof(short);
- // include size of message, sizeof MPMSG_FREE_MSG
- if( memPtr != common_msg_buf ) // the real allocation block start 2 bytes before remoteMsgPtr
- mem_del( memPtr );
- }
- //--------- End of function Remote::free_msg ---------//
- //-------- Begin of function Remote::send_msg ---------//
- //
- // <RemoteMsg*> remoteMsgPtr - the pointer to RemoteMsg to be sent.
- // [DPID] receiverId - send to whom, 0 for everybody
- // (default : 0)
- //
- // <short> size of RemoteMsg + <RemoteMsg> RemoteMsg body
- // ^ ^
- // | Allocate starts here | return variable here to the client function
- //
- void Remote::send_msg(RemoteMsg* remoteMsgPtr, int receiverId)
- {
- if( handle_vga_lock )
- vga_front.temp_unlock();
- // structure : <short>, <RemoteMsg>
- char* memPtr = (char*)remoteMsgPtr - sizeof(short); // the preceeding <short> is the size of RemoteMsg
- int msgSize = *(short *)memPtr + sizeof(short);
- // mp_ptr->send( receiverId, memPtr, msgSize );
- ec_remote.send( ec_remote.get_ec_player_id(receiverId), memPtr, msgSize);
- packet_send_count++;
- if( handle_vga_lock )
- vga_front.temp_restore_lock();
- }
- //--------- End of function Remote::send_msg ---------//
- //-------- Begin of function Remote::send_free_msg ---------//
- //
- // <RemoteMsg*> remoteMsgPtr - the pointer to RemoteMsg to be sent.
- // [DPID] receiverId - send to whom, 0 for everybody
- // (default : 0)
- //
- // <short> size of RemoteMsg + <RemoteMsg> RemoteMsg body
- // ^ ^
- // | Allocate starts here | return variable here to the client function
- //
- void Remote::send_free_msg(RemoteMsg* remoteMsgPtr, int receiverId)
- {
- if( handle_vga_lock )
- vga_front.temp_unlock();
- char* memPtr = (char*)remoteMsgPtr - sizeof(short); // the preceeding <short> is the size of RemoteMsg
- int msgSize = *(short *)memPtr + sizeof(short);
- // mp_ptr->send( receiverId, memPtr, msgSize );
- ec_remote.send( ec_remote.get_ec_player_id(receiverId), memPtr, msgSize);
- packet_send_count++;
- if( memPtr != common_msg_buf ) // the real allocation block start 2 bytes before remoteMsgPtr
- mem_del( memPtr );
- if( handle_vga_lock )
- vga_front.temp_restore_lock();
- }
- //--------- End of function Remote::send_free_msg ---------//
- //-------- Begin of function Remote::new_send_queue_msg ---------//
- //
- // Add the message into the sending queue.
- //
- // <short> msgId - id. of the message.
- // <int> dataSize - the data size of the RemoteMsg needed (size of RemoteMsg::data_buf)
- //
- // Queue data structure:
- //
- // <1st msg size> + <1st msg body> + <2nd msg size> + ...
- //
- // return : <char*> the pointer RemoteMsg::data_buf of the allocated message
- //
- char* Remote::new_send_queue_msg(int msgId, int dataSize)
- {
- char *dataPtr = send_queue[0].reserve(sizeof(short) + sizeof(DWORD) + dataSize);
- // ----- put the size of message ------//
- *(short *)dataPtr = sizeof(DWORD) + dataSize;
- dataPtr += sizeof(short);
- // ----- put the message id --------//
- ((RemoteMsg *)dataPtr)->id = msgId;
- return ((RemoteMsg *)dataPtr)->data_buf;
- }
- //--------- End of function Remote::new_send_queue_msg ---------//
- //-------- Begin of function Remote::send_queue_now ---------//
- //
- // Send out all send_queued message.
- //
- // [DPID] receiverId - send to whom, 0 for everybody
- // (default: 0)
- //
- // return : <int> 1 - sent successfully, the message has been received
- // by the receivers.
- // 0 - not successful.
- //
- int Remote::send_queue_now(int receiverId)
- {
- if( send_queue[0].length() ==0 )
- return 1;
- if( !send_queue[0].validate_queue() )
- err.run( "Queue Corrupted, Remote::send_queue_now()" );
- if( handle_vga_lock )
- vga_front.temp_unlock();
- //----------------------------------------------//
- int sendFlag = 1;
- //if(!mp_ptr->send( receiverId, send_queue[0].queue_buf, send_queue[0].length()))
- if(ec_remote.send( ec_remote.get_ec_player_id(receiverId), send_queue[0].queue_buf, send_queue[0].length()) <= 0 )
- sendFlag = 0;
- packet_send_count++;
- //---------------------------------------------//
- if( handle_vga_lock )
- vga_front.temp_restore_lock();
- return sendFlag;
- }
- //--------- End of function Remote::send_queue_now ---------//
- //-------- Begin of function Remote::append_send_to_receive ---------//
- //
- // Append all send queues to the receiving queue.
- //
- void Remote::append_send_to_receive()
- {
- if( send_queue[0].length() ==0 )
- return;
- int n;
- for( n = 0; n < RECEIVE_QUEUE_BACKUP; ++n)
- {
- if( send_frame_count[0] == receive_frame_count[n])
- {
- receive_queue[n].append_queue(send_queue[0]);
- if( !receive_queue[n].validate_queue() )
- err.run( "Queue Corrupted, Remote::append_send_to_receive()-3" );
- break;
- }
- }
- err_when( n >= RECEIVE_QUEUE_BACKUP ); // not found
- }
- //--------- End of function Remote::append_send_to_receive ---------//
- //-------- Begin of function Remote::poll_msg ---------//
- int Remote::poll_msg()
- {
- if ( !is_enable() || poll_msg_flag <= 0)
- return 0;
- //--------------------------------------------//
- int receivedFlag=0;
- DWORD msgListSize;
- int loopCount=0;
- if( handle_vga_lock )
- vga_front.temp_unlock();
- ec_remote.yield();
- char *recvBuf;
- // DPID from, to;
- char from;
- DWORD recvLen;
- // while( (recvBuf = mp_ptr->receive(&from, &to, &recvLen)) != NULL)
- while( (recvBuf = ec_remote.receive(&from, (long unsigned int *)&recvLen)) != NULL)
- {
- err_when(++loopCount > 1000 );
- msgListSize = recvLen;
- //-------- received successfully ----------//
- /*
- if( !power.enable_flag ) // power.enable_flag determines whether the multiplayer game has started or not
- {
- int validateLen = receive_queue[0].length();
- memcpy( receive_queue[0].reserve(msgListSize), recvBuf, msgListSize );
- if( !receive_queue[0].validate_queue(validateLen) )
- err.run( "Queue Corrupted, Remote::poll_msg()-99" );
- receivedFlag=1;
- }
- else
- */
- err_when( msgListSize < sizeof(short) + sizeof(DWORD) );
- RemoteMsg *rMsg = (RemoteMsg *)(recvBuf + sizeof(short) );
- int queueToCopy = -1;
- //--- if message id !=MSG_QUEUE_HEADER, this packet is sent by send_free_msg(), not by send_queue_now() ---//
- if( rMsg->id != MSG_QUEUE_HEADER )
- {
- // DEBUG_LOG("begin MSG_xxxx received");
- // DEBUG_LOG(rMsg->id);
- // DEBUG_LOG(sys.frame_count);
- // DEBUG_LOG("end MSG_xxxx received");
- queueToCopy = 0;
- }
- else
- {
- // ------- find which receive queue to hold the message -----//
- DWORD senderFrameCount = *(DWORD *)rMsg->data_buf;
- for(int n = 0; n < RECEIVE_QUEUE_BACKUP; ++n )
- {
- if( senderFrameCount == receive_frame_count[n] )
- {
- queueToCopy = n;
- break;
- }
- }
- // DEBUG_LOG("begin MSG_QUEUE_HEADER received");
- // DEBUG_LOG(senderFrameCount);
- // DEBUG_LOG(sys.frame_count);
- // DEBUG_LOG(n);
- // DEBUG_LOG("end MSG_QUEUE_HEADER received");
- }
- if( queueToCopy >= 0 && queueToCopy < RECEIVE_QUEUE_BACKUP )
- {
- RemoteQueue &rq = receive_queue[queueToCopy];
- int validateLen = rq.length();
- memcpy( rq.reserve(msgListSize), recvBuf, msgListSize );
- if( !rq.validate_queue(validateLen) )
- err.run( "Queue Corrupted, Remote::poll_msg()-2" );
- }
- else
- {
- // discard the frame in non-debug mode
- DEBUG_LOG("message is discard" );
- if( rMsg->id != MSG_QUEUE_HEADER )
- {
- DEBUG_LOG(rMsg->id);
- }
- else
- {
- DWORD senderFrameCount = *(DWORD *)rMsg->data_buf;
- DEBUG_LOG("MSG_QUEUE_HEADER message");
- DEBUG_LOG(senderFrameCount);
- }
- }
- ec_remote.de_recv_queue();
- receivedFlag = 1;
- packet_receive_count++;
- }
- if( handle_vga_lock )
- vga_front.temp_restore_lock();
- return receivedFlag;
- }
- //--------- End of function Remote::poll_msg ---------//
- //-------- 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(DEBUG) && 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();
- }
- //--------- End of function Remote::process_receive_queue ---------//
- //-------- 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();
- }
- //--------- End of function Remote::process_specific_msg ---------//
- /*
- //-------- Begin of function Remote::validate_queue ---------//
- //
- // Pre-process a specific message type.
- //
- static int validate_queue(char* queueBuf, int queuedSize)
- {
- char* queuePtr = queueBuf;
- RemoteMsg* remoteMsgPtr;
- int msgSize, processedSize=0;
- int loopCount=0;
- while( processedSize < queuedSize )
- {
- msgSize = *((short*)queuePtr);
- remoteMsgPtr = (RemoteMsg*) (queuePtr + sizeof(short));
- if( remoteMsgPtr->id )
- {
- if( remoteMsgPtr->id<FIRST_REMOTE_MSG_ID || remoteMsgPtr->id>LAST_REMOTE_MSG_ID )
- return 0;
- }
- queuePtr += sizeof(short) + msgSize;
- processedSize += sizeof(short) + msgSize;
- err_when( loopCount++ > 10000 ); // deadloop
- }
- return 1;
- }
- //--------- End of function Remote::validate_queue ---------//
- */
- //-------- Begin of function Remote::copy_send_to_backup ---------//
- //
- // Copy the whole send queue to the backup queue.
- //
- void Remote::copy_send_to_backup()
- {
- // ------ shift send_queue ---------//
- send_queue[SEND_QUEUE_BACKUP-1].clear();
- for(int n = SEND_QUEUE_BACKUP-1; n > 1; --n)
- {
- send_queue[n].swap(send_queue[n-1]);
- send_frame_count[n] = send_frame_count[n-1];
- }
- // now send_queue[1] is empty.
- send_queue[1] = send_queue[0];
- send_frame_count[1] = send_frame_count[0];
- }
- //--------- End of function Remote::copy_send_to_backup ---------//
- //-------- Begin of function Remote::send_backup_now ---------//
- //
- // Send out the backup queue now.
- //
- // [DPID] receiverId - send to whom, 0 for everybody
- // (default: 0)
- //
- // <int> requestFrameCount - need to send the backup buffer of the requested frame count
- //
- // return : <int> 1 - sent successfully, the message has been received
- // by the receivers.
- // 0 - not successful.
- //
- int Remote::send_backup_now(int receiverId, DWORD requestFrameCount)
- {
- //------ determine which backup buffer to send -----//
- font_san.disp( ZOOM_X2-100, 4, "", ZOOM_X2);
- for( int n = 1; n < SEND_QUEUE_BACKUP; ++n)
- {
- if( requestFrameCount == send_frame_count[n] )
- {
- //---------- if nothing to send -------------//
- int retFlag = 1;
- if( send_queue[n].length() > 0 )
- {
- if( handle_vga_lock )
- vga_front.temp_unlock();
- // retFlag = mp_ptr->send(receiverId, send_queue[n].queue_buf, send_queue[n].length());
- retFlag = ec_remote.send(ec_remote.get_ec_player_id(receiverId), send_queue[n].queue_buf, send_queue[n].length()) > 0;
- packet_send_count++;
- if( handle_vga_lock )
- vga_front.temp_restore_lock();
- }
- return retFlag;
- }
- }
- if( requestFrameCount < send_frame_count[SEND_QUEUE_BACKUP-1])
- err.run( "requestFrameCount:%d < backup2_frame_count:%d", requestFrameCount, send_frame_count[SEND_QUEUE_BACKUP-1] );
- return 0;
- }
- //--------- End of function Remote::send_backup_now ---------//
- //-------- Begin of function Remote::init_send_queue ---------//
- //
- // Initialize the header of the sending queue.
- //
- // <int> frameCount - frame count of this queue
- // <short> nationCount - nation recno of the sender
- //
- void Remote::init_send_queue(DWORD frameCount, short nationRecno)
- {
- send_queue[0].clear();
- // put into the queue : <message length>, MSG_QUEUE_HEADER, <frameCount>, <nationRecno>
- int msgSize = sizeof(DWORD)*2 + sizeof(short);
- char *sendPtr = send_queue[0].reserve(sizeof(short) + msgSize);
- *(short *)sendPtr = msgSize;
- sendPtr += sizeof(short);
- *(DWORD *)sendPtr = MSG_QUEUE_HEADER;
- sendPtr += sizeof(DWORD);
- *(DWORD *)sendPtr = send_frame_count[0] = next_send_frame(nationRecno, frameCount + process_frame_delay);
- sendPtr += sizeof(DWORD);
- *(short *)sendPtr = nationRecno;
- sendPtr += sizeof(short);
- }
- //--------- End of function Remote::init_send_queue ----------//
- //-------- Begin of function Remote::init_receive_queue ---------//
- //
- // Initialize the header of the receiving queue,
- // call this only when power is just enabled
- //
- // <int> frameCount - frame count of this queue
- // <short> nationCount - nation recno of the receiveer
- //
- void Remote::init_receive_queue(DWORD frameCount)
- {
- int n;
- for(n = 0; n < RECEIVE_QUEUE_BACKUP; ++n)
- {
- receive_queue[n].clear();
- receive_frame_count[n] = n+frameCount;
- }
- for(n = 0; n < process_frame_delay; ++n)
- {
- // nations are not created yet, put MSG_QUEUE_HEADER/MSG_NEXT_FRAME and MSG_QUEUE_TRAILER
- // even though the nation will not exist
- for(short nationRecno = 1; nationRecno <= MAX_NATION; ++nationRecno)
- {
- //if( nation_array.is_deleted(nationRecno) ||
- // nation_array[nationRecno]->nation_type==NATION_AI )
- // continue;
- char *receivePtr;
- int msgSize;
- // put into the queue : <message length>, MSG_QUEUE_HEADER, <frameCount>, <nationRecno>
- msgSize = sizeof(DWORD)*2 + sizeof(short);
- receivePtr = receive_queue[n].reserve(sizeof(short) + msgSize);
- *(short *)receivePtr = msgSize;
- receivePtr += sizeof(short);
- *(DWORD *)receivePtr = MSG_QUEUE_HEADER;
- receivePtr += sizeof(DWORD);
- *(DWORD *)receivePtr = frameCount + n;
- receivePtr += sizeof(DWORD);
- *(short *)receivePtr = nationRecno;
- receivePtr += sizeof(short);
- // put into the queue : <message length>, MSG_NEXT_FRAME, <nationRecno>
- msgSize = sizeof(DWORD) + sizeof(short);
- receivePtr = receive_queue[n].reserve(sizeof(short) + msgSize);
- *(short *)receivePtr = msgSize;
- receivePtr += sizeof(short);
- *(DWORD *)receivePtr = MSG_NEXT_FRAME;
- receivePtr += sizeof(DWORD);
- *(short *)receivePtr = nationRecno;
- receivePtr += sizeof(short);
- // put into the queue : <message length>, MSG_QUEUE_TRAILER, <nationRecno>
- msgSize = sizeof(DWORD) + sizeof(short);
- receivePtr = receive_queue[n].reserve(sizeof(short) + msgSize);
- *(short *)receivePtr = msgSize;
- receivePtr += sizeof(short);
- *(DWORD *)receivePtr = MSG_QUEUE_TRAILER;
- receivePtr += sizeof(DWORD);
- *(short *)receivePtr = nationRecno;
- receivePtr += sizeof(short);
- }
- }
- }
- //--------- End of function Remote::init_receive_queue ----------//
- //--------- Begin of function Remote::init_start_mp ----------//
- void Remote::init_start_mp()
- {
- int n;
- for( n = 0; n < SEND_QUEUE_BACKUP; ++n)
- {
- send_queue[n].clear();
- send_frame_count[n] = 0;
- }
- for( n = 0; n < RECEIVE_QUEUE_BACKUP; ++n)
- {
- receive_queue[n].clear();
- receive_frame_count[n] = 0;
- }
- }
- //--------- End of function Remote::init_start_mp ----------//
- //--------- Begin of function Remote::enable_process_queue --------//
- void Remote::enable_process_queue()
- {
- process_queue_flag = 1;
- }
- //--------- End of function Remote::enable_process_queue --------//
- //--------- Begin of function Remote::disable_process_queue --------//
- void Remote::disable_process_queue()
- {
- process_queue_flag = 0;
- }
- //--------- End of function Remote::disable_process_queue --------//
- //-------- Begin of function Remote::enable_poll_msg ---------//
- void Remote::enable_poll_msg()
- {
- poll_msg_flag = 1;
- }
- //-------- End of function Remote::enable_poll_msg ---------//
- //-------- Begin of function Remote::disable_poll_msg ---------//
- void Remote::disable_poll_msg()
- {
- poll_msg_flag = 0;
- }
- //-------- End of function Remote::disable_poll_msg ---------//
|