Download presentation
Presentation is loading. Please wait.
Published byGrant Nichols Modified over 9 years ago
1
Network Replication Possibly the ugliest thing to learn this semester Many different states Simulated Functions Is it an Event or function? Roles
2
More Architecture Unreal is made of Objects. The Game Level is an Object Actor is an Object capable of moving and interacting within the Level Object The Level is filled with Actors
3
The Server This is the source of all the gameplay, and the server is responsible for ticking the game. –A tick is the games clock –The tick is not fixed and scalable, to allow the game to run at a variable Frame Rate In a single player game the server is the machine you play on
4
Clients Maintain as closely as possible a proper representation of what is happening on the server
5
The Game Loop The Server sends the current state of play to all clients Clients send their requested movements and actions to the server, and receive the new game state information from the server The server then performs a tick operation updating the game state
6
During the Tick operation –Variables and Actors can be modified –Actors can be created or destroyed In games of old, like Doom each client ran a copy of the game world, and sent their actions to every other client. (A P2P network) The complexities of Unreal Negate this approach –Thankyou Physics!
7
The problem The bandwidth needed to update the entire game state on client machines would be incredible. (Approx 300kb/s for standard deathmatch levels of the original Unreal Tournament)
8
The Solution Doesn’t exist….. The Network code in Unreal is intended to give the clients a reasonable approximation of the game state.
9
Relevant Actors Unreal minimises the Actors which it updates for clients, to only those deemed relevant Pretty much any actor the player can see, or has seen recently, as well as any actors with static=true or bNoDelete=true See the references if you want the full details on relevance.
10
Further Prioritising Every Actor has a variable called NetPriority –Relative Ratios Default of Actor is 1.0 Inventory / Pickups 1.4 Players / Vehicles 3.0 Replication can be divided into 3 parts –Actors –Variables –Function Calls
11
Your Responsibility The game engine does not keep track of what actors are relevant to who This is your job. –Any Objects / Variables you create How? –The Replication Statement
12
Do you need one for every class? No Only when your Class defines new variables or functions which need to be replicated In UT only about 10 of the 500 classes needed replication statements In ut2004 there are roughly 140 replication statements
13
Stolen from RocketLauncher.uc replication { reliable if (Role == ROLE_Authority && bNetOwner) bLockedOn; reliable if (Role < ROLE_Authority) ServerSetTightSpread, ServerClearTightSpread; }
14
replication { // Variables the server should send to the client. reliable if( Role==ROLE_Authority ) Weapon; reliable if( Role==ROLE_Authority && bNetOwner ) PlayerName, Team, TeamName, bIsPlayer, CarriedDecoration, SelectedItem, GroundSpeed, WaterSpeed, AirSpeed, AccelRate, JumpZ, MaxStepHeight, bBehindView; unreliable if( Role==ROLE_Authority && bNetOwner && bIsPlayer && bNetInitial ) ViewRotation; unreliable if( Role==ROLE_Authority && bNetOwner ) Health, MoveTarget, Score; // Functions the server calls on the client side. reliable if( Role==ROLE_Authority && RemoteRole==ROLE_AutonomousProxy ) ClientDying, ClientReStart, ClientGameEnded, ClientSetRotation; unreliable if( Role==ROLE_Authority ) ClientHearSound, ClientMessage; reliable if( Role<ROLE_Authority ) NextItem, SwitchToBestWeapon, bExtra0, bExtra1, bExtra2, bExtra3; // Input sent from the client to the server. unreliable if( Role<ROLE_AutonomousProxy ) bZoom, bRun, bLook, bDuck, bSnapLevel, bStrafe; unreliable always if( Role<=ROLE_AutonomousProxy ) bFire, bAltFire; }
15
Reliable and Unreliable Unreliable Packets may –Disappear –Arrive out of order Reliable Packets will eventually be received The amount of packets lost varies, and an estimate is between 1% and 10% of all unreliable packets could be lost
16
Replication Conditions Firstly the roles each Class may have –ROLE_None –ROLE_DumbProxy –ROLE_SimulatedProxy –ROLE_AutonomousProxy –ROLE_Authority Checks can also be done using boolean checks –EG: if (Role < Role_Authority)
17
Simulated Functions For proxy Actors only functions marked simulated will execute on the client machines Actors like Weapon.uc and Vehicle.uc rely heavily on simulated functions
18
AutonomousProxy Aka The player This code is written in UnrealScript (As of up to UT2004) Uses an error / correction approach
19
Network management GameInfo – Runs the game from the server –InitGame This function recieves the startup command line –PreLogin Called on the server before a player is allowed to log in to the game –Login This is where the player will be spawned within the game Called after players download content, so rejecting players now is rude!
20
Optimisation The game already runs on the server fine The Network optimisation goal is to make the clients view of the game world as realistic as possible to the player Vectors get rounded!!! –Converted to 16bit ints for data stream –Bypass this by passing 3x Floats IF you need the accuracy
21
Network capabilities of UT You have both TCP and UDP class access built in to UT Get Excited, it will allow you to interface with the real world! (Well any software you like)
22
References http://unreal.epicgames.com/Network.htm
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.