Player Controller
The ARTSPlayerController class is the main representation for the actual player during a game.
It handles player input, sets up the HUD class, etc.
Player controller also has importance regarding multiplayer setup, since it can perform server RPCs from clients. Remember that player controllers only exist in the server and the owning client, it is not replicated to all clients. Therefore, any logic or data representing a player that needs to be known to other clients should live in the player handle (or substitute for player state). For example, resources are handled by the player handle because we might want to see or interact with other player's resources (for example when transferring resources to an ally).
TODO: Add warning about legacy code in this class
Some relevant pieces of logic contained in the player controller:
Spawning the Niagara visualisation helpers
This actors and components handle Niagara visualisation for unit healthbars, fog of war and minimap compute shaders, rendering selected decals, projectiles, and visualisation lines for order queues (when pressing shift while having units selected).
GetWorld()->SpawnActor<ARTSNiagaraRenderActor>(BoidSettings->NiagaraActorClass)->SetActorLocation({0, 0, -1000});
GetWorld()->SpawnActor<ARTSNiagaraDecalRenderActor>(BoidSettings->NiagaraDecalActorClass)->SetActorLocation({0, 0, -1000});
GetWorld()->SpawnActor<ARTSNiagaraProjectileRenderActor>(BoidSettings->NiagaraProjectileActorClass)->SetActorLocation({0, 0, -1000});
auto GeneralSettings = GetDefault<URTSGeneralSettings>();
UINiagaraActor = Cast<ARTSUINiagaraRenderActor>(GetWorld()->SpawnActor(GeneralSettings->UINiagaraActor));
Entry point to get UI data
See function ARTSPlayerController::GetDataForUISlot(ERTSUISelectableSlotsEnum Slot, uint8 Page, AActor* SourceActor)
Input setup
We migrated all our mouse/keyboard inputs to Unreal's new Enhanced input system. The input actions are defined in Blueprints, and
assigned to logic functions in the player controller. See function ARTSPlayerController::SetupInputComponent() for a complete list of inputs and functions.
Mouse clicking and dragging
All functionality related to mouse clicks on the map, selecting units etc is performed on the player controller. TODO: Expand or write specific section
Control group management
Functions to create control groups, select them, add/remove units, and focus camera on a specific control group.
Building placement logic
Should probably be refactored to builders or other classes, complex setup currently.
Wall setup (deprecated)
Old code to build walls. Should be moved to a separate component and updated with all new entity logic. Low priority.