Exemple #1
0
        public void CompleteSetup()
        {
            // Test using a complex object for both key and value. Since we're implementing an optional
            // hash generator here, this also is test/proof that we can use an object as its own key AND
            // value. What's neat about that is we could use more sophisticated hashing mechanisms without
            // updating every spot in our code, as we would if we had to pre-extract and provide a single
            // key to the alg. For example, suppose we have an employee{id, name, ssn, dob, ...} object to
            // store. Initially we might key off the user.id field, but maybe that's a lengthy GUID. What
            // if we later determine it's acceptable to key off the SSN? We'd have to update all of our code
            // to implement that change, and risk a bug. Here, we can simply swap out the hashing routine
            // when the cache is initialized.
            SACache <TestType, TestType> cache = new SACache <TestType, TestType>(4, 2, new TestEvictor(), new TestHashGenerator());

            var t1 = new TestType(0, "Test");

            cache.put(t1, t1);

            var t2 = new TestType(1, "Test2");

            cache.put(t2, t2);

            var t3 = new TestType(2, "Test3");

            Assert.AreEqual(cache.get(t1), t1);
            Assert.AreEqual(cache.get(t2), t2);
            Assert.AreNotEqual(cache.get(t2), t1);
            Assert.IsNull(cache.get(t3));

            Assert.AreEqual(cache.cacheHits, (ulong)3);
            Assert.AreEqual(cache.cacheMisses, (ulong)1);
            Assert.AreEqual(cache.cacheEvictions, (ulong)0);
        }
Exemple #2
0
        /*IEnumerator DoSomething ()
         * {
         *  FishData f;
         *  for (int i; i < sof.Length; ++i)
         *  {
         *      f = sof[i];
         *
         *  }
         *              for (int i = 0; i < 300; ++i) {
         *                      fish.FishFactory.RandomFish (this);
         *                      yield return new WaitForSeconds(1);
         *              }
         *      }*/
        IEnumerator refresh()
        {
            int      i = 0;//数组递增
            FishData fd;
            int      gap = 0;

            delay = currentTime - startTime;//获取当前已逝去时间
            while (true)
            {
                fd = sof[i];
                if (fd.delay > delay)
                {
                    gap    = (int)(fd.delay - delay);
                    delay += gap;
                    yield return(new WaitForSeconds(gap / 1000));
                }
                else
                {
                    GameObject test = GameObject.Instantiate((GameObject)SACache.getObjectWithName("model/fish/" + fd.fishID));
                    FishSwim   fs   = test.AddComponent <FishSwim>();
                    fs.setInfo(graph, fd, delay);
                    ++i;
                }
                if (i >= sof.Count || exit)
                {
                    break;//结束
                }
            }
            StopCoroutine("refresh");
        }
Exemple #3
0
        private void downloadComplete()
        {
            StopAllCoroutines();
            SALang.MakDirValid(SAAppConfig.RemotePath);

            convertXML.Save(Path.Combine(SAAppConfig.RemotePath, MD5_NAME));//写入本地最新XML
            version = newVersion;
            //资源缓存
            SACache.LoadLuaPackage(SAAppConfig.RemotePath, SAAppConfig.LanguagePlatform + "/" + SAAppConfig.LuaPathName); //lua 缓存
            //unity资源
            abs          = new AssetBundle[(version.Count - 3) / 2 + 2];                                                  //Platform Platform.manifest lua.bytes other.manifest
            abs_position = 0;
            //shader
            loadAssetBundleManifest(SAAppConfig.LanguagePlatform + "s");
            //资源
            loadAssetBundleManifest(SAAppConfig.LanguagePlatform);
            for (int i = 0; i < abs.Length; ++i)
            {
                if (null != abs[i])
                {
                    abs[i].Unload(false);
                    abs[i] = null;
                }
            }
            SACache.getResDictionary(SAACollection.AtlasStr).Clear();

            abs_position = 0;
            removeEventDispatcher(SAACollection.REFRESH + ActionCollection.LocalFile);                  //资源加载
            dispatchEvent(SAACollection.REFRESH + ActionCollection.LocalFile + SAACollection.COMPLETE); //更新完成
        }
