Пример #1
0
        public void Tick(float dt)
        {
            if (CGameSession.Instance().IsProcessingPaused)
            {
                return;
            }

            if (!IgnoreTimer)
            {
                if (_TimerList != null)
                {
                    _TimerList.Tick(false);
                }
            }

            if (!IgnoreCollisionDetecr)
            {
                UpdateCollision();
            }

            if (!IgnoreBehavior)
            {
                UpdateBehaviors();
            }
        }
Пример #2
0
    public bool StartGameSession(CGameSession.CStartParams StartParams)
    {
        _gameStartParams = StartParams;

        if (_gameSession != null)
        {
            _gameSession.Destroy();
        }

        _gameSession = new CGameSession();
        if (!_gameSession.Init(StartParams))
        {
            Debug.LogError("Game session failed to launch");
            TerminateGameSession();
            return(false);
        }

        _gameSession.Start();

        Analytics.CustomEvent("levelStart", new Dictionary <string, object>
        {
            { "name", StartParams.mLevelName },
            { "type", (int)StartParams.mPlayType }
        });

        return(true);
    }
Пример #3
0
    static int Instance(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        CGameSession o = CGameSession.Instance();

        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
Пример #4
0
 public static CGameSession Instance()
 {
     if (_Instance == null)
     {
         _Instance = new CGameSession();
     }
     return(_Instance);
 }
Пример #5
0
    static int Close(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        CGameSession obj = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");

        obj.Close();
        return(0);
    }
Пример #6
0
    static int IsConnected(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        CGameSession obj = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");
        bool         o   = obj.IsConnected();

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Пример #7
0
    static int CheckConnection(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        CGameSession obj  = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");
        int          arg0 = (int)LuaScriptMgr.GetNumber(L, 2);

        //obj.CheckConnection(arg0);
        return(0);
    }
Пример #8
0
    static int IsValidIpAddress(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        CGameSession obj  = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");
        string       arg0 = LuaScriptMgr.GetLuaString(L, 2);
        bool         o    = obj.IsValidIpAddress(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Пример #9
0
    static void ClientDisConnect()
    {
#if UNITY_EDITOR || UNITY_STANDALONE
        if (CGameSession.Instance().IsConnected())
        {
            LuaScriptMgr.Instance.CallLuaOnConnectionEventFunc((int)Common.Net.EVENT.DISCONNECTED);
            CGameSession.Instance().Close();
        }
#endif
    }
Пример #10
0
    static int IntToBytes(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        int             arg0 = (int)LuaScriptMgr.GetNumber(L, 1);
        LuaStringBuffer arg1 = LuaScriptMgr.GetStringBuffer(L, 2);
        int             arg2 = (int)LuaScriptMgr.GetNumber(L, 3);

        CGameSession.IntToBytes(arg0, arg1.buffer, arg2);
        return(0);
    }
Пример #11
0
    static int TestBytes(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 4);
        CGameSession obj  = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");
        CS2CPrtcData arg0 = (CS2CPrtcData)LuaScriptMgr.GetNetObject(L, 2, typeof(CS2CPrtcData));
        bool         arg1 = LuaScriptMgr.GetBoolean(L, 3);
        bool         arg2 = LuaScriptMgr.GetBoolean(L, 4);

        obj.TestBytes(arg0, arg1, arg2);
        return(0);
    }
Пример #12
0
    static int ConnectToServer(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 5);
        CGameSession obj  = (CGameSession)LuaScriptMgr.GetNetObjectSelf(L, 1, "CGameSession");
        string       arg0 = LuaScriptMgr.GetLuaString(L, 2);
        int          arg1 = (int)LuaScriptMgr.GetNumber(L, 3);
        string       arg2 = LuaScriptMgr.GetLuaString(L, 4);
        string       arg3 = LuaScriptMgr.GetLuaString(L, 5);

        obj.ConnectToServer(arg0, arg1, arg2, arg3);
        return(0);
    }
Пример #13
0
    public void TerminateGameSession(bool TransitionToMainMenu = false)
    {
        if (_gameSession != null)
        {
            _gameSession.Destroy();
            _gameSession = null;
        }

        if (TransitionToMainMenu)
        {
            UIManager.AddInterface(new CMainMenuUI());
        }

        // TODO: Game UI needs to f**k off.
    }
Пример #14
0
    /// <summary>
    /// Copy initial state.
    /// </summary>
    public void Init(CGameSession Session, CWorld World, CUserSession PlayMode, int ViewPlayerIndex)
    {
        _gameSession     = Session;
        _world           = World;
        _userSession     = PlayMode;
        _viewPlayerIndex = ViewPlayerIndex;
        mStateViews      = new List <CStateView>();

        mPlayerViews = new CPlayerView[_world.mPlayers.Length];

        for (int i = 0; i < mPlayerViews.Length; ++i)
        {
            mPlayerViews[i] = new CPlayerView();
        }

        GenerateFlowTesters();
        GenerateFlowField(new Rect(15, 21, 4, 4));
        mNavMesh = new CNavMesh(World.mMap.mStaticVisSegments);
    }
Пример #15
0
    private IEnumerable ProtocolProcessCoroutine()
    {
        while (true)
        {
            var gameSession = CGameSession.Instance();

            if (gameSession.IsPaused)
            {
                yield return(null);
            }

            var canProcess     = true;
            var processedCount = 0;
            var count          = gameSession.FetchProtocols();
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    if (!canProcess || processedCount >= MAX_PROTO_PER_FRAME)
                    {
                        break;
                    }

                    gameSession.ProcessOneProtocol(count > SIMPLE_PROTO_PROCESS_THRESHOLD);

                    processedCount++;

                    if (gameSession.IsPaused)
                    {
                        canProcess = false;
                    }

                    // TODO: 增加限时,如果超出时间上限,yield return
                }
            }

            yield return(null);
        }
    }
