Skip to content

Commit

Permalink
perf
Browse files Browse the repository at this point in the history
  • Loading branch information
LeZi9916 committed Jan 20, 2025
1 parent e4fc362 commit ad93eb1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 57 deletions.
59 changes: 14 additions & 45 deletions Assets/Script/DontDestroy/Managers/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class GameManager : MonoBehaviour
public GameSetting Setting
{
get => MajInstances.Setting;
set => MajInstances.Setting = value;
}
/// <summary>
/// Current difficult
Expand All @@ -39,9 +38,6 @@ public ChartLevel SelectedDiff
private ChartLevel _selectedDiff = ChartLevel.Easy;
public int LastSettingPage { get; set; } = 0;

//public bool isDanMode = false;
//public int DanHP = 500;
//public List<GameResult> DanResults = new();

readonly static CancellationTokenSource _globalCTS;
[SerializeField]
Expand Down Expand Up @@ -69,37 +65,23 @@ void Awake()
_timer = MajTimeline.Timer;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
DontDestroyOnLoad(this);
ApplyScreenConfig();

if (File.Exists(MajEnv.SettingPath))
{
var js = File.ReadAllText(MajEnv.SettingPath);
GameSetting? setting;

if (!Serializer.Json.TryDeserialize(js, out setting, MajEnv.UserJsonReaderOption) || setting is null)
{
Setting = new();
MajDebug.LogError("Failed to read setting from file");
}
else
{
Setting = setting;
//Reset Mod option after reboot
Setting.Mod = new ModOptions();
}
}
else
var thiss = Process.GetCurrentProcess();
thiss.PriorityClass = ProcessPriorityClass.RealTime;
var availableLangs = Localization.Available;
if (availableLangs.IsEmpty())
return;
var lang = availableLangs.Find(x => x.ToString() == Setting.Game.Language);
if (lang is null)
{
Setting = new GameSetting();
Save();
lang = availableLangs.First();
Setting.Game.Language = lang.ToString();
}
MajInstances.Setting = Setting;
Setting.Misc.InputDevice.ButtonRing.PollingRateMs = Math.Max(0, Setting.Misc.InputDevice.ButtonRing.PollingRateMs);
Setting.Misc.InputDevice.TouchPanel.PollingRateMs = Math.Max(0, Setting.Misc.InputDevice.TouchPanel.PollingRateMs);
Setting.Misc.InputDevice.ButtonRing.DebounceThresholdMs = Math.Max(0, Setting.Misc.InputDevice.ButtonRing.DebounceThresholdMs);
Setting.Misc.InputDevice.TouchPanel.DebounceThresholdMs = Math.Max(0, Setting.Misc.InputDevice.TouchPanel.DebounceThresholdMs);
Setting.Display.InnerJudgeDistance = Setting.Display.InnerJudgeDistance.Clamp(0, 1);
Setting.Display.OuterJudgeDistance = Setting.Display.OuterJudgeDistance.Clamp(0, 1);

Localization.Current = lang;
}
void ApplyScreenConfig()
{
var fullScreen = Setting.Debug.FullScreen;
Screen.fullScreen = fullScreen;

Expand All @@ -116,19 +98,6 @@ void Awake()
Screen.SetResolution(width, height, fullScreen);
}
Application.targetFrameRate = Setting.Display.TargetFPS;

var thiss = Process.GetCurrentProcess();
thiss.PriorityClass = ProcessPriorityClass.RealTime;
var availableLangs = Localization.Available;
if (availableLangs.IsEmpty())
return;
var lang = availableLangs.Find(x => x.ToString() == Setting.Game.Language);
if (lang is null)
{
lang = availableLangs.First();
Setting.Game.Language = lang.ToString();
}
Localization.Current = lang;
}
void Start()
{
Expand Down
11 changes: 1 addition & 10 deletions Assets/Script/DontDestroy/Managers/SkinManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ private void Awake()
{
DontDestroyOnLoad(this);
MajInstances.SkinManager = this;
}

// Start is called before the first frame update
private void Start()
{
var path = MajEnv.SkinPath;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);

var selectedSkinName = MajInstances.Setting.Display.Skin;
var dicts = Directory.GetDirectories(path);

Expand All @@ -47,10 +40,8 @@ private void Start()
targetSkin = new CustomSkin(Path.Combine(path, selectedSkinName));

SelectedSkin = targetSkin;

print(path);
MajDebug.Log(test);
}

public JudgeTextSkin GetJudgeTextSkin()
{
return new()
Expand Down
56 changes: 54 additions & 2 deletions Assets/Script/Utils/MajEnv.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MajdataPlay.Types;
using MajdataPlay.Extensions;
using MajdataPlay.Types;
using MychIO;
using System;
using System.Collections.Concurrent;
Expand All @@ -11,7 +12,7 @@
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;

#nullable enable
namespace MajdataPlay.Utils
{
public static class MajEnv
Expand Down Expand Up @@ -40,5 +41,56 @@ public static class MajEnv
ReadCommentHandling = JsonCommentHandling.Skip,
WriteIndented = true
};

static MajEnv()
{
CheckAndLoadUserSetting();
CheckNoteSkinFolder();

if(!Directory.Exists(CachePath))
Directory.CreateDirectory(CachePath);

if (!Directory.Exists(ChartPath))
Directory.CreateDirectory(ChartPath);
}
static void CheckAndLoadUserSetting()
{
if (File.Exists(SettingPath))
{
var js = File.ReadAllText(SettingPath);
GameSetting? setting;

if (!Serializer.Json.TryDeserialize(js, out setting, UserJsonReaderOption) || setting is null)
{
MajInstances.Setting = new();
MajDebug.LogError("Failed to read setting from file");
}
else
{
MajInstances.Setting = setting;
//Reset Mod option after reboot
MajInstances.Setting.Mod = new ModOptions();
}
}
else
{
MajInstances.Setting = new GameSetting();

var json = Serializer.Json.Serialize(UserSetting, UserJsonReaderOption);
File.WriteAllText(SettingPath, json);
}

UserSetting.Misc.InputDevice.ButtonRing.PollingRateMs = Math.Max(0, UserSetting.Misc.InputDevice.ButtonRing.PollingRateMs);
UserSetting.Misc.InputDevice.TouchPanel.PollingRateMs = Math.Max(0, UserSetting.Misc.InputDevice.TouchPanel.PollingRateMs);
UserSetting.Misc.InputDevice.ButtonRing.DebounceThresholdMs = Math.Max(0, UserSetting.Misc.InputDevice.ButtonRing.DebounceThresholdMs);
UserSetting.Misc.InputDevice.TouchPanel.DebounceThresholdMs = Math.Max(0, UserSetting.Misc.InputDevice.TouchPanel.DebounceThresholdMs);
UserSetting.Display.InnerJudgeDistance = UserSetting.Display.InnerJudgeDistance.Clamp(0, 1);
UserSetting.Display.OuterJudgeDistance = UserSetting.Display.OuterJudgeDistance.Clamp(0, 1);
}
static void CheckNoteSkinFolder()
{
if (!Directory.Exists(SkinPath))
Directory.CreateDirectory(SkinPath);
}
}
}

0 comments on commit ad93eb1

Please sign in to comment.