Exemple #4
0
        public void MisbehavedEvictor()
        {
            SACache <int, string> cache = new SACache <int, string>(4, 2, new BadEvictor(), null);

            cache.put(0, "Test");
            cache.put(1, "Test");
            cache.put(4, "Test"); // Should evict
        }
Exemple #5
0
        public void BindAtlas(string name)
        {
            UISprite[] sprites = SAGameObject.GetComponentsInChildren <UISprite>();
            UISprite   sprite;

            for (int i = 0; i < sprites.Length; ++i)
            {
                sprite       = sprites[i];
                sprite.atlas = (UIAtlas)SACache.getObjectWithName(name);
            }
        }
Exemple #6
0
        public void SimpleSetup()
        {
            SACache <int, string> cache = new SACache <int, string>();

            // We should be able to store an item
            cache.put(0, "Test");
            Assert.AreEqual(cache.get(0), "Test");

            // And we should be able to replace it in-place.
            cache.put(0, "Replacement");
            Assert.AreEqual(cache.get(0), "Replacement");

            Assert.AreEqual(cache.cacheHits, (ulong)2);
            Assert.AreEqual(cache.cacheMisses, (ulong)0);
            Assert.AreEqual(cache.cacheEvictions, (ulong)0);
        }
Exemple #7
0
        void Update()
        {
            Vector3 pos   = Input.mousePosition;
            float   px    = Math.Abs(pos.x) - Screen.width / 2;
            float   py    = pos.y;       // + hhlaf;
            Vector3 q     = c.eulerAngles;
            double  angle = 0;

            if (px == 0)
            {
                if (py > 0)
                {
                    angle = 90;
                }
                if (py < 0)
                {
                    angle = 270;
                }
            }
            else
            {
                double tan = py / px;
                if (px > 0)
                {
                    angle = Math.Atan(tan) * 180 / Math.PI - 90;
                }
                else
                {
                    angle = Math.Atan(tan) * 180 / Math.PI + 90;
                }
            }
            q.z           = (float)angle;
            c.eulerAngles = q;
            if (Input.GetKey(KeyCode.Mouse0))
            {
                if (++ct > mt)
                {
                    ct = 0;
                    GameObject projectile = GameObject.Instantiate((GameObject)SACache.getObjectWithName("model/bullet/" + bullets [UnityEngine.Random.Range(0, bullets.Length)]));
                    projectile.transform.position    = c.position;
                    projectile.transform.eulerAngles = q;
                    projectile.GetComponent <Rigidbody> ().AddForce(projectile.transform.up * 400);
                    projectile.GetComponent <ETFXProjectileScript> ().impactNormal = Vector3.forward;
                }
            }
        }
Exemple #8
0
        public void PartialSetup()
        {
            SACache <int, string> cache = new SACache <int, string>(4, 2);

            // With 4 lines, 2 per set, we have two sets. That means we should be able
            // to store 2 objects, while the third pushes something out. Yet a higher
            // address does NOT push anything out.
            cache.put(0, "Test");
            cache.put(1, "Test2");
            cache.put(4, "Test3");

            Assert.AreEqual(cache.get(0), null); // Should have been evicted. SACache defaults to LRU.
            Assert.AreEqual(cache.get(4), "Test3");
            Assert.AreEqual(cache.get(1), "Test2");
            Assert.AreEqual(cache.get(2), null);

            Assert.AreEqual(cache.cacheHits, (ulong)2);
            Assert.AreEqual(cache.cacheMisses, (ulong)2);
            Assert.AreEqual(cache.cacheEvictions, (ulong)1);
        }
