reformat code + level load events

This commit is contained in:
2022-05-05 18:52:53 +03:00
parent 8762138fe3
commit fe443b9f50
38 changed files with 6380 additions and 6408 deletions

View File

@@ -1,22 +1,15 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using FlaxEditor;
using FlaxEngine;
using FlaxEngine.Networking;
using Console = Cabrito.Console;
using Debug = FlaxEngine.Debug;
namespace Game
{
[AttributeUsage(AttributeTargets.Class)]
public class NetworkPredictedAttribute : Attribute
{
public NetworkPredictedAttribute()
{
}
}
// TODO: insert code to update variables with this attribute?
@@ -24,9 +17,6 @@ namespace Game
[AttributeUsage(AttributeTargets.Class)]
public class NetworkedAttribute : Attribute
{
public NetworkedAttribute()
{
}
}
// NetworkMulticastAttribute: calls methods marked with this in all clients
@@ -34,24 +24,23 @@ namespace Game
public enum NetworkMessageType : byte
{
Handshake = 1,
Message,
Message
}
public static partial class NetworkManager
{
private static bool initialized = false;
public delegate bool OnMessageDecl(NetworkMessage message);
private static bool initialized;
private static NetworkPeer server;
private static NetworkPeer client;
private static ushort ServerPort = 59183;
private static string ServerAddress = null;
private static ushort MTU = 1500;
private static ushort MaximumClients = 32;
public delegate bool OnMessageDecl(NetworkMessage message);
private static readonly ushort ServerPort = 59183;
private static string ServerAddress;
private static readonly ushort MTU = 1500;
private static readonly ushort MaximumClients = 32;
public static OnMessageDecl OnMessage;
public static void Init()
@@ -79,14 +68,18 @@ namespace Game
initialized = true;
GameModeManager.Init(); // FIXME
#if FLAX_EDITOR
Editor.Instance.PlayModeEnd += Cleanup;
#endif
}
public static void Deinitialize()
public static void Cleanup()
{
if (server != null)
{
Scripting.FixedUpdate -= OnServerUpdate;
Scripting.Exit -= Deinitialize;
Scripting.Exit -= Cleanup;
Level.ActorSpawned -= OnServerActorSpawned;
NetworkPeer.ShutdownPeer(server);
server = null;
@@ -95,11 +88,16 @@ namespace Game
if (client != null)
{
Scripting.FixedUpdate -= OnClientUpdate;
Scripting.Exit -= Deinitialize;
Scripting.Exit -= Cleanup;
Level.ActorSpawned -= OnClientActorSpawned;
NetworkPeer.ShutdownPeer(client);
client = null;
}
#if FLAX_EDITOR
Editor.Instance.PlayModeEnd -= Cleanup;
GameModeManager.Cleanup();
#endif
}
private static void OnNetworkMessage(NetworkEvent networkEvent)
@@ -117,14 +115,13 @@ namespace Game
{
case NetworkMessageType.Handshake:
{
var message = networkEvent.Message.ReadString();
string message = networkEvent.Message.ReadString();
Console.Print($"Received handshake from {networkEvent.Sender.ConnectionId}, msg: " + message);
break;
}
case NetworkMessageType.Message:
{
if (OnMessage != null)
{
foreach (OnMessageDecl func in OnMessage.GetInvocationList()
.Cast<OnMessageDecl>().ToArray())
{
@@ -132,7 +129,7 @@ namespace Game
if (ret)
break;
}
}
break;
}
default: