122 lines
4.0 KiB
C++
122 lines
4.0 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
// Copyright 2016 Mookie. All Rights Reserved.
|
|
|
|
#include "EasyBallistics.h"
|
|
#include "EBBullet.h"
|
|
#include "Engine/World.h"
|
|
#include "Engine/Engine.h"
|
|
#include "EngineUtils.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "FEasyBallisticsModule"
|
|
|
|
// Console commands for debug control
|
|
static FAutoConsoleCommand EBDebugToggleCommand(
|
|
TEXT("eb.debug.toggle"),
|
|
TEXT("Toggle EasyBallistics debug display on/off"),
|
|
FConsoleCommandDelegate::CreateStatic([]()
|
|
{
|
|
if (GEngine && GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull))
|
|
{
|
|
UWorld* World = GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull);
|
|
for (TActorIterator<AEBBullet> ActorItr(World); ActorItr; ++ActorItr)
|
|
{
|
|
AEBBullet* Bullet = *ActorItr;
|
|
if (Bullet)
|
|
{
|
|
Bullet->DebugEnabled = !Bullet->DebugEnabled;
|
|
}
|
|
}
|
|
UE_LOG(LogTemp, Warning, TEXT("EasyBallistics debug toggled"));
|
|
}
|
|
})
|
|
);
|
|
|
|
static FAutoConsoleCommand EBDebugCategoryCommand(
|
|
TEXT("eb.debug.category"),
|
|
TEXT("Toggle specific debug category: eb.debug.category <CategoryName> <0|1>"),
|
|
FConsoleCommandWithArgsDelegate::CreateStatic([](const TArray<FString>& Args)
|
|
{
|
|
if (Args.Num() < 2)
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("Usage: eb.debug.category <CategoryName> <0|1>"));
|
|
UE_LOG(LogTemp, Warning, TEXT("Categories: Trajectory, Impact, Physics, Performance, Ballistics, Spalling, Pooling"));
|
|
return;
|
|
}
|
|
|
|
FString CategoryName = Args[0];
|
|
bool bEnabled = FCString::Atoi(*Args[1]) != 0;
|
|
|
|
if (GEngine && GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull))
|
|
{
|
|
UWorld* World = GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull);
|
|
for (TActorIterator<AEBBullet> ActorItr(World); ActorItr; ++ActorItr)
|
|
{
|
|
AEBBullet* Bullet = *ActorItr;
|
|
if (Bullet)
|
|
{
|
|
Bullet->ToggleDebugCategory(CategoryName, bEnabled);
|
|
}
|
|
}
|
|
UE_LOG(LogTemp, Warning, TEXT("EasyBallistics debug category '%s' set to %s"), *CategoryName, bEnabled ? TEXT("ON") : TEXT("OFF"));
|
|
}
|
|
})
|
|
);
|
|
|
|
static FAutoConsoleCommand EBDebugClearCommand(
|
|
TEXT("eb.debug.clear"),
|
|
TEXT("Clear all EasyBallistics debug display"),
|
|
FConsoleCommandDelegate::CreateStatic([]()
|
|
{
|
|
if (GEngine && GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull))
|
|
{
|
|
UWorld* World = GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull);
|
|
for (TActorIterator<AEBBullet> ActorItr(World); ActorItr; ++ActorItr)
|
|
{
|
|
AEBBullet* Bullet = *ActorItr;
|
|
if (Bullet)
|
|
{
|
|
Bullet->ClearDebugDisplay();
|
|
}
|
|
}
|
|
UE_LOG(LogTemp, Warning, TEXT("EasyBallistics debug display cleared"));
|
|
}
|
|
})
|
|
);
|
|
|
|
static FAutoConsoleCommand EBDebugInfoCommand(
|
|
TEXT("eb.debug.info"),
|
|
TEXT("Print debug information for all bullets"),
|
|
FConsoleCommandDelegate::CreateStatic([]()
|
|
{
|
|
if (GEngine && GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull))
|
|
{
|
|
UWorld* World = GEngine->GetWorldFromContextObject(GEngine->GameViewport, EGetWorldErrorMode::LogAndReturnNull);
|
|
int32 BulletCount = 0;
|
|
for (TActorIterator<AEBBullet> ActorItr(World); ActorItr; ++ActorItr)
|
|
{
|
|
AEBBullet* Bullet = *ActorItr;
|
|
if (Bullet)
|
|
{
|
|
FString DebugInfo = Bullet->GetDebugInfoString();
|
|
UE_LOG(LogTemp, Warning, TEXT("Bullet %d: %s"), BulletCount++, *DebugInfo);
|
|
}
|
|
}
|
|
UE_LOG(LogTemp, Warning, TEXT("Total active bullets: %d"), BulletCount);
|
|
}
|
|
})
|
|
);
|
|
|
|
void FEasyBallisticsModule::StartupModule()
|
|
{
|
|
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
|
|
}
|
|
|
|
void FEasyBallisticsModule::ShutdownModule()
|
|
{
|
|
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
|
|
// we call this function before unloading the module.
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|
|
|
|
IMPLEMENT_MODULE(FEasyBallisticsModule, EasyBallistics) |