Exemple #9
0
        private void addDependToCache(string dependName, string dir)
        {
            int    dot       = dependName.LastIndexOf('.');
            string contrast  = dependName.Substring(0, dot);                     //缓存名称
            string cacheName = dependName.Substring(0, dependName.IndexOf('.')); //缓存集合

            Dictionary <string, System.Object> assetCache = SACache.getResDictionary(cacheName);

            if (null != assetCache && !assetCache.ContainsKey(contrast))
            {
                AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(SAAppConfig.RemotePath, dir + "/" + dependName));//加载依赖文件
                dependName          = SAAppConfig.LocalDevDir.ToLower() + dependName.Substring(0, dot).Replace(".", "/") + dependName.Substring(dot);
                abs[abs_position++] = ab;
                dot = contrast.IndexOf(".") + 1;
                string tempContrast = contrast.Substring(dot);
                if (SAAppConfig.CacheModel ||
                    (cacheName.Equals(SAACollection.UIStr) && tempContrast.Length >= SAACollection.ComminLen && tempContrast.Substring(0, SAACollection.ComminLen).Equals(SAACollection.CommonStr)))
                {
                    assetCache[contrast] = ab.LoadAsset(dependName);
                }
                else if (cacheName.Equals(SAACollection.ShaderStr))
                {
                    string[] names = ab.GetAllAssetNames();
                    string   tempKey;
                    string   tempName;
                    int      tempKeyBegin;
                    for (int i = 0; i < names.Length; ++i)
                    {
                        tempName            = names[i];
                        tempKeyBegin        = tempName.LastIndexOf("/") + 1;
                        tempKey             = tempName.Substring(tempKeyBegin, tempName.Length - tempKeyBegin - SAACollection.MatSuffixLen);
                        assetCache[tempKey] = ab.LoadAsset(tempName);
                    }
                }
            }
        }
Exemple #10
0
 public void InvalidCacheSize()
 {
     SACache <int, string> cache = new SACache <int, string>(1, 2);
 }
Exemple #11
0
        virtual public void joinGraph(IOCGraphWorker workerData)
        {
            GameObject    display;
            SAGraphWorker graph;

            string DotName   = workerData.name.Replace("/", ".");
            string NoDotName = workerData.name.Replace(".", "/");

            if (repeatObjects.ContainsKey(DotName))
            {
                display = repeatObjects[DotName];
            }
            else
            {
                string prefabName;
                int    languageDot = DotName.LastIndexOf(".") + 1;
                if (workerData.isLocal)//强制本地
                {
                    prefabName = NoDotName.Substring(0, languageDot) + SAAppConfig.Language + "_" + NoDotName.Substring(languageDot);
                    display    = (GameObject)UnityEngine.Object.Instantiate(Resources.Load(prefabName));
                }
                else
                {
                    prefabName = DotName.Substring(0, languageDot) + SAAppConfig.Language + "_" + DotName.Substring(languageDot);
                    display    = (GameObject)UnityEngine.Object.Instantiate(SACache.getResWithName <GameObject>(prefabName, "prefab"));
                }
                //repeatObjects.Add(DotName, display);//关闭缓存
            }
            //笔记
            Transform  _SATransform  = display.transform;
            GameObject _SAGameObject = display;
            //shell
            GameObject shell = new GameObject();

            shell.name  = _SAGameObject.name + "[SHELL]";
            shell.layer = display.layer;
            display.transform.SetParent(shell.transform);
            display = shell;

            if (null != SAManager.Instance.UIRootCamera && display.layer == SAManager.Instance.NGUILayer)
            {
                display.transform.SetParent(SAManager.Instance.UIRootCamera.transform, false);
            }
            Type graphType = Type.GetType(DotName);

            if (null == graphType)
            {
                string graphName = DotName.Substring(DotName.LastIndexOf(".") + 1);
                graphType = Type.GetType(SAACollection.GraphsStr + graphName + SAACollection.GraphSuffix);
            }
            if (null == graphType)
            {
                graph = display.AddComponent <SAGraphWorker>();
            }
            else
            {
                graph = (SAGraphWorker)display.AddComponent(graphType);
            }
            graph.setOrigin(_SAGameObject, _SATransform);
            graph.setActiveDispose(workerData.isActiveDispose);
            graph.setDefaultStart(workerData.defaultStart);

            graph._init(DotName, NoDotName);
            graphWorkers.Add(graph);
            if (_start)
            {
                registerGraphicsWorker(graph);
            }
        }