public static MCOutputData Get(Vector3[] srcPosArray, Vector2[] srcNorm01Array, Vector2[] srcNorm2tArray, int srcIdx, int len) { MCOutputData ret; if (len > SurfExtractorsMan.c_vertsCnt4Pool) { Vector3[] pos = new Vector3[len]; Vector2[] norm01 = new Vector2[len]; Vector2[] norm2t = new Vector2[len]; int[] indice = new int[len]; Array.Copy(srcPosArray, srcIdx, pos, 0, len); Array.Copy(srcNorm01Array, srcIdx, norm01, 0, len); Array.Copy(srcNorm2tArray, srcIdx, norm2t, 0, len); Array.Copy(SurfExtractorsMan.s_indiceMax, indice, len); ret = new MCOutputData(pos, norm01, norm2t, indice); return(ret); } else { ret = s_dataPool.Get(); Array.Copy(srcPosArray, srcIdx, ret._pos, 0, len); Array.Copy(srcNorm01Array, srcIdx, ret._norm01, 0, len); Array.Copy(srcNorm2tArray, srcIdx, ret._norm2t, 0, len); if (len == SurfExtractorsMan.c_vertsCnt4Pool) { ret._indice = SurfExtractorsMan.s_indice4Pool; } else if (ret._indice == null || len != ret._indice.Length) { ret._indice = new int[len]; Array.Copy(SurfExtractorsMan.s_indiceMax, ret._indice, len); } } return(ret); }
/// <summary> /// Creates a <see cref="ReadOnlyMessageFragment"/> which represents string that should be preserved and not modified by any other pseudo methods. /// Fragments are created using an ObjectPool so they can be reused. Use <see cref="ReleaseFragment(MessageFragment)"/> to /// return the fragment or allow the Message to handle returning the fragment if it is part of <see cref="Fragments"/>. /// </summary> /// <param name="original">The source string.</param> /// <returns>A new fragment.</returns> public ReadOnlyMessageFragment CreateReadonlyTextFragment(string original) { var frag = GenericPool <ReadOnlyMessageFragment> .Get(); frag.Initialize(this, original); return(frag); }
/// <summary> /// Creates a new <see cref="WritableMessageFragment"/> which represents a string. /// Fragments are created using an ObjectPool so they can be reused. Use <see cref="ReleaseFragment(MessageFragment)"/> to /// return the fragment or allow the Message to handle returning the fragment if it is part of <see cref="Fragments"/>. /// </summary> /// <param name="original">The source string.</param> /// <returns>A new fragment.</returns> public WritableMessageFragment CreateTextFragment(string original) { var frag = GenericPool <WritableMessageFragment> .Get(); frag.Initialize(this, original); return(frag); }
public void SpawnNumber(int number, Color c) { GameObject damageNumber = pool.GetObject(); ((RectTransform)damageNumber.transform).anchoredPosition = new Vector2(0, 0); TextMeshProUGUI tmpugui = damageNumber.GetComponent <TextMeshProUGUI>(); tmpugui.SetText(number.ToString()); tmpugui.faceColor = c; Color outline = Color.black; UpdateTimer ut = timers.Get(); ut.Start(2, () => { // finish pool.Return(damageNumber); timers.Return(ut); }, (percentComplete) => { // update c.a = 1 - percentComplete; tmpugui.faceColor = c; outline.a = c.a; tmpugui.outlineColor = outline; }); }
/// <summary> /// Creates a new message to represent a piece of text. /// </summary> /// <param name="text">The source text.</param> /// <returns>A new Message instance.</returns> internal static Message CreateMessage(string text) { var message = GenericPool <Message> .Get(); message.Fragments.Add(message.CreateTextFragment(text)); message.Original = text; return(message); }
internal void WriteAsyncLogEvents(ArraySegment <AsyncLogEventInfo> logEventInfos, AsyncContinuation continuation) { if (logEventInfos.Count == 0) { continuation(null); } else { AsyncLogEventInfo[] wrappedLogEventInfos = null; try { Counter counter; GenericPool <ContinueWhenAll> continuePool = null; int remaining = logEventInfos.Count; if (this.LoggingConfiguration.PoolingEnabled()) { counter = this.LoggingConfiguration.PoolFactory.Get <Counter>(); continuePool = this.LoggingConfiguration.PoolFactory.Get <GenericPool <ContinueWhenAll>, ContinueWhenAll>(); wrappedLogEventInfos = this.LoggingConfiguration.PoolFactory.Get <AsyncLogEventInfoArrayPool, AsyncLogEventInfo[]>().Get(logEventInfos.Count); } else { wrappedLogEventInfos = new AsyncLogEventInfo[logEventInfos.Count]; counter = new Counter(); } counter.Reset(remaining); for (int i = 0; i < logEventInfos.Count; ++i) { AsyncContinuation originalContinuation = logEventInfos.Array[i].Continuation; ContinueWhenAll cont; if (continuePool != null) { cont = continuePool.Get(); cont.Reset(counter, originalContinuation, continuation); wrappedLogEventInfos[i] = logEventInfos.Array[i].LogEvent.WithContinuation(cont.Delegate); } else { cont = new ContinueWhenAll(); } cont.Reset(counter, originalContinuation, continuation); wrappedLogEventInfos[i] = logEventInfos.Array[i].LogEvent.WithContinuation(cont.Delegate); } this.WriteAsyncLogEvents(new ArraySegment <AsyncLogEventInfo>(wrappedLogEventInfos, 0, logEventInfos.Count)); } finally { this.LoggingConfiguration.PutBack(wrappedLogEventInfos); } } }
/// <inheritdoc cref="Message.CreateReadonlyTextFragment(string, int, int)"/> public ReadOnlyMessageFragment CreateReadonlyTextFragment(int start, int end) { var frag = GenericPool <ReadOnlyMessageFragment> .Get(); var startIndex = m_StartIndex == -1 ? start : m_StartIndex + start; frag.Initialize(@Message, m_OriginalString, startIndex, end); return(frag); }
public static GameObject Get(object key) { ObjectItem item = objects.Get(key); if (item == null) { return(null); } return(Reset(item).gameObject); }
public static T Get <T>(object key) where T : Component { ObjectItem item = components.Get(key); if (item == null) { return(null); } return((T)Reset(item).component); }
public static SurfExtractReqB45 Get(int chunkStamp, Block45OctNode chunkData, Action <SurfExtractReqB45> finHandler, int nVertsPerMesh = SurfExtractorsMan.c_vertsCntMax) { //SurfExtractReqB45 req = new SurfExtractReqB45 (); SurfExtractReqB45 req = s_reqPool.Get(); req._chunkStamp = chunkStamp; req._chunkData = chunkData; req._nVertsPerMesh = nVertsPerMesh; req._finHandler = finHandler; return(req); }
public static XRPass Create(XRPassCreateInfo createInfo) { XRPassUniversal pass = GenericPool <XRPassUniversal> .Get(); pass.InitBase(createInfo); // Initialize fields specific to Universal pass.isLateLatchEnabled = false; pass.canMarkLateLatch = false; pass.hasMarkedLateLatch = false; return(pass); }
public static SurfExtractReqMC Get(VFVoxelChunkData chunk, int nVertsPerMesh = SurfExtractorsMan.c_vertsCnt4Pool) { //SurfExtractReqMC req = new SurfExtractReqMC (); SurfExtractReqMC req = s_reqPool.Get(); req._chunk = chunk; req._chunkData = chunk.DataVT; req._chunkSig = chunk.SigOfChnk; req._chunkStamp = chunk.StampOfUpdating; req._customFinHandler = null; req._nVertsPerMesh = nVertsPerMesh; return(req); }
public Set this[int index] { get { if (!m_Requests.TryGetValue(index, out var v)) { v = GenericPool <Set> .Get(); m_Requests.Add(index, v); } return(v); } }
/// <summary> /// Implementation for all versions of <see cref="GetLocalizedAssetAsync"/>. /// </summary> /// <typeparam name="TObject">The type of asset that should be loaded.</typeparam> /// <param name="tableReference">A reference to the table that the asset should be loaded from.</param> /// <param name="tableEntryReference">A reference to the entry in the table.</param> /// <param name="locale">The <see cref="Locale"/> to use instead of the default <see cref="LocalizationSettings.SelectedLocale"/></param> protected virtual AsyncOperationHandle <TObject> GetLocalizedAssetAsyncInternal <TObject>(TableReference tableReference, TableEntryReference tableEntryReference, Locale locale) where TObject : Object { var loadTableOperation = GetTableAsync(tableReference, locale); var operation = GenericPool <LoadAssetOperation <TObject> > .Get(); operation.Init(loadTableOperation, tableEntryReference); var handle = AddressablesInterface.ResourceManager.StartOperation(operation, loadTableOperation); // We don't want to force users to have to manage the reference counting so by default we will release the operation for reuse once completed in the next frame // If a user wants to hold onto it then they should call Acquire on the operation and later Release. handle.CompletedTypeless += ReleaseNextFrame; return(handle); }
public CreateChunkAndRenderBlock( World world, Dictionary <string, Texture> textureDictionary, string texturePath, RenderSettings renderSettings, IGraphicsApi <TImage> graphics, int chunkSize, int chunksPerDimension, ExecutionDataflowBlockOptions options) { int tileSize = chunksPerDimension * chunkSize; graphics.SetPoolDimensions(tileSize, tileSize); int chunkRenderedCounter = 0; var renderCombiPool = new GenericPool <RendererCombi <TImage> >(() => new RendererCombi <TImage>(textureDictionary, texturePath, renderSettings, graphics)); Block = new TransformBlock <IEnumerable <ChunkData>, ImageInfo <TImage> >(chunkDatas => { RendererCombi <TImage> chunkRenderer = null; try { var b = graphics.GetPooledImage(); // pooled //var b = graphics.CreateEmptyImage(tileSize, tileSize); chunkRenderer = renderCombiPool.Get(); var firstX = -1; var firstZ = -1; var count = 0; var chunkDataList = chunkDatas.ToList(); foreach (var chunkData in chunkDataList) { var chunk = world.GetChunk(chunkData.X, chunkData.Z, chunkData); if (firstX == -1) { firstX = chunkData.X; } if (firstZ == -1) { firstZ = chunkData.Z; } var x = chunk.X % chunksPerDimension; var z = chunk.Z % chunksPerDimension; if (x < 0) { x += chunksPerDimension; } if (z < 0) { z += chunksPerDimension; } chunkRenderer.ChunkRenderer.RenderChunk(b, chunk, x * chunkSize, z * chunkSize); world.ChunkPool?.Return(chunk); count++; } var fx = CoordHelpers.GetGroupedCoordinate(firstX, chunksPerDimension); var fz = CoordHelpers.GetGroupedCoordinate(firstZ, chunksPerDimension); Interlocked.Increment(ref processedCount); Interlocked.Add(ref chunkRenderedCounter, count); if (chunkRenderedCounter >= 128) { var v = chunkRenderedCounter; ChunksRendered?.Invoke(this, new ChunksRenderedEventArgs(v)); Interlocked.Add(ref chunkRenderedCounter, -v); } /*if (r.Next(100) == 0) * { * throw new ArgumentOutOfRangeException("Test Error in CreateChunkAndRender"); * }*/ return(new ImageInfo <TImage>() { Image = b, X = fx, Z = fz, Cd = chunkDataList.SelectMany(x => x.SubChunks) }); } catch (Exception ex) { Console.WriteLine("Error in CreateChunkAndRenderBlock: " + ex.Message); return(null); } finally { if (chunkRenderer != null) { renderCombiPool.Return(chunkRenderer); } } }, options); }
internal static void GetMenuOptions(int mask, string[] flagNames, int[] flagValues, out string buttonText, out string buttonMixedValuesText, out string[] optionNames, out int[] optionMaskValues, out int[] selectedOptions, Type enumType = null) { const int everythingValue = ~0; bool hasNothingName = flagValues[0] == 0; bool hasEverythingName = flagValues[flagValues.Length - 1] == everythingValue; var nothingName = (hasNothingName ? flagNames[0] : "Nothing"); var everythingName = (hasEverythingName ? flagNames[flagValues.Length - 1] : "Everything"); var optionCount = flagNames.Length + (hasNothingName ? 0 : 1) + (hasEverythingName ? 0 : 1); var flagCount = flagNames.Length - (hasNothingName ? 1 : 0) - (hasEverythingName ? 1 : 0); // These indices refer to flags that are not 0 and everythingValue var flagStartIndex = (hasNothingName ? 1 : 0); var flagEndIndex = flagStartIndex + flagCount; // Options names optionNames = GetBuffer(s_OptionNames, optionCount); optionNames[0] = nothingName; optionNames[1] = everythingName; for (var flagIndex = flagStartIndex; flagIndex < flagEndIndex; flagIndex++) { var optionIndex = flagIndex - flagStartIndex + 2; optionNames[optionIndex] = flagNames[flagIndex]; } var flagMask = 0; // Disjunction of all flags (except 0 and everythingValue) var intermediateMask = 0; // Mask used to compute new mask value for each options // Selected options s_SelectedOptionsSet.Clear(); for (var flagIndex = flagStartIndex; flagIndex < flagEndIndex; flagIndex++) { var flagValue = flagValues[flagIndex]; flagMask |= flagValue; if ((mask & flagValue) == flagValue) { var optionIndex = flagIndex - flagStartIndex + 2; s_SelectedOptionsSet.Add(optionIndex); intermediateMask |= flagValue; } } // Button text buttonText = null; buttonMixedValuesText = null; for (var flagIndex = flagStartIndex; flagIndex < flagEndIndex; flagIndex++) { // Check if a specific value is set. if (mask == flagValues[flagIndex]) { buttonText = flagNames[flagIndex]; } } if (buttonText == null) { if (flagMask == intermediateMask) { // If all of the available flags are set then show the Everything name. s_SelectedOptionsSet.Add(1); buttonText = everythingName; } else if (mask == 0 || s_SelectedOptionsSet.Count == 0) { // If the mask is 0 or none of the actual flags are set we use the nothing name. s_SelectedOptionsSet.Add(0); buttonText = nothingName; } else { buttonText = "Mixed..."; // Extract mixed labels var sb = GenericPool <StringBuilder> .Get(); var iterator = s_SelectedOptionsSet.GetEnumerator(); iterator.MoveNext(); sb.Append(flagNames[iterator.Current + flagStartIndex - 2]); while (iterator.MoveNext()) { sb.Append(", "); sb.Append(flagNames[iterator.Current + flagStartIndex - 2]); } buttonMixedValuesText = sb.ToString(); sb.Clear(); GenericPool <StringBuilder> .Release(sb); } } selectedOptions = GetBuffer(s_SelectedOptions, s_SelectedOptionsSet.Count); var x = 0; foreach (var selected in s_SelectedOptionsSet) { selectedOptions[x] = selected; ++x; } // Option mask values optionMaskValues = GetBuffer(s_OptionValues, optionCount); optionMaskValues[0] = 0; optionMaskValues[1] = everythingValue; if (EditorGUI.showMixedValue) { intermediateMask = 0; } for (var flagIndex = flagStartIndex; flagIndex < flagEndIndex; flagIndex++) { var optionIndex = flagIndex - flagStartIndex + 2; var flagValue = flagValues[flagIndex]; var flagSet = ((intermediateMask & flagValue) == flagValue); var newMask = (flagSet ? intermediateMask & ~flagValue : intermediateMask | flagValue); // If all flag options are selected the mask becomes everythingValue to be consistent with the "Everything" option if (newMask == flagMask) { newMask = everythingValue; } optionMaskValues[optionIndex] = newMask; } }
internal static void GetMaskButtonValue(int mask, string[] flagNames, int[] flagValues, out string buttonText, out string buttonMixedValuesText) { const int everythingValue = ~0; bool hasNothingName = flagValues[0] == 0; bool hasEverythingName = flagValues[flagValues.Length - 1] == everythingValue; var nothingName = (hasNothingName ? flagNames[0] : "Nothing"); var everythingName = (hasEverythingName ? flagNames[flagValues.Length - 1] : "Everything"); var flagCount = flagNames.Length - (hasNothingName ? 1 : 0) - (hasEverythingName ? 1 : 0); var flagStartIndex = (hasNothingName ? 1 : 0); var flagEndIndex = flagStartIndex + flagCount; var flagMask = 0; // Disjunction of all flags (except 0 and everythingValue) var intermediateMask = 0; // Mask used to compute new mask value for each options var usedFlags = ListPool <int> .Get(); buttonText = null; buttonMixedValuesText = null; for (var flagIndex = flagStartIndex; flagIndex < flagEndIndex; flagIndex++) { var flagValue = flagValues[flagIndex]; flagMask |= flagValue; if (mask == flagValues[flagIndex]) { buttonText = flagNames[flagIndex]; } if ((mask & flagValue) == flagValue) { intermediateMask |= flagValue; usedFlags.Add(flagIndex); } } if (buttonText == null) { if (flagMask == intermediateMask) { // If all of the available flags are set then show the Everything name. buttonText = everythingName; } else if (intermediateMask == 0) { // If the mask is 0 or none of the actual flags are set we use the nothing name. buttonText = nothingName; } else { buttonText = "Mixed..."; // Extract mixed labels var sb = GenericPool <StringBuilder> .Get(); sb.Append(flagNames[usedFlags[0]]); for (int i = 1; i < usedFlags.Count; ++i) { sb.Append(", "); sb.Append(flagNames[usedFlags[i]]); } buttonMixedValuesText = sb.ToString(); sb.Clear(); GenericPool <StringBuilder> .Release(sb); } } ListPool <int> .Release(usedFlags); }
public Bitmap GetPooledImage() { return(pool.Get()); }