network.c
changeset 2080 48d009b783f3
parent 2079 5afd2e7fc3bd
child 2153 91e89aa8c299
equal deleted inserted replaced
2079:5afd2e7fc3bd 2080:48d009b783f3
  1099 }
  1099 }
  1100 
  1100 
  1101 // Handle the local-command-queue
  1101 // Handle the local-command-queue
  1102 static void NetworkHandleLocalQueue(void)
  1102 static void NetworkHandleLocalQueue(void)
  1103 {
  1103 {
  1104 	if (_local_command_queue != NULL) {
  1104 	CommandPacket *cp, **cp_prev;
  1105 		CommandPacket *cp;
  1105 
  1106 		CommandPacket *cp_prev;
  1106 	cp_prev = &_local_command_queue;
  1107 
  1107 
  1108 		cp = _local_command_queue;
  1108 	while ( (cp = *cp_prev) != NULL) {
  1109 		cp_prev = NULL;
  1109 
  1110 
  1110 		// The queue is always in order, which means
  1111 		while (cp != NULL) {
  1111 		// that the first element will be executed first.
  1112 			if (_frame_counter > cp->frame) {
  1112 		if (_frame_counter < cp->frame)
  1113 				// We can execute this command
  1113 			break;
  1114 				NetworkExecuteCommand(cp);
  1114 
  1115 
  1115 		if (_frame_counter > cp->frame) {
  1116 				if (cp_prev != NULL) {
  1116 			// If we reach here, it means for whatever reason, we've already executed
  1117 					cp_prev->next = cp->next;
  1117 			// past the command we need to execute.
  1118 					free(cp);
  1118 			DEBUG(net, 0)("[NET] Trying to execute a packet in the past!");
  1119 					cp = cp_prev->next;
  1119 			assert(0);
  1120 				} else {
  1120 		}
  1121 					// This means we are at our first packet
  1121 
  1122 					_local_command_queue = cp->next;
  1122 		// We can execute this command
  1123 					free(cp);
  1123 		NetworkExecuteCommand(cp);
  1124 					cp = _local_command_queue;
  1124 
  1125 				}
  1125 		*cp_prev = cp->next;
  1126 
  1126 		free(cp);
  1127 			} else {
  1127 	}
  1128 				// Command is in the future, skip to next
  1128 
  1129 				//  (commands don't have to be in order in the queue!!)
  1129 	// Just a safety check, to be removed in the future.
  1130 				cp_prev = cp;
  1130 	// Make sure that no older command appears towards the end of the queue
  1131 				cp = cp->next;
  1131 	// In that case we missed executing it. This will never happen.
  1132 			}
  1132 	for(cp = _local_command_queue; cp; cp = cp->next) {
  1133 		}
  1133 		assert(_frame_counter < cp->frame);
  1134 	}
  1134 	}
       
  1135 
  1135 }
  1136 }
  1136 
  1137 
  1137 static bool NetworkDoClientLoop(void)
  1138 static bool NetworkDoClientLoop(void)
  1138 {
  1139 {
  1139 	_frame_counter++;
  1140 	_frame_counter++;