Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Panakotta00 committed Mar 16, 2020
2 parents 12bbc8a + becc631 commit e33a1e8
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 64 deletions.
Binary file modified Content/LightItUp/Lamps/-Shared/LampMenu/GroupEntry.uasset
Binary file not shown.
Binary file modified Content/LightItUp/Lamps/-Shared/LampMenu/LampInteraction.uasset
Binary file not shown.
Binary file not shown.
Binary file removed Content/LightItUp/Lamps/FueldLampBase.uasset
Binary file not shown.
Binary file modified Content/LightItUp/Lamps/PortableLight/PortableLamp.uasset
Binary file not shown.
Binary file not shown.
Binary file removed Content/LightItUp/Lamps/Widget_CreateGroup.uasset
Binary file not shown.
Binary file removed Content/LightItUp/Lamps/Widget_FueldLamp.uasset
Binary file not shown.
2 changes: 1 addition & 1 deletion FactoryGame.uproject
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "{1A040AC1-4C66-B453-21B2-5F8D29E1F9F7}",
"EngineAssociation": "4.22.3-CSS",
"Category": "",
"Description": "",
"Modules": [
Expand Down
37 changes: 37 additions & 0 deletions Source/LightItUp/FueledLampBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "FueledLampBase.h"
#include "FGActorRepresentationManager.h"
#include "Components/SpotLightComponent.h"
#include "UnrealNetwork.h"

AFueledLampBase::AFueledLampBase() {
PowerConnectionProduction = CreateDefaultSubobject<UFGPowerConnectionComponent>("PowerConnectionProduction");
PowerConnectionProduction->SetIsHidden(true);

PowerConnectionConsumption = CreateDefaultSubobject<UFGPowerConnectionComponent>("PowerConnectionConsumption");
PowerConnectionConsumption->SetIsHidden(true);
}

void AFueledLampBase::BeginPlay() {
Super::BeginPlay();

if (HasAuthority()) {
PowerConnectionProduction->SetPowerInfo(GetPowerInfo());
PowerConnectionConsumption->SetPowerInfo(GetPowerInfo());
PowerConnectionConsumption->AddHiddenConnection(PowerConnectionProduction);
}
}

void AFueledLampBase::TickActor(float DeltaTime, ELevelTick TickType, FActorTickFunction& ThisTickFunction) {
Super::TickActor(DeltaTime, TickType, ThisTickFunction);

TArray<UActorComponent*> lights = GetComponentsByClass(ULightComponent::StaticClass());
bool bLampOn = HasPower() && !IsProductionPaused();
for (auto& light : lights) {
Cast<ULightComponent>(light)->SetVisibilitySML(bLampOn, true);
}
}

void AFueledLampBase::Factory_Tick(float dt) {
if (HasAuthority()) GetPowerInfo()->SetTargetConsumption(GetPendingPotential() * mPowerProduction / 4.1);
Super::Factory_Tick(dt);
}
30 changes: 30 additions & 0 deletions Source/LightItUp/FueledLampBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "CoreMinimal.h"
#include "FGBuildableGeneratorFuel.h"
#include "FGPowerConnectionComponent.h"
#include "FGPowerInfoComponent.h"
#include "FueledLampBase.generated.h"

UCLASS(Blueprintable)
class AFueledLampBase : public AFGBuildableGeneratorFuel {
GENERATED_BODY()

public:
UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Light")
UFGPowerConnectionComponent* PowerConnectionProduction;

UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Light")
UFGPowerConnectionComponent* PowerConnectionConsumption;

AFueledLampBase();

// Begin AActor
virtual void BeginPlay() override;
virtual void TickActor(float DeltaTime, ELevelTick TickType, FActorTickFunction& ThisTickFunction) override;
// End AActor

// Begin Buildable Interface
void Factory_Tick(float dt) override;
// End Buildable Interface
};
102 changes: 84 additions & 18 deletions Source/LightItUp/LampBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,44 @@
#include "FGTimeSubsystem.h"
#include "util/Logging.h"
#include "UnrealNetwork.h"
#include "FGPlayerController.h"
#include "Components/SceneComponent.h"

#define DefaultLampGroup TEXT("Default")

void ULampBaseRCO::SetGroup_Implementation(ALampBase* lamp, const FString& string) {
lamp->mGroup = string;
lamp->ForceNetUpdate();
}

bool ULampBaseRCO::SetGroup_Validate(ALampBase* lamp, const FString& group) {
return true;
}

void ULampBaseRCO::SetMode_Implementation(ALampBase* lamp, ELampMode mode) {
lamp->mMode = mode;
lamp->ForceNetUpdate();
}

bool ULampBaseRCO::SetMode_Validate(ALampBase* lamp, ELampMode mode) {
return true;
}

void ULampBaseRCO::SetUseGroup_Implementation(ALampBase* lamp, bool useGroup) {
lamp->mUseGroup = useGroup;
lamp->ForceNetUpdate();
}

bool ULampBaseRCO::SetUseGroup_Validate(ALampBase* lamp, bool useGroup) {
return true;
}

void ULampBaseRCO::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const {
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

DOREPLIFETIME(ULampBaseRCO, bTest)
}

bool ALampBase::shouldLampBeOn(ELampMode mode) {
switch (mode) {
case ON:
Expand All @@ -30,13 +64,15 @@ ALampBase::ALampBase() {
mFactoryTickFunction.bRunOnAnyThread = true;
mFactoryTickFunction.bAllowTickOnDedicatedServer = true;

mFactoryTickFunction.SetTickFunctionEnable(true);
if (HasAuthority()) mFactoryTickFunction.SetTickFunctionEnable(true);

PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bAllowTickOnDedicatedServer = true;
PrimaryActorTick.bStartWithTickEnabled = true;

PrimaryActorTick.SetTickFunctionEnable(true);

bReplicates = true;
}

void ALampBase::BeginPlay() {
Expand All @@ -46,42 +82,72 @@ void ALampBase::BeginPlay() {
}

void ALampBase::TickActor(float DeltaTime, ELevelTick TickType, FActorTickFunction & ThisTickFunction) {
if ((mLampOn != (bool)mLastLampOn) || mLastLampOn == 2) {
mLastLampOn = mLampOn;
if ((bLampOn != (mLastLampOn == 1)) || mLastLampOn == 2) {
mLastLampOn = bLampOn ? 1 : 0;
auto lights = GetComponentsByClass(ULightComponent::StaticClass());
for (auto& light : lights) {
Cast<USceneComponent>(light)->SetVisibilitySML(mLampOn);
Cast<USceneComponent>(light)->SetVisibilitySML(bLampOn);
}
auto meshes = GetComponentsByClass(UStaticMeshComponent::StaticClass());
for (auto mesh : meshes) {
Cast<UStaticMeshComponent>(mesh)->SetScalarParameterValueOnMaterials("LitUp", mLampOn ? mEmessiveStrength : 0.0f);
Cast<UStaticMeshComponent>(mesh)->SetScalarParameterValueOnMaterials("LitUp", bLampOn ? mEmessiveStrength : 0.0f);
}
}
Super::TickActor(DeltaTime, TickType, ThisTickFunction);
}

void ALampBase::Factory_Tick(float dt) {
ELampMode mode = mMode;
if (mUseGroup) {
bool worked = false;
auto gmode = lampSubSys->getGroup(mGroup, worked);
if (worked) mode = gmode;
else {
mode = mMode = OFF;
mGroup = DefaultLampGroup;
if (HasAuthority()) {
ELampMode mode = mMode;
if (mUseGroup) {
bool worked = false;
auto gmode = lampSubSys->getGroup(mGroup, worked);
if (worked) mode = gmode;
else {
mode = mMode = OFF;
mGroup = DefaultLampGroup;
}
}
auto shouldBeOn = shouldLampBeOn(mode);
mPowerInfo->SetTargetConsumption(shouldBeOn ? mPowerConsumption : 0.0f);
bool hasPower = mPowerInfo->HasPower();
if (hasPower != bLampOn) {
bLampOn = hasPower;
ForceNetUpdate();
}
}
auto shouldBeOn = shouldLampBeOn(mode);
mPowerInfo->SetTargetConsumption(shouldBeOn ? mPowerConsumption : 0.0f);
mLampOn = mPowerInfo->HasPower();
}

bool ALampBase::ShouldSave_Implementation() const {
return true;
}

void ALampBase::SetGroup(const FString& group) {
auto rco = Cast<ULampBaseRCO>(Cast<AFGPlayerController>(GetWorld()->GetFirstPlayerController())->GetRemoteCallObjectOfClass(ULampBaseRCO::StaticClass()));
if (rco) {
rco->SetGroup(this, group);
}
}

void ALampBase::SetMode(TEnumAsByte<ELampMode> mode) {
auto rco = Cast<ULampBaseRCO>(Cast<AFGPlayerController>(GetWorld()->GetFirstPlayerController())->GetRemoteCallObjectOfClass(ULampBaseRCO::StaticClass()));
if (rco) {
rco->SetMode(this, mode);
}
}

void ALampBase::SetUseGroup(bool useGroup) {
auto rco = Cast<ULampBaseRCO>(Cast<AFGPlayerController>(GetWorld()->GetFirstPlayerController())->GetRemoteCallObjectOfClass(ULampBaseRCO::StaticClass()));
if (rco) {
rco->SetUseGroup(this, useGroup);
}
}

void ALampBase::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const {
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

DOREPLIFETIME(ALampBase, mLampOn);
}
DOREPLIFETIME(ALampBase, bLampOn);
DOREPLIFETIME(ALampBase, mMode);
DOREPLIFETIME(ALampBase, mGroup);
DOREPLIFETIME(ALampBase, mUseGroup);
}
42 changes: 38 additions & 4 deletions Source/LightItUp/LampBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@

#define DefaultLampGroup TEXT("Default")

class ALampBase;

UCLASS()
class LIGHTITUP_API ULampBaseRCO : public UFGRemoteCallObject {
GENERATED_BODY()

private:
UPROPERTY(Replicated)
bool bTest;

public:
UFUNCTION(Server, WithValidation, Reliable)
void SetGroup(ALampBase* lamp, const FString& group);

UFUNCTION(Server, WithValidation, Reliable)
void SetMode(ALampBase* lamp, ELampMode mode);

UFUNCTION(Server, WithValidation, Reliable)
void SetUseGroup(ALampBase* lamp, bool useGroup);
};

/**
* The Base Class for normal lamp buildings consuming power
*/
Expand All @@ -32,13 +53,13 @@ class LIGHTITUP_API ALampBase : public AFGBuildable
UPROPERTY()
UFGPowerInfoComponent* mPowerInfo = nullptr;

UPROPERTY(BlueprintReadWrite, SaveGame, Category = "Light")
UPROPERTY(BlueprintReadWrite, Replicated, SaveGame, Category = "Light")
TEnumAsByte<ELampMode> mMode = OFF;

UPROPERTY(BlueprintReadWrite, SaveGame, Category = "Light")
UPROPERTY(BlueprintReadWrite, Replicated, SaveGame, Category = "Light")
FString mGroup = DefaultLampGroup;

UPROPERTY(BlueprintReadWrite, SaveGame, Category = "Light")
UPROPERTY(BlueprintReadWrite, Replicated, SaveGame, Category = "Light")
bool mUseGroup = false;

UPROPERTY(EditDefaultsOnly, Category = "Light")
Expand All @@ -48,10 +69,14 @@ class LIGHTITUP_API ALampBase : public AFGBuildable
float mEmessiveStrength = 1.0;

UPROPERTY(BlueprintReadOnly, Replicated, Category = "Light")
bool mLampOn = false;
bool bLampOn = false;

ALampBase();

// Begin UObject
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
// End UObject

// Begin Actor Interface
virtual void BeginPlay() override;
virtual void TickActor(float DeltaTime, ELevelTick TickType, FActorTickFunction& ThisTickFunction) override;
Expand All @@ -64,4 +89,13 @@ class LIGHTITUP_API ALampBase : public AFGBuildable
// Begin IFGSaveInterface
bool ShouldSave_Implementation() const override;
// End IFGSaveInterface

UFUNCTION(BlueprintCallable, Category = "Lamps")
void SetGroup(const FString& group);

UFUNCTION(BlueprintCallable, Category = "Lamps")
void SetMode(TEnumAsByte<ELampMode> mode);

UFUNCTION(BlueprintCallable, Category = "Lamps")
void SetUseGroup(bool useGroup);
};
Loading

0 comments on commit e33a1e8

Please sign in to comment.