Entangle (Multiplayer Game development Framework)

Entangle is a high level room based networking solution built on top of FigNet Core

Drop in solution for multiplayer games

Entangle is a high-level networking solution powered by FigNet built on a client-server model. It provides high-level components out of the box to develop your multiplayer games faster. It provides a Room to host a game session, a user can create or join a room on demand. Network Entities creation and state replication is handled automatically. It is semi authoritative Items creation is handled by the server whereas Network physic is calculated on the client-side and distributed by the server.

If you want to try it out join the Discord server

Demo Showcasing Entangle Features

Core Concepts

Entangle provides following Network Entity types to handle all use cases a game might need

NetworkEntity is a base class that contains common behavior

NetPlayer represents a player, an instance is created once you joined a room and user has the authority for that entity through out the game session.

NetItem game Items that needs to be synced across all connected users are handled by NetItem. A user can request the ownership of NetItems e.g. Weapon, loot item & Ammo etc.

NetAgent entities that contain logic or AI are handled by NetAgent. Master client’s (user with lowest ping) Master client’s state is considered as source of truth for other users in the room. e.g. Boss, NPC or Machines are few examples of Agents.

State Replication

Entangle State is the heart of Entangle it automatically syncs the state of Entities across all users at defined interval that you can set in Configuration. As a developer all you need to Set or Get your properties. Entangle provides following Reactive Property types
– FNShort
– FNInt
– FNFloat
– FNString
– FNVector2
– FNVector3
– FNVector4

EntangleState contains dictionary of IFNProperty a user can feed 0-255 properties in Entangles against each delivery method. There are four deliver methods in total [ Unreliable | Reliable | ReliableUnordered | Sequenced]

How to Set/Get a property in Network Entity (EntangleState)


	NetworkEntity networkEntity;
	// Define FNProperty
	public FNVector3 pos = default;

	void Start()
	{
		// if you own the entity set the property
		if (networkEntity.IsMine)
		{
			pos = new FNVector3();
			networkEntity.SetNetProperty(1, pos, FigNet.Core.DeliveryMethod.Unreliable);
		}
		else
		{
			// you are observer read the property 
			networkEntity.GetNetProperty(1, FigNet.Core.DeliveryMethod.Unreliable, (position) =>
			{
				pos = position;
				pos.OnValueChange += Pos_OnValueChange;
			});
		}
	}

	// will be triggered automatically for other users on value change
    private void Pos_OnValueChange(FNVec3 pos)
    {
		Debug.Log($"{gameObject.name} On position changed {obj.X}|{obj.Y}|{obj.Z}");
	}
	
	void Update()
	{
		// if you own the entity set the property values 
		// changes will be broadcasted to all users
		if(networkEntity.IsMine)
			pos.Value = new FNVec3(transform.position.x, transform.position.y, transform.position.z);
	}

Network Prefabs

To convert a GameObject into network prefab attach EntangleView component and set EntityId & Type and add your network prefabs in PrefabRegistory window. Whenever an Network Entity will be created in a room it’s corresponding prefab will be automatically instantiated in the scene.

Entangle Setting

Lobby

Lobby class provides API to create, Join, Leave & Get Rooms.

Lobby.CreateRoom


// <summary>
// Creates a room on server 
// </summary>
//  Display Name of Room 
//  Maximum numbers of players allowed in a room 
//  set password to none empty string to create private room 
//  bool: isRoom creation is sucessful, uint: uid of room, it is used to join room  
public static void CreateRoom(string roomName, short maxPlayers, string password, Action callBack)

Lobby.JoinRoom


// <summary>
// Join a room on server
// </summary>
// uid of room to join
// provide password if room is password protected else pass empty sting
// status code [Sucess|InvalidPassword|RoomLocked|RoomFull|Unknown|Failure]
public static void JoinRoom(uint roomId, string password, Action onRoomJoin)

Lobby.LeaveRoom


// <summary>
// Leave room
// </summary>
// status code [Sucess|InvalidPassword|RoomLocked|RoomFull|Unknown|Failure]
public static void LeaveRoom(Action onRoomLeft)

Lobby.GetRooms


// <summary>
// Get List of Avaliable rooms/game sessions
// </summary>
// RoomQuery [All | Avaliable ]
// list of RoomInfo ( Id | RoomName | MaxPlayer | ActivePlayer | State )
public static void GetRooms(RoomQuery query, Action&lt;List&gt; callBack)


Room

Room is used to create a game session by grouping players together.

Room exposes following properties


// uid of rood
public uint RoomId { get; set; }
// Display name
public string RoomName { get; set; }
// Max allowed players in a session
public int MaxPlayer { get; set; }
// my player Id
public uint MyPlayerId { get; set; }
// if room is locked entry of new player is banned
public bool IsLocked { get; set; }
// used to set the state of room e.g. [waiting for player | Setting up | In progress | Result]
public int RoomState { get; set; }
// Gets triggered in CreateRoom response
public static event Action OnRoomCreate;
// Gets triggered in LeaveRoom response
public static event Action OnRoomDispose;
// Gets Triggered when a player Joins a room
public static event Action OnPlayerJoined;
// Gets Triggered when a player Left the room
public static event Action OnPlayerLeft;
// Gets Triggered when a NetworkItem or NetworkAgent is Spawned
public static event Action OnEntityCreated;
// Gets Triggered a NetworkItem or NetworkAgent is deleted
public static event Action OnEntityDeleted;
// Gets Triggered when a player broadcast an event in a room
public static event Action OnEventReceived;


As an alternate to manually bind event listeners of room class. Entangle provides IEntangleRoomListener interface that can be used to listen to Room Events

// Use Room.BindListener to subscribe to room events
public static void BindListener(IEntangleRoomListener listener)
// Use Room.UnBindListener to subscribe to room events
public static void UnBindListener(IEntangleRoomListener listener)


// Implement IEntangleRoomListener interface and bind it using above method

public interface IEntangleRoomListener
{
    void OnRoomCreated();
    void OnRoomDispose();
    void OnRoomStateChange(int status);
    void OnPlayerJoined(NetPlayer player);
    void OnPlayerLeft(NetPlayer player);
    void OnItemCreated(NetItem item, System.Numerics.Vector3 position, System.Numerics.Vector4 rotation, System.Numerics.Vector3 scale);
    void OnItemDeleted(NetItem item);
    void OnAgentCreated(NetAgent agent, System.Numerics.Vector3 position, System.Numerics.Vector4 rotation, System.Numerics.Vector3 scale);
    void OnAgentDeleted(NetAgent agent);
    void OnEventReceived(uint sender, RoomEventData eventData);

}



Leave a comment