Skip to content

Commit

Permalink
Initial commit of Plugin Files
Browse files Browse the repository at this point in the history
  • Loading branch information
samynjonas committed Apr 16, 2024
1 parent 13d354b commit 77197b1
Show file tree
Hide file tree
Showing 58 changed files with 3,987 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ Plugins/*/Intermediate/*

# Cache files for the editor to use
DerivedDataCache/*

# Custom ignore files
Platforms/*
Content/*
Config/*
Source/*

*.uproject


!Plugins/AdvancedTrafficSystem
13 changes: 13 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1.0",
"components": [
"Microsoft.Net.Component.4.6.2.TargetingPack",
"Microsoft.VisualStudio.Component.VC.14.34.17.4.x86.x64",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Windows10SDK",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Workload.ManagedDesktop",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.Workload.NativeGame"
]
}
24 changes: 24 additions & 0 deletions Plugins/AdvancedTrafficSystem/AdvancedTrafficSystem.uplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "AdvancedTrafficSystem",
"Description": "Custom traffic implementation usings Epic Games' ZoneGraph system",
"Category": "Other",
"CreatedBy": "Jonas Samyn",
"CreatedByURL": "",
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": false,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "AdvancedTrafficSystem",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class AdvancedTrafficSystem : ModuleRules
{
public AdvancedTrafficSystem(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);


PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);


PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Engine",
"InputCore" ,
"ChaosVehicles"
// ... add other public dependencies that you statically link with here ...
}
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"ZoneGraph"
// ... add private dependencies that you statically link with here ...
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "../Public/ATS_AgentActor.h"
#include "../Public/ATS_AgentNavigation.h"
#include "../Public/ATS_AgentMain.h"

// Sets default values
AATS_AgentActor::AATS_AgentActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AATS_AgentActor::BeginPlay()
{
Super::BeginPlay();
SpawnActor();
SwitchToActor(false);
}

// Called every frame
void AATS_AgentActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

m_ElapsedTime += DeltaTime;
if (m_ElapsedTime > m_DistanceCheckInterval)
{
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Distance check"));
m_ElapsedTime = 0.f;
DistanceToMainAgentCheck();
}
}

void AATS_AgentActor::SwitchToActor(bool bPhysics)
{
if(bPhysics == bIsPhysicsActor)
{
return;
}


if (m_PhysicsActor == nullptr || m_SimpleActor == nullptr)
{
return;
}

EnableActor(m_PhysicsActor, bPhysics);
EnableActor(m_SimpleActor, !bPhysics);

if (bPhysics)
{
CompareAgentData(m_PhysicsActor, m_SimpleActor);
}
else
{
CompareAgentData(m_SimpleActor, m_PhysicsActor);
}

bIsPhysicsActor = bPhysics;
}

void AATS_AgentActor::EnableActor(AActor* actor, bool bEnable)
{
actor->SetActorHiddenInGame(!bEnable);
actor->SetActorTickEnabled(bEnable);
actor->SetActorEnableCollision(bEnable);
}

void AATS_AgentActor::CompareAgentData(AActor* receiver, AActor* sender)
{
UATS_AgentNavigation* receiverNavigation = receiver->FindComponentByClass<UATS_AgentNavigation>();
UATS_AgentNavigation* senderNavigation = sender->FindComponentByClass<UATS_AgentNavigation>();

if (receiverNavigation == nullptr || senderNavigation == nullptr)
{
return;
}

receiverNavigation->SetAgentData(senderNavigation->GetAgentData());

receiverNavigation->EnableAgent();
senderNavigation->DissableAgent();

// Assuming `sender` is the actor you want to move
FTransform SenderOriginalTransform = sender->GetActorTransform();

FVector SenderLocation = SenderOriginalTransform.GetLocation();
SenderLocation.Z = -1000.0f; // Move the actor 1000 units down on the Z-axis

// Use SetActorLocation with the Teleport flag set to true
sender->SetActorLocation(SenderLocation, false, nullptr, ETeleportType::ResetPhysics);

// If you want to set the entire transform, including rotation and scale, use SetActorTransform
receiver->SetActorTransform(SenderOriginalTransform, true, nullptr, ETeleportType::ResetPhysics);

}

void AATS_AgentActor::DistanceToMainAgentCheck()
{
if (m_AgentMain == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Main agent is null"));
return;
}

if (m_PhysicsActor == nullptr || m_SimpleActor == nullptr)
{
return;
}

float distance{ 0.f };
if (bIsPhysicsActor)
{
distance = m_PhysicsActor->GetSquaredDistanceTo(m_AgentMain->GetOwner());
}
else
{
distance = m_SimpleActor->GetSquaredDistanceTo(m_AgentMain->GetOwner());
}
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Distance to main agent: %f"), distance);
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Distance to LowDetail Distance: %f"), m_AgentMain->GetLowDetailSquaredDistance());
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Distance to HighDetail Distance: %f"), m_AgentMain->GetHighDetailSquaredDistance());

if (distance > m_AgentMain->GetLowDetailSquaredDistance())
{
//To far away -- nothing to show
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Too far away -- remove"));

m_PhysicsActor->Destroy();
m_SimpleActor->Destroy();
Destroy();
}
else
{
//Show high detail
SwitchToActor(true);
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Switch to high detail"));
}
}

void AATS_AgentActor::SetMainAgent(UATS_AgentMain* pAgentMain)
{
if (pAgentMain == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("AgentActor::Main agent is null"));
return;
}

m_AgentMain = pAgentMain;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "../Public/ATS_AgentLifeTime.h"
#include "../Public/ATS_AgentMain.h"


UATS_AgentLifeTime::UATS_AgentLifeTime()
{
PrimaryComponentTick.bCanEverTick = true;
}


void UATS_AgentLifeTime::BeginPlay()
{
Super::BeginPlay();
}


// Called every frame
void UATS_AgentLifeTime::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

if (bIsDisabled)
{
return;
}

m_ElapsedTime += DeltaTime;
if (m_ElapsedTime > m_DistanceCheckInterval)
{
UE_LOG(LogTemp, Warning, TEXT("AgentLifeTime::Distance check"));
m_ElapsedTime = 0.f;
DistanceToMainAgentCheck();
}
}

void UATS_AgentLifeTime::DistanceToMainAgentCheck()
{
if (m_AgentMain == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("AgentLifeTime::Main agent is null"));
return;
}

float distance = GetOwner()->GetSquaredDistanceTo(m_AgentMain->GetOwner());
UE_LOG(LogTemp, Warning, TEXT("AgentLifeTime::Distance to main agent: %f"), distance);
UE_LOG(LogTemp, Warning, TEXT("AgentLifeTime::Distance to LowDetail Distance: %f"), m_AgentMain->GetLowDetailSquaredDistance());

if (distance > m_AgentMain->GetHighDetailSquaredDistance())
{
//To far away -- nothing to show
UE_LOG(LogTemp, Warning, TEXT("AgentLifeTime::Too far away -- remove"));
GetOwner()->Destroy();
m_AgentMain->RegisterAgentLoss();
}
}

void UATS_AgentLifeTime::SetMainAgent(UATS_AgentMain* pAgentMain)
{
if (pAgentMain == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("AgentLifeTime::Main agent is null"));
return;
}

m_AgentMain = pAgentMain;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "../Public/ATS_AgentMain.h"

UATS_AgentMain::UATS_AgentMain()
{
PrimaryComponentTick.bCanEverTick = true;
}


// Called when the game starts
void UATS_AgentMain::BeginPlay()
{
Super::BeginPlay();

m_HighDetailDistanceSquared = m_HighDetailDistance * m_HighDetailDistance;
m_LowDetailDistanceSquared = m_LowDetailDistance * m_LowDetailDistance;
}


// Called every frame
void UATS_AgentMain::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

// ...
}

void UATS_AgentMain::RegisterAgentLoss()
{
++m_AgentLoss;
}

Loading

0 comments on commit 77197b1

Please sign in to comment.