Spaces:
Running
Running
Download native/unreal/Source/Singularity/SingularityRolePlayerController.cpp from sankalphs/singularity1: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/sankalphs/singularity1/resolve/main/native/unreal/Source/Singularity/SingularityRolePlayerController.cpp
- Command line
-
hf download hf://spaces/sankalphs/singularity1/native/unreal/Source/Singularity/SingularityRolePlayerController.cpp
-
curl -L -o SingularityRolePlayerController.cpp https://huggingface.co/spaces/sankalphs/singularity1/resolve/main/native/unreal/Source/Singularity/SingularityRolePlayerController.cpp
2.21 kB
| ASingularityRolePlayerController::ASingularityRolePlayerController() | |
| { | |
| PrimaryActorTick.bCanEverTick = true; | |
| } | |
| void ASingularityRolePlayerController::BeginPlay() | |
| { | |
| Super::BeginPlay(); | |
| if (const ASingularityGameMode* Mode = GetWorld()->GetAuthGameMode<ASingularityGameMode>()) | |
| { | |
| SpacetimeBridge = Mode->SpacetimeBridge; | |
| } | |
| if (!SpacetimeBridge) | |
| { | |
| // Clients do not own an authoritative GameMode, so they get a local | |
| // bridge instance that their transport adapter can bind to. | |
| SpacetimeBridge = NewObject<USingularitySpacetimeBridge>(this); | |
| } | |
| } | |
| void ASingularityRolePlayerController::SetupInputComponent() | |
| { | |
| Super::SetupInputComponent(); | |
| check(InputComponent); | |
| InputComponent->BindAxis(TEXT("Singularity_MoveX"), this, &ASingularityRolePlayerController::HandleMoveX); | |
| InputComponent->BindAxis(TEXT("Singularity_MoveZ"), this, &ASingularityRolePlayerController::HandleMoveZ); | |
| InputComponent->BindAction(TEXT("Singularity_Action"), IE_Pressed, this, &ASingularityRolePlayerController::HandleActionPressed); | |
| InputComponent->BindAction(TEXT("Singularity_Action"), IE_Released, this, &ASingularityRolePlayerController::HandleActionReleased); | |
| } | |
| void ASingularityRolePlayerController::Tick(float DeltaSeconds) | |
| { | |
| Super::Tick(DeltaSeconds); | |
| if (!IsLocalController()) return; | |
| SendAccumulator += DeltaSeconds; | |
| if (SpacetimeBridge && SendAccumulator >= (1.0f / 30.0f)) | |
| { | |
| SendAccumulator = 0.0f; | |
| ++ClientTick; | |
| SpacetimeBridge->SubmitRoleInput(ControlledRole, MoveX, MoveZ, bAction, ClientTick); | |
| } | |
| } | |
| void ASingularityRolePlayerController::HandleMoveX(float Value) | |
| { | |
| MoveX = FMath::Clamp(Value, -1.0f, 1.0f); | |
| } | |
| void ASingularityRolePlayerController::HandleMoveZ(float Value) | |
| { | |
| MoveZ = FMath::Clamp(Value, -1.0f, 1.0f); | |
| } | |
| void ASingularityRolePlayerController::HandleActionPressed() | |
| { | |
| bAction = true; | |
| } | |
| void ASingularityRolePlayerController::HandleActionReleased() | |
| { | |
| bAction = false; | |
| } | |