This commit is contained in:
2023-03-07 17:51:43 +02:00
parent 5e48806b8c
commit 59ef64fe3b
8 changed files with 95 additions and 26 deletions

View File

@@ -11,9 +11,6 @@
},
{
"Name": "$(ProjectPath)/Plugins/FidelityFX-FSR/FidelityFX-FSR.flaxproj"
},
{
"Name": "$(ProjectPath)/Plugins/DLSS/DLSS.flaxproj"
}
],
"DefaultScene": "194e05f445ece24ec5448d886e1334df",

View File

@@ -1,4 +1,4 @@
#define COMPILE_WITH_DLSS
//#define COMPILE_WITH_DLSS
using Flax.Build;
using Flax.Build.NativeCpp;
@@ -31,6 +31,9 @@ public class Game : GameModule
base.Setup(options);
Tags["Network"] = string.Empty;
options.PublicDependencies.Add("Networking");
options.PrivateDependencies.Add("FidelityFXFSR");
//options.ScriptingAPI.FileReferences.Add(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "DotNet", "Newtonsoft.Json.dll"));

View File

@@ -201,14 +201,15 @@ namespace Game
PlayerActor playerActor = PrefabManager.SpawnPrefab(playerPrefab).As<PlayerActor>();
NetworkReplicator.AddObject(playerActor);
playerActor.hai = 123;
playerActor.Initialize(clientId);
playerActor.IsActive = true;
playerActor.Teleport(spawnPosition, spawnAngles);
//NetworkReplicator.SetObjectOwnership(playerActor, clientId);
NetworkReplicator.SpawnObject(playerActor);
//playerActor.Initialize(clientId);
//playerActor.hai = 345;
}
public void OnPlayerInit()

View File

