예제 #1
0
        public void tick(int delay)
        {
            IntObjectMap <TimeExecuteData> timeExDic;

            if (!(timeExDic = _timeExDic).isEmpty())
            {
                foreach (TimeExecuteData tData in timeExDic)
                {
                    if (!tData.pause)
                    {
                        tData.time += delay;

                        if (tData.time >= tData.timeMax)
                        {
                            tData.intArg = tData.time;

                            if (tData.isCut)
                            {
                                tData.time = 0;
                            }
                            else
                            {
                                tData.time -= tData.timeMax;
                            }

                            if (!tData.isGoOn)
                            {
                                //移除
                                timeExDic.remove(tData.index);
                            }

                            executeTimeExFunc(tData);
                        }
                    }
                }
            }


            //frame

            IntObjectMap <Action <int> > frameDic;

            if (!(frameDic = _frameDic).isEmpty())
            {
                foreach (Action <int> v in frameDic)
                {
                    try
                    {
                        v(delay);
                    }
                    catch (Exception e)
                    {
                        Ctrl.errorLog(e);
                    }
                }
            }

            //callLater(放在最下面,用来在一次tick的最后执行逻辑)

            SList <Action> callLaters;

            if (!(callLaters = _callLaters).isEmpty())
            {
                _callLaterForEaching = true;

                Action[] values = callLaters.getValues();

                for (int i = 0, len = callLaters.size(); i < len; ++i)
                {
                    try
                    {
                        values[i]();
                    }
                    catch (Exception e)
                    {
                        Ctrl.errorLog(e);
                    }

                    values[i] = null;
                }

                callLaters.justClearSize();

                _callLaterForEaching = false;

                SList <Action> callLaterTemps;

                if (!(callLaterTemps = _callLaterTemps).isEmpty())
                {
                    callLaters.addAll(callLaterTemps);

                    callLaterTemps.clear();
                }
            }
        }
예제 #2
0
        /** 执行加载 */
        private void toLoad()
        {
            _needSize = 0;

            switch (_loadMethod)
            {
            case LoadMethodType.Resource:
            {
                if (ShineSetting.debugJumpResourceVersion || ShineSetting.localLoadWithOutBundle)
                {
                    _needSize     = 0;
                    _useURL       = ResourceInfoControl.getStreamingAssetsPath(_url, true);
                    _resourceType = ResourceType.Unknown;
                }
                else
                {
                    if ((_currentSaveData = ResourceInfoControl.getResourceSaveData(_url)) == null)
                    {
                        Ctrl.throwError("不该找不到资源数据", _url);
                        return;
                    }

                    _resourceType = _currentSaveData.getType();
                    bool isBundle = _resourceType == ResourceType.Bundle;

                    _needSize = _currentSaveData.size;

                    //从steamingAsset中加载
                    if (_currentSaveData.state == ResourceSaveStateType.StreamingAssetsReady)
                    {
                        _useURL = ResourceInfoControl.getStreamingAssetsPath(_url, !isBundle);
                    }
                    //从持久化中加载
                    else if (_currentSaveData.state == ResourceSaveStateType.Downloaded)
                    {
                        _useURL = ResourceInfoControl.getPersistentPath(_url, !isBundle);
                    }
                    //需要加载
                    else
                    {
                        _useURL    = ResourceInfoControl.getCDNResourcePath(_url, _currentSaveData.version);
                        _needCache = true;
                    }
                }
            }
            break;

            case LoadMethodType.StreamingAssets:
            {
                _useURL       = ResourceInfoControl.getStreamingAssetsPath(_url, true);
                _resourceType = ResourceType.Unknown;
            }
            break;

            default:
            {
                _useURL       = _url;
                _resourceType = ResourceType.Unknown;
            }
            break;
            }

            _reloadTimes = 0;
            //标记开始加载
            _loadState = LoadState_Loading;

            resetTimeOut();
            toDoLoad();
        }
