Optimize gamemode and gamestate code
This commit is contained in:
parent
c35cf74b49
commit
8e1c017515
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -17,8 +17,9 @@ public class Luckyrobots : ModuleRules
|
|||||||
"LuckyMujoco",
|
"LuckyMujoco",
|
||||||
"LuckyTextWrite",
|
"LuckyTextWrite",
|
||||||
"SocketIOClient",
|
"SocketIOClient",
|
||||||
"VaRest"
|
"VaRest",
|
||||||
});
|
"SIOJson"
|
||||||
|
});
|
||||||
|
|
||||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||||
|
|
||||||
|
@ -2,4 +2,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "LobbyGameMode.h"
|
#include "LobbyGameMode.h"
|
||||||
|
#include "LuckyRobotsFunctionLibrary.h"
|
||||||
|
|
||||||
|
void ALobbyGameMode::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
ULuckyRobotsFunctionLibrary::UpdateQualitySettings(this);
|
||||||
|
}
|
@ -3,11 +3,17 @@
|
|||||||
|
|
||||||
#include "LuckyRobotsFunctionLibrary.h"
|
#include "LuckyRobotsFunctionLibrary.h"
|
||||||
#include "LuckyRobotsGameInstance.h"
|
#include "LuckyRobotsGameInstance.h"
|
||||||
|
#include "GameFramework/GameUserSettings.h"
|
||||||
|
|
||||||
|
ULuckyRobotsGameInstance* ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(const UObject* WorldContextObject)
|
||||||
|
{
|
||||||
|
return Cast<ULuckyRobotsGameInstance>(WorldContextObject->GetWorld()->GetGameInstance());
|
||||||
|
}
|
||||||
|
|
||||||
TArray<FRobotData> ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(const UObject* WorldContextObject)
|
TArray<FRobotData> ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(const UObject* WorldContextObject)
|
||||||
{
|
{
|
||||||
TArray<FRobotData> RobotDataList;
|
TArray<FRobotData> RobotDataList;
|
||||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(WorldContextObject->GetWorld()->GetGameInstance());
|
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject);
|
||||||
if (LuckyRobotsGameInstance)
|
if (LuckyRobotsGameInstance)
|
||||||
{
|
{
|
||||||
if (LuckyRobotsGameInstance->RobotDataDataTable)
|
if (LuckyRobotsGameInstance->RobotDataDataTable)
|
||||||
@ -33,7 +39,7 @@ TArray<FRobotData> ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(const UOb
|
|||||||
TArray<FLevelData> ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(const UObject* WorldContextObject)
|
TArray<FLevelData> ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(const UObject* WorldContextObject)
|
||||||
{
|
{
|
||||||
TArray<FLevelData> LevelDataList;
|
TArray<FLevelData> LevelDataList;
|
||||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(WorldContextObject->GetWorld()->GetGameInstance());
|
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject);
|
||||||
if (LuckyRobotsGameInstance)
|
if (LuckyRobotsGameInstance)
|
||||||
{
|
{
|
||||||
if (LuckyRobotsGameInstance->LevelDataTable)
|
if (LuckyRobotsGameInstance->LevelDataTable)
|
||||||
@ -54,4 +60,20 @@ TArray<FLevelData> ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(const UOb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return LevelDataList;
|
return LevelDataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ULuckyRobotsFunctionLibrary::UpdateQualitySettings(const UObject* WorldContextObject)
|
||||||
|
{
|
||||||
|
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject);
|
||||||
|
if (LuckyRobotsGameInstance)
|
||||||
|
{
|
||||||
|
// Load game user settings and apply
|
||||||
|
UGameUserSettings* GameUserSettings = GEngine->GetGameUserSettings();
|
||||||
|
if (GameUserSettings)
|
||||||
|
{
|
||||||
|
GameUserSettings->SetOverallScalabilityLevel(int(LuckyRobotsGameInstance->CurrentSelectQuality));
|
||||||
|
GameUserSettings->SaveSettings();
|
||||||
|
GameUserSettings->ApplySettings(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,6 +5,13 @@
|
|||||||
#include "LuckyRobotsGameInstance.h"
|
#include "LuckyRobotsGameInstance.h"
|
||||||
#include "LuckyRobotsFunctionLibrary.h"
|
#include "LuckyRobotsFunctionLibrary.h"
|
||||||
|
|
||||||
|
void ALuckyRobotsGameMode::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
ULuckyRobotsFunctionLibrary::UpdateQualitySettings(this);
|
||||||
|
}
|
||||||
|
|
||||||
UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AController* InController)
|
UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AController* InController)
|
||||||
{
|
{
|
||||||
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
|
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
|
||||||
@ -29,4 +36,5 @@ UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AC
|
|||||||
}
|
}
|
||||||
|
|
||||||
return RobotClass;
|
return RobotClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,4 +2,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "LuckyRobotsGameState.h"
|
#include "LuckyRobotsGameState.h"
|
||||||
|
#include "SocketIOClientComponent.h"
|
||||||
|
#include "LuckyRobotsFunctionLibrary.h"
|
||||||
|
#include "LuckyRobotsGameInstance.h"
|
||||||
|
|
||||||
|
ALuckyRobotsGameState::ALuckyRobotsGameState()
|
||||||
|
{
|
||||||
|
SocketIOClientComponent = CreateDefaultSubobject<USocketIOClientComponent>(TEXT("SocketIOClientComponent"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ALuckyRobotsGameState::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
if (SocketIOClientComponent)
|
||||||
|
{
|
||||||
|
SocketIOClientComponent->Connect(L"http://localhost:3000/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ALuckyRobotsGameState::DoSendMessage(FString SendValue)
|
||||||
|
{
|
||||||
|
if (SocketIOClientComponent)
|
||||||
|
{
|
||||||
|
if (SocketIOClientComponent->bIsConnected)
|
||||||
|
{
|
||||||
|
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
|
||||||
|
SocketIOClientComponent->Emit("message", SIOJsonValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ALuckyRobotsGameState::DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection)
|
||||||
|
{
|
||||||
|
if (SocketIOClientComponent)
|
||||||
|
{
|
||||||
|
if (SocketIOClientComponent->bIsConnected)
|
||||||
|
{
|
||||||
|
SocketIOClientComponent->BindEventToGenericEvent("response");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData)
|
||||||
|
{
|
||||||
|
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
|
||||||
|
if (LuckyRobotsGameInstance)
|
||||||
|
{
|
||||||
|
LuckyRobotsGameInstance->DoGetDispatch(EventName, EventData);
|
||||||
|
}
|
||||||
|
}
|
@ -104,7 +104,7 @@ void UMainScreenUserWidget::SelectNextQuality()
|
|||||||
{
|
{
|
||||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||||
int QualityEnumNum = QualityEnum->NumEnums() - 1;
|
int QualityEnumNum = QualityEnum->NumEnums() - 1;
|
||||||
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality + 1, 0, QualityEnumNum - 1);
|
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality - 1, 0, QualityEnumNum - 1);
|
||||||
|
|
||||||
UpdateSelectQuality();
|
UpdateSelectQuality();
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ void UMainScreenUserWidget::SelectPreviousQuality()
|
|||||||
{
|
{
|
||||||
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
|
||||||
int QualityEnumNum = QualityEnum->NumEnums() - 1;
|
int QualityEnumNum = QualityEnum->NumEnums() - 1;
|
||||||
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality - 1, 0, QualityEnumNum - 1);
|
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality + 1, 0, QualityEnumNum - 1);
|
||||||
|
|
||||||
UpdateSelectQuality();
|
UpdateSelectQuality();
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@ UCLASS()
|
|||||||
class LUCKYROBOTS_API ALobbyGameMode : public AGameModeBase
|
class LUCKYROBOTS_API ALobbyGameMode : public AGameModeBase
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "SharedDef.h"
|
#include "SharedDef.h"
|
||||||
#include "LuckyRobotsFunctionLibrary.generated.h"
|
#include "LuckyRobotsFunctionLibrary.generated.h"
|
||||||
|
|
||||||
|
class ULuckyRobotsGameInstance;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -15,9 +16,15 @@ class LUCKYROBOTS_API ULuckyRobotsFunctionLibrary : public UBlueprintFunctionLib
|
|||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
public:
|
||||||
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
|
||||||
|
static ULuckyRobotsGameInstance* GetLuckyRobotsGameInstance(const UObject* WorldContextObject);
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
|
||||||
static TArray<FRobotData> GetActiveRobotDataList(const UObject* WorldContextObject);
|
static TArray<FRobotData> GetActiveRobotDataList(const UObject* WorldContextObject);
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
|
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
|
||||||
static TArray<FLevelData> GetActiveLevelDataList(const UObject* WorldContextObject);
|
static TArray<FLevelData> GetActiveLevelDataList(const UObject* WorldContextObject);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"))
|
||||||
|
static void UpdateQualitySettings(const UObject* WorldContextObject);
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "SharedDef.h"
|
#include "SharedDef.h"
|
||||||
#include "LuckyRobotsGameInstance.generated.h"
|
#include "LuckyRobotsGameInstance.generated.h"
|
||||||
|
|
||||||
|
class USIOJsonValue;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -24,13 +25,15 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
ERobotsName CurrentSelectRobot;
|
ERobotsName CurrentSelectRobot = ERobotsName::None;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
ELevelEnum CurrentSelectLevel;
|
ELevelEnum CurrentSelectLevel = ELevelEnum::None;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
EQualityEnum CurrentSelectQuality;
|
EQualityEnum CurrentSelectQuality = EQualityEnum::Epic;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFUNCTION(BlueprintImplementableEvent)
|
||||||
|
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,9 @@ UCLASS()
|
|||||||
class LUCKYROBOTS_API ALuckyRobotsGameMode : public AGameModeBase
|
class LUCKYROBOTS_API ALuckyRobotsGameMode : public AGameModeBase
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
virtual UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;
|
virtual UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "GameFramework/GameStateBase.h"
|
#include "GameFramework/GameStateBase.h"
|
||||||
#include "LuckyRobotsGameState.generated.h"
|
#include "LuckyRobotsGameState.generated.h"
|
||||||
|
|
||||||
|
class USocketIOClientComponent;
|
||||||
|
class USIOJsonValue;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -13,5 +15,21 @@ UCLASS()
|
|||||||
class LUCKYROBOTS_API ALuckyRobotsGameState : public AGameStateBase
|
class LUCKYROBOTS_API ALuckyRobotsGameState : public AGameStateBase
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
protected:
|
||||||
|
ALuckyRobotsGameState();
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(Category = Character, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
|
||||||
|
USocketIOClientComponent* SocketIOClientComponent;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void DoSendMessage(FString SendValue);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData);
|
||||||
};
|
};
|
||||||
|
@ -64,10 +64,18 @@ enum class ELevelEnum : uint8
|
|||||||
UENUM(BlueprintType)
|
UENUM(BlueprintType)
|
||||||
enum class EQualityEnum : uint8
|
enum class EQualityEnum : uint8
|
||||||
{
|
{
|
||||||
Epic UMETA(DisplayName = "Epic"),
|
Low UMETA(DisplayName = "Low"),
|
||||||
High UMETA(DisplayName = "High"),
|
|
||||||
Middle UMETA(DisplayName = "Middle"),
|
Middle UMETA(DisplayName = "Middle"),
|
||||||
Low UMETA(DisplayName = "Low")
|
High UMETA(DisplayName = "High"),
|
||||||
|
Epic UMETA(DisplayName = "Epic")
|
||||||
|
};
|
||||||
|
|
||||||
|
UENUM(BlueprintType)
|
||||||
|
enum class EGoalType : uint8
|
||||||
|
{
|
||||||
|
GrabAndPull UMETA(DisplayName = "Grab and Pull"),
|
||||||
|
GrabAndRotate UMETA(DisplayName = "Grab and Rotate"),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
USTRUCT(BlueprintType)
|
USTRUCT(BlueprintType)
|
||||||
@ -123,4 +131,92 @@ public:
|
|||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TArray<ERobotsCategories> RobotTypeList;
|
TArray<ERobotsCategories> RobotTypeList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FGoalsTaskData : public FTableRowBase
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
EGoalType GoalType;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bIsStart;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FTransform TargetLocation;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
AActor* TargetActor;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bIsComplate;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FVector DropOffLocation;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FString ObjectName;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bActive;
|
||||||
|
};
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FCaptureSettingsData : public FTableRowBase
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText FolderName;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText FileName;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText WritesPerSec;
|
||||||
|
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool IsScenario;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<FGoalsTaskData> TaskList;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bLight;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bMaterials;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bRobotPosition;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bPets;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText NumberOfPets;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bPeople;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText NumberOfPeople;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bObjects;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText NumberOfObjects;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<UStaticMeshComponent*> RandomMeshes;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
bool bInfiniteCapture;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FText NumberOfCaptures;
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user