Ejemplo n.º 1
0
        public void CachesForTheCorrectTime()
        {
            DateTime ExecuteFunc()
            {
                return(DateTime.Now);
            }

            var cachingTime = TimeSpan.FromMilliseconds(100);
            var fnc         = new CachedFunction <DateTime>(ExecuteFunc, cachingTime);

            Assert.False(fnc.HasCached());

            var firstResult = fnc.Execute();

            Assert.True(fnc.HasCached());
            Assert.Equal(firstResult, fnc.Execute());

            Assert.True(fnc.HasCached());
            Assert.Equal(firstResult, fnc.Execute());

            Assert.True(fnc.HasCached());
            Assert.Equal(firstResult, fnc.Execute());

            Assert.True(fnc.HasCached());
            Assert.Equal(firstResult, fnc.Execute());

            Thread.Sleep(cachingTime + TimeSpan.FromSeconds(1));

            Assert.False(fnc.HasCached());
            Assert.NotEqual(firstResult, fnc.Execute());
        }
Ejemplo n.º 2
0
        public static unsafe JobHandle?GetVector3sSparseJob(
            void *indexBuffer,
            void *valueBuffer,
            int sparseCount,
            GLTFComponentType indexType,
            GLTFComponentType valueType,
            float3 *output,
            int outputByteStride,
            ref JobHandle?dependsOn,
            bool normalized = false
            )
        {
            JobHandle?jobHandle;

            Profiler.BeginSample("GetVector3sSparseJob");
            var job = new ConvertVector3SparseJob {
                indexBuffer      = (ushort *)indexBuffer,
                indexConverter   = CachedFunction.GetIndexConverter(indexType),
                inputByteStride  = 3 * Accessor.GetComponentTypeSize(valueType),
                input            = valueBuffer,
                valueConverter   = CachedFunction.GetPositionConverter(valueType, normalized),
                outputByteStride = outputByteStride,
                result           = output,
            };

            jobHandle = job.Schedule(
                sparseCount,
                GltfImport.DefaultBatchCount,
                dependsOn: dependsOn.HasValue ? dependsOn.Value : default(JobHandle)
                );
            Profiler.EndSample();
            return(jobHandle);
        }
Ejemplo n.º 3
0
            internal bool PushFunction(ILuaState lua, CachedFunction type)
            {
                int func = _cachedFunctions[(int)type];

                if (func < 0)
                {
                    return(false);
                }
                lua.RawGetI(LuaDef.LUA_REGISTRYINDEX, func);
                return(true);
            }
Ejemplo n.º 4
0
            internal int InvokeFunction(ILuaState lua, CachedFunction type, int narg, int selftable = LuaConstants.LUA_NOREF)
            {
                int func = _cachedFunctions[(int)type];

                if (func != LuaConstants.LUA_NOREF)
                {
                    lua.RawGetI(LuaDef.LUA_REGISTRYINDEX, func);
                    if (narg > 0)
                    {
                        lua.Insert(-(narg + 1));
                    }
                    return(invoke_function(lua, narg, selftable));
                }
                return(0);
            }
Ejemplo n.º 5
0
 public GridDeadzone(IMyCubeGrid grid)
 {
     this.grid         = grid;
     cachedBlockSearch = new CachedFunction <CalculationValues, bool>(IsBlockInTheWay);
     cubeExists        = new CachedFunction <Vector3I, bool>(grid.CubeExists);
 }
Ejemplo n.º 6
0
 internal bool HasFunction(CachedFunction type)
 {
     return(_cachedFunctions[(int)type] != LuaConstants.LUA_NOREF);
 }