Пример #16
0
    static int set_IsProcessingPaused(IntPtr L)
    {
        object       o   = LuaScriptMgr.GetLuaObject(L, 1);
        CGameSession obj = (CGameSession)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name IsProcessingPaused");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index IsProcessingPaused on a nil value");
            }
        }

        obj.IsProcessingPaused = LuaScriptMgr.GetBoolean(L, 3);
        return(0);
    }
Пример #17
0
    void OnApplicationQuit()
    {
        _IsQuiting = true;

        //CTimerList.ShowDiagnostics();
        //EntityVisualEffect.EffectObjectPool.ShowDiagnostics();
        //MaterialPool.Instance.ShowDiagnostics();
        //FileImage.ShowDiagnostics();
        if (_IsCurlInited)
        {
            Curl.GlobalCleanup();
            _IsCurlInited = false;
        }

        CGameSession.Instance().Close();

        if (_IsInited)
        {
            LuaScriptMgr.Instance.CallLuaFunction("ReleaseGame");
            LuaScriptMgr.Instance.Destroy();
            NavMeshManager.Instance.Release();
            LuaDLL.HOBA_Release();
            _IsInited = false;
        }

        _TimerList.Clear();
        _LateTimerList.Clear();

        CLogicObjectMan <ObjectBehaviour> .Instance.Cleanup();

        CLogicObjectMan <EntityEffectComponent> .Instance.Cleanup();

        ResCacheMan.Instance.Cleanup();
        CFxCacheMan.Instance.Cleanup();

        HobaDebuger.Log("Application Quit!");
    }
