User Tools

Site Tools


global:netcode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
global:netcode [2018/08/28 00:55]
Mistermind [UFE 2.0 Netcode]
global:netcode [2024/01/07 06:17] (current)
Mistermind
Line 2: Line 2:
  
 **UFE Netcode** is the second iteration of the network system for UFE. It allows the game to run online matches in a smooth lag-free environment thanks to its native //rollback mechanics// and //deterministic physics//. The netcode also uses raw //manual tracking// to its own core variables, optimizing CPU usage (even mobiles).\\ **UFE Netcode** is the second iteration of the network system for UFE. It allows the game to run online matches in a smooth lag-free environment thanks to its native //rollback mechanics// and //deterministic physics//. The netcode also uses raw //manual tracking// to its own core variables, optimizing CPU usage (even mobiles).\\
-The new network options also comes with its own client/server structure (using Photon Network, UNet, Steam among others) allowing direct player connection without the use of IP.+The new network options also comes with its own client/server structure (powered by Photon Network) allowing direct player connection without the use of IP.
  
-[[http://www.ufe3d.com/demo/ufe2/pc/UFE2.zip|PC]] | [[http://www.ufe3d.com/demo/ufe2/webgl/|WebGL]] | [[http://www.ufe3d.com/demo/ufe2/android/UFE2.apk|Android]] 
  
-  * Hit Online to search for a match (US Server) +The new Rollback netcode is available on [[https://assetstore.unity.com/packages/templates/systems/ufe-2-pro-125472|UFE 2 PRO]] and [[https://assetstore.unity.com/packages/templates/systems/ufe-2-source-126124|UFE 2 Source]]. For more information [[https://forum.unity.com/threads/universal-fighting-engine-2.541442/|click here]].
-  * All builds are **cross-platform**+
  
  
Line 16: Line 14:
   * **What is Rollback?**   * **What is Rollback?**
 Rollback (name might change depending on game or developer) is a technique in which a game is able to return to a previous frame, change the outcome of an event (say, an input), and return to the current frame, all in a span of a single frame of animation. This allows a game to //catch up// with whatever concurrent event instead of [[global:network|waiting]] for both clients to sync up. When done right this can create an experience nearly identical to local play.\\ Rollback (name might change depending on game or developer) is a technique in which a game is able to return to a previous frame, change the outcome of an event (say, an input), and return to the current frame, all in a span of a single frame of animation. This allows a game to //catch up// with whatever concurrent event instead of [[global:network|waiting]] for both clients to sync up. When done right this can create an experience nearly identical to local play.\\
-The subject can be extensive and have been topic of several games for years (often referred as [[https://en.wikipedia.org/wiki/GGPO|GGPO]]). You can read more about it on this great article by //@mauvecow//[[http://mauve.mizuumi.net/2012/07/05/understanding-fighting-game-networking/]]+The subject can be extensive and have been topic of several games for years (often referred as [[https://en.wikipedia.org/wiki/GGPO|GGPO]]). If you'd like to know more about the subject, there is a great video from Core-A Gaming on youtubehttps://www.youtube.com/watch?v=0NLe4IpdS1w
  
   * **If Rollback is so good, why use Frame Delay at all?**   * **If Rollback is so good, why use Frame Delay at all?**
Line 30: Line 28:
  
 {{ :global:netcode_upgrade.jpg?direct&100|}} {{ :global:netcode_upgrade.jpg?direct&100|}}
-One of the key changes made to the code is the use of ''Fixed Point'' (Fix64), a format that replaces all uses of //float// throughout the code. This update copies all serialized Floats and Vectors to a new similar declaration.\\ +One of the key changes made to the code is the use of ''Fixed Point'' (Fix64), a format that replaces all uses of //float// throughout the code. If you are running UFE 1.x and wish to update your files without having to redo them, use this system to update all serialized Floats and Vectors to a new declaration.\\ 
-To run the auto update, right click on one of your UFE files ([[global:introduction|Global]] , [[character:introduction|Character]] or [[move:introduction|Move]]) from the project tab and select "UFE -> Upgrade to 2.0". This will automatically assign all the new variables (including nested files).\\+To run the auto update, right click on one of your UFE files ([[global:introduction|Global]] , [[character:introduction|Character]] or [[move:introduction|Move]]) from the project tab and select "UFE 2.0 -> Update All Definitions". This will automatically assign all the new variables (including nested files).\\
 \\ \\
  
-  * **Step 2: Record Character Maps**+  * **Step 2: Record Character Maps (PRO/Source)**
 Now that we have our asset files converted to //Fix64// we can move to the next step to ensure synchronization: Map the character animations. This is a fairly simple process, but can be a bit time consuming depending on how many characters you have or how often you change your animation files.\\ Now that we have our asset files converted to //Fix64// we can move to the next step to ensure synchronization: Map the character animations. This is a fairly simple process, but can be a bit time consuming depending on how many characters you have or how often you change your animation files.\\
 First, open the scene ''Scenes\MapRecorder.unity'' and under the hierarchy click on the Main Camera. Notice the script attached to it: Animation Recorder.  First, open the scene ''Scenes\MapRecorder.unity'' and under the hierarchy click on the Main Camera. Notice the script attached to it: Animation Recorder. 
Line 52: Line 50:
 \\ \\
  
-  * **Step 4: Photon Setup**+  * **Step 4: Photon Setup (Standard/PRO/Source)**
 In order to have the client-server accessibility you need to download [[https://assetstore.unity.com/packages/tools/network/photon-unity-networking-free-1786|Photon Unity Networking]] and create your own Photon Account. Sign up for free: [[https://www.photonengine.com/en/PUN]]\\ In order to have the client-server accessibility you need to download [[https://assetstore.unity.com/packages/tools/network/photon-unity-networking-free-1786|Photon Unity Networking]] and create your own Photon Account. Sign up for free: [[https://www.photonengine.com/en/PUN]]\\
 Once you have an account go your Public Cloud -> Applications and copy your App ID as displayed here: Once you have an account go your Public Cloud -> Applications and copy your App ID as displayed here:
Line 76: Line 74:
 To solve this, Map Recorder runs and stores the //position maps// (and delta displacements) of all identified hitbox on every frame of animation throughout the character's moveset, saving them in //Fix64// format (deterministic). UFE Engine will then play these maps synchronously to the animation during gameplay.\\ To solve this, Map Recorder runs and stores the //position maps// (and delta displacements) of all identified hitbox on every frame of animation throughout the character's moveset, saving them in //Fix64// format (deterministic). UFE Engine will then play these maps synchronously to the animation during gameplay.\\
 \\ \\
-Map Recorder is located at ''UFE\Scenes\MapRecorder.unity''. Run it whenever you have to add new moves or change one of the character's animation files.+Map Recorder is located at ''UFE\Engine\MapRecorder.unity''. Run it whenever you have to add new moves or change one of the character's animation files.
  
  
Line 136: Line 134:
  [RecordVar] public bool isBroken;  [RecordVar] public bool isBroken;
  
- void UFEFixedUpdate() {+ public override void UFEFixedUpdate() {
  if (position.y > .1f) BreakMe();  if (position.y > .1f) BreakMe();
  }  }
Line 149: Line 147:
 </code> </code>
  
-Notice we only use the //[RecordVar]// attribute to track the variables that can change during gameplay. Weight doesn't need to be tracked because it's assumed that value is persistent.\\+Notice we only use the //[RecordVar]// attribute to track the variables that can change during gameplay. Weight doesn't need to be tracked because it's assumed that value is persistent. //[RecordVar]// variables must be public.\\
 Also, notice we are using //UFEFixedUpdate// instead of //FixedUpdate// and //UFEBehaviour// instead of //MonoBehaviour//. This is so we can have those events deterministic.\\ Also, notice we are using //UFEFixedUpdate// instead of //FixedUpdate// and //UFEBehaviour// instead of //MonoBehaviour//. This is so we can have those events deterministic.\\
 An example of the auto-tracking system can be found under the projectile script: ''UFE\Scripts\ProjectileScripts.cs'' An example of the auto-tracking system can be found under the projectile script: ''UFE\Scripts\ProjectileScripts.cs''
Line 167: Line 165:
 ---- ----
 ===== Network 2.0 Options ===== ===== Network 2.0 Options =====
 +For a detailed explanation on each option [[global:network|click here]].
  
-{{ :global:global_netcode.png?nolink |}} +{{ :global:global_networkoptions.png |}}
  
 ---- ----
-==== Online Service ==== +====== Video Tutorials ====== 
- +{{youtube>OSovR17apP0?large}} 
-**Network Service:** Choose which online server to use. If you use Unity you must have a [[http://developer.cloud.unity3d.com|Developer Profile]] with access to Multiplayer. You must then connect your Unity to your profile via ''Window -> Services''+{{youtube>-dmVAf_cyN8?large}} 
- +{{youtube>j3B-lhd8JBw?large}}
-**Photon Service: ** (Photon Only) Choose which cloud service to be used in conjunction with Photon (Photon Server, Photon Cloud, Playfab) +
- +
-**Photon Application ID:** (Photon Only) The application ID provided by Photon (read **Step 4** above for more info) +
- +
- +
----- +
-==== LAN Games ==== +
- +
-**Network Port:** Set which Network port should the game use to connect between the clients in the local network. If you are testing your game using ''Play Mode'' under Unity, make sure your router and/or firewall are not blocking the port used. +
- +
-**Lan Discovery Port:** The port used in the network to search for games. +
- +
-**Lan Discovery Broadcast Interval:** The interval for the host to broadcast its signal. +
- +
-**Lan Discovery Search Interval:** The interval for the broadcast of witch the game searches for hosts. +
- +
-**Lan Discovery Search Timeout:** How long before it stops searching. +
- +
- +
----- +
-==== Animation Control ==== +
- +
-**Fake Network:** Toggle to run local network packaging tests. It forces local PvP matches to emulate a network game. Useful to test the Netcode without running 2 clients. +
- +
-**Force UFE Animation Control:** UFE Netcode works by forcing a full synchronization between 2 clients. To ensure there are no desyncs, toggle this option to make it so the UFE Engine is always in charge of the [[character:movesets|animation control]] during online matches regardless of your offline options. +
- +
-**Disable Blending:** Override all animation blending states to be 0. Using this feature helps you "mask" the times there is a rollback as it needs to refresh the animation component. +
- +
-**Disable Rotation Blend:** (Mecanim only) Override the blending done during rotation to 0. +
- +
- +
----- +
-==== Package Options ==== +
- +
-**Network Message Size:** How big should the package be. If your game only uses 4 buttons, use 8 bits. Use 16 bits for more than 4, and 32 bits if you plan to use more than 12 buttons or if you need to send different data through the same broadcast system (such as debug logs or sync checks). +
- +
-**Broadcast Frequency:** How often should the network attempt to send changes to the inputsThe higher the frequency, the more bandwidth is used. +
- +
-**Only Send Input Changes:** If enable, the network will only send data that has been changed (instead of sending every broadcast frequency tick) +
- +
- +
----- +
-==== Rollback Netcode ==== +
- +
-**Allow Rollbacks:** Enable Rollbacks in your game. +
- +
-**Track UFE Variables:** Toggle so UFE will use the //auto tracking// technique to search for its interface (''UFEInterface'') and attributed variables (''RecordVar'') on its own instantiated classes. The deeper a variable is from the UFE instance, the more CPU power it consumes. +
- +
-**Max Fast-Forward Per Frame:** When using rollback, depending on the distance between packages sent, how many frames can your game recover from. The more frames, the more CPU power it needs. +
- +
-**Input Buffer Size:** The amount of inputs that can be stored and reproduced in case of a rollback. +
- +
-**Spawn Buffer Size:** The amount of game objects that can be stored in a "safe pool" before they get //garbage collected//. Adjust this value based on the amount of object spawns (effects, projectiles, etc) you have at once in your game. +
- +
-**Rollback Balancing:** Use this option to balance out the rollback experience between the players. +
-  * //Disabled:// Only one of the players feels the effects of rollback. The host (or player with better connection) plays the game like there is nothing wrong. +
-  * //Conservative:// One player feels the effects of rollback more often the other. +
-  * //Aggressive:// Both players share the same impact when a rollback is needed to stabilize the connection. Use this option to "share" the impact of a rollback between players (recommended). +
- +
- +
----- +
-==== Frame Delay Netcode ==== +
- +
-**Frame Delay Type:** If set to ''Auto'', UFE will determine based on the ping what frame delay better fits the match. if you plan to toggle ''Apply Frame Delay Online'', use ''Fixed'' instead for a better user experience. +
- +
-**Min Frame Delay:** When connection is //ideal// (<10ms ping) what is the best value for //minimum// input delay in your gameLarge values makes the game more tolerant to lag spikes. On ideal connections it's recommended that you leave at least 4 frames (for 60 fps) or 3 (for 30 fps) - according to your [[global:advanced|FPS structure]].\\ +
-If you are using Rollback, the game will always attempt to use this value. Games less dependent on animation blending (such as 2D) can try for lower values, while games more dependent on hardware optimization (or better visual fidelity) should try for higher. +
- +
-**Max Frame Delay:** In case of bad connections, how far should the input delay before increase before it relies on rollback to keep the network packages synchronized? +
- +
-**Apply Frame Delay Offline:** Makes it so every game (including CPU matches and Training Mode) are always running with the ''Min Frame Delay'' value.+
  
  
Line 252: Line 179:
 ====== Hints ====== ====== Hints ======
 Networking is a relatively complicated aspect of the engine. Don't be alarmed if you can't get running at first. Here are a few hints to help out on common issues: Networking is a relatively complicated aspect of the engine. Don't be alarmed if you can't get running at first. Here are a few hints to help out on common issues:
-  * If you are having trouble connecting to the other peers, you might need to work on your router's [[http://portforward.com/|port forwarding]]. 
   * Make sure your moves don't have empty references when using ''UFE Upgrade''.   * Make sure your moves don't have empty references when using ''UFE Upgrade''.
   * The ''Animation Recorder'' tracks the animations based on what is listed on the character asset. If you have moves that are linked but not properly listed, the animation recorder might not find the animation.   * The ''Animation Recorder'' tracks the animations based on what is listed on the character asset. If you have moves that are linked but not properly listed, the animation recorder might not find the animation.
Line 261: Line 187:
 ---- ----
  
-[[global:start|< Back to Global Editor]]+[[global:network|< Back to Network]]
global/netcode.1535432122.txt.gz · Last modified: 2018/08/28 00:55 by Mistermind