This commit is contained in:
2023-03-02 22:07:43 +02:00
parent 1a0709d113
commit 5e48806b8c
21 changed files with 145 additions and 82 deletions

View File

@@ -1,12 +1,13 @@
{
"ID": "82e58c9d462fba5a0df1a599417ff684",
"TypeName": "FlaxEngine.Prefab",
"EngineBuild": 6332,
"EngineBuild": 6340,
"Data": [
{
"ID": "a50f3639419a8306036ecfab7115e772",
"TypeName": "Game.PlayerActor",
"V": {},
"IsActive": false,
"Name": "PlayerPrefab",
"Transform": {
"Translation": {
@@ -29,7 +30,8 @@
"ID": "bc518e2f40ec06a4523d78b52809c668",
"TypeName": "Game.PlayerMovement",
"ParentID": "a50f3639419a8306036ecfab7115e772",
"V": {}
"V": {},
"Enabled": false
},
{
"ID": "e590615440a1c571c7b1b4956f55078b",
@@ -88,6 +90,7 @@
"ID": "0e2e8a4f4623887ca2be699fe858beb2",
"TypeName": "FlaxEngine.Camera",
"ParentID": "51c770f24232abbb112cc98b296820d8",
"IsActive": false,
"Name": "ViewModelCamera",
"StaticFlags": 0,
"Layer": 2,
@@ -116,8 +119,7 @@
"Z": 0.0
}
},
"StaticFlags": 0,
"Layer": 2
"StaticFlags": 0
},
{
"ID": "195f796349961ef9a9d46a8657fc693b",
@@ -139,6 +141,7 @@
"PrefabID": "7f0707924e86984317e6a78b55e68245",
"PrefabObjectID": "bb8115cf4fd8d0906b1e928a171763c5",
"ParentID": "99f2289f4f483aba1fcabdba40a2c899",
"Layer": 0,
"Buffer": {
"Entries": [
{}
@@ -150,6 +153,7 @@
"PrefabID": "7f0707924e86984317e6a78b55e68245",
"PrefabObjectID": "a54aa52147b86b56df27fdaa9ba7ca52",
"ParentID": "234dca27419c27d758db29953fd9f992",
"Layer": 0,
"Buffer": {
"Entries": [
{}

View File

@@ -49,13 +49,13 @@
"ParentID": "ff6b6db54b5aa08e7286ef86246149ef",
"Transform": {
"Translation": {
"X": -47.0,
"Y": -54.0,
"X": 1841.0,
"Y": 972.0,
"Z": 0.0
}
},
"Data": {
"Text": "16192 tris\n 281 drawcalls\n830fps"
"Text": "1302 tris\n 131 drawcalls\n434fps2\n1921fps"
}
},
{

View File

@@ -1,7 +1,7 @@
{
"ID": "0c69a0c7471f8d0805965caf343d2f27",
"TypeName": "FlaxEditor.Content.Settings.NetworkSettings",
"EngineBuild": 6335,
"EngineBuild": 6340,
"Data": {
"MaxClients": 100,
"ProtocolVersion": 1,

View File

@@ -1,7 +1,7 @@
{
"ID": "51fb8bec4cfc9095612aaf992382a255",
"TypeName": "Game.BrushMaterialList",
"EngineBuild": 6332,
"EngineBuild": 6340,
"Data": {
"materialAssets": [
{
@@ -39,6 +39,14 @@
{
"name": "COP1_7",
"asset": "cfe2d8d64700dc00dc2c5088ee028477"
},
{
"name": "common/WTF",
"asset": "1d721da34229caaacacf43a07f0702c5"
},
{
"name": "__TB_empty",
"asset": "1d721da34229caaacacf43a07f0702c5"
}
]
}

View File

@@ -1,7 +1,7 @@
// comment
r_shadows 0
r_lighting 1
cl_maxfps 0
r_lighting 0
cl_maxfps 240
r_upscaling 0
r_gi 0
r_staticbatch 0

View File

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

View File

@@ -16,15 +16,17 @@ namespace Game
set => dictionary[key] = value;
}
// This is for debugging only, remove this later
public string[] Commands;
public string[] GetLines()
{
string[] lines = new string[dictionary.Count];
string[] lines = new string[dictionary.Count + Commands.Length];
int lineIndex = 0;
foreach (var kvp in dictionary)
{
lines[lineIndex] = $"{kvp.Key} {kvp.Value}";
lineIndex++;
}
lines[lineIndex++] = $"{kvp.Key} {kvp.Value}";
foreach (var cmd in Commands)
lines[lineIndex++] = cmd;
return lines;
}

View File

@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
namespace Game
{
@@ -20,6 +21,7 @@ namespace Game
/*using*/ FileStream file = File.OpenRead(path);
/*using*/ StreamReader sr = new StreamReader(file);
List<string> commands = new List<string>();
string line;
while ((line = sr.ReadLine()?.Trim()) != null)
{
@@ -28,7 +30,10 @@ namespace Game
int spacePos = line.IndexOf(' ');
if (spacePos == -1)
{
commands.Add(line);
continue;
}
string key = line.Substring(0, spacePos);
string value = line.Substring(spacePos+1);
@@ -38,6 +43,8 @@ namespace Game
config[key] = value;
}
config.Commands = commands.ToArray();
return config;
}
}

View File

@@ -24,20 +24,20 @@ namespace Game
//AssetManager.Init(); // TODO: move these elsewhere
#if !FLAX_EDITOR
Level.SceneLoaded += OnSceneLoaded;
Level.SceneLoading += OnSceneLoading;
#endif
}
public override void Deinitialize()
{
#if !FLAX_EDITOR
Level.SceneLoaded -= OnSceneLoaded;
Level.SceneLoading -= OnSceneLoading;
#endif
}
private void OnSceneLoaded(Scene scene, Guid guid)
private void OnSceneLoading(Scene scene, Guid guid)
{
Level.SceneLoaded -= OnSceneLoaded;
Level.SceneLoading -= OnSceneLoading;
LoadConfig();
}
@@ -78,7 +78,7 @@ namespace Game
//AssetManager.Init();
Level.SceneLoaded += OnSceneLoaded;
Level.SceneLoading += OnSceneLoading;
FlaxEditor.Editor.Instance.PlayModeBegin += OnPlayModeBegin;
FlaxEditor.Editor.Instance.PlayModeEnd += OnPlayModeEnd;
@@ -111,8 +111,8 @@ namespace Game
public override void Deinitialize()
{
Level.SceneLoaded -= OnSceneLoaded;
Level.SceneLoaded -= OnSceneLoaded;
//Level.SceneLoaded -= OnSceneLoaded;
Level.SceneLoading -= OnSceneLoading;
if (FlaxEditor.Editor.Instance != null)
{
FlaxEditor.Editor.Instance.PlayModeBegin -= OnPlayModeBegin;
@@ -120,10 +120,10 @@ namespace Game
}
}
private void OnSceneLoaded(Scene scene, Guid guid)
private void OnSceneLoading(Scene scene, Guid guid)
{
Level.SceneLoaded -= OnSceneLoaded;
Level.SceneLoaded -= OnSceneLoaded;
//Level.SceneLoaded -= OnSceneLoaded;
Level.SceneLoading -= OnSceneLoading;
LoadConfig();
}

View File

@@ -228,6 +228,7 @@ namespace Game
// hide console by default, and close it instantly
Console.Close();
OnConsoleClose();
Float2 rootlocation = rootControl.Control.Location;
rootlocation.Y = -rootControl.Control.Height;
rootControl.Control.Location = rootlocation;

View File

@@ -13,6 +13,7 @@ namespace Game
public enum UpscalingMode
{
None,
FSR2,
DLSS,
FSR1,
}

View File

@@ -1,4 +1,4 @@
//#define COMPILE_WITH_DLSS
#define COMPILE_WITH_DLSS
using Flax.Build;
using Flax.Build.NativeCpp;
@@ -6,6 +6,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
#if COMPILE_WITH_DLSS
//using Nvidia;
#endif
public class Game : GameModule
{
@@ -34,7 +37,7 @@ public class Game : GameModule
#if COMPILE_WITH_DLSS
DLSS.ConditionalImport(options, options.PrivateDependencies);
options.PrivateDefinitions.Add("COMPILE_WITH_DLSS");
options.ScriptingAPI.Defines.Add("COMPILE_WITH_DLSS");
#endif
// Here you can modify the build options for your game module
// To reference another module use: options.PublicDependencies.Add("Audio");

View File

@@ -27,6 +27,7 @@ namespace Game
public static bool Connect(string ip = null, ushort port = 0)
{
Console.Clear();
if (ServerRunning)
NetworkManager_Cleanup();
@@ -48,6 +49,7 @@ namespace Game
public static bool StartServer(bool listenServer)
{
Console.Clear();
if (ServerRunning)
NetworkManager_Cleanup();
@@ -198,8 +200,15 @@ namespace Game
Console.PrintError("GameModeManager: Failed to find PlayerPrefab");
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);
}
public void OnPlayerInit()

View File

@@ -14,9 +14,12 @@ namespace Game
private Label label;
private Stopwatch stopwatch;
private Stopwatch stopwatch2;
private double updateTimeAvg;
private double updateTimeAvg2;
private ulong updateTimeCount;
private ulong updateTimeCount2;
public override void OnAwake()
{
@@ -25,10 +28,20 @@ namespace Game
control.HideFlags = HideFlags.None;
stopwatch = Stopwatch.StartNew();
stopwatch2 = Stopwatch.StartNew();
}
public override void OnUpdate()
{
updateTimeCount2++;
double elapsed2 = stopwatch2.Elapsed.TotalSeconds;
if (elapsed2 >= updateInterval * 10)
{
stopwatch2.Restart();
updateTimeAvg2 = elapsed2 / updateTimeCount2;
updateTimeCount2 = 0;
}
updateTimeCount++;
double elapsed = stopwatch.Elapsed.TotalSeconds;
if (elapsed >= updateInterval)
@@ -52,7 +65,7 @@ namespace Game
#endif
label.Text += $"{triangles} tris\n {drawCalls} drawcalls\n";
label.Text += $"{(int)Math.Round(1.0f / updateTimeAvg2)}fps2\n";
label.Text += $"{(int)Math.Round(1.0f / updateTimeAvg)}fps";
}

View File

@@ -41,7 +41,7 @@ namespace Game
[ExecuteInEditMode]
public class Q3MapImporter : Script
{
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\cube_q1.map";
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\cube_q1.map";u8
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\cube_q3.map";
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\cube_valve.map";
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\dm4.map";
@@ -414,7 +414,9 @@ namespace Game
string mapPath_ = mapPath;
if (!File.Exists(mapPath_))
mapPath_ = Path.Combine(Directory.GetCurrentDirectory(), mapPath_);
mapPath_ = Path.Combine(Directory.GetCurrentDirectory(), mapPath);
if (!File.Exists(mapPath_))
mapPath_ = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", mapPath);
byte[] mapChars = File.ReadAllBytes(mapPath_);
root = MapParser.Parse(mapChars);
@@ -661,17 +663,10 @@ namespace Game
if (mesh.vertices.Count == 0)
continue;
var tassk = Task.Run(() =>
{
List<int> indices = new List<int>();
foreach (var ind in mesh.indices)
indices.Add((int)ind);
geom.model.LODs[0].Meshes[i].UpdateMesh(mesh.vertices.ToArray(), indices.ToArray(), mesh.normals.ToArray() /*,
null, mesh.uvs*/);
geom.model.LODs[0].Meshes[i].MaterialSlotIndex = i;
geom.model.MaterialSlots[i].Material = geom.meshes[i].material;
});
tassk.Wait();
geom.model.LODs[0].Meshes[i].UpdateMesh(mesh.vertices, mesh.indices, mesh.normals,
null, mesh.uvs);
geom.model.LODs[0].Meshes[i].MaterialSlotIndex = i;
geom.model.MaterialSlots[i].Material = geom.meshes[i].material;
}
//Not supported yet, should be done here
@@ -1109,7 +1104,7 @@ namespace Game
break;
}
Console.Print("entity parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
//Console.Print("entity parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
}

View File

@@ -17,7 +17,7 @@ namespace Game
var items = GetItemsForType(type, type.IsClass, true);
// Remove all Rigid Body options
items.RemoveAll(x => x.Display.Group == "Rigid Body");
items.RemoveAll(x => x.Display?.Group == "Rigid Body");
// Inject scripts editor
ScriptMemberInfo scriptsMember = type.GetProperty("Scripts");
@@ -40,6 +40,12 @@ namespace Game
private PlayerMovement playerMovement;
private RigidBody playerRigidBody;
[NetworkReplicated]
public uint PlayerId = uint.MaxValue;
[NetworkReplicated]
public uint hai = 1;
public PlayerActor()
{
// Default internal values for RigidBody
@@ -56,20 +62,33 @@ namespace Game
playerMovement = FindScript<PlayerMovement>();
playerRigidBody = FindActor<RigidBody>();
}
NetworkReplicator.AddObject(this);
public override void OnEnable()
{
// Trigger OnEnable manually, does not seem to propagate when parent gets enabled/disabled
playerMovement.Enabled = true;
//NetworkReplicator.AddObject(this);
}
public override void OnDisable()
{
playerMovement.Enabled = false;
//NetworkReplicator.RemoveObject(this);
}
public void Initialize(uint playerId)
{
playerMovement.SetInput(playerId);
//if (playerId == NetworkManager.LocalPlayerClientId)
if (NetworkReplicator.GetObjectRole(this) == NetworkObjectRole.OwnedAuthoritative)
PlayerId = playerId;
//playerMovement.SetInput(playerId);
if (playerId == NetworkManager.LocalClientId)
{
FindActor("CameraHolder").IsActive = true;
//FindActor("ViewModelHolder").IsActive = true;
FindActor("PlayerModel").IsActive = false;
}
else
FindActor("PlayerModel").IsActive = true;
}
public void UpdateNetworkInput(PlayerInputState inputState)

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using FlaxEngine;
using FlaxEngine.Assertions;
using FlaxEngine.Networking;
using Console = Game.Console;
@@ -100,6 +101,7 @@ namespace Game
private RigidBody rigidBody;
private Actor cameraHolder;
private PlayerActor playerActor;
private Actor rootActor;
private float startupTime;
@@ -114,6 +116,7 @@ namespace Game
//private Float3 safePosition;
[NetworkReplicated]
public uint PlayerId = 0;
[ReadOnly]
@@ -138,10 +141,6 @@ namespace Game
public override void OnAwake()
{
base.OnAwake();
Console.Print("player awake");
// Setup input with no controller
SetInput(PlayerId);
onExit.Triggered += () =>
{
@@ -149,25 +148,35 @@ namespace Game
Engine.RequestExit();
};
Console.Print("player awake, playerid: " + PlayerId);
rootActor = Actor.GetChild("RootActor");
rigidBody = Actor.As<RigidBody>();
playerActor = Actor.As<PlayerActor>();
cameraHolder = rootActor.GetChild("CameraHolder");
// Setup input with no controller
//SetInput(NetworkReplicator.GetObjectOwnerClientId(this.Parent));
//rigidBody.CollisionEnter += OnCollisionEnter;
//rigidBody.TriggerEnter += OnTriggerEnter;
//rigidBody.TriggerExit += OnTriggerExit;
startupTime = Time.TimeSinceStartup;
Console.Print("hai: " + playerActor.hai);
}
public void SetInput(uint playerId)
{
//if (playerId == 0)
// input = new PlayerInput();
Assert.IsTrue(playerId != uint.MaxValue);
PlayerId = playerId;
if (NetworkReplicator.GetObjectRole(this.Parent) == NetworkObjectRole.OwnedAuthoritative)// if (playerId == NetworkManager.LocalPlayerClientId)
if (PlayerId == NetworkManager.LocalClientId)//if (NetworkReplicator.GetObjectRole(this.Parent) == NetworkObjectRole.OwnedAuthoritative)// if (playerId == NetworkManager.LocalPlayerClientId)
{
Console.Print("local player: " + playerId.ToString());
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
@@ -194,6 +203,10 @@ namespace Game
public override void OnEnable()
{
//var playerId = NetworkReplicator.GetObjectOwnerClientId(this.Parent);
//SetInput(playerId);
Console.Print("hai: " + playerActor.hai);
SetInput(playerActor.PlayerId);
}
public override void OnDisable()
{

View File

@@ -1,11 +1,7 @@
//#define COMPILE_WITH_DLSS
using Flax.Build;
public class GameEditorTarget : GameProjectEditorTarget
{
private bool UseDLSS = false;
/// <inheritdoc />
public override void Init()
{
@@ -15,10 +11,6 @@ public class GameEditorTarget : GameProjectEditorTarget
Platforms = new TargetPlatform[] { TargetPlatform.Windows, TargetPlatform.Linux };
Modules.Add("Game");
//Modules.Add("FidelityFXFSR");
#if COMPILE_WITH_DLSS
//Modules.Add("DLSS");
#endif
}
}

View File

@@ -1,13 +1,10 @@
//#define COMPILE_WITH_DLSS
using System;
using System.IO;
using Flax.Build;
using Flax.Build.NativeCpp;
public class GameTarget : GameProjectTarget
{
private bool UseDLSS = false;
/// <inheritdoc />
public override void Init()
{
@@ -19,34 +16,30 @@ public class GameTarget : GameProjectTarget
Architectures = new TargetArchitecture[] { TargetArchitecture.x64 };
Platforms = new TargetPlatform[] { TargetPlatform.Windows, TargetPlatform.Linux };
//LinkType = TargetLinkType.Monolithic;
// Monolithic build only seems to work on Windows for now?
LinkType = TargetLinkType.Monolithic;
if (LinkType == TargetLinkType.Monolithic)
{
//only for windows?
//Modules.Add("Main");
//OutputType = TargetOutputType.Executable;
Modules.Add("Main");
OutputType = TargetOutputType.Executable;
}
Modules.Add("Game");
//Modules.Add("FidelityFXFSR");
#if COMPILE_WITH_DLSS
//Modules.Add("DLSS");
#endif
}
/*public override string GetOutputFilePath(BuildOptions options, TargetOutputType? outputType = null)
public override string GetOutputFilePath(BuildOptions options, TargetOutputType? outputType = null)
{
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)
options.OutputFolder = @"C:\dev\GoakeFlax\Output\WindowsDevelopment";
options.OutputFolder = Path.Combine(FolderPath, "..", "Output", "WindowsDevelopment");
else if (options.Configuration == TargetConfiguration.Release)
options.OutputFolder = @"C:\dev\GoakeFlax\Output\WindowsRelease";
options.OutputFolder = Path.Combine(FolderPath, "..", "Output", "WindowsRelease");
}
return base.GetOutputFilePath(options, outputType);
}*/
}
}