Beispiel #1
0
        /** 测试暂停 */
        public void testPause(int time)
        {
            Ctrl.print("测试暂停");

            _resumeTime = Ctrl.getTimer() + time;
            _testPause  = true;
        }
Beispiel #2
0
        private static void doExit()
        {
            if (!_inited)
            {
                return;
            }

            if (_exited)
            {
                return;
            }

            _exited = true;

            Ctrl.print("shine exit");

            if (_exitRun != null)
            {
                _exitRun();
            }

            NetControl.dispose();
            ThreadControl.dispose();
            SystemControl.dispose();

#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
Beispiel #3
0
        private void startSocketThread()
        {
            Ctrl.print("启动socket线程");

            if (ShineSetting.useKCP)
            {
                _kcpThread = new BaseThread("kcpThread");
                _kcpThread.setRunCall(kcpLoop);
                ThreadControl.addThread(_kcpThread);
                _kcpThread.start();
            }

            if (ShineSetting.socketUseAsync)
            {
                return;
            }

            _sendThread = new BaseThread("ioSendThread");
            _sendThread.setRunCall(sendLoop);
            ThreadControl.addThread(_sendThread);

            _receiveThread = new BaseThread("ioReceiveThread");
            _receiveThread.setRunCall(receiveLoop);
            _receiveThread.setSleepTime(1);
            ThreadControl.addThread(_receiveThread);

            _sendThread.start();
            _receiveThread.start();
        }
Beispiel #4
0
        /** 输出数据列表 */
        public static void printDataList <T>(SList <T> list) where T : BaseData
        {
            StringBuilder sb = StringBuilderPool.create();

            T data;

            for (int i = 0, len = list.size(); i < len; i++)
            {
                data = list.get(i);

                sb.Append(i);
                sb.Append(":");

                if (data == null)
                {
                    sb.Append("null");
                }
                else
                {
                    sb.Append(data.toDataString());
                }

                sb.Append("\n");
            }

            Ctrl.print(StringBuilderPool.releaseStr(sb));
        }
Beispiel #5
0
        public static void GenerateAll()
        {
            initGenerate();

            string sFront = "Assets/src/shine";
            XML    sXML   = preDoOneGenerate(sFront + "/sGenerateAdapter.xml");
            string cFront = "Assets/src/commonGame";
            XML    cXML   = preDoOneGenerate(cFront + "/cGenerateAdapter.xml");
            string gFront = "Assets/src/game";
            XML    gXML   = preDoOneGenerate(gFront + "/gGenerateAdapter.xml");

            loadAssembly();

            doOneGenerate(sXML
                          , sFront + "/control/ILRuntimeControl.cs"
                          , sFront + "/adapters", Project_Shine);

            doOneGenerate(cXML
                          , cFront + "/control/CILRuntimeControl.cs"
                          , cFront + "/adapters", Project_Common);


            doOneGenerate(gXML
                          , gFront + "/control/GILRuntimeControl.cs"
                          , gFront + "/adapters", Project_Game);

            Ctrl.print("OK!");
            AssetDatabase.Refresh();
        }
Beispiel #6
0
        /** 连接成功(主线程) */
        public void preConnectSuccessForIO()
        {
            if (!isConnecting())
            {
                return;
            }

            _state = Connected;

            Ctrl.print("socket连接成功:", _doIndex);

            //重连中
            if (_reconnecting && _receiveID > 0)
            {
                Ctrl.print("发送重连消息", _receiveID, _receiveToken, _receiveMsgIndex);

                refreshPingTime();

                clearSend();
                sendAbs(SocketReconnectRequest.create(_receiveID, _receiveToken, _receiveMsgIndex));

                sendPingRequest();
                _reConnectTime.start();
            }
            else
            {
                clear();
                //发一次ping
                sendPingRequest();

                onConnectSuccess();
            }
        }
        /** 添加缓冲 */
        public void append(byte[] bs, int off, int length)
        {
            int dLen = 0;

            int i = 0;

            while (i < length)
            {
                try
                {
                    Buffer.BlockCopy(bs, off + i, _buf, _length, dLen = Math.Min(length - i, _buf.Length - _length));
                }
                catch (Exception e)
                {
                    Ctrl.printExceptionForIO(e);
                    Ctrl.print(off, length, i, _buf.Length, _length);
                }

                i       += dLen;
                _length += dLen;

                if (!toRead())
                {
                    return;
                }
            }
        }
Beispiel #8
0
 public void closeTest()
 {
     if (_socket.Connected)
     {
         Ctrl.print("测试断开");
         _socket.Close();
     }
 }
Beispiel #9
0
        public static void init()
        {
            GameObject gameObject = GameObject.Find("Main Camera");

            if (gameObject == null)
            {
                Ctrl.print("找不到主摄像机");
                return;
            }

            mainCamera.init(gameObject.GetComponent <Camera>());
        }
Beispiel #10
0
        private void OnApplicationQuit()
        {
            //退出就开编辑器模式

            if (!ShineSetting.isRelease)
            {
                ShineSetting.isEditor = true;
            }

            SystemControl.onApplicationQuit();

            Ctrl.print("应用结束");
        }
Beispiel #11
0
        public static void GenerateCommon()
        {
            initGenerate();

            string front = "Assets/src/commonGame";

            doOneGenerate(front + "/cGenerateAdapter.xml"
                          , front + "/control/CILRuntimeControl.cs"
                          , front + "/adapters", Project_Common);

            Ctrl.print("OK!");
            AssetDatabase.Refresh();
        }
Beispiel #12
0
        private void OnApplicationPause(bool pauseStatus)
        {
            if (pauseStatus)
            {
                Ctrl.print("暂停游戏");
            }
            else
            {
                Ctrl.print("暂停结束,恢复游戏");
            }

            SystemControl.onApplicationPause(pauseStatus);
        }
Beispiel #13
0
        /** 执行关闭(主线程) */
        private void closeForIO(int reason, bool canRec)
        {
            ThreadControl.checkCurrentIsMainThread();

            if (_state == Closed)
            {
                return;
            }

            //正在连接中
            if (isConnecting())
            {
                stopConnect();
            }

            _state = Closed;

            Ctrl.print("连接断开,reason:", reason, _doIndex);

            _doIndex++;            //序号加

            bool isInitiative = reason == Close_Initiative;

            if (isInitiative)
            {
                toFlush();
            }

            onDisconnect();

            //重连中,会再次重连
            if (_openReconnect && !isInitiative && canRec && canReconnect())            //!_reconnecting &&
            {
                Ctrl.log("连接断线,进入重连阶段");
                _reconnecting            = true;
                _disConnectLastSendIndex = _sendMsgIndex;
                _reconnectLastTime       = ShineSetting.socketReConnectKeepTime;
                _closeByInitiative       = isInitiative;

                clearSend();

                beginReconnect();
            }
            else
            {
                _closeByInitiative = isInitiative;
                realClose();
            }
        }
Beispiel #14
0
        private void Update()
        {
            if (_testPause)
            {
                if (Ctrl.getTimer() >= _resumeTime)
                {
                    Ctrl.print("暂停恢复");
                    _testPause = false;
                }
                else
                {
                    return;
                }
            }

            Ctrl.makeFixDirty();

            long now = Ctrl.getTimer();
            int  dd  = (int)(now - _lastTime);

            _lastTime = now;

            if (dd > 0)
            {
                if ((_dateFixDelayTick -= dd) <= 0)
                {
                    _dateFixDelayTick = ShineSetting.dateFixDelay;

                    DateControl.makeFixDirty();
                }

                //系统逻辑
                SystemControl.onFrame();
                //计时器
                TimeDriver.instance.tick(dd);
            }

            TimeDriver.instance.update();

            //线程事务最后执行
            if (dd > 0)
            {
                //线程
                ThreadControl.onFrame();
            }
        }
Beispiel #15
0
        /// <summary>
        /// 放回一个
        /// </summary>
        public virtual void back(T obj)
        {
            if (obj == null)
            {
                Ctrl.throwError("对象池添加空对象");
                return;
            }

            if (!_enable || _queue.size() >= _maxSize)
            {
                if (_releaseFunc != null)
                {
                    _releaseFunc(obj);
                }

                return;
            }

            if (_needClear)
            {
                if (obj is IPoolObject)
                {
                    ((IPoolObject)obj).clear();
                }
            }


            if (ShineSetting.openCheck)
            {
                if (_checkSet.contains(obj))
                {
                    Ctrl.print("上次调用", _callStackDic.get(obj));
                    Ctrl.throwError("对象池重复添加!", obj);
                    return;
                }

                _checkSet.add(obj);
                string stackTrace = Ctrl.getStackTrace();
                stackTrace = stackTrace.Replace("\n", " ");
                _callStackDic.put(obj, stackTrace);
            }


            _queue.add(obj);
        }
Beispiel #16
0
        public static void testMethod(Action func, int loop)
        {
            int warmupLoop = loop * 20;

            for (int i = 0; i < warmupLoop; ++i)
            {
                func();
            }

            long t = Ctrl.getNanoTime();

            for (int i = 0; i < loop; ++i)
            {
                func();
            }

            Ctrl.print(Ctrl.getNanoTime() - t);
        }
Beispiel #17
0
        /** io出错(1:wwwError,2:超时,3:不完整) */
        private void toIoError(int type)
        {
            //把www停了
            if (_www != null)
            {
                _www.Dispose();
                _www = null;
            }

            Ctrl.print("io出错:" + type, _url);

            //本地缓存资源被删除了
            if (_loadMethod == LoadMethodType.Resource && _currentSaveData != null && _currentSaveData.state == ResourceSaveStateType.Downloaded)
            {
                //改成cdn下载
                _currentSaveData.state = ResourceSaveStateType.None;
                ResourceInfoControl.versionModified();
                _useURL    = ResourceInfoControl.getCDNResourcePath(_url, _currentSaveData.version);
                _needCache = true;

                toReload();
            }
            else
            {
                if (_tryForever)
                {
                    //等2秒
                    _tryWaitTime = _ioErrorWaitTime;
                }
                else
                {
                    unload();

                    if (_ioErrorCall != null)
                    {
                        _ioErrorCall();
                    }
                }
            }
        }
Beispiel #18
0
        /** 休息 */
        protected void threadSleep()
        {
            _sleeping = true;

            try
            {
                Thread.Sleep(_sleepTime);
            }
            catch
            {
                Ctrl.print("interrupt");
            }

            _sleeping = false;

            // int delay=(int)(Ctrl.getTimer()-t);
            //
            // if(delay>0)
            // {
            //  _restTime+=delay;
            // }
        }
Beispiel #19
0
        /** 主线程 */
        private void toConnectOnce()
        {
            Ctrl.print("connectOnce");

            createNewContent();

            if (_currentInfo == null)
            {
                Ctrl.errorLog("此时不该没有currentInfo");
                toGetDNS();
                return;
            }

            _hostAddress = _currentInfo.getOnce();

            _state       = Connecting;
            _connectTime = 0;
            ++_currentTryCount;

            Ctrl.printForIO("toConnect一次:" + _hostAddress, _content.GetHashCode());

            _content.connect(_hostAddress, _port);
        }
Beispiel #20
0
        private void toGetDNS()
        {
            _state       = Connecting;
            _connectTime = 0;

            int index = ++_doIndex;

            _currentInfo = _ipInfoDic.get(_host);

            if (_currentInfo != null)
            {
                preConnectAfterAddress();
            }
            else
            {
                IPAddress address;

                if (!IPAddress.TryParse(_host, out address))
                {
                    Ctrl.debugLog("dns上");

                    Dns.BeginGetHostAddresses(_host, v =>
                    {
                        IPAddress[] addresses = null;

                        try
                        {
                            addresses = Dns.EndGetHostAddresses(v);
                        }
                        catch (Exception e)
                        {
                            Ctrl.printExceptionForIO(e);
                        }

                        ThreadControl.addMainFunc(() =>
                        {
                            if (index == _doIndex)
                            {
                                if (addresses != null)
                                {
                                    foreach (IPAddress ipAddress in addresses)
                                    {
                                        Ctrl.print("dns看收到的上地址", ipAddress);
                                    }

                                    _currentInfo = registIPInfo(_host, addresses);
                                    preConnectAfterAddress();
                                }
                                else
                                {
                                    Ctrl.printForIO("解析dns失败");
                                }
                            }
                            else
                            {
                                Ctrl.print("dns获取完,已经到下个index");
                            }
                        });
                    }, null);
                }
                else
                {
                    Ctrl.debugLog("dns下");
                    _currentInfo = registIPInfo(_host, new[] { address });
                    preConnectAfterAddress();
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// 刷新语言
        /// </summary>
        public void refreshLanguage()
        {
#if UNITY_EDITOR
            GameC.app.initConfigForEditor();
#endif
            //补丁,以后想办法
            if (FontConfig.getDic() == null)
            {
                Ctrl.print("**********************出现异常情况***************");
                return;
            }

            //暂时加个补丁
            if (_fontId == -1)
            {
                _fontId = 1;
            }

            //获取字体
            string fontSource = FontConfig.getFontSource(_fontId);

            if (String.IsNullOrEmpty(fontSource))
            {
                return;
            }

            if (font != null)
            {
                if (fontSource.Contains(this.font.name))
                {
                    return;
                }
            }

            Font loadFont = null;

            if (ShineSetting.isEditor)
            {
#if UNITY_EDITOR
                if (fontSource.Contains("Arial"))
                {
                    this.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
                }
                else
                {
                    this.font = AssetDatabase.LoadAssetAtPath <Font>("Assets/source/" + fontSource);
                }
#endif
            }
            else
            {
                if (fontSource.Contains("Arial"))
                {
                    loadFont = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

                    if (loadFont != null)
                    {
                        this.font = loadFont;
                    }
                }
                else
                {
                    LoadControl.loadOne(fontSource, () =>
                    {
                        if (this != null)
                        {
                            loadFont = LoadControl.getResource(fontSource) as Font;

                            if (loadFont != null)
                            {
                                this.font = loadFont;
                            }
                        }
                    });
                }
            }
        }
Beispiel #22
0
        public bool remove(int key)
        {
            if (_size == 0)
            {
                return(false);
            }

            int free;

            if (key != (free = _freeValue))
            {
                int[] keys         = _set;
                int   capacityMask = (keys.Length) - 1;
                int   index;
                int   cur;
                if ((cur = keys[(index = hashInt(key) & capacityMask)]) != key)
                {
                    if (cur == free)
                    {
                        return(false);
                    }
                    else
                    {
                        while (true)
                        {
                            if ((cur = keys[(index = (index - 1) & capacityMask)]) == key)
                            {
                                break;
                            }
                            else if (cur == free)
                            {
                                return(false);
                            }
                        }
                    }
                }

                int indexToRemove = index;
                int indexToShift  = indexToRemove;
                int shiftDistance = 1;
                while (true)
                {
                    indexToShift = (indexToShift - 1) & capacityMask;
                    int keyToShift;
                    if ((keyToShift = keys[indexToShift]) == free)
                    {
                        break;
                    }

                    if (((hashInt(keyToShift) - indexToShift) & capacityMask) >= shiftDistance)
                    {
                        keys[indexToRemove] = keyToShift;
                        indexToRemove       = indexToShift;
                        shiftDistance       = 1;
                    }
                    else
                    {
                        shiftDistance++;
                        if (indexToShift == (1 + index))
                        {
                            Ctrl.print("遍历中删除");
                        }
                    }
                }

                keys[indexToRemove] = free;
                postRemoveHook(indexToRemove);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #23
0
        /** 每帧调用 */
        public void onFrame(int delay)
        {
            //不是正在加载
            if (_loadState != LoadState_Loading)
            {
                return;
            }

            if (_tryWaitTime > 0)
            {
                if ((_tryWaitTime -= delay) <= 0)
                {
                    _tryWaitTime = 0;

                    toReload();
                }
            }
            else
            {
                if (_assetBundleCreateRequest != null)
                {
                    if (_assetBundleCreateRequest.isDone)
                    {
                        toComplete();

                        return;
                    }
                }
                else if (_www != null)
                {
                    if (_www.isDone)
                    {
                        //_loadCompleteTime = Ctrl.getTimer();

                        if (!string.IsNullOrEmpty(_www.error))
                        {
                            Ctrl.print("io出错", _www.error, _url, _useURL);

                            toIoError(IOError_Error);
                            return;
                        }
                        else
                        {
                            //有记录
                            if (_needSize > 0 && ShineSetting.isRelease)
                            {
                                //不够
                                if (_needSize != _www.bytesDownloaded)
                                {
                                    Ctrl.warnLog("加载不完整:", _url, _needSize, _www.bytesDownloaded);

                                    toIoError(IOError_SizeNotMatch);
                                    return;
                                }
                            }

                            toComplete();
                        }

                        return;
                    }
                }
                else
                {
                    Ctrl.throwError("没有加载驱动主体");
                    return;
                }

                if (_checkTimePass > 0)
                {
                    if ((_checkTimePass -= delay) <= 0)
                    {
                        _checkTimePass = 0;
                        timeOutCheck();
                    }
                }
            }
        }
Beispiel #24
0
 private void OnDestroy()
 {
     Ctrl.print("destroy FrameContainer");
 }