@@ -43,10 +43,7 @@ namespace Game
[NetworkReplicated]
public uint PlayerId = uint.MaxValue;
[NetworkReplicated]
public uint hai = 1;
public PlayerActor()
/*public PlayerActor()
{
// Default internal values for RigidBody
IsKinematic = true;
@@ -54,10 +51,17 @@ namespace Game
LinearDamping = 0f;
AngularDamping = 0f;
Constraints = RigidbodyConstraints.LockRotation;
}
}*/
public override void OnBeginPlay()
{
// Default internal values for RigidBody
IsKinematic = true;
EnableGravity = false;
LinearDamping = 0f;
AngularDamping = 0f;
Constraints = RigidbodyConstraints.LockRotation;
base.OnBeginPlay();
playerMovement = FindScript<PlayerMovement>();
@@ -66,7 +70,7 @@ namespace Game
public override void OnEnable()
{
// Trigger OnEnable manually, does not seem to propagate when parent gets enabled/disabled
// Trigger OnEnable manually, does not seem 8to propagate when parent gets enabled/disabled
playerMovement.Enabled = true;
//NetworkReplicator.AddObject(this);
}
@@ -77,10 +81,11 @@ namespace Game
//NetworkReplicator.RemoveObject(this);
}
[NetworkRpc(client: true)]
public void Initialize(uint playerId)
{
PlayerId = playerId;
//playerMovement.SetInput(playerId);
playerMovement.SetInput(playerId);
if (playerId == NetworkManager.LocalClientId)
{
FindActor("CameraHolder").IsActive = true;
@@ -89,12 +94,17 @@ namespace Game
}
else
FindActor("PlayerModel").IsActive = true;
IsActive = true;
}
public void UpdateNetworkInput(PlayerInputState inputState)
[NetworkRpc(server: true)]
public void UpdateNetworkInput(ulong frame, Float4 viewDeltaXYMoveForwardRight, bool attacking, bool jumping)
{
if (playerMovement.input is PlayerInputNetwork)
(playerMovement.input as PlayerInputNetwork).currentState.input = inputState;
if (playerMovement.input is not PlayerInputNetwork playerInputNetwork)
return;
PlayerInputState inputState = new PlayerInputState(frame, viewDeltaXYMoveForwardRight.X, viewDeltaXYMoveForwardRight.Y, viewDeltaXYMoveForwardRight.Z, viewDeltaXYMoveForwardRight.W, attacking, jumping);
playerInputNetwork.currentState.input = inputState;
}
public void SetPosition(Float3 newPosition)
@@ -107,6 +117,7 @@ namespace Game
playerMovement.ResetRotation(eulerAngles);
}
[NetworkRpc(client: true)]
public void Teleport(Float3 newPosition, Float3 eulerAngles)
{
SetPosition(newPosition);

View File

@@ -1,11 +1,58 @@
using System.Runtime.InteropServices;
using FlaxEngine;
using FlaxEngine.Networking;
namespace Game
{
[StructLayout(LayoutKind.Sequential)]
public struct PlayerInputState
{
/*static PlayerInputState()
{
NetworkReplicator.AddSerializer(typeof(PlayerInputState),
(ptr, streamPtr) =>
{
},
(ptr, streamPtr) =>
{
});
}*/
public PlayerInputState(ulong frame, float viewDeltaX, float viewDeltaY, float moveForward, float moveRight,
bool attacking, bool jumping)
{
this.frame = frame;
this.viewDeltaX = viewDeltaX;
this.viewDeltaY = viewDeltaY;
this.moveForward = moveForward;
this.moveRight = moveRight;
this.attacking = attacking;
this.jumping = jumping;
/*this.verificationPosition = verificationPosition;
this.verificationVelocity = verificationVelocity;
this.verificationViewAngles = verificationViewAngles;
this.verificationOrientation = verificationOrientation;*/
}
public PlayerInputState(ulong frame, float viewDeltaX, float viewDeltaY, float moveForward, float moveRight,
bool attacking, bool jumping, Float3 verificationPosition, Float3 verificationVelocity,
Float3 verificationViewAngles, Quaternion verificationOrientation)
{
this.frame = frame;
this.viewDeltaX = viewDeltaX;
this.viewDeltaY = viewDeltaY;
this.moveForward = moveForward;
this.moveRight = moveRight;
this.attacking = attacking;
this.jumping = jumping;
this.verificationPosition = verificationPosition;
this.verificationVelocity = verificationVelocity;
this.verificationViewAngles = verificationViewAngles;
this.verificationOrientation = verificationOrientation;
}
public ulong frame;
public float viewDeltaX, viewDeltaY;
public float moveForward;

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using FlaxEngine;
using FlaxEngine.Networking;
using Console = Game.Console;
namespace Game
@@ -14,14 +15,16 @@ namespace Game
protected GZipStream demoFileStream;
protected FileStream demoFileStream2;
private PlayerActor playerActor;
//public bool IsNetworked => NetworkManager.client != null;
public PlayerInputLocal()
/*public PlayerInputLocal()
{
}
}*/
public PlayerInputLocal(string demoPath)
public PlayerInputLocal(PlayerActor playerActor, string demoPath)
{
this.playerActor = playerActor;
var demoFolder = Directory.GetParent(demoPath);
if (!demoFolder.Exists)
Directory.CreateDirectory(demoFolder.FullName);
@@ -56,6 +59,8 @@ namespace Game
currentState.input.moveRight = InputManager.GetAxis("Horizontal");
currentState.input.attacking = InputManager.GetAction("Attack");
currentState.input.jumping = InputManager.GetAction("Jump");
}
public override void OnFixedUpdate()
@@ -75,6 +80,12 @@ namespace Game
buffer.Add(currentState.input);
}
if (playerActor != null)
{
playerActor.UpdateNetworkInput(currentState.input.frame, new Float4(currentState.input.viewDeltaX, currentState.input.viewDeltaY, currentState.input.moveForward, currentState.input.moveRight), currentState.input.attacking, currentState.input.jumping);
}
//playerActor.UpdateNetworkInput(currentState.input.frame, currentState.input.viewDeltaX, currentState.input.viewDeltaY, currentState.input.moveForward, currentState.input.moveRight, currentState.input.attacking, currentState.input.jumping, currentState.input.verificationPosition, currentState.input.verificationVelocity, currentState.input.verificationViewAngles, currentState.input.verificationOrientation);
/*if (IsNetworked)
{
var message = NetworkManager.ClientBeginSendMessage();

View File

@@ -164,7 +164,6 @@ namespace Game
//rigidBody.TriggerExit += OnTriggerExit;
startupTime = Time.TimeSinceStartup;
Console.Print("hai: " + playerActor.hai);
}
public void SetInput(uint playerId)
@@ -178,7 +177,7 @@ namespace Game
{
Console.Print("local player?: " + playerId.ToString());
string demoPath = System.IO.Path.Combine(AssetManager.DemoPath, $"{DateTimeOffset.Now.UtcTicks}.gdem");
input = new PlayerInputLocal(demoPath); // TODO: support recording
input = new PlayerInputLocal(playerActor, demoPath); // TODO: support recording
}
else
@@ -193,7 +192,7 @@ namespace Game
input = new PlayerInputDemo(demoFile);
/*Actor.Position = input.GetCurrentActorState().position;
currentVelocity = input.GetCurrentActorState().velocity;
currentVelocity = input.GetCurrentActorState().velocity; f
SetCameraEulerAngles(input.GetCurrentActorState().viewAngles);*/
Actor.Position = input.GetCurrentInputState().verificationPosition;
//rootActor.Orientation = input.GetCurrentInputState().verificationOrientation;
@@ -205,8 +204,8 @@ namespace Game
{
//var playerId = NetworkReplicator.GetObjectOwnerClientId(this.Parent);
//SetInput(playerId);
Console.Print("hai: " + playerActor.hai);
SetInput(playerActor.PlayerId);
//Console.Print("hai: " + playerActor.hai);
//SetInput(playerActor.PlayerId);
}
public override void OnDisable()
{

View File

@@ -33,7 +33,7 @@ public class GameTarget : GameProjectTarget
if (!Environment.CommandLine.Contains("Cooker")) // Hacky way to detect if this is run during cooking
{
// Output files directly to cooked folders (used only during development)
if (options.Configuration == TargetConfiguration.Development)
if (options.Configuration == TargetConfiguration.Development || options.Configuration == TargetConfiguration.Debug)
options.OutputFolder = Path.Combine(FolderPath, "..", "Output", "WindowsDevelopment");
else if (options.Configuration == TargetConfiguration.Release)
options.OutputFolder = Path.Combine(FolderPath, "..", "Output", "WindowsRelease");