예제 #3
0
 /** 抛错 */
 public void throwError(string str)
 {
     Ctrl.throwError(str);
 }
예제 #4
0
        /** 读失败(IO线程) */
        protected void onError(string msg)
        {
            Ctrl.printForIO("socket读取失败:" + msg);

            preBeClose(2);
        }
예제 #5
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();
                    }
                }
            }
        }
예제 #6
0
        private void run()
        {
            try
            {
                SFuncQueue queue = _queue;

                _running = true;

                long lastTime = Ctrl.getTimer();
                long time;
                int  delay;
                int  tickMax  = _tickDelay;
                int  tickTime = 0;

                while (_running)
                {
                    time     = Ctrl.getTimer();
                    delay    = (int)(time - lastTime);
                    lastTime = time;

                    //防止系统时间改小
                    if (delay < 0)
                    {
                        delay = 0;
                    }

                    if (delay > 0)
                    {
                        if ((tickTime += delay) >= tickMax)
                        {
                            try
                            {
                                tick(tickTime);
                            }
                            catch (Exception e)
                            {
                                Ctrl.errorLog("线程tick出错", e);
                            }

                            tickTime = 0;
                        }
                    }

                    try
                    {
                        runEx();
                    }
                    catch (Exception e)
                    {
                        Ctrl.errorLog("线程runEx出错", e);
                    }

                    //再事务
                    queue.runOnce();

                    //最后睡
                    threadSleep();
                }
            }
            catch (ThreadAbortException)
            {
                //线程结束
            }
            catch (Exception e)
            {
                Ctrl.printExceptionForIO(e);
            }
        }
예제 #7
0
        /** 收到一个协议包(netIO线程) */
        private void onSocketDataT(byte[] data, int pos, int len)
        {
            _readStream.setBuf(data, pos, len);

            //客户端不需要检测

            int mid = _readStream.natureReadUnsignedShort();

            //检测序号
            if (!BytesControl.isIgnoreMessage(mid))
            {
                int receiveIndex = _readStream.natureReadShort();

                int nowIndex = _receiveMsgIndex;

                if (receiveIndex != nowIndex)
                {
                    ThreadControl.addMainFunc(() =>
                    {
                        Ctrl.warnLog("序号检测没对上," + " nowIndex:" + nowIndex + " receiveIndex:" + receiveIndex + " mid:" + mid);

                        //视为被动关闭
                        closeForIO(Close_Error);
                    });

                    return;
                }

                ++_receiveMsgIndex;
            }

            if (_createResponseFunc != null)
            {
                BaseResponse response = _createResponseFunc(mid);

                if (response == null)
                {
                    if (ShineSetting.needMessageExistCheck)
                    {
                        ThreadControl.addMainFunc(() =>
                        {
                            Ctrl.throwError("未解析mid为" + mid + "的协议");
                        });
                    }

                    return;
                }

                if (response.isNewOne)
                {
                    _newResponseNum++;
                }

                response.socket = this;

                BaseResponse response2 = response.readFromStream(_readStream);

                //变了
                if (response2 != response)
                {
                    //直接回收 IO
                    BytesControl.releaseResponse(response);
                }

                if (response2 != null)
                {
                    if (ShineSetting.messageUsePool && response2.needRelease())
                    {
                        _responseCacheQueue.offer(response2);
                    }

                    //入队
                    _receiveQueue.add(response2);
                }
            }
        }
