Commit MetaInfo

修订版4792aac73c0c7811fb50cf0d293e5ce2e104c595 (tree)
时间2020-11-22 22:24:24
作者Adam Kaminski <kaminskiadam9@gmai...>
CommiterAdam Kaminski

Log Message

Added network optimizations to DoSetActorProperty for any actor properties that didn't already check if they changed before sending a server command to all the clients.

更改概述

差异

diff -r 695f098a12bf -r 4792aac73c0c src/p_acs.cpp
--- a/src/p_acs.cpp Sun Nov 22 08:23:25 2020 -0500
+++ b/src/p_acs.cpp Sun Nov 22 08:24:24 2020 -0500
@@ -4286,11 +4286,15 @@
42864286 actor->health = value;
42874287 if (actor->player != NULL)
42884288 {
4289+ // [AK] Save the original value.
4290+ oldValue = actor->health;
4291+
42894292 actor->player->health = value;
42904293
42914294 // [BC/BB] If we're the server, tell all clients about the new health value.
4295+ // [AK] Only bother the clients if the health has actually changed.
42924296 if (( NETWORK_GetState( ) == NETSTATE_SERVER ) &&
4293- ( SERVER_IsValidClient( actor->player - players )))
4297+ ( SERVER_IsValidClient( actor->player - players )) && ( oldValue != actor->health ))
42944298 {
42954299 SERVERCOMMANDS_SetPlayerHealth( static_cast<ULONG>( actor->player - players ) );
42964300 }
@@ -4319,14 +4323,21 @@
43194323 break;
43204324
43214325 case APROP_Alpha:
4326+ // [AK] Save the original value.
4327+ oldValue = actor->alpha;
4328+
43224329 actor->alpha = value;
43234330
43244331 // [BC] If we're the server, tell clients to update this actor property.
4325- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4332+ // [AK] Only bother the clients if the alpha has actually changed.
4333+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->alpha ) )
43264334 SERVERCOMMANDS_SetThingProperty( actor, APROP_Alpha );
43274335 break;
43284336
43294337 case APROP_RenderStyle:
4338+ // [AK] Save the original render style.
4339+ FRenderStyle oldRenderStyle = actor->RenderStyle;
4340+
43304341 for(int i=0; LegacyRenderStyleIndices[i] >= 0; i++)
43314342 {
43324343 if (LegacyRenderStyleIndices[i] == value)
@@ -4337,7 +4348,8 @@
43374348 }
43384349
43394350 // [BC] If we're the server, tell clients to update this actor property.
4340- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4351+ // [AK] Only bother the clients if the rendering has actually changed.
4352+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && !( oldRenderStyle == actor->RenderStyle ) )
43414353 SERVERCOMMANDS_SetThingProperty( actor, APROP_RenderStyle );
43424354
43434355 break;
@@ -4351,10 +4363,14 @@
43514363 break;
43524364
43534365 case APROP_Invulnerable:
4366+ // [AK] Save the original value.
4367+ oldValue = actor->flags2;
4368+
43544369 if (value) actor->flags2 |= MF2_INVULNERABLE; else actor->flags2 &= ~MF2_INVULNERABLE;
43554370
43564371 // [BC] If we're the server, tell clients to update this actor property.
4357- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4372+ // [AK] Only bother the clients if the flags were actually changed.
4373+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->flags2 ) )
43584374 SERVERCOMMANDS_SetThingFlags( actor, FLAGSET_FLAGS2 );
43594375 break;
43604376
@@ -4368,11 +4384,18 @@
43684384
43694385 case APROP_JumpZ:
43704386 if (actor->IsKindOf (RUNTIME_CLASS (APlayerPawn)))
4371- static_cast<APlayerPawn *>(actor)->JumpZ = value;
4372-
4373- // [BC] If we're the server, tell clients to update this actor property.
4374- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4375- SERVERCOMMANDS_SetThingProperty( actor, APROP_JumpZ );
4387+ {
4388+ // [AK] Save the original value.
4389+ APlayerPawn *playerActor = static_cast<APlayerPawn *>(actor);
4390+ oldValue = playerActor->JumpZ;
4391+
4392+ playerActor->JumpZ = value;
4393+
4394+ // [BC] If we're the server, tell clients to update this actor property.
4395+ // [AK] Only bother the clients if the JumpZ has actually changed.
4396+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != playerActor->JumpZ ) )
4397+ SERVERCOMMANDS_SetThingProperty( actor, APROP_JumpZ );
4398+ }
43764399 break; // [GRB]
43774400
43784401 case APROP_ChaseGoal:
@@ -4406,12 +4429,18 @@
44064429 case APROP_SpawnHealth:
44074430 if (actor->IsKindOf (RUNTIME_CLASS (APlayerPawn)))
44084431 {
4409- static_cast<APlayerPawn *>(actor)->MaxHealth = value;
4432+ // [AK] Save the original value.
4433+ APlayerPawn *playerActor = static_cast<APlayerPawn *>(actor);
4434+ oldValue = playerActor->MaxHealth;
4435+
4436+ playerActor->MaxHealth = value;
44104437
44114438 // [BB] If we're the server, tell clients to update this actor property.
44124439 // Note: Don't do this if the actor is a voodoo doll, the client would
44134440 // alter the value of the real player body in this case.
4414- if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && actor->player && ( actor->player->mo == actor ) )
4441+ // [AK] Only bother the clients if the max health has actually changed.
4442+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && actor->player &&
4443+ ( actor->player->mo == actor ) && ( oldValue != playerActor->MaxHealth ) )
44154444 SERVERCOMMANDS_SetPlayerMaxHealth( static_cast<ULONG>( actor->player - players ) );
44164445 }
44174446 break;
@@ -4429,50 +4458,74 @@
44294458 break;
44304459
44314460 case APROP_SeeSound:
4461+ // [AK] Save the original sound.
4462+ oldValue = actor->SeeSound;
4463+
44324464 actor->SeeSound = FBehavior::StaticLookupString(value);
44334465
44344466 // [BC] If we're the server, tell clients to update this actor property.
4435- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4467+ // [AK] Only bother the clients if the sound has actually changed.
4468+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->SeeSound ) )
44364469 SERVERCOMMANDS_SetThingSound( actor, ACTORSOUND_SEESOUND, FBehavior::StaticLookupString( value ));
44374470 break;
44384471
44394472 case APROP_AttackSound:
4473+ // [AK] Save the original sound.
4474+ oldValue = actor->AttackSound;
4475+
44404476 actor->AttackSound = FBehavior::StaticLookupString(value);
44414477
44424478 // [BC] If we're the server, tell clients to update this actor property.
4443- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4479+ // [AK] Only bother the clients if the sound has actually changed.
4480+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->AttackSound ) )
44444481 SERVERCOMMANDS_SetThingSound( actor, ACTORSOUND_ATTACKSOUND, FBehavior::StaticLookupString( value ));
44454482 break;
44464483
44474484 case APROP_PainSound:
4485+ // [AK] Save the original sound.
4486+ oldValue = actor->PainSound;
4487+
44484488 actor->PainSound = FBehavior::StaticLookupString(value);
44494489
44504490 // [BC] If we're the server, tell clients to update this actor property.
4451- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4491+ // [AK] Only bother the clients if the sound has actually changed.
4492+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->PainSound ) )
44524493 SERVERCOMMANDS_SetThingSound( actor, ACTORSOUND_PAINSOUND, FBehavior::StaticLookupString( value ));
44534494 break;
44544495
44554496 case APROP_DeathSound:
4497+ // [AK] Save the original sound.
4498+ oldValue = actor->DeathSound;
4499+
44564500 actor->DeathSound = FBehavior::StaticLookupString(value);
44574501
44584502 // [BC] If we're the server, tell clients to update this actor property.
4459- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4503+ // [AK] Only bother the clients if the sound has actually changed.
4504+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->DeathSound ) )
44604505 SERVERCOMMANDS_SetThingSound( actor, ACTORSOUND_DEATHSOUND, FBehavior::StaticLookupString( value ));
44614506 break;
44624507
44634508 case APROP_ActiveSound:
4509+ // [AK] Save the original sound.
4510+ oldValue = actor->ActiveSound;
4511+
44644512 actor->ActiveSound = FBehavior::StaticLookupString(value);
44654513
44664514 // [BC] If we're the server, tell clients to update this actor property.
4467- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4515+ // [AK] Only bother the clients if the sound has actually changed.
4516+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->ActiveSound ) )
44684517 SERVERCOMMANDS_SetThingSound( actor, ACTORSOUND_ACTIVESOUND, FBehavior::StaticLookupString( value ));
44694518 break;
44704519
44714520 case APROP_Species:
4521+ // [AK] Save the original species.
4522+ oldValue = actor->Species;
4523+
44724524 actor->Species = FBehavior::StaticLookupString(value);
44734525
44744526 // [AK] If we're the server, tell clients to update this actor property.
4475- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4527+ // Only bother the clients if the species has actually changed.
4528+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->Species ) )
44764529 SERVERCOMMANDS_SetThingSpecies( actor );
44774530 break;
44784531
@@ -4495,18 +4548,26 @@
44954548 break;
44964549
44974550 case APROP_ScaleX:
4551+ // [AK] Save the original value.
4552+ oldValue = actor->scaleX;
4553+
44984554 actor->scaleX = value;
44994555
45004556 // [TP] If we're the server, tell clients to update this actor property.
4501- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4557+ // [AK] Only bother the clients if the scale has actually changed.
4558+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->scaleX ) )
45024559 SERVERCOMMANDS_SetThingScale( actor, ACTORSCALE_X );
45034560 break;
45044561
45054562 case APROP_ScaleY:
4563+ // [AK] Save the original value.
4564+ oldValue = actor->scaleY;
4565+
45064566 actor->scaleY = value;
45074567
45084568 // [TP] If we're the server, tell clients to update this actor property.
4509- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4569+ // [AK] Only bother the clients if the scale has actually changed.
4570+ if ( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != actor->scaleY ) )
45104571 SERVERCOMMANDS_SetThingScale( actor, ACTORSCALE_Y );
45114572 break;
45124573
@@ -4529,13 +4590,18 @@
45294590 case APROP_ViewHeight:
45304591 if (actor->IsKindOf (RUNTIME_CLASS (APlayerPawn)))
45314592 {
4532- static_cast<APlayerPawn *>(actor)->ViewHeight = value;
4593+ // [AK] Save the original value.
4594+ APlayerPawn *playerActor = static_cast<APlayerPawn *>(actor);
4595+ oldValue = playerActor->ViewHeight;
4596+
4597+ playerActor->ViewHeight = value;
45334598 if (actor->player != NULL)
45344599 {
45354600 actor->player->viewheight = value;
45364601
45374602 // [BB] Tell the clients about the changed view height.
4538- if( NETWORK_GetState() == NETSTATE_SERVER )
4603+ // [AK] Only bother the clients if the view height has actually changed.
4604+ if( ( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( oldValue != playerActor->ViewHeight ) )
45394605 SERVERCOMMANDS_SetPlayerViewHeight ( actor->player - players );
45404606 }
45414607 }
Show on old repository browser