diff --git a/Content/Materials/SimpleMapMaterial.flax b/Content/Materials/SimpleMapMaterial.flax index f4d4260..9b39606 100644 Binary files a/Content/Materials/SimpleMapMaterial.flax and b/Content/Materials/SimpleMapMaterial.flax differ diff --git a/Content/Materials/SkyMaterial.flax b/Content/Materials/SkyMaterial.flax index 1481272..46ba9d5 100644 Binary files a/Content/Materials/SkyMaterial.flax and b/Content/Materials/SkyMaterial.flax differ diff --git a/Content/Materials/ViewModelMaterial.flax b/Content/Materials/ViewModelMaterial.flax index fa8cf2b..66db88e 100644 Binary files a/Content/Materials/ViewModelMaterial.flax and b/Content/Materials/ViewModelMaterial.flax differ diff --git a/Content/Materials/WeaponMaterial.flax b/Content/Materials/WeaponMaterial.flax index 50df83c..efaaf6c 100644 Binary files a/Content/Materials/WeaponMaterial.flax and b/Content/Materials/WeaponMaterial.flax differ diff --git a/Content/Materials/dev/dev_128_gray.flax b/Content/Materials/dev/dev_128_gray.flax index c00d883..dcd1f27 100644 Binary files a/Content/Materials/dev/dev_128_gray.flax and b/Content/Materials/dev/dev_128_gray.flax differ diff --git a/Content/Materials/dev/dev_128_green.flax b/Content/Materials/dev/dev_128_green.flax index d866e11..9f10ebf 100644 Binary files a/Content/Materials/dev/dev_128_green.flax and b/Content/Materials/dev/dev_128_green.flax differ diff --git a/Content/Materials/interface/crosshairs/cross.flax b/Content/Materials/interface/crosshairs/cross.flax index 2bf73be..5a10466 100644 Binary files a/Content/Materials/interface/crosshairs/cross.flax and b/Content/Materials/interface/crosshairs/cross.flax differ diff --git a/Content/Materials/missing.flax b/Content/Materials/missing.flax index cacfde0..75850b8 100644 Binary files a/Content/Materials/missing.flax and b/Content/Materials/missing.flax differ diff --git a/Content/GameplayGlobals.flax b/Content/Settings/GameSettings/GameplayGlobals.flax similarity index 56% rename from Content/GameplayGlobals.flax rename to Content/Settings/GameSettings/GameplayGlobals.flax index c57f570..fca84a5 100644 Binary files a/Content/GameplayGlobals.flax and b/Content/Settings/GameSettings/GameplayGlobals.flax differ diff --git a/Content/config.cfg b/Content/config.cfg new file mode 100644 index 0000000..ef15ab6 --- /dev/null +++ b/Content/config.cfg @@ -0,0 +1,2 @@ +// comment +r_lighting 0 diff --git a/Source/Game/AudioManager.cs b/Source/Game/AudioManager.cs index f741399..c253434 100644 --- a/Source/Game/AudioManager.cs +++ b/Source/Game/AudioManager.cs @@ -220,8 +220,7 @@ namespace Game AudioInfo audio = new AudioInfo(); - string workDir = Directory.GetCurrentDirectory(); - string audioBasePath = Path.Combine(workDir, "Content", "Audio"); + string audioBasePath = Path.Combine(AssetManager.ContentPath, "Audio"); AudioClip audioClip = Content.Load(Path.Combine(audioBasePath, soundName + ".flax")); if (audioClip != null) { diff --git a/Source/Game/Console/Config.cs b/Source/Game/Console/Config.cs new file mode 100644 index 0000000..eab236c --- /dev/null +++ b/Source/Game/Console/Config.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace Game +{ + public class Config + { + private Dictionary dictionary = new Dictionary(); + + public Config() + { + } + + public string this[string key] + { + get => dictionary[key]; + set => dictionary[key] = value; + } + + public string[] GetLines() + { + string[] lines = new string[dictionary.Count]; + int lineIndex = 0; + foreach (var kvp in dictionary) + { + lines[lineIndex] = $"{kvp.Key} {kvp.Value}"; + lineIndex++; + } + + return lines; + } + } +} \ No newline at end of file diff --git a/Source/Game/Console/ConfigParser.cs b/Source/Game/Console/ConfigParser.cs new file mode 100644 index 0000000..b77d99d --- /dev/null +++ b/Source/Game/Console/ConfigParser.cs @@ -0,0 +1,39 @@ +using System.IO; + +namespace Game +{ + public class ConfigParser + { + private ConfigParser() + { + + } + + public static Config ParseFile(string path) + { + Config config = new Config(); + using FileStream file = File.OpenRead(path); + using StreamReader sr = new StreamReader(file); + + string line; + while ((line = sr.ReadLine()?.Trim()) != null) + { + if (line.StartsWith(@"//")) + continue; + + int spacePos = line.IndexOf(' '); + if (spacePos == -1) + continue; + + string key = line.Substring(0, spacePos); + string value = line.Substring(spacePos+1); + + value = value.Trim('"'); + + config[key] = value; + } + + return config; + } + } +} \ No newline at end of file diff --git a/Source/Game/Console/Console.cs b/Source/Game/Console/Console.cs index 6879961..a67b8bc 100644 --- a/Source/Game/Console/Console.cs +++ b/Source/Game/Console/Console.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; using FlaxEditor; +using FlaxEngine; namespace Game { @@ -89,6 +90,12 @@ namespace Game ScriptsBuilder.ScriptsReload += Destroy; Editor.Instance.PlayModeEnd += OnEditorPlayModeChanged; #endif + + AssetManager.Init(); // TODO: move these elsewhere + AssetManager.Globals.ResetValues(); + + foreach (var line in AssetManager.Config.GetLines()) + Console.Execute(line, false, true); } public static void Destroy() @@ -108,6 +115,7 @@ namespace Game #if FLAX_EDITOR private static void OnEditorPlayModeChanged() { + //AssetManager.Globals.ResetValues(); // Clear console buffer when leaving play mode if (instance != null) Clear(); @@ -173,9 +181,9 @@ namespace Game instance.Clear(); } - public static void Execute(string str, bool bufferInput = false) + public static void Execute(string str, bool bufferInput = false, bool noOutput = false) { - instance.Execute(str, bufferInput); + instance.Execute(str, bufferInput, noOutput); } public static string GetVariable(string variableName) @@ -455,14 +463,14 @@ namespace Game consoleLines.Clear(); } - public void Execute(string str, bool bufferInput = false) + public void Execute(string str, bool bufferInput = false, bool noOutput = false) { if (bufferInput) consoleBufferHistory.Insert(0, str); str = str.Trim(); - if (ShowExecutedLines) + if (ShowExecutedLines && !noOutput) Console.Print(LinePrefix + str); string[] strs = str.Split(' '); @@ -488,7 +496,8 @@ namespace Game if (value != null) cvar.SetValue(value); - Console.Print("'" + execute + "' is '" + cvar.GetValueString() + "'"); + //if (!noOutput) + Console.Print("'" + execute + "' is '" + cvar.GetValueString() + "'"); } else { diff --git a/Source/Game/Console/EngineSubsystem.cs b/Source/Game/Console/EngineSubsystem.cs index b6d872c..8474b20 100644 --- a/Source/Game/Console/EngineSubsystem.cs +++ b/Source/Game/Console/EngineSubsystem.cs @@ -195,29 +195,17 @@ namespace Game { get { - string workDir = Directory.GetCurrentDirectory(); - string matBasePath = Path.Combine(workDir, "Content"); - string assetPath = Path.Combine(matBasePath, "GameplayGlobals.flax"); - - GameplayGlobals globals = Content.Load(assetPath); - - return ((bool)globals.GetValue("Scene Lighting") ? "1" : "0"); + return ((bool)AssetManager.Globals.GetValue("Scene Lighting") ? "1" : "0"); } set { - string workDir = Directory.GetCurrentDirectory(); - string matBasePath = Path.Combine(workDir, "Content"); - string assetPath = Path.Combine(matBasePath, "GameplayGlobals.flax"); - - GameplayGlobals globals = Content.Load(assetPath); - bool boolValue = false; if (int.TryParse(value, out int intValue)) boolValue = intValue != 0; else if (float.TryParse(value, out float valueFloat)) boolValue = valueFloat != 0f; - globals.SetValue("Scene Lighting", boolValue); + AssetManager.Globals.SetValue("Scene Lighting", boolValue); PostFxVolume postFx = Level.FindActor(); @@ -234,10 +222,26 @@ namespace Game } // TODO: disable GI + Graphics.EnableGlobalSDF = boolValue; + } + } - Light[] lights = Level.GetActors(); - foreach (Light light in lights) - light.IsActive = boolValue; + [ConsoleVariable("r_shadows")] + public static string SceneShadows + { + get + { + return ((bool)AssetManager.Globals.GetValue("Scene Shadows") ? "1" : "0"); + } + set + { + bool boolValue = false; + if (int.TryParse(value, out int intValue)) + boolValue = intValue != 0; + else if (float.TryParse(value, out float valueFloat)) + boolValue = valueFloat != 0f; + + AssetManager.Globals.SetValue("Scene Shadows", boolValue); } } diff --git a/Source/Game/GameMode/GameModeManager.cs b/Source/Game/GameMode/GameModeManager.cs index 2e57203..a2e858f 100644 --- a/Source/Game/GameMode/GameModeManager.cs +++ b/Source/Game/GameMode/GameModeManager.cs @@ -384,8 +384,7 @@ namespace Game spawned = true; - string workDir = Directory.GetCurrentDirectory(); - string prefabPath = Path.Combine(workDir, "Content", "Common"); + string prefabPath = Path.Combine(AssetManager.ContentPath, "Common"); var playerPrefab = Content.Load(Path.Combine(prefabPath, "PlayerPrefab.prefab")); if (playerPrefab == null) Console.PrintError("GameModeManager: Failed to find PlayerPrefab"); diff --git a/Source/Game/Level/Q3MapImporter.cs b/Source/Game/Level/Q3MapImporter.cs index 16c3d93..e822b25 100644 --- a/Source/Game/Level/Q3MapImporter.cs +++ b/Source/Game/Level/Q3MapImporter.cs @@ -49,6 +49,7 @@ namespace Game private Model model; private MaterialBase missingMaterial; + private bool resetLights = false; private bool dirtyLights = false; private float brightnessMultiplier_ = 0.82f; @@ -62,28 +63,28 @@ namespace Game public float BrightnessMultiplier { get => brightnessMultiplier_; - set { brightnessMultiplier_ = value; dirtyLights = true; } + set { brightnessMultiplier_ = value; resetLights = true; } } [Range(0.1f, 40f)] public float LightRadiusMultiplier { get => lightRadiusMultiplier_; - set { lightRadiusMultiplier_ = value; dirtyLights = true; } + set { lightRadiusMultiplier_ = value; resetLights = true; } } [Range(2f, 8f)] public float FallOffExponent { get => fallOffExponent_; - set { fallOffExponent_ = value; dirtyLights = true; } + set { fallOffExponent_ = value; resetLights = true; } } [Range(0.01f, 1f)] public float SaturationMultiplier { get => saturationMultiplier_; - set { saturationMultiplier_ = value; dirtyLights = true; } + set { saturationMultiplier_ = value; resetLights = true; } } @@ -249,6 +250,7 @@ namespace Game { if (worldSpawnActor != null) worldSpawnActor.HideFlags |= HideFlags.DontSave; + dirtyLights = true; } catch (Exception e) { @@ -274,9 +276,24 @@ namespace Game LoadMap(false); } + private bool lastSceneLighting = false; + private bool lastSceneShadows = false; public override void OnUpdate() { - if (dirtyLights) + bool sceneLighting = EngineSubsystem.SceneLighting == "1"; + if (lastSceneLighting != sceneLighting) + { + lastSceneLighting = sceneLighting; + dirtyLights = true; + } + bool sceneShadows = EngineSubsystem.SceneShadows == "1"; + if (lastSceneShadows != sceneShadows) + { + lastSceneShadows = sceneShadows; + dirtyLights = true; + } + + if (resetLights) { if (worldSpawnActor == null || !worldSpawnActor || root == null) return; @@ -297,6 +314,18 @@ namespace Game // break; } + resetLights = false; + } + + if (dirtyLights) + { + foreach (var light in worldSpawnActor.GetChildren()) + { + light.IsActive = sceneLighting; + if (light is PointLight pointLight) + pointLight.ShadowsStrength = sceneShadows ? 1.0f : 0.0f; + } + dirtyLights = false; } } @@ -314,7 +343,7 @@ namespace Game else { FlaxEngine.Debug.Log("Map already loaded in the scene"); - dirtyLights = false; + resetLights = false; return; } } @@ -322,8 +351,7 @@ namespace Game FlaxEngine.Debug.Log("Loading map"); { - string workDir = Directory.GetCurrentDirectory(); - string matBasePath = Path.Combine(workDir, "Content", "Materials"); + string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials"); string assetPath = Path.Combine(matBasePath, "missing.flax"); missingMaterial = Content.Load(assetPath); } @@ -395,8 +423,7 @@ namespace Game if (!materials.TryGetValue(textureName, out MaterialBase brushMaterial)) { - string workDir = Directory.GetCurrentDirectory(); - string matBasePath = Path.Combine(workDir, "Content", "Materials"); + string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials"); string assetPath = Path.Combine(matBasePath, textureName + ".flax"); brushMaterial = Content.Load(assetPath); if (brushMaterial != null) @@ -768,8 +795,7 @@ namespace Game childModel.Model = model; //childModel.SetMaterial(0, missingMaterial); - string workDir = Directory.GetCurrentDirectory(); - string matBasePath = Path.Combine(workDir, "Content", "Materials"); + string matBasePath = Path.Combine(AssetManager.ContentPath, "Materials"); string assetPath = Path.Combine(matBasePath, "dev/dev_128_gray" + ".flax"); var brushMaterial = Content.Load(assetPath); if (brushMaterial != null) diff --git a/Source/Game/Utility/AssetManager.cs b/Source/Game/Utility/AssetManager.cs new file mode 100644 index 0000000..33229d2 --- /dev/null +++ b/Source/Game/Utility/AssetManager.cs @@ -0,0 +1,20 @@ +using System.IO; +using FlaxEngine; + +namespace Game +{ + public static class AssetManager + { + public static string ContentPath { get; private set; } = + Path.Combine(Directory.GetCurrentDirectory(), "Content"); + + public static GameplayGlobals Globals { get; private set; } + public static Config Config { get; private set; } + + public static void Init() + { + Globals = Content.Load(Path.Combine(ContentPath, "Settings", "GameSettings", "GameplayGlobals.flax")); + Config = ConfigParser.ParseFile(Path.Combine(ContentPath, "config.cfg")); + } + } +} \ No newline at end of file