internal void PopIndent() { if (istack.Count > 0) { istack.Pop(); expectIndent = istack.Count > 0 ? istack.Peek() : -1; } else { expectIndent = -1; } }
public T GetItem() { if (pool.Count > 0) { return(pool.Pop()); } if (allowExpansion && prefill) { Expand(pool.Capacity * 2); } return(pool.Count > 0 ? pool.Pop() : default);
/// <summary> /// Obtains a new item by reusing an instance from the pool or by creating a new instance if /// necessary. /// </summary> /// <returns>The item.</returns> public T Obtain() { // Re-use existing item or create a new item. T item = null; if (Enabled) { lock (_stack) { item = _stack.Pop(); } } if (item == null) { item = _create(); } // Initialize item if necessary. if (_initialize != null) { _initialize(item); } return(item); }
/// <summary> /// Create an uninitialized RTSAgent /// </summary> /// <returns>The raw agent.</returns> /// <param name="agentCode">Agent code.</param> /// <param name="isBare">If set to <c>true</c> is bare.</param> public static RTSAgent CreateRawAgent(string agentCode, Vector2d startPosition = default(Vector2d), Vector2d startRotation = default(Vector2d)) { if (!GameResourceManager.IsValidAgentCode(agentCode)) { throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode)); } FastStack <RTSAgent> cache = CachedAgents[agentCode]; RTSAgent curAgent = null; if (cache.IsNotNull() && cache.Count > 0) { curAgent = cache.Pop(); ushort agentCodeID = GameResourceManager.GetAgentCodeIndex(agentCode); Debug.Log(curAgent.TypeIndex); TypeAgentsActive[agentCodeID][curAgent.TypeIndex] = true; } else { IAgentData interfacer = GameResourceManager.AgentCodeInterfacerMap[agentCode]; Vector3 pos = startPosition.ToVector3(); Quaternion rot = new Quaternion(0, startRotation.y, 0, startRotation.x); curAgent = GameObject.Instantiate(GameResourceManager.GetAgentTemplate(agentCode).gameObject, pos, rot).GetComponent <RTSAgent>(); curAgent.Setup(interfacer); RegisterRawAgent(curAgent); } return(curAgent); }
internal void PushPipeArguments() { var arguments = _availablePipeArguments.Count > 0 ? _availablePipeArguments.Pop() : new ScriptPipeArguments(1); _pipeArguments.Push(arguments); _currentPipeArguments = arguments; }
/// <summary> /// Get new instance of prefab from pool. /// </summary> /// <param name="isNew">Is instance was created during this call.</param> public IPoolObject Get(out bool isNew) { if ((object)_cachedAsset == null) { if (!LoadPrefab()) { isNew = true; return(null); } } IPoolObject obj; if (_store.Count > 0) { obj = _store.Pop(); isNew = false; } else { obj = _needToAddPoolObject ? (IPoolObject)((GameObject)Instantiate(_cachedAsset)).AddComponent(_overridedType) : (IPoolObject)Instantiate(_cachedAsset); obj.PoolContainer = this; var tr = obj.PoolTransform; if ((object)tr != null) { tr.gameObject.SetActive(false); tr.SetParent(_itemsRoot, false); tr.localScale = _cachedScale; } isNew = true; } return(obj); }
public TemplateRewriterContext Write(ScriptNode node) { if (node != null) { bool pushedWhileLoop = false; if (node is ScriptLoopStatementBase) { _isWhileLoop.Push(node is ScriptWhileStatement); pushedWhileLoop = true; } try { WriteBegin(node); node.Write(this); WriteEnd(node); } finally { if (pushedWhileLoop) { _isWhileLoop.Pop(); } if (!IsBlockOrPage(node)) { _previousRawStatement = node as ScriptRawStatement; } } } return(this); }
public ScriptPrinter Write(ScriptNode node) { if (node != null) { bool pushedWhileLoop = false; if (node is ScriptLoopStatementBase) { _isWhileLoop.Push(node is ScriptWhileStatement); pushedWhileLoop = true; } try { WriteBegin(node); // Reset comma before node if (node is IScriptTerminal) { _hasComma = false; } node.PrintTo(this); WriteEnd(node); } finally { if (pushedWhileLoop) { _isWhileLoop.Pop(); } } } return(this); }
public TreePage Pop() { if (Pages.Count == 0) { throw new InvalidOperationException("No page to pop"); } var p = Pages.Pop(); var removedPrimary = _pagesByNum.Remove(p.PageNumber); var removedSecondary = false; if (_anyOverrides) { var pagesNumbersToRemove = new HashSet <long>(); foreach (var page in _pagesByNum.Where(page => page.Value.PageNumber == p.PageNumber)) { pagesNumbersToRemove.Add(page.Key); } foreach (var pageToRemove in pagesNumbersToRemove) { removedSecondary |= _pagesByNum.Remove(pageToRemove); } } Debug.Assert(removedPrimary || removedSecondary); return(p); }
internal static int Assimilate(LSBody body, bool isDynamic) { if (CachedIDs.Count > 0) { id = CachedIDs.Pop(); } else { id = PeakCount; PeakCount++; if (PeakCount == SimObjects.Length) { //very very expensive Array.Resize(ref SimObjects, SimObjects.Length * 2); } } SimObjects[id] = body; //Important: If isDynamic is false, PhysicsManager won't check to update the item every frame. When the object is changed, it must be updated manually. if (isDynamic) { body.DynamicID = DynamicSimObjects.Add(body); } AssimilatedCount++; return(id); }
/// <summary> /// Notifies this context when exiting a loop. /// </summary> internal void ExitLoop(ScriptLoopStatementBase loop) { OnExitLoop(loop); PopVariableScope(ScriptVariableScope.Loop); _loops.Pop(); _loopStep = 0; }
/// <summary> /// Create an uninitialized LSAgent /// </summary> /// <returns>The raw agent.</returns> /// <param name="agentCode">Agent code.</param> /// <param name="isBare">If set to <c>true</c> is bare.</param> public static LSAgent CreateRawAgent(string agentCode) { if (!ResourceManager.IsValidAgentCode(agentCode)) { throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode)); } FastStack <LSAgent> cache = CachedAgents[agentCode]; LSAgent curAgent = null; if (cache.IsNotNull() && cache.Count > 0) { curAgent = cache.Pop(); ushort agentCodeID = ResourceManager.GetAgentCodeIndex(agentCode); Debug.Log(curAgent.TypeIndex); TypeAgentsActive[agentCodeID][curAgent.TypeIndex] = true; } else { IAgentData interfacer = ResourceManager.AgentCodeInterfacerMap[agentCode]; curAgent = GameObject.Instantiate(ResourceManager.GetAgentTemplate(agentCode).gameObject).GetComponent <LSAgent>(); curAgent.Setup(interfacer); RegisterRawAgent(curAgent); } return(curAgent); }
internal void EndFunction(int handle, int offset) { var f = funs.Pop(); f.Handle = handle; f.EndOffset = offset; Symbols.Functions.Add(f); }
/// <summary> /// Pops the page being executed. /// </summary> /// <returns>The Pagee that was executed</returns> /// <exception cref="System.InvalidOperationException">Cannot PopSourceFile more than PushSourceFile</exception> public ScriptPage PopPage() { if (_pages.Count == 0) { throw new InvalidOperationException("Cannot PopPage more than PushPage"); } return(_pages.Pop()); }
/// <summary> /// Pops the current culture used on the stack. /// </summary> /// <returns></returns> public CultureInfo PopCulture() { if (_cultures.Count == 0) { throw new InvalidOperationException("Cannot PopCulture more than PushCulture"); } return(_cultures.Pop()); }
private static ushort GenerateGlobalID() { if (OpenGlobalIDs.Count > 0) { return(OpenGlobalIDs.Pop()); } return(PeakGlobalID++); }
internal object PopCase() { if (_caseValues.Count == 0) { throw new InvalidOperationException("Cannot PopCase more than PushCase"); } return(_caseValues.Pop()); }
/// <summary> /// Pops the source file being executed. /// </summary> /// <returns>The source file that was executed</returns> /// <exception cref="System.InvalidOperationException">Cannot PopSourceFile more than PushSourceFile</exception> public string PopSourceFile() { if (_sourceFiles.Count == 0) { throw new InvalidOperationException("Cannot PopSourceFile more than PushSourceFile"); } return(_sourceFiles.Pop()); }
internal void EndScope(int offset, int line, int col) { var s = scopes.Pop(); s.EndOffset = offset; s.EndLine = line; s.EndColumn = col; Symbols.Scopes.Add(s); }
public static MovementGroup CreateGroup(Command com) { MovementGroup moveGroup = pooledGroups.Count > 0 ? pooledGroups.Pop() : new MovementGroup(); moveGroup.indexID = activeGroups.Add(moveGroup); LastCreatedGroup = moveGroup; moveGroup.Initialize(com); return(moveGroup); }
public static LocalTable <T> GetTransactional(int hierarchyLevel, LocalTable <T> parent) { var trans = _cache.Count != 0 ? _cache.Pop() : new LocalTable <T>(new ArrayTupleStorage <T>(LocalSpaceConsts.TransactionWrittenCapacity)); trans.HierarchyLevel = hierarchyLevel; trans._parent = parent; trans.Root = parent.Root ?? parent; return(trans); }
private static void Generate() { #region Pooling; no need to create all those nodes again if (Grid != null) { int min = Grid.Length; CachedGridNodes.EnsureCapacity(min); for (int i = min - 1; i >= 0; i--) { if (LockstepManager.PoolingEnabled) { CachedGridNodes.Add(Grid[i]); } } } if (ScanGrid != null) { int min = ScanGrid.Length; CachedScanNodes.EnsureCapacity(min); for (int i = min - 1; i >= 0; i--) { if (LockstepManager.PoolingEnabled) { CachedScanNodes.Add(ScanGrid[i]); } } } #endregion //long startMem = System.GC.GetTotalMemory (true); ScanGrid = new ScanNode[ScanGridSize]; for (int i = ScanWidth - 1; i >= 0; i--) { for (int j = ScanHeight - 1; j >= 0; j--) { ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode(); node.Setup(i, j); ScanGrid [GetScanIndex(i, j)] = node; } } Grid = new GridNode[GridSize]; for (int i = Width - 1; i >= 0; i--) { for (int j = Height - 1; j >= 0; j--) { GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode(); node.Setup(i, j); Grid [GetGridIndex(i, j)] = node; } } //long usedMem = System.GC.GetTotalMemory (true) - startMem; //Debug.Log ("Grid generated using " + usedMem + " Bytes!"); }
internal List <ScriptExpression> GetOrCreateListOfScriptExpressions(int capacity) { var list = _availableScriptExpressionLists.Count > 0 ? _availableScriptExpressionLists.Pop() : new List <ScriptExpression>(); if (capacity > list.Capacity) { list.Capacity = capacity; } return(list); }
private static int GenerateID() { if (OpenSlots.Count > 0) { return(OpenSlots.Pop()); } else { return(PeakCount++); } }
private ushort GenerateLocalID() { if (OpenLocalIDs.Count > 0) { return(OpenLocalIDs.Pop()); } else { return(PeakLocalID++); } }
/// <summary> /// Pops the previous object context. /// </summary> /// <returns>The previous object context</returns> /// <exception cref="System.InvalidOperationException">Unexpected PopGlobal() not matching a PushGlobal</exception> public IScriptObject PopGlobal() { if (_globalStores.Count == 1) { throw new InvalidOperationException("Unexpected PopGlobal() not matching a PushGlobal"); } var store = _globalStores.Pop(); PopVariableScope(ScriptVariableScope.Local); return(store); }
/// <summary> /// Pops a previous output. /// </summary> public IScriptOutput PopOutput() { if (_outputs.Count == 1) { throw new InvalidOperationException("Unexpected PopOutput for top level writer"); } var previous = _outputs.Pop(); _output = _outputs.Peek(); return(previous); }
public static void WorksForValueTypes() { var c = new FastStack <int>(); c.Push(1); Assert.Equal(1, c.Count); Assert.Equal(1, c.Peek()); Assert.Equal(1, c.Count); Assert.Equal(1, c.Pop()); Assert.Equal(0, c.Count); c.Push(1); c.Push(2); Assert.Equal(2, c.Count); Assert.Equal(2, c.Peek()); Assert.Equal(2, c.Count); Assert.Equal(2, c.Pop()); Assert.Equal(1, c.Count); Assert.Equal(1, c.Peek()); Assert.Equal(1, c.Count); Assert.Equal(1, c.Pop()); Assert.Equal(0, c.Count); }
internal void PopPipeArguments() { if (_pipeArguments.Count == 0) { throw new InvalidOperationException("Cannot PopPipeArguments more than PushPipeArguments"); } var pipeFrom = _pipeArguments.Pop(); pipeFrom.Clear(); _currentPipeArguments = _pipeArguments.Count > 0 ? _pipeArguments.Peek() : null; _availablePipeArguments.Push(pipeFrom); }
public static void WorksForReferenceTypes() { var c = new FastStack <string>(); c.Push("1"); Assert.Equal(1, c.Count); Assert.Equal("1", c.Peek()); Assert.Equal(1, c.Count); Assert.Equal("1", c.Pop()); Assert.Equal(0, c.Count); c.Push("1"); c.Push("2"); Assert.Equal(2, c.Count); Assert.Equal("2", c.Peek()); Assert.Equal(2, c.Count); Assert.Equal("2", c.Pop()); Assert.Equal(1, c.Count); Assert.Equal("1", c.Peek()); Assert.Equal(1, c.Count); Assert.Equal("1", c.Pop()); Assert.Equal(0, c.Count); }
private void DefloodLight(IEnumerable<Vector3i> start) { FastStack<Vector3i> q = new FastStack<Vector3i>(); q.Initialize(1024); Vector3i ss = new Vector3i(); foreach (var s in start) { q.Push(s); ss = s; } Dictionary<Vector3i, bool> reflood = new Dictionary<Vector3i, bool>(); int searched = 1; for (; ; ) { if (q.Count == 0) { break; } Vector3i v = q.Pop(); searched++; if (distancesquare(v, new Vector3i(ss.x, ss.y, ss.z)) > maxlight * 2 * maxlight * 2) { continue; } int vblock = map.GetBlock(v.x, v.y, v.z); if (!data.GrassGrowsUnder(vblock) && data.GetLightRadius(vblock) == 0) { continue; } int vlight = LightGetBlock(v.x, v.y, v.z); if (vlight == maxlight || data.GetLightRadius(vblock) != 0) { reflood[v] = true; continue; } if (vlight == minlight) { continue; } SetLight(v.x, v.y, v.z, minlight); foreach (var n in BlocksNear(v.x, v.y, v.z)) { if (!MapUtil.IsValidPos(map, n.x, n.y, n.z)) { continue; } if (LightGetBlock(n.x, n.y, n.z) < vlight) { q.Push(n); } else { reflood[n] = true; } } } //Console.WriteLine("reflood: {0}, searched: {1}", reflood.Keys.Count, searched); foreach (var p in reflood.Keys) { currentlightchunk = null; FloodLight(p.x, p.y, p.z); } }