(svn r2589) Fix: [network] Fixed static variable that wasn't initialized. Would stop the sync checking from working in some cases.
This commit is contained in:
		@@ -947,6 +947,7 @@ bool NetworkServerStart(void)
 | 
				
			|||||||
	_frame_counter = 0;
 | 
						_frame_counter = 0;
 | 
				
			||||||
	_frame_counter_server = 0;
 | 
						_frame_counter_server = 0;
 | 
				
			||||||
	_frame_counter_max = 0;
 | 
						_frame_counter_max = 0;
 | 
				
			||||||
 | 
						_last_sync_frame = 0;
 | 
				
			||||||
	_network_own_client_index = NETWORK_SERVER_INDEX;
 | 
						_network_own_client_index = NETWORK_SERVER_INDEX;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!_network_dedicated)
 | 
						if (!_network_dedicated)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -146,6 +146,8 @@ VARDEF char _network_unique_id[NETWORK_NAME_LENGTH]; // Our own unique ID
 | 
				
			|||||||
VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
 | 
					VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
 | 
				
			||||||
VARDEF uint32 _frame_counter_max; // To where we may go with our clients
 | 
					VARDEF uint32 _frame_counter_max; // To where we may go with our clients
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// networking settings
 | 
					// networking settings
 | 
				
			||||||
VARDEF uint32 _network_ip_list[MAX_INTERFACES + 1]; // Network IPs
 | 
					VARDEF uint32 _network_ip_list[MAX_INTERFACES + 1]; // Network IPs
 | 
				
			||||||
VARDEF uint16 _network_game_count;
 | 
					VARDEF uint16 _network_game_count;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1512,11 +1512,11 @@ void NetworkHandleCommandQueue(NetworkClientState *cs) {
 | 
				
			|||||||
// This is called every tick if this is a _network_server
 | 
					// This is called every tick if this is a _network_server
 | 
				
			||||||
void NetworkServer_Tick(void)
 | 
					void NetworkServer_Tick(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 | 
					 | 
				
			||||||
	static uint32 last_sync_frame = 0;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	NetworkClientState *cs;
 | 
						NetworkClientState *cs;
 | 
				
			||||||
	bool send_frame = false;
 | 
						bool send_frame = false;
 | 
				
			||||||
 | 
					#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 | 
				
			||||||
 | 
						bool send_sync = false;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Update max-frame-counter
 | 
						// Update max-frame-counter
 | 
				
			||||||
	if (_frame_counter > _frame_counter_max) {
 | 
						if (_frame_counter > _frame_counter_max) {
 | 
				
			||||||
@@ -1524,6 +1524,13 @@ void NetworkServer_Tick(void)
 | 
				
			|||||||
		send_frame = true;
 | 
							send_frame = true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 | 
				
			||||||
 | 
						if (_frame_counter >= _last_sync_frame + _network_sync_freq) {
 | 
				
			||||||
 | 
							_last_sync_frame = _frame_counter;
 | 
				
			||||||
 | 
							send_sync = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Now we are done with the frame, inform the clients that they can
 | 
						// Now we are done with the frame, inform the clients that they can
 | 
				
			||||||
	//  do their frame!
 | 
						//  do their frame!
 | 
				
			||||||
	FOR_ALL_CLIENTS(cs) {
 | 
						FOR_ALL_CLIENTS(cs) {
 | 
				
			||||||
@@ -1556,30 +1563,21 @@ void NetworkServer_Tick(void)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (cs->status >= STATUS_PRE_ACTIVE) {
 | 
				
			||||||
		// Check if we can send command, and if we have anything in the queue
 | 
								// Check if we can send command, and if we have anything in the queue
 | 
				
			||||||
		if (cs->status > STATUS_DONE_MAP) {
 | 
					 | 
				
			||||||
			NetworkHandleCommandQueue(cs);
 | 
								NetworkHandleCommandQueue(cs);
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Do we need to send the new frame-packet?
 | 
								// Send an updated _frame_counter_max to the client
 | 
				
			||||||
		if (send_frame && (cs->status == STATUS_ACTIVE || cs->status == STATUS_PRE_ACTIVE)) {
 | 
								if (send_frame)
 | 
				
			||||||
			SEND_COMMAND(PACKET_SERVER_FRAME)(cs);
 | 
									SEND_COMMAND(PACKET_SERVER_FRAME)(cs);
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 | 
					 | 
				
			||||||
		// Is it time to send a sync-packet to all clients?
 | 
					 | 
				
			||||||
		if (last_sync_frame + _network_sync_freq < _frame_counter) {
 | 
					 | 
				
			||||||
			SEND_COMMAND(PACKET_SERVER_SYNC)(cs);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 | 
					#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 | 
				
			||||||
	// Update the last_sync_frame if needed!
 | 
								// Send a sync-check packet
 | 
				
			||||||
	if (last_sync_frame + _network_sync_freq < _frame_counter) {
 | 
								if (send_sync)
 | 
				
			||||||
		last_sync_frame = _frame_counter;
 | 
									SEND_COMMAND(PACKET_SERVER_SYNC)(cs);
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* See if we need to advertise */
 | 
						/* See if we need to advertise */
 | 
				
			||||||
	NetworkUDPAdvertise();
 | 
						NetworkUDPAdvertise();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user