예제 #8
0
        public V remove(K key)
        {
            if (_size == 0)
            {
                return(_defaultValue);
            }

            K[] keys         = _set;
            int capacityMask = (keys.Length) - 1;
            int index;
            K   cur;

            if (!key.Equals((cur = keys[(index = hashObj(key) & capacityMask)])))
            {
                if (Equals(_defaultKey, cur))
                {
                    return(default(V));
                }
                else
                {
                    while (true)
                    {
                        if (key.Equals((cur = keys[(index = (index - 1) & capacityMask)])))
                        {
                            break;
                        }
                        else if (Equals(_defaultKey, cur))
                        {
                            return(default(V));
                        }
                    }
                }
            }

            V[] vals          = _values;
            V   val           = vals[index];
            int indexToRemove = index;
            int indexToShift  = indexToRemove;
            int shiftDistance = 1;

            while (true)
            {
                indexToShift = (indexToShift - 1) & capacityMask;
                K keyToShift;
                if (Equals(_defaultKey, keyToShift = keys[indexToShift]))
                {
                    break;
                }

                if (((hashObj(keyToShift) - indexToShift) & capacityMask) >= shiftDistance)
                {
                    keys[indexToRemove] = keyToShift;
                    vals[indexToRemove] = vals[indexToShift];
                    indexToRemove       = indexToShift;
                    shiftDistance       = 1;
                }
                else
                {
                    shiftDistance++;

                    if (indexToShift == (1 + index))
                    {
                        Ctrl.throwError("ConcurrentModificationException");
                    }
                }
            }

            keys[indexToRemove] = default(K);
            vals[indexToRemove] = default(V);
            postRemoveHook(indexToRemove);
            return(val);
        }
