Skip to content

Latest commit

 

History

History
189 lines (148 loc) · 3.15 KB

File metadata and controls

189 lines (148 loc) · 3.15 KB

Programmation réseau dans les jeux vidéo 2

Components

AGameMode
    Règles de jeu
    Server only # client return null
    e.g. N players
AGameState
    Données de la game
    Autorité serveur
    Repliqué client
    e.g. team score
APlayerState
    Données d'un player
    Autorité serveur
    Repliqué clients
    e.g. K/D
APlayerController
    Contrôle un player
    Autorité serveur
    Repliqué sur le owning client
    e.g. Life
APawn / ACharacter
    Représentation Player
    Autorité serveur
    Repliqué aux clients
    e.g. Mesh
AHud

Structure

  • Dedicate server
  • Listen server 服务器为客户之一

RPC Remote Procedure Call 回调

  • Server
    • Owning Client -> Server
    • Server / Drop
  • Client
    • Server -> Owning Client
    • Owning Client / Server
  • Multicast
    • Server -> All Clients
    • Server + Clients

Reliability

  • Reliable
  • Unreliable

Validation

if the parameters are correct. anti-cheat. etc.

Replication

Varaibles classes herite d'Actor

Type Variable : NetSerializable

UPROPERTY(Replicated) // 服务器修改自动扩散
GetLifetimeReplicatedProps // 应当被重载(?)
bReplicates = true;
OnRepNotify() {} // 修改后自动执行
UPROPERTY(ReplicatedUsing = FUNCTION) // Don't execute on server

Ownership

Server own TOUT, sauf :

  • Pawn
  • PlayerController
Actor
    Collider
Component
Line Sweep
Interface
Customisation BP

Plugin

Add C++ plugin. Plngin should be put in a git, then there is a plugin insert it into Unreal.

InteractFramework

File named *.Build.cs can add dependencies:

PublicDependcyModuleNames.AddRange(
    new String[] {
        "Core",
        "AIModule",
        // dependcies
    }
);
class SomeClass: public OtherClass
{
    void SomeClass::StartupModule() {}
    void SomeClass::ShutdownModule() {}
    // 不要乱动……
}
UINTERFACE()
class UIFInterface: public UInterface {
    GENERATED_BODY()
}; // no touche pas

class INTERACTFRAMEWORK_API IIFInteractable : public AActor : public Interactable
{
    GENERATED_BODY()
    public:
    virtual void Interact(AActor* Interactor) = 0;
    
    UPROPERTY(EditAnywhere, Blueprintxxx)
    class Trigger* XXX;
}

AIFInteractibleActor::AIFInteractibleActor() {
    PrimaryActorTick.bCanEverTick = false;
    
    Trigger = CreateDefaultSubobject<USphereComponent>(TEXT("Trigger"));
    RootComponent = Trigger;
    Trigger->SetCollisionProfileName(TEXT("Trigger"));
    Trigger->SetGenerateOverlapEvents(true);
}

void AIFInteractiableActor::BeginPlay() {
    Super::BeginPlay();
    Trigger->OnComponenetOverlap.AddDynamic(this, ...)
}

void AIFInteractiableActor::HandleOverlapEvent(...) {
    if (OtherActor == nullptr) return;
    auto* xxx = Cast<UIFInteractiableActor>(Src::OtherActor->SetComponent...);
}
UFUNCTION(Blueprintxxx) // create an event in blueprint
BP_Interact(Interactor);
void UIFInteractorComponent::Interact()
{
    if (!GetOwner()->HasAuthority()) {
        Server_Interact();
        return;
    }
    XXX();
}