mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 00:01:37 -07:00
6d9494b685
Cog integration has been reworked to make it easier, to keep Cog available between level loadings, and to properly tick ImGui while the game is paused. Cog 's WindowManager is now a GameInstanceSubsystem. The WindowManager ticks ImGui and the windows during the OnWorldPostActorTick delegate. (If this is not working for your project, don't hesitate to open an issue.) Check the readme to see how to integrate Cog. The Plot debug functions (displayed by the Engine/Plot window) have been reworked as they were not properly working in Multi PIE in Single Process. API changes: - use FCogDebug::Plot instead of FCogDebugPlot::PlotValue - use FCogDebug::InstantEvent instead of FCogDebugPlot::PlotEventInstant - use FCogDebug::StartEvent instead of FCogDebugPlot::PlotEventStart - use FCogDebug::StopEvent instead of FCogDebugPlot::PlotEventStop
106 lines
3.9 KiB
C++
106 lines
3.9 KiB
C++
#include "CogSampleGameState.h"
|
|
|
|
#include "CogSampleAbilitySystemComponent.h"
|
|
#include "GameFramework/GameState.h"
|
|
#include "GameFramework/PlayerState.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "Net/UnrealNetwork.h"
|
|
|
|
#if ENABLE_COG
|
|
#include "CogAll.h"
|
|
#include "CogSampleWindow_Team.h"
|
|
#include "CogWindowManager.h"
|
|
#endif //ENABLE_COG
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
ACogSampleGameState::ACogSampleGameState(const FObjectInitializer & ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
SetActorTickEnabled(true);
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
PrimaryActorTick.SetTickFunctionEnable(true);
|
|
PrimaryActorTick.bStartWithTickEnabled = true;
|
|
|
|
AbilitySystemComponent = CreateDefaultSubobject<UCogSampleAbilitySystemComponent>(TEXT("AbilitySystemComponent"));
|
|
AbilitySystemComponent->SetIsReplicated(true);
|
|
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
void ACogSampleGameState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
{
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
DOREPLIFETIME(ThisClass, _ServerFramerateRaw);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
void ACogSampleGameState::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
AbilitySystemComponent->InitAbilityActorInfo(this, this);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
void ACogSampleGameState::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
|
{
|
|
Super::EndPlay(EndPlayReason);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
void ACogSampleGameState::Tick(float DeltaSeconds)
|
|
{
|
|
Super::Tick(DeltaSeconds);
|
|
|
|
#if ENABLE_COG
|
|
|
|
extern ENGINE_API float GAverageFPS;
|
|
|
|
constexpr float smoothing = 10.0f;
|
|
|
|
_ClientFramerateSmooth = _ClientFramerateSmooth >= 0.0f
|
|
? FMath::FInterpTo(_ClientFramerateSmooth, GAverageFPS, DeltaSeconds, smoothing)
|
|
: GAverageFPS;
|
|
|
|
_ServerFramerateSmooth = _ServerFramerateSmooth >= 0.0f
|
|
? FMath::FInterpTo(_ServerFramerateSmooth, _ServerFramerateRaw, DeltaSeconds, smoothing)
|
|
: _ServerFramerateRaw;
|
|
|
|
if (GetLocalRole() != ROLE_Authority)
|
|
{
|
|
FCogDebug::Plot(this, "Frame Rate Client Raw", GAverageFPS);
|
|
FCogDebug::Plot(this, "Frame Rate Client Smooth", _ClientFramerateSmooth);
|
|
FCogDebug::Plot(this, "Frame Rate Server Raw", _ServerFramerateRaw);
|
|
FCogDebug::Plot(this, "Frame Rate Server Smooth", _ServerFramerateSmooth);
|
|
|
|
if (const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController())
|
|
{
|
|
if (const APlayerController* PlayerController = LocalPlayer->PlayerController)
|
|
{
|
|
if (const APlayerState* PlayerState = PlayerController->GetPlayerState<APlayerState>())
|
|
{
|
|
FCogDebug::Plot(this, "Ping", PlayerState->GetPingInMilliseconds());
|
|
}
|
|
|
|
if (const UNetConnection* Connection = PlayerController->GetNetConnection())
|
|
{
|
|
FCogDebug::Plot(this,
|
|
"Packet Loss In",
|
|
Connection->GetInLossPercentage().GetAvgLossPercentage() * 100.0f);
|
|
|
|
FCogDebug::Plot(this,
|
|
"Packet Loss Out",
|
|
Connection->GetOutLossPercentage().GetAvgLossPercentage() * 100.0f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FCogDebug::Plot(this, "Frame Rate Raw", GAverageFPS);
|
|
FCogDebug::Plot(this, "Frame Rate Smooth", _ClientFramerateSmooth);
|
|
}
|
|
|
|
#endif //ENABLE_COG
|
|
}
|