public unsafe void returned_buffers_are_empty_and_can_be_reused() { var mgr = new BufferManager("test"); var buf1 = mgr.GetBuffer(30); Assert.NotNull(buf1); var source = new byte[30]; for (int i = 0; i < 30; i++) { source[i] = (byte)(i % 8); } fixed(byte *s = source) { Utility.CopyMemory(buf1.Buffer, s, 30); // fill the whole buffer Assert.True(BufferTests.BufferEqual(s, buf1.Buffer, 30)); } var empty = new byte[30]; var addr = (long)buf1.Buffer; buf1.Dispose(); buf1 = mgr.GetBuffer(30); Assert.Equal(addr, (long)buf1.Buffer); fixed(byte *e = empty) { Assert.True(BufferTests.BufferEqual(e, buf1.Buffer, 30)); } }
public void GettingMoreThanInitiallyAllocatedWorks() { var settings = CreateSettings(1, 10, 1); var manager = new BufferManager(settings); byte[] test = manager.GetBuffer(10); Assert.NotNull(test); test = manager.GetBuffer(10); Assert.NotNull(test); }
public void GettingADifferentSizeThenConfigured() { var settings = CreateSettings(1, 10, 1); var manager = new BufferManager(settings); byte[] test = manager.GetBuffer(11); Assert.NotNull(test); test = manager.GetBuffer(10); Assert.NotNull(test); }
public void all_buffers_are_released_by_manager() { var mgr = new BufferManager("test"); var buf1 = mgr.GetBuffer(30); var buf2 = mgr.GetBuffer(30); var buf3 = mgr.GetBuffer(40); mgr.Dispose(); Assert.Throws <ObjectDisposedException>(() => buf1.Length); Assert.Throws <ObjectDisposedException>(() => buf2.Length); Assert.Throws <ObjectDisposedException>(() => buf3.Length); }
public unsafe void new_buffers_are_different() { var mgr = new BufferManager("test"); var buf1 = mgr.GetBuffer(30); var buf2 = mgr.GetBuffer(30); Assert.NotEqual((long)buf1.Buffer, (long)buf2.Buffer); var buf3 = mgr.GetBuffer(40); Assert.NotEqual((long)buf1.Buffer, (long)buf3.Buffer); Assert.NotEqual((long)buf2.Buffer, (long)buf3.Buffer); }
private void InitArgs() { for (int i = 0; i < _maxConnections; ++i) { SocketAsyncEventArgs arg = new SocketAsyncEventArgs(); arg.Completed += IO_Completed; AsyncUserToken token = new AsyncUserToken(_recvBufManager); arg.UserToken = token; arg.SetBuffer(_recvBufManager.GetBuffer()); _pool.Push(arg); } }
public void CanWeClearBufferContent() { var settings = CreateSettings(1, 10, 1); var manager = new BufferManager(settings); byte[] test = manager.GetBuffer(10); test[0] = 0x01; Assert.NotNull(test); Assert.AreEqual(test.Length, 10); //we get the same length manager.FreeBuffer(ref test, true); test = manager.GetBuffer(10); Assert.True(test[0] == 0x00);//we got a cleared one }
public void CanWeAllocateBuffers() { var settings = CreateSettings(1, 10, 1); var manager = new BufferManager(settings); byte[] test = manager.GetBuffer(10); test[0] = 0x01; Assert.NotNull(test); Assert.AreEqual(test.Length, 10); //we get the same length manager.FreeBuffer(ref test); Assert.True(test == BufferManager.EmptyBuffer); //we aren't referencing it anymore test = manager.GetBuffer(10); Assert.True(test[0] == 0x01);//we got the same one back }
public Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken) { var doc = bufferManager.GetBuffer(request.TextDocument.Uri.AbsolutePath); if (doc == null) { return(Task.FromResult <LocationOrLocationLinks>(null)); } var identifier = doc.GetWordRangeAtPosition(request.Position); var symbol = documentsManager.LookupSymbol(identifier); if (symbol == null || symbol.Source == null || symbol.Source.LocalPath.Contains("DaedalusBuiltins")) { return(Task.FromResult <LocationOrLocationLinks>(null)); } var symbolStart = new Position(symbol.Line - 1, symbol.Column); var symbolEnd = new Position(symbol.Line - 1, symbol.Column + symbol.Name.Length); var result = new LocationOrLocationLinks(new LocationOrLocationLink(new LocationLink { TargetRange = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range(symbolStart, symbolEnd), TargetSelectionRange = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range(symbolStart, symbolEnd), TargetUri = new Uri(symbol.Source.AbsoluteUri), })); return(Task.FromResult(result)); }
private async Task Receive(WebSocket socket) { var playerID = gameServer.FindPlayer(socket)?.PlayerId ?? 0; if (playerID <= 0) { logger.LogInformation($"#### Invalid player ID: {playerID} ####"); return; } logger.LogInformation($"#### Receiving for ID: {playerID} ####"); using (var buffer = bufferManager.GetBuffer()) { try { var result = await socket.ReceiveAsync(buffer.Buffer, CancellationToken.None); while (!result.CloseStatus.HasValue) { HandleMessage(result, playerID, buffer.Buffer); result = await socket.ReceiveAsync(buffer.Buffer, CancellationToken.None); } gameServer.ClosedConnection(playerID); } catch (Exception) { } } }
public override void NewFrameReady(RecordingSession session) { if (!audioSettings.m_PreserveAudio) { return; } var sampleFrameCount = (uint)AudioRenderer.GetSampleCountForCaptureFrame(); if (Verbose.enabled) { Debug.Log(string.Format("AudioInput.NewFrameReady {0} audio sample frames @ {1} ch", sampleFrameCount, m_ChannelCount)); } ushort bufferCount = #if RECORD_AUDIO_MIXERS (ushort)(audioSettings.m_AudioMixerGroups.Length + 1) #else 1 #endif ; m_BufferManager = new BufferManager(bufferCount, sampleFrameCount, m_ChannelCount); var mainBuffer = m_BufferManager.GetBuffer(0); #if RECORD_AUDIO_MIXERS for (int n = 1; n < bufferCount; n++) { var group = audioSettings.m_AudioMixerGroups[n - 1]; if (group.m_MixerGroup == null) { continue; } var buffer = m_BufferManager.GetBuffer(n); AudioRenderer.AddMixerGroupRecorder(group.m_MixerGroup, buffer, group.m_Isolate); } #endif AudioRenderer.Render(mainBuffer); }
private void InitLoggerSet() { loggerSet = new HashSet <MachineStatLogger> { // Add new loggers here... //new BandwidthLogger(_logFrequency, bufMgr.GetBuffer(StatType.Bandwidth)), //new CPULogger(_logFrequency, bufMgr.GetBuffer(StatType.CPU)), //new ThreadPoolLogger(_logFrequency, bufMgr.GetBuffer(StatType.ThreadPool)), new PageFaultLogger(_logFrequency, bufMgr.GetBuffer(StatType.PageFaults)) }; }
/// <summary> /// uploads from offline to online data /// </summary> public void Upload() { if (!IsSoftware) { if (physicalBuffer == null) { physicalBuffer = BufferManager.GetBuffer(this); } physicalBuffer.Upload(Data, position, 0, Data.Length); this.changeCounter = physicalBuffer.ChangeCounter; } }
/// <summary> /// uploads from offline to online data /// </summary> /// <param name="start">The start index for uploading.</param> /// <param name="length">The number of elements to upload</param> public void Upload(int start, int length) { if (!IsSoftware) { if (physicalBuffer == null) { physicalBuffer = BufferManager.GetBuffer(this); } Purple.Profiling.Profiler.Instance.Begin("Upload"); physicalBuffer.Upload(Data, position, start, length); Profiling.Profiler.Instance.End("Upload"); this.changeCounter = physicalBuffer.ChangeCounter; } }
public TextDocumentSyncHandler(ILanguageServer router, BufferManager buffers) { this.router = router; this.buffers = buffers; compiler = new Compiler((fp) => { var result = buffers.GetBuffer(fp); if (result == null) { if (File.Exists(fp)) { result = File.ReadAllText(fp); buffers.UpdateBuffer(fp, result); } } return(result); }); }
public unsafe void can_get_new_buffer() { var mgr = new BufferManager("test"); var buf1 = mgr.GetBuffer(30); Assert.NotNull(buf1); var source = new byte[30]; for (int i = 0; i < 30; i++) { source[i] = (byte)(i % 8); } fixed(byte *s = source) { Utility.CopyMemory(buf1.Buffer, s, 30); // fill the whole buffer Assert.True(BufferTests.BufferEqual(s, buf1.Buffer, 30)); } }
public Task <Hover> Handle(HoverParams request, CancellationToken cancellationToken) { var doc = bufferManager.GetBuffer(request.TextDocument.Uri.AbsolutePath); if (doc == null) { return(Task.FromResult <Hover>(null)); } var symbol = doc.GetWordRangeAtPosition(request.Position); var v = documentsManager.LookupSymbol(symbol); if (v == null) { return(Task.FromResult <Hover>(null)); } return(Task.FromResult(new Hover { Contents = new MarkedStringsOrMarkupContent(GetSymbolDocumentation(v)) })); }
public async Task <CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken) { var documentPath = DocumentUri.GetFileSystemPath(request.TextDocument.Uri); if (string.IsNullOrEmpty(documentPath)) { return(new CompletionList()); } var(rootScope, tc) = buffers.GetScope(documentPath); if (rootScope == null) { return(new CompletionList()); } var scope = GetCurrentScope(rootScope, (int)request.Position.Character, (int)request.Position.Line, documentPath); var completions = new List <CompletionItem>(); if (request.Context.TriggerKind == CompletionTriggerKind.TriggerCharacter) { var text = buffers.GetBuffer(documentPath); var charIdx = (int)request.Position.Character; var lineIdx = (int)request.Position.Line; var lines = text.Split(System.Environment.NewLine); var line = default(string); if (lineIdx >= 0 && lineIdx < lines.Length) { line = lines[lineIdx]; } if (line == null) { return(new CompletionList(completions)); } if (request.Context.TriggerCharacter == " ") { charIdx--; if (line.ElementAtOrDefault(charIdx) == ' ' && line.ElementAtOrDefault(charIdx - 1) == ':') { AddToScope(scope, AddToScopeFlags.Types | AddToScopeFlags.Recursive, completions, tc); return(new CompletionList(completions)); } if (line.ElementAtOrDefault(charIdx) == ' ' && line.ElementAtOrDefault(charIdx - 1) == '>' && line.ElementAtOrDefault(charIdx - 2) == '=') { AddToScope(scope, AddToScopeFlags.Types | AddToScopeFlags.Recursive, completions, tc); return(new CompletionList(completions)); } } if (request.Context.TriggerCharacter == ">") { charIdx--; if (line.ElementAtOrDefault(charIdx) == '>' && line.ElementAtOrDefault(charIdx - 1) == '=') { AddToScope(scope, AddToScopeFlags.Types | AddToScopeFlags.Recursive | AddToScopeFlags.AddSpaceToType, completions, tc); return(new CompletionList(completions)); } } if (request.Context.TriggerCharacter == "@") { AddToScope(scope, AddToScopeFlags.Types | AddToScopeFlags.Recursive, completions, tc); return(new CompletionList(completions)); } if (request.Context.TriggerCharacter == ":") { charIdx--; if (line.ElementAtOrDefault(charIdx) == ':' && line.ElementAtOrDefault(charIdx - 1) != ':') { AddToScope(scope, AddToScopeFlags.Types | AddToScopeFlags.Recursive | AddToScopeFlags.AddSpaceToType, completions, tc); return(new CompletionList(completions)); } if (line.ElementAtOrDefault(charIdx) != ':' || line.ElementAtOrDefault(charIdx - 1) != ':') { return(new CompletionList(completions)); } charIdx = charIdx - 2; List <string> query = new List <string>(); while (true) { var current = ""; while (charIdx >= 0 && Token.isIdentifierChar(line[charIdx])) { current = line[charIdx] + current; charIdx--; } if (string.IsNullOrWhiteSpace(current)) { break; } else { query.Add(current); } while (charIdx >= 0 && char.IsWhiteSpace(line[charIdx])) { charIdx--; } if (charIdx <= 1 || line[charIdx] != ':' || line[charIdx - 1] != ':') { break; } charIdx -= 2; } if (query.Count > 0) { var mod = scope.GetModule(query); if (mod != null) { AddToScope(mod.scope, AddToScopeFlags.Types | AddToScopeFlags.Variables, completions, tc); } } return(new CompletionList(completions)); } if (request.Context.TriggerCharacter == ".") { charIdx = System.Math.Clamp(charIdx, 0, line.Length - 1); while (charIdx >= 0 && line[charIdx] != '.') { charIdx--; } if (charIdx >= 0 && charIdx < line.Length) { if (line[charIdx] == '.') { charIdx--; } } List <string> query = new List <string>(); while (true) { var current = ""; while (charIdx >= 0 && Token.isIdentifierChar(line[charIdx])) { current = line[charIdx] + current; charIdx--; } if (string.IsNullOrWhiteSpace(current)) { break; } else { query.Add(current); } while (charIdx >= 0 && char.IsWhiteSpace(line[charIdx])) { charIdx--; } if (charIdx <= 0 || line[charIdx] != '.') { break; } charIdx--; } List <string> modPath = new List <string>(); if (line.ElementAtOrDefault(charIdx) == ':' && line.ElementAtOrDefault(charIdx - 1) == ':') { charIdx -= 2; while (true) { var current = ""; while (charIdx >= 0 && Token.isIdentifierChar(line[charIdx])) { current = line[charIdx] + current; charIdx--; } if (string.IsNullOrWhiteSpace(current)) { break; } else { modPath.Add(current); } while (charIdx >= 0 && char.IsWhiteSpace(line[charIdx])) { charIdx--; } if (charIdx <= 1 || line[charIdx] != ':' || line[charIdx - 1] != ':') { break; } charIdx -= 2; } } if (query.Count > 0) { FrontendStructType st = null; for (int i = query.Count - 1; i >= 0; --i) { var current = query[i]; if (i == query.Count - 1) { if (modPath.Count > 0) { scope = scope.GetModule(modPath)?.scope; if (scope == null) { break; } } var v = scope.GetVar(current, Token.Undefined)?.First; if (v == null) { st = null; break; } FrontendType vt; if (v.node == null) { vt = v.type; } else { vt = tc.GetNodeType(v.node); } st = vt as FrontendStructType; if (st == null && vt is FrontendPointerType pt) { st = pt.elementType as FrontendStructType; } } else { var f = st.fields.Where(f => f.name == current).FirstOrDefault(); if (f == null) { st = null; break; } st = f.type as FrontendStructType; if (st == null && f.type is FrontendPointerType pt) { st = pt.elementType as FrontendStructType; } } if (st == null) { break; } } if (st != null) { foreach (var f in st.fields) { var item = new CompletionItem { Kind = CompletionItemKind.Field, Label = f.name, Detail = f.type.ToString() }; completions.Add(item); } } } } } if (request.Context.TriggerKind == CompletionTriggerKind.Invoked || request.Context.TriggerKind == CompletionTriggerKind.TriggerForIncompleteCompletions) { completions.Add(Keyword("let")); completions.Add(Keyword("var")); completions.Add(Keyword("struct")); completions.Add(Keyword("enum")); completions.Add(Keyword("fun")); completions.Add(Keyword("return")); completions.Add(Keyword("true")); completions.Add(Keyword("false")); completions.Add(Keyword("if")); completions.Add(Keyword("elif")); completions.Add(Keyword("else")); completions.Add(Keyword("for")); completions.Add(Keyword("while")); completions.Add(Keyword("break")); completions.Add(Keyword("continue")); completions.Add(Keyword("size_of")); completions.Add(Keyword("extern")); completions.Add(Keyword("import")); completions.Add(Keyword("mod")); completions.Add(Keyword("with")); AddToScope(scope, AddToScopeFlags.Variables | AddToScopeFlags.Modules | AddToScopeFlags.Recursive, completions, tc); } return(new CompletionList(completions)); }
public Task <SignatureHelp> Handle(SignatureHelpParams request, CancellationToken cancellationToken) { var doc = bufferManager.GetBuffer(request.TextDocument.Uri.AbsolutePath); if (doc == null) { return(null); } var line = doc.GetMethodCall(request.Position).Trim(); if (rxFuncDef.IsMatch(line)) { return(null); } var contextLine = line; contextLine = rxStringValues.Replace(contextLine, ""); var oldLen = -1; while (contextLine.Length != oldLen) { oldLen = contextLine.Length; contextLine = rxFuncCall.Replace(contextLine, ""); } var idxOfParen = contextLine.LastIndexOf('('); if (idxOfParen < 0) { return(NullSignatureHelp); } string word = null; for (var i = idxOfParen - 1; i > 0; i--) { var c = contextLine[i]; if (!BufferedDocument.IsIdentifier(c)) { var start = i + 1; word = contextLine.Substring(start, idxOfParen - start); break; } } if (word == null) { word = contextLine.Substring(0, idxOfParen); } word = word.Trim(); var sigCtx = contextLine.Substring(idxOfParen + 1); var func = (Function)documentsManager.GetGlobalSymbols() .FirstOrDefault(x => x is Function && x.Name.Equals(word, StringComparison.OrdinalIgnoreCase)); if (func != null) { var signatureHelp = new SignatureHelp { Signatures = new Container <SignatureInformation>(new SignatureInformation { Label = func.ToString(), Parameters = new Container <ParameterInformation>(func.Parameters.Select(x => new ParameterInformation { Label = x.ToString(), })), Documentation = func.Documentation, }), ActiveParameter = sigCtx.Count(x => x == ','), ActiveSignature = 0 }; return(Task.FromResult(signatureHelp)); } return(NullSignatureHelp); }
public override void Render() { Renderer.DrawSkyBox(TextureManager, BufferManager.GetBuffer("SkyCube")); Renderer.DrawObject(TextureManager, BufferManager.GetBuffer("MengerSponge")); }
public async Task <SignatureHelp> Handle(SignatureHelpParams request, CancellationToken cancellationToken) { var documentPath = DocumentUri.GetFileSystemPath(request.TextDocument.Uri); if (string.IsNullOrEmpty(documentPath)) { return(new SignatureHelp()); } var(rootScope, tc) = buffers.GetScope(documentPath); if (rootScope == null) { return(new SignatureHelp()); } var scope = GetCurrentScope(rootScope, (int)request.Position.Character, (int)request.Position.Line, documentPath); var text = buffers.GetBuffer(documentPath); var charIdx = (int)request.Position.Character; var lineIdx = (int)request.Position.Line; var lines = text.Split(System.Environment.NewLine); var line = default(string); if (lineIdx >= 0 && lineIdx < lines.Length) { line = lines[lineIdx]; } if (line == null) { return(new SignatureHelp()); } charIdx = System.Math.Clamp(charIdx, 0, line.Length - 1); int activeParam = 0; while (charIdx >= 0 && line[charIdx] != '(') { if (line[charIdx] == ',') { activeParam++; } charIdx--; } if (charIdx >= 0 && charIdx < line.Length) { if (line[charIdx] == '(') { charIdx--; } } List <string> query = new List <string>(); while (true) { var current = ""; while (charIdx >= 0 && Token.isIdentifierChar(line[charIdx])) { current = line[charIdx] + current; charIdx--; } if (string.IsNullOrWhiteSpace(current)) { break; } else { query.Add(current); } while (charIdx >= 0 && char.IsWhiteSpace(line[charIdx])) { charIdx--; } if (charIdx <= 0 || line[charIdx] != '.') { break; } charIdx--; } List <string> modPath = new List <string>(); if (line.ElementAtOrDefault(charIdx) == ':' && line.ElementAtOrDefault(charIdx - 1) == ':') { charIdx -= 2; while (true) { var current = ""; while (charIdx >= 0 && Token.isIdentifierChar(line[charIdx])) { current = line[charIdx] + current; charIdx--; } if (string.IsNullOrWhiteSpace(current)) { break; } else { modPath.Add(current); } while (charIdx >= 0 && char.IsWhiteSpace(line[charIdx])) { charIdx--; } if (charIdx <= 1 || line[charIdx] != ':' || line[charIdx - 1] != ':') { break; } charIdx -= 2; } } if (query.Count > 0) { Scope.OverloadedVariableDefinition vd = null; FrontendStructType st = null; for (int i = query.Count - 1; i >= 0; --i) { var current = query[i]; FrontendType vt; if (i == query.Count - 1) { if (modPath.Count > 0) { scope = scope.GetModule(modPath)?.scope; if (scope == null) { break; } } if (i == 0) { vd = scope.GetVar(current, Token.Undefined); } else { var v = scope.GetVar(current, Token.Undefined)?.First; if (v == null) { st = null; break; } if (v.node == null) { vt = v.type; } else { vt = tc.GetNodeType(v.node); } st = vt as FrontendStructType; if (st == null && vt is FrontendPointerType pt) { st = pt.elementType as FrontendStructType; } if (st == null) { break; } } } else { if (i == 0) { vd = scope.GetVar(current, Token.Undefined); } else { var f = st.fields.Where(f => f.name == current).FirstOrDefault(); if (f == null) { st = null; break; } vt = f.type; st = vt as FrontendStructType; if (st == null && vt is FrontendPointerType pt) { st = pt.elementType as FrontendStructType; } if (st == null) { break; } } } } if (vd != null) { var infos = new List <SignatureInformation>(); foreach (var v in vd.variables) { FrontendFunctionType ft; if (v.node == null) { ft = v.type as FrontendFunctionType; } else { ft = tc.GetNodeType(v.node) as FrontendFunctionType; } if (ft != null) { var info = new SignatureInformation(); var parameInfos = new List <ParameterInformation>(); var funName = ft.funName; if (string.IsNullOrEmpty(funName)) { funName = v.name; } var funString = $"{funName}("; for (int i = 0; i < ft.parameters.Count; ++i) { var p = ft.parameters[i]; var paramString = $"{p.name}: {p.type}"; parameInfos.Add( new ParameterInformation() { Label = paramString, } ); funString += paramString; if (i < ft.parameters.Count - 1) { funString += "; "; } } funString += $") => {ft.returnType}"; info.Label = funString; info.Parameters = parameInfos; infos.Add(info); } } var result = new SignatureHelp { ActiveParameter = activeParam, Signatures = new Container <SignatureInformation>(infos) }; return(result); } } return(new SignatureHelp()); }
public StatsBuffer <MachineStat> GetStatBuffer(StatType statType) { return(_bufMgr.GetBuffer(statType)); }