Пример #18
0
    IEnumerable InitGameCoroutine()
    {
        DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine Start...");

        foreach (var item in PreInitGameCoroutine())
        {
            yield return(item);
        }

        SetupPath();

        HobaDebuger.GameLogLevel = WriteLogLevel;

        //IOS Application.persistentDataPath  /var/mobile/Containers/Data/Application/app sandbox/Documents
        //Android /storage/emulated/0/Android/data/package name/files
#if UNITY_IOS
        _DocPath = Application.persistentDataPath;
        _LibPath = Path.Combine(Application.persistentDataPath, "UpdateRes");
        _TmpPath = Path.Combine(Application.persistentDataPath, "Tmp");
#elif UNITY_ANDROID
        _DocPath = Application.persistentDataPath;
        _LibPath = Path.Combine(Application.persistentDataPath, "UpdateRes");
        _TmpPath = Path.Combine(Application.persistentDataPath, "Tmp");
#else
        _DocPath = Environment.CurrentDirectory;
        _LibPath = Path.Combine(Environment.CurrentDirectory, "UpdateRes");
        _TmpPath = Path.Combine(Environment.CurrentDirectory, "Tmp");
#endif
        yield return(null);

#if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS
        //初始化异常上报SDK
        CLogReport.Init();
        yield return(null);
#endif

        //初始化基础目录
        {
            string path = EntryPoint.Instance.ResPath;
            path = path.Replace("file://", "");
            LuaDLL.HOBA_Init(path, _DocPath, _LibPath, _TmpPath);
        }

        _VoiceDir         = Path.Combine(_TmpPath, "Voice");
        _CustomPicDir     = Path.Combine(_TmpPath, "CustomPic");
        _UserLanguageFile = Path.Combine(_DocPath, "userlanguage.txt");
        _UserBillingFile  = Path.Combine(_DocPath, "userbilling.bin");
        _UserDataDir      = Path.Combine(_DocPath, "UserData");

        string strOSLanguage   = OSUtility.GetSystemLanguageCode();
        string strUserLanguage = GetUserLanguageCode();

        if (!Directory.Exists(_LibPath))
        {
            Directory.CreateDirectory(_LibPath);
        }
        if (!Directory.Exists(_VoiceDir))
        {
            Directory.CreateDirectory(_VoiceDir);
        }
        if (!Directory.Exists(_CustomPicDir))
        {
            Directory.CreateDirectory(_CustomPicDir);
        }
        if (!Directory.Exists(_UserDataDir))
        {
            Directory.CreateDirectory(_UserDataDir);
        }
        LuaDLL.HOBA_DeleteFilesInDirectory(_VoiceDir);               //清空Tmp目录
        LuaDLL.HOBA_DeleteFilesInDirectory(_CustomPicDir);           //清空Tmp目录
        yield return(null);

        if (!File.Exists(_UserLanguageFile))                //创建语言配置文件
        {
            WriteUserLanguageCode(strOSLanguage);
        }
        yield return(null);

        //目录信息
//#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)
//         var pType = LTPlatformBase.ShareInstance().GetPlatformType();
//         HobaDebuger.LogWarningFormat("LTPlatformType: {0}", pType.ToString());
//         HobaDebuger.LogWarningFormat("AssetBundlePath: {0}", _AssetBundlePath);
//         HobaDebuger.LogWarningFormat("ResPath: {0}", ResPath);
//         HobaDebuger.LogWarningFormat("DocPath: {0}", _DocPath);
//         HobaDebuger.LogWarningFormat("LibPath: {0}", _LibPath);
//         HobaDebuger.LogWarningFormat("TmpPath: {0}", _TmpPath);
//         HobaDebuger.LogWarningFormat("ConfigPath: {0}", _ConfigPath);
//         HobaDebuger.LogWarningFormat("LuaPath: {0}", _LuaPath);
//         HobaDebuger.LogWarningFormat("VoiceDir: {0}", _VoiceDir);
//         HobaDebuger.LogWarningFormat("CustomPickDir: {0}", _CustomPicDir);
//         HobaDebuger.LogWarningFormat("OSLanguage: {0}, UserLanguage: {1}", strOSLanguage, strUserLanguage);
//         yield return null;
//#endif

        //根据语言设置更新语言
        ReadUpdateStringXmlFromResources(strUserLanguage);
        yield return(null);

#if (UNITY_EDITOR || UNITY_STANDALONE_WIN)               //只在windows下起作用
        bool bDebugSetting = ReadDebugSettingXml();
//         HobaDebuger.LogWarningFormat("DebugSetting: {0}", bDebugSetting);
//         HobaDebuger.LogWarningFormat("DebugSetting SkipUpdate: {0}, Shortcut: {1}, LocalData: {2}, LocalLua: {3}, Is1080P: {4}, FullScreen: {5}",
//             _DebugSetting.SkipUpdate,
//             _DebugSetting.ShortCut,
//             _DebugSetting.LocalData,
//             _DebugSetting.LocalLua,
//             _DebugSetting.Is1080P,
//             _DebugSetting.FullScreen);

        _SkipUpdate = _DebugSetting.SkipUpdate || File.Exists(Path.Combine(_DocPath, "skip.txt"));
        //HobaDebuger.LogWarningFormat("SkipUpdate: {0}", _SkipUpdate);
#endif

#if !UNITY_EDITOR && UNITY_STANDALONE_WIN
        if (_DebugSetting.Is1080P)
        {
            Screen.SetResolution(1920, 1080, _DebugSetting.FullScreen);
        }

        if (_DebugSetting.FPSLimit > 0)
        {
            Application.targetFrameRate = _DebugSetting.FPSLimit;
        }
#endif

        //初始化平台SDK
        {
            GameUpdateMan.Instance.InitUpdateUI(); //显示更新界面

            bool isFinish = false;
            int  code     = -1;
            LTPlatformBase.ShareInstance().InitSDK((_, resultCode) =>
            {
                code     = resultCode;
                isFinish = true;
            });
            LTPlatformBase.ShareInstance().SetBreakPoint(SDK.POINT_STATE.Game_Start); //平台SDK打点:开始游戏

            while (!isFinish)
            {
                yield return(null);
            }

            bool isInited = LTPlatformBase.ShareInstance().IsInited;
            var  pType    = LTPlatformBase.ShareInstance().GetPlatformType();
            DeviceLogger.Instance.WriteLogFormat("LTPlatform InitSDK result:{0}, return code:{1}, platform type:{2}", isInited.ToString(), code.ToString(), pType.ToString());
            if (!isInited)
            {
                // 初始化失败,弹窗提示,退出游戏
                GameUpdateMan.Instance.HotUpdateViewer.SetCircle(false);
                string errStr = LTPlatformBase.ShareInstance().GetErrStr(code);
                yield return(new WaitForUserClick(MessageBoxStyle.MB_OK, errStr, _UpdateStringConfigParams.PlatformSDKString_InitFailedTitle));

                ExitGame();
                yield break;
            }
        }

        {
            // copy base res
#if UNITY_ANDROID
            string srcDir  = "res_base";
            string destDir = Path.Combine(Application.persistentDataPath, "res_base");

            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            IsInstallFinished = File.Exists(destDir + "/.lock");
            if (!IsInstallFinished)
            {
                DeviceLogger.Instance.WriteLog(string.Format("Begin RunInstallStage... from {0} to {1}", srcDir, destDir));
                foreach (var item in GameUpdateMan.Instance.RunInstallStage(srcDir, destDir))
                {
                    yield return(item);
                }
                DeviceLogger.Instance.WriteLog("End RunInstallStage...");
            }

            if (IsInstallFinished)
            {
                string       lockFile = Path.Combine(destDir, ".lock");
                StreamWriter writer   = File.CreateText(lockFile);
                writer.Write(TotalSizeToCopy);
                writer.Close();
                DeviceLogger.Instance.WriteLog("EntryPoint InitGameCoroutine EntryPoint.Instance.RunInstallStage() Success...");
            }
            else
            {
                DeviceLogger.Instance.WriteLog("EntryPoint InitGameCoroutine EntryPoint.Instance.RunInstallStage() Failed!");
            }
            yield return(null);
#endif
            //在更新开始前,获取ServerConfig.xml
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            {
                string configsDir = Path.Combine(_ResPath, "Configs");
                string path       = Path.Combine(configsDir, "ServerConfig.xml");
                if (!ReadServerConfigXml(path))
                {
                    HobaDebuger.LogWarningFormat("Read ServerConfig Failed: {0}", path);
                }
            }
#else
            {
                string url     = EntryPoint.Instance.GetClientServerUrl().NormalizeDir() + "ServerConfig.xml";
                string tmpPath = Path.Combine(EntryPoint.Instance.TmpPath, "ServerConfig.xml");
                string errMsg;
                var    code = Patcher.FetchByUrl(url, tmpPath, Downloader.DownloadMan.reqTimeOut, out errMsg);
                if (code == Downloader.DownloadTaskErrorCode.Success)
                {
                    if (!ReadServerConfigXml(tmpPath))
                    {
                        HobaDebuger.LogWarningFormat("Read ServerConfig Failed: {0}", url);
                    }
                }
                else
                {
                    HobaDebuger.LogWarningFormat("Download ServerConfig Failed: {0}, {1}", url, code);
                }
            }
#endif
            yield return(null);

            DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine UpdateRoutine Start...");
            //IAP Verify url init and check receipt cache.
            LTPlatformBase.ShareInstance().InitPurchaseVerifyUrl(_ServerConfigParams.GetPurchaseVerifyUrl());
            LTPlatformBase.ShareInstance().ProcessPurchaseCache();
            LTPlatformBase.ShareInstance().SetBreakPoint(SDK.POINT_STATE.Game_Start_Update); //平台SDK打点:开始更新

            // App & 资源更新
            foreach (var item in GameUpdateMan.Instance.UpdateRoutine())
            {
                yield return(item);
            }
            LTPlatformBase.ShareInstance().SetBreakPoint(SDK.POINT_STATE.Game_End_Update); //平台SDK打点:结束更新

            DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine UpdateRoutine End...");
        }

        //初始化pck包, 编辑器模式下不使用pck,策划编辑器模式下使用
#if !UNITY_EDITOR
        {
            string path = _ResPath;
            path = path.Replace("file://", "");
            LuaDLL.HOBA_InitPackages(path);
        }
#endif
        //FIX ME:: 加载不等待2帧 Windows崩溃 待查
        yield return(null);  //等待一帧,否则部分 Android 设置闪烁

        yield return(null);  //等待一帧,否则部分 Android 设置闪烁

        ReadGameCustomConfigParams();
        yield return(null);

        ReadWwiseBankConfigParams();
        yield return(null);

        ReadWwiseSoundConfigParams();
        yield return(null);

        ReadPlayerFollowCameraConfig();
        yield return(null);

        CLogFile.Init();
        yield return(null);

        CGameSession.Instance().PingInterval              = GameCustomConfigParams.PingInterval;
        CGameSession.Instance().MaxProcessProtocol        = GameCustomConfigParams.MaxProcessProtocol;
        CGameSession.Instance().MaxProcessSpecialProtocol = GameCustomConfigParams.MaxProcessSpecialProtocol;

        foreach (var item in InitGameInternal())
        {
            yield return(item);
        }

        CleanupUpdateResources();

        if (PanelLogo != null)
        {
            PanelLogo.SetActive(true);
            yield return(null);
        }

        string videoPath = System.IO.Path.Combine(Application.streamingAssetsPath, "TERA_BackgroundStory.mp4");
        VideoManager.PlayVideo(videoPath, null, null, null, true);
        yield return(null);

        GFXConfig.Instance.Init();

        foreach (var item in DoStartGame())
        {
            yield return(item);
        }

        //DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine DoStartGame End...");

        DeviceLogger.Instance.WriteLogFormat("EntryPoint InitGameCoroutine End...");

        //TestLoadResource("Assets/Outputs/Sfx/Scene/scene_chuansong_chuanzou01.prefab");
    }
