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()); }
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); }
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); }
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); }
public GridDeadzone(IMyCubeGrid grid) { this.grid = grid; cachedBlockSearch = new CachedFunction <CalculationValues, bool>(IsBlockInTheWay); cubeExists = new CachedFunction <Vector3I, bool>(grid.CubeExists); }
internal bool HasFunction(CachedFunction type) { return(_cachedFunctions[(int)type] != LuaConstants.LUA_NOREF); }