summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XGame.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/XGame.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XGame.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/XGame.cs615
1 files changed, 615 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/XGame.cs b/Client/Assets/Scripts/XMainClient/XGame.cs
new file mode 100644
index 00000000..cd375fcf
--- /dev/null
+++ b/Client/Assets/Scripts/XMainClient/XGame.cs
@@ -0,0 +1,615 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+using KKSG;
+using ProtoBuf;
+using UnityEngine;
+using XMainClient.UI;
+using XMainClient.UI.UICommon;
+using XUpdater;
+using XUtliPoolLib;
+
+namespace XMainClient
+{
+ public class XGame : XSingleton<XGame>
+ {
+ public bool IsGMAccount
+ {
+ get
+ {
+ return this._isgmaccount;
+ }
+ set
+ {
+ this._isgmaccount = value;
+ }
+ }
+
+ public bool ShowBuildLog
+ {
+ get
+ {
+ return this._show_build_log;
+ }
+ set
+ {
+ this._show_build_log = value;
+ }
+ }
+
+ public ulong PlayerID
+ {
+ get
+ {
+ return this._player_id;
+ }
+ set
+ {
+ this._player_id = value;
+ }
+ }
+
+ public bool CalcFps
+ {
+ get
+ {
+ return this._calc_fps;
+ }
+ }
+
+ public float Fps
+ {
+ get
+ {
+ return this._fps;
+ }
+ }
+
+ public float FpsAvg
+ {
+ get
+ {
+ return this._fpsAvg;
+ }
+ }
+
+ public XStage CurrentStage
+ {
+ get
+ {
+ return this._stage;
+ }
+ }
+
+ public bool StageReady
+ {
+ get
+ {
+ return this._stage != null && this._stage.IsEntered;
+ }
+ }
+
+ internal XDocuments Doc
+ {
+ get
+ {
+ return this._doc;
+ }
+ }
+
+ public int SyncModeValue
+ {
+ get
+ {
+ return this._nSyncMode;
+ }
+ set
+ {
+ this._nSyncMode = value;
+ Physics.IgnoreLayerCollision(10, 10, this.SyncMode);
+ Physics.IgnoreLayerCollision(21, 13, this.SyncMode);
+ }
+ }
+
+ public bool SyncMode
+ {
+ get
+ {
+ return this._nSyncMode == 1;
+ }
+ }
+
+ public static int RoleCount;
+
+ private XStage _stage = null;
+
+ private XStage _old_stage = null;
+
+ private List<XBaseSingleton> _singletons = null;
+
+ private XDocuments _doc = null;
+
+ private int _nSyncMode = 0;
+
+ private bool _show_build_log = true;
+
+ private int _fps_count = 0;
+
+ private float _fps = (float)XShell.TargetFrame;
+
+ private float _fpsAvg = (float)XShell.TargetFrame;
+
+ private float _fps_interval = 0.16667f;
+
+ private bool _calc_fps = true;
+
+ private float _fps_real_time = 0f;
+
+ private int _fpsCalcCount = 0;
+
+ private float _fpsAcc = 0f;
+
+ private bool _isgmaccount = false;
+
+ private ulong _player_id = 0UL;
+
+ private int _millisecondsToWait = 0;
+
+ private float _lastExitClickTime = 0f;
+
+ private XTimerMgr.ElapsedEventHandler _fpsHandler = null;
+
+ private XTimerMgr.ElapsedEventHandler _innerSwitchCb = null;
+
+ public bool notLoadScene = true;
+
+ public bool networkRun = true;
+
+ public bool switchScene = false;
+
+ public static bool EditorMode = false;
+
+ public XGame()
+ {
+ this._singletons = new List<XBaseSingleton>();
+ this._singletons.Add(XSingleton<BufferPoolMgr>.singleton);
+ this._singletons.Add(XSingleton<ScriptCode>.singleton);
+ XSingleton<XStringTable>.singleton.Uninit();
+ this._singletons.Add(XSingleton<XStringTable>.singleton);
+ this._singletons.Add(XSingleton<XInput>.singleton);
+ this._singletons.Add(XSingleton<XServerTimeMgr>.singleton);
+ this._singletons.Add(XSingleton<XGlobalConfig>.singleton);
+ this._singletons.Add(XSingleton<XGameUI>.singleton);
+ this._singletons.Add(XSingleton<XSceneMgr>.singleton);
+ this._singletons.Add(XSingleton<XBuffTemplateManager>.singleton);
+ this._singletons.Add(XSingleton<XAudioMgr>.singleton);
+ this._singletons.Add(XSingleton<XSkillEffectMgr>.singleton);
+ this._singletons.Add(XSingleton<XPostEffectMgr>.singleton);
+ this._singletons.Add(XSingleton<XLevelFinishMgr>.singleton);
+ this._singletons.Add(XSingleton<XCombat>.singleton);
+ this._singletons.Add(XSingleton<XProfessionSkillMgr>.singleton);
+ this._singletons.Add(XSingleton<XGameSysMgr>.singleton);
+ this._singletons.Add(XSingleton<XOperationRecord>.singleton);
+ this._singletons.Add(XSingleton<XLevelDoodadMgr>.singleton);
+ this._singletons.Add(XSingleton<XTutorialMgr>.singleton);
+ this._singletons.Add(XSingleton<XEntityMgr>.singleton);
+ this._singletons.Add(XSingleton<XScene>.singleton);
+ this._singletons.Add(XSingleton<XForbidWordMgr>.singleton);
+ this._singletons.Add(XSingleton<XSkillFactory>.singleton);
+ this._singletons.Add(XSingleton<XCutScene>.singleton);
+ this._singletons.Add(XSingleton<XBulletMgr>.singleton);
+ this._singletons.Add(XSingleton<XAttributeMgr>.singleton);
+ this._singletons.Add(XSingleton<XEventMgr>.singleton);
+ this._singletons.Add(XSingleton<XPowerPointCalculator>.singleton);
+ this._singletons.Add(XSingleton<UIManager>.singleton);
+ this._singletons.Add(XSingleton<XLevelSpawnMgr>.singleton);
+ this._fpsHandler = new XTimerMgr.ElapsedEventHandler(this.CalculateFPS);
+ this._innerSwitchCb = new XTimerMgr.ElapsedEventHandler(this.InnerSwitch);
+ this._doc = new XDocuments();
+ }
+
+ public IEnumerator Awake()
+ {
+ XLinkTimeStamp.FetchBuildDateTime();
+ this.TriggerFps();
+ PtcRegister.RegistProtocol();
+ XSingleton<XResourceLoaderMgr>.singleton.LoadServerCurve("Table/Curve");
+ XSingleton<XClientNetwork>.singleton.Initialize();
+ CVSReader.Init();
+ int i = 0;
+ int num;
+ for (i = 0; i < this._singletons.Count; i = num + 1)
+ {
+ int tryCount = 0;
+ while (!this._singletons[i].Init())
+ {
+ num = tryCount;
+ tryCount = num + 1;
+ bool flag = tryCount % 1000 == 0;
+ if (flag)
+ {
+ Thread.Sleep(1);
+ }
+ }
+ num = i;
+ }
+ GC.Collect();
+ i = 0;
+ XBagDocument.Execute(new OnLoadedCallback(XBagDocument.OnTableLoaded));
+ while (!XBagDocument.AsyncLoader.IsDone)
+ {
+ num = i + 1;
+ i = num;
+ bool flag2 = num % 1000 == 0;
+ if (flag2)
+ {
+ Thread.Sleep(1);
+ }
+ }
+ this._doc.CtorLoad();
+ this._doc.Initilize(0);
+ Serializer.SetMultiThread(XSingleton<XGlobalConfig>.singleton.GetSettingEnum(ESettingConfig.EMultiThreadProtoBuf));
+ Serializer.SetSkipProtoIgnore(XSingleton<XGlobalConfig>.singleton.GetSettingEnum(ESettingConfig.ESkipProtoIgnore));
+ XAutoFade.MakeBlack(true);
+ XOptionsDocument optDoc = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
+ bool flag3 = optDoc != null;
+ if (flag3)
+ {
+ int value = optDoc.GetValue(XOptionsDefine.OD_SMOOTH);
+ XSingleton<XGameUI>.singleton.SetUIOptOption(false, value == 1, false, false);
+ }
+ bool settingEnum = XSingleton<XGlobalConfig>.singleton.GetSettingEnum(ESettingConfig.EApm);
+ if (settingEnum)
+ {
+ XSingleton<XUpdater.XUpdater>.singleton.XPlatform.InitApm();
+ }
+ XResourceLoaderMgr.UseCurveTable = XSingleton<XGlobalConfig>.singleton.GetSettingEnum(ESettingConfig.ELoadCurveTable);
+ XSingleton<XResourceLoaderMgr>.singleton.DelayLoad = XSingleton<XGlobalConfig>.singleton.GetSettingEnum(ESettingConfig.EDelayLoad);
+ XFxMgr.FilterFarFx = XSingleton<XGlobalConfig>.singleton.GetSettingEnum(ESettingConfig.EFilterFarFx);
+ yield return null;
+ yield break;
+ }
+
+ public override bool Init()
+ {
+ XQualitySetting.InitResolution();
+ bool flag = (int)Application.platform == 7 || (int)Application.platform == 0|| (int)Application.platform == 2;
+ if (flag)
+ {
+ Application.targetFrameRate = 60;
+ }
+ else
+ {
+ Application.targetFrameRate = XShell.TargetFrame;
+ }
+ XAutoFade.FadeIn(0f, true);
+ this.SwitchTo(EXStage.Login, 3u);
+ return true;
+ }
+
+ public override void Uninit()
+ {
+ this.SwitchTo(EXStage.Null, 0u);
+ this._doc.Uninitilize();
+ for (int i = this._singletons.Count - 1; i >= 0; i--)
+ {
+ this._singletons[i].Uninit();
+ }
+ XSingleton<XClientNetwork>.singleton.Close(NetErrCode.Net_NoError);
+ XSingleton<XInterfaceMgr>.singleton.Uninit();
+ INativePlugin nativePlugin = XSingleton<XUpdater.XUpdater>.singleton.XPlatform.GetNativePlugin();
+ bool flag = nativePlugin != null;
+ if (flag)
+ {
+ nativePlugin.CloseHooks();
+ }
+ }
+
+ public void UpdateNetwork()
+ {
+ bool flag = this.networkRun;
+ if (flag)
+ {
+ XSingleton<XClientNetwork>.singleton.Update();
+ }
+ }
+
+ public void PreUpdate(float fDeltaT)
+ {
+ bool flag = this.StageReady && this.notLoadScene;
+ if (flag)
+ {
+ XSingleton<XInput>.singleton.Update();
+ this._stage.PreUpdate(fDeltaT);
+ }
+ }
+
+ public void Update(float fDeltaT)
+ {
+ bool flag = this.StageReady && this.notLoadScene;
+ if (flag)
+ {
+ this._stage.Update(fDeltaT);
+ this._doc.Update(fDeltaT);
+ XSingleton<UIManager>.singleton.Update(fDeltaT);
+ }
+ bool calc_fps = this._calc_fps;
+ if (calc_fps)
+ {
+ this._fps_count++;
+ }
+ bool key = Input.GetKey((KeyCode)284);
+ if (key)
+ {
+ XSingleton<X3DTouchMgr>.singleton.OnProcess3DTouch("");
+ }
+ }
+
+ private void CheckExit()
+ {
+ bool keyDown = Input.GetKeyDown((KeyCode)27);
+ if (keyDown)
+ {
+ bool flag = Time.time - this._lastExitClickTime < float.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("DoubleClickExitTime"));
+ if (flag)
+ {
+ Application.Quit();
+ }
+ XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("EXIT_GAME_TIP"), "fece00");
+ this._lastExitClickTime = Time.time;
+ }
+ }
+
+ public void PostUpdate(float fDeltaT)
+ {
+ bool flag = this.StageReady && this.notLoadScene;
+ if (flag)
+ {
+ this._stage.PostUpdate(fDeltaT);
+ this._doc.PostUpdate(fDeltaT);
+ XSingleton<UIManager>.singleton.PostUpdate(fDeltaT);
+ }
+ }
+
+ public void SwitchTo(EXStage eStage, uint sceneID)
+ {
+ bool flag = sceneID == XSingleton<XScene>.singleton.SceneID && this.CurrentStage.Stage == eStage && sceneID != 3u && XSingleton<XScene>.singleton.SceneType != SceneType.SCENE_TOWER;
+ if (flag)
+ {
+ XSingleton<XDebug>.singleton.AddLog("switch to the same scene id ", sceneID.ToString(), " with same stage.", null, null, null, XDebugColor.XDebug_None);
+ }
+ bool flag2 = eStage == EXStage.Null || sceneID == 0u;
+ if (flag2)
+ {
+ this._old_stage = this._stage;
+ this._old_stage.OnLeaveStage(EXStage.Null);
+ this._old_stage.OnLeaveScene(false);
+ XSingleton<XScene>.singleton.OnLeaveScene(false);
+ this._old_stage = null;
+ }
+ else
+ {
+ int num = XFastEnumIntEqualityComparer<EXStage>.ToInt(eStage);
+ uint num2 = (uint)(num << 24 | (int)sceneID);
+ bool flag3 = this._stage == null || sceneID != XSingleton<XScene>.singleton.SceneID || XSingleton<XSceneMgr>.singleton.GetSceneSwitchToSelf(sceneID);
+ if (flag3)
+ {
+ XSingleton<XScene>.singleton.UntriggerScene();
+ }
+ bool flag4 = (eStage == EXStage.World || eStage == EXStage.Hall) && XSingleton<XScene>.singleton.TurnToTransfer(sceneID);
+ if (flag4)
+ {
+ XAutoFade.FadeOut(0.5f);
+ XSingleton<XTimerMgr>.singleton.SetTimer(1f, this._innerSwitchCb, num2 | 2147483648u);
+ }
+ else
+ {
+ float sceneDelayTransfer = XSingleton<XSceneMgr>.singleton.GetSceneDelayTransfer(sceneID);
+ bool flag5 = sceneDelayTransfer > 0f;
+ if (flag5)
+ {
+ XAutoFade.FadeOut(sceneDelayTransfer);
+ XSingleton<XTimerMgr>.singleton.SetTimer(sceneDelayTransfer + 0.03f, this._innerSwitchCb, num2);
+ }
+ else
+ {
+ this.InnerSwitch(num2);
+ }
+ }
+ }
+ }
+
+ public XStage CreateSpecifiecStage(EXStage eStage)
+ {
+ XStage result;
+ switch (eStage)
+ {
+ case EXStage.Login:
+ result = XStage.CreateSpecificStage<XLoginStage>();
+ break;
+ case EXStage.SelectChar:
+ result = XStage.CreateSpecificStage<XSelectcharStage>();
+ break;
+ case EXStage.World:
+ result = XStage.CreateSpecificStage<XWorldStage>();
+ break;
+ case EXStage.Hall:
+ result = XStage.CreateSpecificStage<XHallStage>();
+ break;
+ default:
+ result = null;
+ break;
+ }
+ return result;
+ }
+
+ public void TriggerFps()
+ {
+ bool calc_fps = this._calc_fps;
+ if (calc_fps)
+ {
+ XSingleton<XTimerMgr>.singleton.SetGlobalTimer(this._fps_interval, this._fpsHandler, null);
+ }
+ }
+
+ private void InnerSwitch(object o)
+ {
+ this.switchScene = true;
+ uint num = (uint)o;
+ bool flag = num >> 31 > 0u;
+ uint num2 = num & 16777215u;
+ EXStage exstage = (EXStage)(num >> 24 & 127u);
+ bool flag2 = flag;
+ if (flag2)
+ {
+ XAutoFade.MakeBlack(false);
+ }
+ bool flag3 = XSingleton<XScene>.singleton.SceneID == 100u;
+ if (flag3)
+ {
+ XAutoFade.FadeIn(0.2f, false);
+ }
+ this._old_stage = this._stage;
+ this._stage = ((this._old_stage != null && exstage == this._old_stage.Stage) ? this._old_stage : this.CreateSpecifiecStage(exstage));
+ bool flag4 = this._old_stage != null;
+ if (flag4)
+ {
+ this._old_stage.OnLeaveStage(this._stage.Stage);
+ bool flag5 = num2 != XSingleton<XScene>.singleton.SceneID || XSingleton<XSceneMgr>.singleton.GetSceneSwitchToSelf(num2);
+ if (flag5)
+ {
+ XSingleton<XGameUI>.singleton.m_uiTool.EnableUILoadingUpdate(false);
+ this._old_stage.OnLeaveScene(flag);
+ bool flag6 = XSingleton<XScene>.singleton.SceneID > 0u;
+ if (flag6)
+ {
+ XSingleton<XScene>.singleton.OnLeaveScene(flag);
+ }
+ XSingleton<XScene>.singleton.LoadSceneAsync(num2, exstage, !flag, flag);
+ }
+ else
+ {
+ this.OnEnterStage();
+ this.switchScene = false;
+ }
+ }
+ else
+ {
+ XSingleton<XScene>.singleton.LoadSceneAsync(num2, exstage, true, false);
+ }
+ }
+
+ private void LockFps(int goal)
+ {
+ float num = 1f / (float)goal - Time.smoothDeltaTime;
+ bool flag = num > 0f;
+ if (flag)
+ {
+ this._millisecondsToWait++;
+ }
+ else
+ {
+ this._millisecondsToWait--;
+ }
+ Thread.Sleep((int)Mathf.Clamp((float)this._millisecondsToWait, 0f, 1f / (float)goal * 1000f));
+ }
+
+ private void CalculateFPS(object o)
+ {
+ float realtimeSinceStartup = Time.realtimeSinceStartup;
+ this._fps = (float)this._fps_count / (realtimeSinceStartup - this._fps_real_time);
+ this._fpsCalcCount++;
+ this._fpsAcc += this._fps;
+ bool flag = this._fpsCalcCount >= 20;
+ if (flag)
+ {
+ this._fpsAvg = this._fpsAcc / (float)this._fpsCalcCount;
+ this._fpsCalcCount = 0;
+ this._fpsAcc = 0f;
+ }
+ bool flag2 = DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc != null;
+ if (flag2)
+ {
+ bool flag3 = DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.GetFpsState == XMainInterfaceDocument.GetFps.start;
+ if (flag3)
+ {
+ DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.FpsStartTime = realtimeSinceStartup;
+ DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.PeakFps = this._fps;
+ DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.FpsCount = this._fps_count;
+ DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.GetFpsState = XMainInterfaceDocument.GetFps.running;
+ }
+ else
+ {
+ bool flag4 = DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.GetFpsState == XMainInterfaceDocument.GetFps.running;
+ if (flag4)
+ {
+ DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.PeakFps = Math.Max(this._fps, DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.PeakFps);
+ DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.MainDoc.FpsCount += this._fps_count;
+ }
+ }
+ }
+ this._fps_real_time = realtimeSinceStartup;
+ this._fps_count = 0;
+ XSingleton<XTimerMgr>.singleton.SetGlobalTimer(this._fps_interval, this._fpsHandler, null);
+ }
+
+ private void OnEnterStage()
+ {
+ this._stage.OnEnterStage((this._old_stage != null) ? this._old_stage.Stage : EXStage.Null);
+ }
+
+ public void OnEnterScene(uint sceneid, bool bTransfer = false)
+ {
+ bool bHall = XSingleton<XSceneMgr>.singleton.GetSceneType(sceneid) == SceneType.SCENE_HALL || XSingleton<XSceneMgr>.singleton.GetSceneType(sceneid) == SceneType.SCENE_GUILD_HALL || XSingleton<XSceneMgr>.singleton.GetSceneType(sceneid) == SceneType.SCENE_LEISURE;
+ XSingleton<XScene>.singleton.GameCamera.PreInstall(GameObject.Find("Main Camera"), bHall);
+ XSingleton<XScene>.singleton.OnEnterScene(sceneid, bTransfer);
+ this._stage.OnEnterScene(sceneid, bTransfer);
+ XSingleton<XScene>.singleton.GameCamera.Installed();
+ XSingleton<XScene>.singleton.AssociatedCamera = XSingleton<XScene>.singleton.GameCamera.UnityCamera;
+ XSingleton<XAIGeneralMgr>.singleton.InitAIMgr();
+ this.OnEnterStage();
+ }
+
+ public string GetSyncModeString()
+ {
+ bool flag = this._nSyncMode == 0;
+ string result;
+ if (flag)
+ {
+ result = " Solo Mode ";
+ }
+ else
+ {
+ bool flag2 = this._nSyncMode == 1;
+ if (flag2)
+ {
+ result = " OnLine Mode ";
+ }
+ else
+ {
+ bool flag3 = this._nSyncMode == 2;
+ if (flag3)
+ {
+ result = " Mixed Mode ";
+ }
+ else
+ {
+ result = "Unknown";
+ }
+ }
+ }
+ return result;
+ }
+
+ public static void SetVisible(GameObject go, int layer)
+ {
+ go.layer = layer;
+ for (int i = 0; i < go.transform.childCount; i++)
+ {
+ Transform child = go.transform.GetChild(i);
+ XGame.SetVisible(child.gameObject, layer);
+ }
+ }
+ }
+}