Пример #19
0
 public RemoteServerPlayer(IPacketConnection connection, CGameSession session)
 {
     this.connection = connection;
     this.session    = session;
 }
Пример #20
0
 static int SetNetLatency(IntPtr L)
 {
     CGameSession.Instance().LatencyMillisecond = (int)LuaDLL.lua_tonumber(L, 1);
     return(0);
 }
Пример #21
0
    void Update()
    {
        if (!_IsInited)
        {
            return;
        }

#if ONGUI_DEBUG
        /*
         * if (Main.HostPalyer != null)
         * {
         *  Vector3 polyPickExt = new Vector3(1, 256, 1);
         *
         *  //Vector3 pos = new Vector3(6.78f, 28.74f, 50.72f);
         *  Vector3 pos = Main.HostPalyer.transform.position;
         *  //Vector3 target = new Vector3(6.78f, 28.74f, 47.72f);        //干尸
         *  //Vector3 target = new Vector3(-21.85f, 27.31f, 38.80f);
         *  //Vector3 target = new Vector3(77.5f, 46.0f, -69.3f);         //110地图某点
         *  //Vector3 target = pos + new Vector3(1, 2, 3);           //110二层楼高点
         *
         *  Vector3 target = new Vector3(142.47f, 24.04f, -127.85f);
         *
         *  Vector3 nearest = target;
         *  _IsValidStart = NavMeshManager.Instance.IsValidPositionStrict(pos);
         *
         *  _IsValidEnd = NavMeshManager.Instance.IsValidPositionStrict(target);
         *
         *  _IsConnected = PathFindingManager.Instance.IsConnected(pos, target);
         *
         *  _CanNavigateTo = PathFindingManager.Instance.CanNavigateTo(pos, target, polyPickExt);
         *
         *  _IsCollideByObstacle = PathFindingManager.Instance.IsCollideWithBlockable(pos, target);
         *
         *  //_FindFirstConnectedPoint = PathFindingManager.Instance.FindFirstConnectedPoint(pos, target, polyPickExt, 1.0f, out _FirstConnectedPoint);
         * }
         * */
#endif
        try
        {
            float dt = Time.deltaTime;

            _TimerList.Tick(true);

            Main.Tick(dt);
            InputManager.Instance.Tick(dt);
            CLogicObjectMan <ObjectBehaviour> .Instance.Tick(dt);

            CLogicObjectMan <EntityEffectComponent> .Instance.Tick(dt);

            LuaScriptMgr.Instance.Tick(dt);
            CGameSession.Instance().Tick(dt);
            UISfxBehaviour.Tick(dt);
            CFxCacheMan.Instance.Tick(dt);
            DynamicEffectManager.Instance.Tick(dt);

            //_SoundMan.Tick(dt);
            VideoManager.Tick(dt);

            CDebugUIMan.Instance.Tick(dt);
        }
        catch (LuaScriptException e)
        {
            HobaDebuger.LogErrorFormat("LuaScriptException: {0}", e.Message);
        }
        catch (Exception e)
        {
            HobaDebuger.LogErrorFormat("{0}\n{1}", e.Message, e.StackTrace);
        }
    }
Пример #22
0
 public CSimThread(CGameSession Session)
 {
     _gameSession = Session;
 }