staf
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Game
|
||||
public enum UpscalingMode
|
||||
{
|
||||
None,
|
||||
FSR2,
|
||||
DLSS,
|
||||
FSR1,
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user