Torr_Samaho avatar Torr_Samaho committed 2a154eb

Ported from TIHan's monster_bandwidth_reduction branch: Converted SERVERCOMMANDS_SpawnThing* and SERVERCOMMANDS_MoveThing* to use NetCommand. This port untangles the command style change from the actual bandwidth reduction and fixes a small bug of that branch (the "ulSize == 0" in SERVERCOMMANDS_MoveThing* was removed in there instead of being updated to work with the new style).

Comments (0)

Files changed (1)

src/sv_commands.cpp

 //
 void SERVERCOMMANDS_SpawnThing( AActor *pActor, ULONG ulPlayerExtra, ULONG ulFlags )
 {
-	ULONG		ulIdx;
 	USHORT		usActorNetworkIndex = 0;
 
 	if ( pActor == NULL )
 
 	usActorNetworkIndex = pActor->GetClass( )->getActorNetworkIndex();
 
-	for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
-	{
-		if ( SERVER_IsValidClient( ulIdx ) == false )
-			continue;
-
-		if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
-			(( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
-		{
-			continue;
-		}
-
-		SERVER_CheckClientBuffer( ulIdx, 11, true );
-		NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_SPAWNTHING );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->x >> FRACBITS );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->y >> FRACBITS );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->z >> FRACBITS );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, usActorNetworkIndex );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->lNetID );
-	}
+	NetCommand command ( SVC_SPAWNTHING );
+	command.addShort( pActor->x >> FRACBITS );
+	command.addShort( pActor->y >> FRACBITS );
+	command.addShort( pActor->z >> FRACBITS );
+	command.addShort( usActorNetworkIndex );
+	command.addShort( pActor->lNetID );
+	command.sendCommandToClients( ulPlayerExtra, ulFlags );
 }
 
 //*****************************************************************************
 //
 void SERVERCOMMANDS_SpawnThingNoNetID( AActor *pActor, ULONG ulPlayerExtra, ULONG ulFlags )
 {
-	ULONG		ulIdx;
 	USHORT		usActorNetworkIndex = 0;
 
 	if ( pActor == NULL )
 
 	usActorNetworkIndex = pActor->GetClass( )->getActorNetworkIndex();
 
-	for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
-	{
-		if ( SERVER_IsValidClient( ulIdx ) == false )
-			continue;
-
-		if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
-			(( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
-		{
-			continue;
-		}
-
-		SERVER_CheckClientBuffer( ulIdx, 9, true );
-		NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_SPAWNTHINGNONETID );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->x >> FRACBITS );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->y >> FRACBITS );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->z >> FRACBITS );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, usActorNetworkIndex );
-	}
+	NetCommand command ( SVC_SPAWNTHINGNONETID );
+	command.addShort( pActor->x >> FRACBITS );
+	command.addShort( pActor->y >> FRACBITS );
+	command.addShort( pActor->z >> FRACBITS );
+	command.addShort( usActorNetworkIndex );
+	command.sendCommandToClients( ulPlayerExtra, ulFlags );
 }
 
 //*****************************************************************************
 //
 void SERVERCOMMANDS_SpawnThingExact( AActor *pActor, ULONG ulPlayerExtra, ULONG ulFlags )
 {
-	ULONG		ulIdx;
 	USHORT		usActorNetworkIndex = 0;
 
 	if ( pActor == NULL )
 
 	usActorNetworkIndex = pActor->GetClass( )->getActorNetworkIndex();
 
-	for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
-	{
-		if ( SERVER_IsValidClient( ulIdx ) == false )
-			continue;
-
-		if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
-			(( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
-		{
-			continue;
-		}
-
-		SERVER_CheckClientBuffer( ulIdx, 17, true );
-		NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_SPAWNTHINGEXACT );
-		NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->x );
-		NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->y );
-		NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->z );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, usActorNetworkIndex );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->lNetID );
-	}
+	NetCommand command ( SVC_SPAWNTHINGEXACT );
+	command.addLong( pActor->x );
+	command.addLong( pActor->y );
+	command.addLong( pActor->z );
+	command.addShort( usActorNetworkIndex );
+	command.addShort( pActor->lNetID );
+	command.sendCommandToClients( ulPlayerExtra, ulFlags );
 }
 
 //*****************************************************************************
 //
 void SERVERCOMMANDS_SpawnThingExactNoNetID( AActor *pActor, ULONG ulPlayerExtra, ULONG ulFlags )
 {
-	ULONG		ulIdx;
 	USHORT		usActorNetworkIndex = 0;
 
 	if ( pActor == NULL )
 
 	usActorNetworkIndex = pActor->GetClass( )->getActorNetworkIndex();
 
-	for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
-	{
-		if ( SERVER_IsValidClient( ulIdx ) == false )
-			continue;
-
-		if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
-			(( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
-		{
-			continue;
-		}
-
-		SERVER_CheckClientBuffer( ulIdx, 15, true );
-		NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_SPAWNTHINGEXACTNONETID );
-		NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->x );
-		NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->y );
-		NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->z );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, usActorNetworkIndex );
-	}
+	NetCommand command ( SVC_SPAWNTHINGEXACTNONETID );
+	command.addLong( pActor->x );
+	command.addLong( pActor->y );
+	command.addLong( pActor->z );
+	command.addShort( usActorNetworkIndex );
+	command.sendCommandToClients( ulPlayerExtra, ulFlags );
 }
 
 //*****************************************************************************
 //
 void SERVERCOMMANDS_MoveThing( AActor *pActor, ULONG ulBits, ULONG ulPlayerExtra, ULONG ulFlags )
 {
-	ULONG	ulIdx;
-	ULONG	ulSize;
-
 	if ( !EnsureActorHasNetID (pActor) )
 		return;
 
 	if ( ulFlags == 0 )
 		RemoveUnnecessaryPositionUpdateFlags ( pActor, ulBits );
 
-	ulSize = 0;
+	// Nothing to update.
+	if ( ulBits == 0 )
+		return;
+
+	NetCommand command ( SVC_MOVETHING );
+	command.addShort( pActor->lNetID );
+	command.addShort( ulBits );
+
+	// Write position.
 	if ( ulBits & CM_X )
-		ulSize += 2;
+		command.addShort( pActor->x >> FRACBITS );
 	if ( ulBits & CM_Y )
-		ulSize += 2;
+		command.addShort( pActor->y >> FRACBITS );
 	if ( ulBits & CM_Z )
-		ulSize += 2;
+		command.addShort( pActor->z >> FRACBITS );
+
+	// Write angle.
 	if ( ulBits & CM_ANGLE )
-		ulSize += 4;
+		command.addLong( pActor->angle );
+
+	// Write velocity.
 	if ( ulBits & CM_MOMX )
-		ulSize += 2;
+		command.addShort( pActor->momx >> FRACBITS );
 	if ( ulBits & CM_MOMY )
-		ulSize += 2;
+		command.addShort( pActor->momy >> FRACBITS );
 	if ( ulBits & CM_MOMZ )
-		ulSize += 2;
+		command.addShort( pActor->momz >> FRACBITS );
+
+	// Write pitch.
 	if ( ulBits & CM_PITCH )
-		ulSize += 4;
+		command.addLong( pActor->pitch );
+
+	// Write movedir.
 	if ( ulBits & CM_MOVEDIR )
-		ulSize += 1;
-
-	// Nothing to update.
-	if ( ulSize == 0 )
-		return;
-
-	ulSize += 5;
-	for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
-	{ 
-		if ( SERVER_IsValidClient( ulIdx ) == false )
-			continue;
-
-		if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
-			(( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
-		{
-			continue;
-		}
-
-		SERVER_CheckClientBuffer( ulIdx, ulSize, true );
-		NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_MOVETHING );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->lNetID );
-
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, ulBits );
-
-		// Write position.
-		if ( ulBits & CM_X )
-			NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->x >> FRACBITS );
-		if ( ulBits & CM_Y )
-			NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->y >> FRACBITS );
-		if ( ulBits & CM_Z )
-			NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->z >> FRACBITS );
-
-		// Write angle.
-		if ( ulBits & CM_ANGLE )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->angle );
-
-		// Write velocity.
-		if ( ulBits & CM_MOMX )
-			NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->momx >> FRACBITS );
-		if ( ulBits & CM_MOMY )
-			NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->momy >> FRACBITS );
-		if ( ulBits & CM_MOMZ )
-			NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->momz >> FRACBITS );
-
-		// Write pitch.
-		if ( ulBits & CM_PITCH )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->pitch );
-
-		// Write movedir.
-		if ( ulBits & CM_MOVEDIR )
-			NETWORK_WriteByte( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->movedir );
-	}
+		command.addByte( pActor->movedir );
+
+	command.sendCommandToClients( ulPlayerExtra, ulFlags );
 
 	// [BB] Only mark something as updated, if it the update was sent to all players.
 	if ( ulFlags == 0 )
 //
 void SERVERCOMMANDS_MoveThingExact( AActor *pActor, ULONG ulBits, ULONG ulPlayerExtra, ULONG ulFlags )
 {
-	ULONG	ulIdx;
-	ULONG	ulSize;
-
 	if ( !EnsureActorHasNetID (pActor) )
 		return;
 
 	if ( ulFlags == 0 )
 		RemoveUnnecessaryPositionUpdateFlags ( pActor, ulBits );
 
-	ulSize = 0;
+	// Nothing to update.
+	if ( ulBits == 0 )
+		return;
+
+	NetCommand command ( SVC_MOVETHINGEXACT );
+	command.addShort( pActor->lNetID );
+	command.addShort( ulBits );
+
+	// Write position.
 	if ( ulBits & CM_X )
-		ulSize += 4;
+		command.addLong( pActor->x );
 	if ( ulBits & CM_Y )
-		ulSize += 4;
+		command.addLong( pActor->y );
 	if ( ulBits & CM_Z )
-		ulSize += 4;
+		command.addLong( pActor->z );
+
+	// Write angle.
 	if ( ulBits & CM_ANGLE )
-		ulSize += 4;
+		command.addLong( pActor->angle );
+
+	// Write velocity.
 	if ( ulBits & CM_MOMX )
-		ulSize += 4;
+		command.addLong( pActor->momx );
 	if ( ulBits & CM_MOMY )
-		ulSize += 4;
+		command.addLong( pActor->momy );
 	if ( ulBits & CM_MOMZ )
-		ulSize += 4;
+		command.addLong( pActor->momz );
+
+	// Write pitch.
 	if ( ulBits & CM_PITCH )
-		ulSize += 4;
+		command.addLong( pActor->pitch );
+
+	// Write movedir.
 	if ( ulBits & CM_MOVEDIR )
-		ulSize += 1;
-
-	// Nothing to update.
-	if ( ulSize == 0 )
-		return;
-
-	ulSize += 5;
-	for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
-	{ 
-		if ( SERVER_IsValidClient( ulIdx ) == false )
-			continue;
-
-		if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
-			(( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
-		{
-			continue;
-		}
-
-		SERVER_CheckClientBuffer( ulIdx, ulSize, true );
-		NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_MOVETHINGEXACT );
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->lNetID );
-
-		NETWORK_WriteShort( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, ulBits );
-
-		// Write position.
-		if ( ulBits & CM_X )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->x );
-		if ( ulBits & CM_Y )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->y );
-		if ( ulBits & CM_Z )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->z );
-
-		// Write angle.
-		if ( ulBits & CM_ANGLE )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->angle );
-
-		// Write velocity.
-		if ( ulBits & CM_MOMX )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->momx );
-		if ( ulBits & CM_MOMY )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->momy );
-		if ( ulBits & CM_MOMZ )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->momz );
-
-		// Write pitch.
-		if ( ulBits & CM_PITCH )
-			NETWORK_WriteLong( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->pitch );
-
-		// Write movedir.
-		if ( ulBits & CM_MOVEDIR )
-			NETWORK_WriteByte( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, pActor->movedir );
-	}
+		command.addByte( pActor->movedir );
+
+	command.sendCommandToClients( ulPlayerExtra, ulFlags );
 
 	// [BB] Only mark something as updated, if it the update was sent to all players.
 	if ( ulFlags == 0 )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.