예제 #9
0
파일: LongSet.cs 프로젝트: shineTeam7/home3
        public bool remove(long key)
        {
            if (_size == 0)
            {
                return(false);
            }

            long free;

            if (key != (free = _freeValue))
            {
                long[] keys         = _set;
                int    capacityMask = (keys.Length) - 1;
                int    index;
                long   cur;
                if ((cur = keys[(index = hashLong(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;
                    long keyToShift;
                    if ((keyToShift = keys[indexToShift]) == free)
                    {
                        break;
                    }

                    if (((hashLong(keyToShift) - indexToShift) & capacityMask) >= shiftDistance)
                    {
                        keys[indexToRemove] = keyToShift;
                        indexToRemove       = indexToShift;
                        shiftDistance       = 1;
                    }
                    else
                    {
                        shiftDistance++;
                        if (indexToShift == (1 + index))
                        {
                            Ctrl.throwError("ConcurrentModificationException");
                        }
                    }
                }

                keys[indexToRemove] = free;
                postRemoveHook(indexToRemove);

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #10
0
        public V remove(long key)
        {
            if (_size == 0)
            {
                return(default(V));
            }

            long free;

            if (key != (free = _freeValue))
            {
                long[] keys         = _set;
                int    capacityMask = (keys.Length) - 1;
                int    index;
                long   cur;

                if ((cur = keys[(index = (hashLong(key)) & capacityMask)]) != key)
                {
                    if (cur == free)
                    {
                        return(default(V));
                    }
                    else
                    {
                        while (true)
                        {
                            if ((cur = keys[(index = (index - 1) & capacityMask)]) == key)
                            {
                                break;
                            }
                            else if (cur == free)
                            {
                                return(default(V));
                            }
                        }
                    }
                }

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

                    if ((((keyToShift) - indexToShift) & capacityMask) >= shiftDistance)
                    {
                        keys[indexToRemove] = keyToShift;
                        vals[indexToRemove] = vals[indexToShift];
                        indexToRemove       = indexToShift;
                        shiftDistance       = 1;
                    }
                    else
                    {
                        shiftDistance++;

                        if (indexToShift == (1 + index))
                        {
                            Ctrl.throwError("不能在遍历中删除");
                        }
                    }
                }

                keys[indexToRemove] = free;
                vals[indexToRemove] = default(V);
                postRemoveHook(indexToRemove);

                return(val);
            }
            else
            {
                return(default(V));
            }
        }
예제 #11
0
        private static void doOneGenerate(string xmlPath, string controlClsPath, string adapterOutPath, int projectType)
        {
            clearGenerate();

            _isShine = projectType == 0;

            //TODO:根据类型取父factory

            XML xml = FileUtils.readFileForXML(xmlPath);

            int aLen = "Assets/".Length;

            //处理屏蔽
            foreach (XML xl in xml.getChildrenByName("ignoreMethod"))
            {
                string[] methods = xl.getProperty("methods").Split(',');

                SSet <string> dd = new SSet <string>();
                dd.addAll(methods);
                _clsIgnoreMethods.put(xl.getProperty("cls"), dd);
            }

            foreach (XML xl in xml.getChildrenByName("allowMethod"))
            {
                string[] methods = xl.getProperty("methods").Split(',');

                SSet <string> dd = new SSet <string>();
                dd.addAll(methods);
                _clsAllowMethods.put(xl.getProperty("cls"), dd);
            }

            //先处理包路径
            foreach (XML xl in xml.getChildrenByName("root"))
            {
                SList <string> ignoreList = new SList <string>();

                foreach (XML pXml in xl.getChildrenByName("ignorePath"))
                {
                    ignoreList.add(pXml.getProperty("path"));
                }

                StringIntMap hotfixPathDic = new StringIntMap();

                foreach (XML pXml in xl.getChildrenByName("hotfixPath"))
                {
                    hotfixPathDic.put(pXml.getProperty("path"), pXml.getProperty("needFactory").Equals("true") ? 1 : 0);
                }

                string rootPath = "Assets/" + xl.getProperty("path");

                string[] deepFileList = FileUtils.getDeepFileList(rootPath, "cs");

                foreach (string s in deepFileList)
                {
                    //编辑器类的跳过
                    if (s.Contains("/Editor/"))
                    {
                        continue;
                    }

                    string tailPath = s.Substring(rootPath.Length + 1);

                    bool failed = false;

                    //排除组
                    foreach (string ig in ignoreList)
                    {
                        if (tailPath.StartsWith(ig))
                        {
                            failed = true;
                            break;
                        }
                    }

                    if (failed)
                    {
                        continue;
                    }

                    string fQName = FileUtils.getFileFrontName(s.Substring(aLen));

                    String fName = FileUtils.getFileName(fQName);

                    _clsNameToPathDic.put(fName, fQName);

                    string[] keys   = hotfixPathDic.getKeys();
                    int[]    values = hotfixPathDic.getValues();
                    string   k;
                    int      v;

                    for (int i = keys.Length - 1; i >= 0; --i)
                    {
                        if ((k = keys[i]) != null)
                        {
                            v = values[i];

                            //需要
                            if (tailPath.StartsWith(k))
                            {
                                _adapterClsDic.add(fName);

                                if (v == 1)
                                {
                                    _factoryClsDic.add(fName);
                                }

                                break;
                            }
                        }
                    }
                }
            }

            //再处理命名空间
            foreach (XML xl in xml.getChildrenByName("namespace"))
            {
                _allowNameSpace.add(xl.getProperty("name"));
            }

            //项目程序集
            Assembly assembly = typeof(ShineSetup).Assembly;

            Type[] types = assembly.GetTypes();

            foreach (Type vType in types)
            {
                string fullName = vType.FullName;

                //内部类不统计
                if (!fullName.Contains("+"))
                {
                    //命名空间允许
                    if (string.IsNullOrEmpty(vType.Namespace) || _allowNameSpace.contains(vType.Namespace))
                    {
                        string vName = vType.Name;

                        int index = vName.IndexOf('`');

                        //去掉泛型标记
                        if (index > 0)
                        {
                            vName = vName.Substring(0, index);
                        }

                        TypeInfo typeInfo = new TypeInfo();
                        typeInfo.clsName = vName;
                        typeInfo.clsType = vType;

                        if (_typeDic.contains(vName))
                        {
                            // Ctrl.print("类名重复",vName);
                            continue;
                        }

                        _typeDic.put(vName, typeInfo);
                        //类路径
                        typeInfo.clsPath = _clsNameToPathDic.get(vName);
                    }
                }
            }

            string clsStr = FileUtils.readFileForUTF(controlClsPath);

            string factoryClsPath = getFactoryClsPath(projectType);

            ClsAnalysis.FactoryClassInfo factoryClass = ClsAnalysis.readFactory(factoryClsPath);
            string projectMark = getProjectMark(projectType);

            string factoryClsName = FileUtils.getFileFrontName(FileUtils.getFileName(factoryClsPath));

            //遍历父
            for (int i = projectType - 1; i >= Project_Common; i--)
            {
                ClsAnalysis.FactoryClassInfo parentFactoryCls = ClsAnalysis.readFactory(getFactoryClsPath(i));

                factoryClass.addParent(parentFactoryCls);
            }


            StringBuilder sb = new StringBuilder();

            endClsLine(sb);

            if (!_isShine)
            {
                sb.Append("base.initOtherAdapters(appdomain);");
                endClsLine(sb);
            }


            XML reXMl = new XML();

            reXMl.name = "info";

            //工厂最后执行
            TypeInfo factoryTypeInfo = getTypeInfo(factoryClsName);

            _clsNameToPathDic.remove(factoryClsName);

            foreach (string k in _clsNameToPathDic.getSortedMapKeys())
            {
                TypeInfo typeInfo = getTypeInfo(k);

                if (typeInfo == null)
                {
                    Ctrl.throwError("不该找不到类型", k);
                }

                if (typeInfo.hasHotfixMark || !typeInfo.isEmpty())
                {
                    //需要工厂,并且不是虚类
                    if (!typeInfo.iCls.isAbstract && (typeInfo.needFactory || _factoryClsDic.contains(k)))
                    {
                        ClsAnalysis.FMethod method = factoryClass.addMethod(k, projectMark);

                        //补方法
                        factoryTypeInfo.iCls.addMethod("create" + method.name, method.returnType, VisitType.Public, true);
                    }

                    //需要适配器
                    if (typeInfo.hasHotfixMark || _adapterClsDic.contains(k))
                    {
                        doOneClass(typeInfo.iCls, adapterOutPath, _isShine, sb);
                    }

                    // reXMl.appendChild(typeInfo.writeXML());
                }
            }

            doOneClass(factoryTypeInfo.iCls, adapterOutPath, _isShine, sb);

            //去掉最后一个tab
            sb.Remove(sb.Length - 1, 1);

            clsStr = replaceMethod(clsStr, "protected " + (_isShine ? "virtual" : "override") + " void initOtherAdapters(AppDomain appdomain)", sb.ToString());

            factoryClass.writeToPath(factoryClsPath);
            FileUtils.writeFileForUTF(controlClsPath, clsStr);

            // FileUtils.writeFileForXML("/Users/sunming/E/temp3/aa.xml",reXMl);
        }
예제 #12
0
 private void Start()
 {
     _lastTime = Ctrl.getTimer();
 }
예제 #13
0
        private void onSecond()
        {
            if (_reconnecting)
            {
                if (--_reconnectLastTime <= 0)
                {
                    _reconnectLastTime = 0;

                    Ctrl.log("重连超时,连接关闭");

                    reconnectFailed();
                }
            }

            // Ctrl.print("newResponseNum",_newResponseNum);
            _newResponseNum = 0;

            if (ShineSetting.messageUsePool)
            {
                long nowTime = Ctrl.getFixedTimer();
                int  key;
                for (short i = _sendCheckIndex; i != _sendMsgIndex; i++)
                {
                    BaseRequest request = _sendCacheRequestQueue[key = (i & ShineSetting.requestCacheMark)];

                    if (request == null)
                    {
                        Ctrl.errorLog("不该找不到消息", i);
                        break;
                    }
                    else
                    {
                        if ((nowTime - request.sendTime) > ShineSetting.requestCacheTime)
                        {
                            if (!request.sended)
                            {
                                Ctrl.warnLog("消息还未发送", request.getDataID());
                                break;
                            }

                            request.doRelease();
                            _sendCacheRequestQueue[key] = null;
                            _sendCheckIndex++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            switch (_state)
            {
            case Connected:
            {
                // if(!_socket.Connected)
                // {
                //  //连接被关闭
                //  beClose();
                // }

                ++_pingIndex;

                if (_pingIndex >= ShineSetting.pingTime)
                {
                    _pingIndex = 0;

                    sendPingRequest();
                }

                if (ShineSetting.needPingCut)
                {
                    ++_pingTimePass;

                    if (_pingTimePass > ShineSetting.pingKeepTime)
                    {
                        Ctrl.warnLog("连接超时,强制关闭");
                        _pingTimePass = 0;
                        closeForIO(Close_TimeOut);
                    }
                }
            }
            break;

            case Connecting:
            {
                //连接超时
                if ((++_connectTime) >= _connectTimeMax)
                {
                    Ctrl.log("连接中超时");

                    _connectTime = 0;
                    preConnectFailedForIO();
                }
            }
            break;

            case Closed:
            {
                _tryConnectTime.onSecond();
            }
            break;
            }
        }
예제 #14
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();
                }
            }
        }
예제 #15
0
        private static void doOneGenerate(XML xml, string controlClsPath, string adapterOutPath, int projectType)
        {
            clearGenerate();

            string[] fileList = FileUtils.getFileList(adapterOutPath, "cs");

            SMap <string, string> fileMap = new SMap <string, string>();

            foreach (string s in fileList)
            {
                string fN = FileUtils.getFileNameWithoutEx(s);

                if (fN.EndsWith("Adapter"))
                {
                    fileMap.put(fN.Substring(0, fN.Length - 7), s);
                }
            }

            _isShine = projectType == 0;

            int aLen = "Assets/".Length;

            //先处理包路径
            foreach (XML xl in xml.getChildrenByName("root"))
            {
                SList <string> ignoreList = new SList <string>();

                foreach (XML pXml in xl.getChildrenByName("ignorePath"))
                {
                    ignoreList.add(pXml.getProperty("path"));
                }

                StringIntMap hotfixPathDic = new StringIntMap();

                foreach (XML pXml in xl.getChildrenByName("hotfixPath"))
                {
                    hotfixPathDic.put(pXml.getProperty("path"), pXml.getProperty("needFactory").Equals("true") ? 1 : 0);
                }

                string rootPath = "Assets/" + xl.getProperty("path");

                string[] deepFileList = FileUtils.getDeepFileList(rootPath, "cs");

                foreach (string s in deepFileList)
                {
                    //编辑器类的跳过
                    if (s.Contains("/Editor/"))
                    {
                        continue;
                    }

                    string tailPath = s.Substring(rootPath.Length + 1);

                    bool failed = false;

                    //排除组
                    foreach (string ig in ignoreList)
                    {
                        if (tailPath.StartsWith(ig))
                        {
                            failed = true;
                            break;
                        }
                    }

                    if (failed)
                    {
                        continue;
                    }

                    string fQName = FileUtils.getFileFrontName(s.Substring(aLen));

                    String fName = FileUtils.getFileName(fQName);

                    _clsNameToPathDic.put(fName, fQName);

                    string[] keys   = hotfixPathDic.getKeys();
                    int[]    values = hotfixPathDic.getValues();
                    string   k;
                    int      v;

                    for (int i = keys.Length - 1; i >= 0; --i)
                    {
                        if ((k = keys[i]) != null)
                        {
                            v = values[i];

                            //需要
                            if (tailPath.StartsWith(k))
                            {
                                _adapterClsDic.add(fName);

                                if (v == 1)
                                {
                                    _factoryClsDic.add(fName);
                                }

                                break;
                            }
                        }
                    }
                }
            }


            string clsStr = FileUtils.readFileForUTF(controlClsPath);

            string projectMark    = getProjectMark(projectType);
            string factoryClsPath = getFactoryClsPath(projectType);

            ClsAnalysis.FactoryClassInfo factoryClass = null;
            string factoryClsName = null;

            if (!_isShine)
            {
                factoryClass   = ClsAnalysis.readFactory(factoryClsPath);
                factoryClsName = FileUtils.getFileFrontName(FileUtils.getFileName(factoryClsPath));

                //遍历父
                for (int i = projectType - 1; i >= Project_Common; i--)
                {
                    ClsAnalysis.FactoryClassInfo parentFactoryCls = ClsAnalysis.readFactory(getFactoryClsPath(i));

                    factoryClass.addParent(parentFactoryCls);
                }
            }

            StringBuilder sb = new StringBuilder();

            endClsLine(sb);

            if (!_isShine)
            {
                sb.Append("base.initOtherAdapters(appdomain);");
                endClsLine(sb);
            }


            TypeInfo factoryTypeInfo = null;

            if (!_isShine)
            {
                //工厂最后执行
                factoryTypeInfo = getTypeInfo(factoryClsName);

                _clsNameToPathDic.remove(factoryClsName);
            }

            //ex
            foreach (XML xl in xml.getChildrenByName("customClass"))
            {
                ILClassInfo cls = new ILClassInfo(xl.getProperty("name"));

                foreach (XML mXml in xl.getChildrenByName("method"))
                {
                    string visitTypeStr = mXml.getProperty("visitType");
                    int    visitType    = visitTypeStr.isEmpty() ? VisitType.Protected : VisitType.getTypeByName(visitTypeStr);

                    string needBaseCallStr = mXml.getProperty("needBaseCall");
                    bool   needBaseCall    = needBaseCallStr.isEmpty() ? true : StringUtils.strToBoolean(needBaseCallStr);

                    string   argsStr = mXml.getProperty("args");
                    string[] args    = argsStr.isEmpty() ? ObjectUtils.EmptyStringArr : argsStr.Split(',');

                    cls.addMethod(mXml.getProperty("name"), mXml.getProperty("returnType"), visitType, needBaseCall, args);
                }

                doOneClass(cls, adapterOutPath, _isShine, sb);
                fileMap.remove(cls.clsName);
            }

            foreach (string k in _clsNameToPathDic.getSortedMapKeys())
            {
                TypeInfo typeInfo = getTypeInfo(k);

                if (typeInfo == null)
                {
                    if (!_isShine)
                    {
                        Ctrl.throwError("不该找不到类型", k);
                    }
                }
                else
                {
                    if (typeInfo.hasHotfixMark || !typeInfo.isEmpty())
                    {
                        //需要工厂,并且不是虚类
                        if (!_isShine && !typeInfo.iCls.isAbstract && (typeInfo.needFactory || _factoryClsDic.contains(k)))
                        {
                            ClsAnalysis.FMethod method = factoryClass.addMethod(k, projectMark);
                            //补方法
                            factoryTypeInfo.iCls.addMethod("create" + method.name, method.returnType, VisitType.Public, true);
                        }

                        //需要适配器
                        if (typeInfo.hasHotfixMark || _adapterClsDic.contains(k))
                        {
                            doOneClass(typeInfo.iCls, adapterOutPath, _isShine, sb);
                            fileMap.remove(typeInfo.clsName);
                        }
                    }
                }
            }

            if (!_isShine)
            {
                doOneClass(factoryTypeInfo.iCls, adapterOutPath, _isShine, sb);
                fileMap.remove(factoryTypeInfo.clsName);
            }

            //去掉最后一个tab
            sb.Remove(sb.Length - 1, 1);

            clsStr = replaceMethod(clsStr, "protected " + (_isShine ? "virtual" : "override") + " void initOtherAdapters(AppDomain appdomain)", sb.ToString());

            if (!_isShine)
            {
                factoryClass.writeToPath(factoryClsPath);
            }

            FileUtils.writeFileForUTF(controlClsPath, clsStr);

            if (!fileMap.isEmpty())
            {
                fileMap.forEach((k, v) =>
                {
                    FileUtils.deleteFile(v);
                });
            }
        }
예제 #16
0
 /** 空对象错误 */
 public void nullObjError(string fieldName)
 {
     Ctrl.throwError("数据写入时为空,dataName:" + getDataClassName() + "fieldName:" + fieldName);
 }
예제 #17
0
        public long remove(int key)
        {
            if (_size == 0)
            {
                return(0L);
            }

            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(0L);
                    }
                    else
                    {
                        while (true)
                        {
                            if ((cur = keys[(index = (index - 1) & capacityMask)]) == key)
                            {
                                break;
                            }
                            else if (cur == free)
                            {
                                return(0L);
                            }
                        }
                    }
                }

                long[] vals          = _values;
                long   val           = vals[index];
                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;
                        vals[indexToRemove] = vals[indexToShift];
                        indexToRemove       = indexToShift;
                        shiftDistance       = 1;
                    }
                    else
                    {
                        shiftDistance++;
                        if (indexToShift == (1 + index))
                        {
                            Ctrl.throwError("ConcurrentModificationException");
                        }
                    }
                }

                keys[indexToRemove] = free;
                vals[indexToRemove] = 0L;
                postRemoveHook(indexToRemove);
                return(val);
            }
            else
            {
                return(0L);
            }
        }
예제 #18
0
 private void OnDestroy()
 {
     Ctrl.print("destroy FrameContainer");
 }
예제 #19
0
파일: SSet.cs 프로젝트: shineTeam7/home3
        public bool remove(K key)
        {
            if (Equals(_defaultKey, key))
            {
                Ctrl.throwError("key不能为空");
                return(false);
            }

            if (_size == 0)
            {
                return(false);
            }

            K k = key;

            K[] keys         = _set;
            int capacityMask = (keys.Length) - 1;
            int index;
            K   cur;

            if (!k.Equals((cur = keys[(index = hashObj(k) & capacityMask)])))
            {
                if (Equals(_defaultKey, cur))
                {
                    return(false);
                }
                else
                {
                    while (true)
                    {
                        if (k.Equals((cur = keys[(index = (index - 1) & capacityMask)])))
                        {
                            break;
                        }
                        else if (Equals(_defaultKey, cur))
                        {
                            return(false);
                        }
                    }
                }
            }

            int indexToRemove = index;
            int indexToShift  = indexToRemove;
            int shiftDistance = 1;

            while (true)
            {
                indexToShift = (indexToShift - 1) & capacityMask;
                K keyToShift;
                if (Equals(_defaultKey, keyToShift = keys[indexToShift]))
                {
                    break;
                }
                K castedKeyToShift = keyToShift;
                if (((hashObj(castedKeyToShift) - indexToShift) & capacityMask) >= shiftDistance)
                {
                    keys[indexToRemove] = castedKeyToShift;
                    indexToRemove       = indexToShift;
                    shiftDistance       = 1;
                }
                else
                {
                    shiftDistance++;
                }
            }

            keys[indexToRemove] = default(K);
            postRemoveHook(indexToRemove);

            return(true);
        }
예제 #20
0
파일: CharSet.cs 프로젝트: shineTeam7/home3
        public bool remove(char key)
        {
            if (_size == 0)
            {
                return(false);
            }

            char free;

            if (key != (free = _freeValue))
            {
                char[] keys         = _set;
                int    capacityMask = (keys.Length) - 1;
                int    index;
                char   cur;
                if ((cur = keys[(index = hashChar(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;
                    char keyToShift;
                    if ((keyToShift = keys[indexToShift]) == free)
                    {
                        break;
                    }

                    if (((hashChar(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);
            }
        }