//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public MonsterZolGreen() { color = MonsterColor.Green; MaxHealth = 1; ContactDamage = 1; moveSpeed = 0.75f; jumpSpeed = new RangeF(2.0f); stopTime = new RangeI(48); stopAnimation = GameData.ANIM_MONSTER_ZOL; jumpAnimation = GameData.ANIM_MONSTER_ZOL_JUMP; }
/// <summary>Create a line plot</summary> private ChartGfxPiece CreateLinePlot(RangeI idx_range) { var n = idx_range.Sizei; if (n == 0) { throw new ArgumentException($"{nameof(ChartControl)}.{nameof(CreateLinePlot)} Index range must not be empty"); } // Resize the geometry buffers m_vbuf.Resize(n); m_ibuf.Resize(n); m_nbuf.Resize(1 + (Options.PointsOnLinePlot ? 1 : 0)); // Create the vertex/index data int vert = 0, indx = 0; var col = Options.Colour; var x_range = RangeF.Invalid; for (int i = 0, iend = Math.Min(n, m_data.Count - idx_range.Begi); i != iend; ++i) { var j = i + idx_range.Begi; var pt = m_data[j]; var v = vert; m_vbuf[vert++] = new View3d.Vertex(new v4((float)pt.xf, (float)pt.yf, 0f, 1f), col); m_ibuf[indx++] = (ushort)(v); x_range.Grow(pt.xf); } // Create a nugget for the list strip using the thick line shader { var mat = View3d.Material.New(); mat.Use(View3d.ERenderStep.ForwardRender, View3d.EShaderGS.ThickLineListGS, $"*LineWidth {{{Options.LineWidth}}}"); m_nbuf[0] = new View3d.Nugget(View3d.ETopo.LineStrip, View3d.EGeom.Vert | View3d.EGeom.Colr, mat: mat); } // Create a nugget for the points (if visible) if (Options.PointsOnLinePlot) { var mat = View3d.Material.New(); mat.m_diff_tex = View3d.Texture.FromStock((View3d.EStockTexture)Options.PointStyle)?.Handle ?? IntPtr.Zero; mat.Use(View3d.ERenderStep.ForwardRender, View3d.EShaderGS.PointSpritesGS, $"*PointSize {{{Options.PointSize} {Options.PointSize}}} *Depth {{{false}}}"); m_nbuf[1] = new View3d.Nugget(View3d.ETopo.PointList, View3d.EGeom.Vert | View3d.EGeom.Colr | View3d.EGeom.Tex0, range_overlaps: true, mat: mat); } // Create the graphics var gfx = new View3d.Object($"{Name}-[{idx_range.Beg},{idx_range.End})", 0xFFFFFFFF, m_vbuf.Count, m_ibuf.Count, m_nbuf.Count, m_vbuf.ToArray(), m_ibuf.ToArray(), m_nbuf.ToArray(), Id); return(new ChartGfxPiece(gfx, x_range)); }
/// <summary>Called when building the line index completes (success or failure)</summary> private void BuildLineIndexComplete(BLIData d, RangeI range, List <RangeI> line_index, Exception error, Action on_success) { // This method runs in the main thread, so if the build issue is the same at // the start of this method it can't be changed until after this function returns. if (BuildCancelled(d.build_issue)) { return; } ReloadInProgress = false; UpdateStatusProgress(1, 1); // If an error occurred if (error != null) { if (error is OperationCanceledException) { } else if (error is FileNotFoundException) { SetStaticStatusMessage($"Error reading {Path.GetFileName(d.file.Name)}", Color.White, Color.DarkRed); } else { Log.Write(ELogLevel.Error, error, "Exception ended BuildLineIndex() call"); BuildLineIndexTerminatedWithError(error); } } // Otherwise, merge the results into the main cache else { // Merge the line index results int row_delta = MergeLineIndex(range, line_index, d.file_buffer_size, d.filepos, d.fileend, d.reload); // Ensure the grid is updated UpdateUI(row_delta); if (on_success != null) { on_success(); } // On completion, check if the file has changed again and rerun if it has Watch.CheckForChangedFiles(); // Trigger a collect to free up memory, this also has the // side effect of triggering a signing test of the exe because // that test is done in a destructor GC.Collect(); } }
public ExportUI(string output_filepath, string row_delim, string col_delim, RangeI byte_range) { InitializeComponent(); OutputFilepath = output_filepath; RowDelim = row_delim; ColDelim = col_delim; ByteRangeLimits = byte_range; ByteRange = byte_range; SetupUI(); UpdateUI(); }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public JumpMonster() { color = MonsterColor.Red; MaxHealth = 1; ContactDamage = 1; moveSpeed = 1.0f; stopTime = new RangeI(30, 60); jumpSpeed = new RangeF(3, 3); stopAnimation = GameData.ANIM_MONSTER_ZOL; jumpAnimation = GameData.ANIM_MONSTER_ZOL_JUMP; syncAnimationWithDirection = false; }
/// <summary>Return a line instance from a buffer of log data</summary> public ILine CreateLine(byte[] line_buf, int start, int count, RangeI file_byte_range) { // Convert the buffer to text // Note: don't trim 'text', it's the logs fault if it has weird newlines at the end of each row. var text = m_encoding.GetString(line_buf, start, count); //todo // Apply any transforms //todo foreach (var tx in transforms) //todo RowText = tx.Txfm(RowText); var line = new Line(text, file_byte_range); return(line); }
public SubRangeScroll() { MinThumbSize = 20; ThumbColor = Color.FromArgb(unchecked ((int)0xFF008000)); TrackColor = SystemColors.ControlDark; TotalRange = new RangeI(0, 100); ThumbRange = new RangeI(35, 50); SetStyle( ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.UserPaint, true); }
/// <summary>Invalidate cache entries for lines that overlap the given memory range</summary> private void InvalidateCache(RangeI rng) { for (var i = 0; i != m_cache.Count; ++i) { if (m_cache[i] == null) { continue; } if (m_cache[i].FileByteRange.Intersect(rng).Empty) { continue; } m_cache[i] = null; } }
/// <summary>Return the candles over the given index range</summary> public IEnumerable <Candle> ReadCandles(RangeI index_range) { // Read from the database. Order by timestamp so that the oldest is first, and the newest is at the end. var candles = DB.Query <Candle>( $"select * from {TimeFrame}\n" + $"order by [{nameof(Candle.Timestamp)}] limit @start,@count", new { start = index_range.Beg, count = index_range.Size }); if (Model.BackTesting) { var latest_time = new TimeFrameTime(Model.UtcNow, TimeFrame).IntgTicks; candles = candles.Select(x => x.Timestamp < latest_time ? x : x.SubCandle(Model.UtcNow, TimeFrame)); } return(candles); }
/// <summary>Sets or clears the bookmark at file address 'addr'</summary> private void SetBookmark(RangeI line, Bit.EState bookmarked) { // Look for the bookmark var idx = Bookmarks.BinarySearch(b => b.Position.CompareTo(line.Beg)); if (idx >= 0 && bookmarked != Bit.EState.Set) { // Bookmark was found, remove it Bookmarks.RemoveAt(idx); } else if (idx < 0 && bookmarked != Bit.EState.Clear) { // Bookmark not found, insert it Bookmarks.Insert(~idx, new Bookmark(line, ReadLine(line).RowText)); } m_batch_refresh_bkmks.Signal(); }
static void CalculateTangentForFace(VertexInfo[] vertices, RangeI indexRange, Vector3F[] tangents, Vector3F[] bitangents, GetTextureCoord getTextureCoord = null) { // triangle or polygon... we always use only the first three indices. A polygon // is supposed to be planar anyways.... if (indexRange.Size < 3) { for (int i = indexRange.Minimum; i < indexRange.Maximum; i++) { tangents[i] = new Vector3F(float.NaN, float.NaN, float.NaN); bitangents[i] = new Vector3F(float.NaN, float.NaN, float.NaN); } FbxImportLog.LogWarning("To calculate the tangents a polygon must have > 2 vertices"); return; } ref StandardVertex pt0 = ref vertices[indexRange.Minimum].Vertex;
/// <summary>Convert a line range into a client-space area, clipped by ClientRectangle</summary> public Rectangle LineRangeToClientArea(RangeI line_range) { var l0 = FirstVisibleLineIndex; var l1 = l0 + VisibleLineCount; if (line_range.End < l0) { return(Rectangle.Empty); } if (line_range.Beg > l1) { return(Rectangle.Empty); } var t = (int)Math.Min(Height, Math.Max(0, (line_range.Beg - l0) * Font.Height)); var b = (int)Math.Min(Height, Math.Max(0, (line_range.End - l0) * Font.Height)); return(Rectangle.FromLTRB(Left, t, Right, b)); }
void SpawnEntities(GameObject[] prefabs, RangeI count) { for (int i = 0; i < count; ++i) { var entity = Instantiate(prefabs[Random.Range( 0, prefabs.Length)], transform); entity.transform.position = GetRandPos(); int rotations = Random.Range(0, 3); for (int j = 0; j < rotations; ++j) { entity.transform.Rotate(Vector3.up, 90.0f); } var entityScr = entity.GetComponent <Entity>(); if (entityScr != null) { entityScr.UpdatePos(); } } }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.KeyCode == Keys.PageUp) { RangeI thm = ThumbRange; thm = thm.Shift(-m_large_change); ThumbRange = thm; RaiseScrollEvent(); RaiseScrollEndEvent(); } if (e.KeyCode == Keys.PageDown) { RangeI thm = ThumbRange; thm = thm.Shift(+m_large_change); ThumbRange = thm; RaiseScrollEvent(); RaiseScrollEndEvent(); } if (e.KeyCode == Keys.Up && e.Control) { RangeI thm = ThumbRange; thm = thm.Shift(-m_small_change); ThumbRange = thm; RaiseScrollEvent(); RaiseScrollEndEvent(); } if (e.KeyCode == Keys.Down && e.Control) { RangeI thm = ThumbRange; thm = thm.Shift(+m_small_change); ThumbRange = thm; RaiseScrollEvent(); RaiseScrollEndEvent(); } }
public Selection(IWpfTextView view) { var snapshot = view.TextSnapshot; var selection = view.Selection; var caret = view.Caret; Pos = new RangeI(selection.Start.Position, selection.End.Position); Lines = new RangeI( snapshot.GetLineNumberFromPosition(Pos.Begi), snapshot.GetLineNumberFromPosition(Pos.Empty ? Pos.Begi : Pos.Endi - 1)); SLine = snapshot.GetLineFromLineNumber(Lines.Begi); ELine = snapshot.GetLineFromLineNumber(Lines.Endi); CaretPos = Math_.Clamp(caret.Position.BufferPosition, SLine.Start.Position, ELine.End.Position); CaretLineNumber = snapshot.GetLineNumberFromPosition(CaretPos); Debug.Assert(Pos.Size >= 0); Debug.Assert(Lines.Size >= 0); }
public ZoomScroll() { m_hoverscroll = new HoverScroll(); DoubleBuffered = true; TotalRange = new RangeI(0, 1000); ZoomedRange = TotalRange; VisibleRange = new RangeI(35, 50); MinimumVisibleRangeSize = 20; VisibleRangeColor = Color.FromArgb(unchecked ((int)0x80008000)); VisibleRangeBorderColor = Color.FromArgb(unchecked ((int)0xFF008000)); TrackColor = SystemColors.ControlDark; SetStyle( ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.UserPaint, true); m_hoverscroll.WindowHandles.Add(Handle); Application.AddMessageFilter(m_hoverscroll); }
/// <summary>Access info about a line (cached)</summary> private Line ReadLine(RangeI rng) { Debug.Assert(Src != null); // Check if the line is already cached Line line = m_line_cache[(int)(rng.Beg % m_line_cache.Count)]; if (line.LineStartAddr == rng.Beg) { return(line); } // If not, read it from file and perform highlighting and transforming on it try { // Read the whole line into m_buf //m_file.Flush(); why?? Src.Stream.Seek(rng.Beg, SeekOrigin.Begin); m_line_buf = rng.Size <= m_line_buf.Length ? m_line_buf : new byte[rng.Size]; int read = Src.Stream.Read(m_line_buf, 0, (int)rng.Size); if (read != rng.Size) { throw new IOException($"Failed to read file over range [{rng.Beg},{rng.End}) ({rng.Size} bytes). Read {read}/{rng.Size} bytes."); } // Cache data for the line line.Read(rng.Beg, m_line_buf, 0, read, m_encoding, m_col_delim, m_highlights, m_transforms); // Save the text size line.TextSize = m_gfx.MeasureString(line.RowText, m_grid.RowsDefaultCellStyle.Font); return(line); } catch (Exception ex) { Log.Write(ELogLevel.Error, ex, "Failed to read source data"); line.RowText = "<read failed>"; return(line); } }
public Token(AlignGroup grp, int grp_index, int patn_index, ITextSnapshotLine line, int line_number, RangeI span, int tab_size) { Grp = grp; GrpIndex = grp_index; Patn = grp.Patterns[patn_index]; Span = span; Line = line; LineNumber = line_number; var line_text = Line.GetText(); int i; for (i = (int)(Span.Beg - 1); i >= 0 && char.IsWhiteSpace(line_text[i]); --i) { } ++i; MinCharIndex = i; MinColumnIndex = CharIndexToColumnIndex(line_text, MinCharIndex, tab_size); CurrentCharIndex = (int)Span.Beg; CurrentColumnIndex = CharIndexToColumnIndex(line_text, (int)Span.Beg, tab_size); }
/// <summary>Export 'filepath' to 'outp'.</summary> /// <param name="d">A copy of the data needed to do the export</param> /// <param name="ranges">Byte ranges within the input file to export</param> /// <param name="row_delimiter">The row delimiter to use in the output file (robitised)</param> /// <param name="col_delimiter">The column delimiter to use in the output file (robitised)</param> /// <param name="outp">The output stream to write the exported result to</param> private static void DoExport(BLIData d, IEnumerable <RangeI> ranges, string row_delimiter, string col_delimiter, StreamWriter outp) { var line = new Line(); // Call back for adding lines to the export result AddLineFunc add_line = (line_rng, baddr, fend, bf, enc) => { if (line_rng.Empty && d.ignore_blanks) { return(true); } // Parse the line from the buffer line.Read(baddr + line_rng.Beg, bf, (int)line_rng.Beg, (int)line_rng.Size, d.encoding, d.col_delim, null, d.transforms); // Keep searching while the text is filtered out or doesn't match the pattern if (!PassesFilters(line.RowText, d.filters)) { return(true); } // Write to the output file outp.Write(string.Join(col_delimiter, line.Column)); outp.Write(row_delimiter); return(true); }; byte[] buf = new byte[d.max_line_length]; foreach (var rng in ranges) { // Find the start of a line (grow the range if necessary) var r = new RangeI(Math_.Clamp(rng.Beg, 0, d.file.Stream.Length), Math_.Clamp(rng.End, 0, d.file.Stream.Length)); r.Beg = FindLineStart(d.file, r.Beg, r.End, d.row_delim, d.encoding, buf); // Read lines and write them to the export file FindLines(d.file, r.Beg, r.End, false, r.Size, add_line, d.encoding, d.row_delim, buf, d.progress); } }
/// <summary>Adjust the scan parameters when doing an incremental update based on the currently loaded data</summary> private static void AdjustForIncrementalBuild(State d, ref bool scan_backward, ref RangeI scan_range, ref int bwd_lines, ref int fwd_lines) { // Determine the direction the cached range is moving based on where 'filepos' is relative // to the current cache centre and which range contains an valid area to be scanned. // With incremental scans we can only update one side of the cache because the returned line index has to // be a contiguous block of lines. This means one of 'bwd_lines' or 'fwd_lines' must be zero. var Lrange = new RangeI(scan_range.Beg, d.m_line_start_range.Beg); var Rrange = new RangeI(d.m_line_start_range.End, scan_range.End); var dir = (!Lrange.Empty && !Rrange.Empty) ? Math.Sign(2 * d.m_index_centre - d.m_line_cache_count) : (!Lrange.Empty) ? -1 : (!Rrange.Empty) ? +1 : 0; // Determine the number of lines to scan, based on direction if (dir < 0) { scan_backward = true; scan_range = Lrange; bwd_lines -= Math_.Clamp(d.m_index_centre - 0, 0, bwd_lines); fwd_lines = 0; } else if (dir > 0) { scan_backward = false; scan_range = Rrange; bwd_lines = 0; fwd_lines -= Math_.Clamp(d.m_index_count - d.m_index_centre - 1, 0, fwd_lines); } else if (dir == 0) { bwd_lines = 0; fwd_lines = 0; scan_range = RangeI.Zero; } }
/// <summary>Access info about a line (cached)</summary> private ILine ReadLine(RangeI rng) { // The position in the cache for file range 'rng' var cache_index = rng.Begi % m_cache.Count; // Check if the line is already cached var line = m_cache[cache_index]; if (line?.FileByteRange == rng) { return(line); } // If not, read it from file and perform highlighting and transforming on it try { // Read the whole line into a buffer m_src.Seek(rng.Beg, SeekOrigin.Begin); m_line_buf = rng.Size <= m_line_buf.Length ? m_line_buf : new byte[rng.Size]; var read = m_src.Read(m_line_buf, 0, (int)rng.Size); if (read != rng.Size) { throw new IOException($"Failed to read file over range [{rng.Beg},{rng.End}) ({rng.Size} bytes). Read {read}/{rng.Size} bytes."); } // Convert the line of data into an 'ILine' line = Formatter.CreateLine(m_line_buf, 0, read, rng); m_cache[cache_index] = line; return(line); } catch (Exception ex) { m_report.ErrorPopup("Failed to read source data", ex); return(new ErrorLine("<read failed>", rng)); } }
public static bool WithinInclusive(this long x, RangeI range) { return(x.WithinInclusive(range.Beg, range.End)); }
/// <summary>Returns a disposable object that preserves the current selection</summary> public static Scope <RangeI> SelectionScope(this TextBox edit) { return(Scope.Create( () => RangeI.FromStartLength(edit.SelectionStart, edit.SelectionLength), rn => edit.Select(rn.Begi, rn.Sizei))); }
public static bool Within(this int x, RangeI range) { return(Within(x, range.Begi, range.Endi)); }
public static bool WithinInclusive(this int x, RangeI range) { return(x.WithinInclusive(range.Begi, range.Endi)); }
public SubRange(RangeI range, Color color) { Range = range; Color = color; }
/// <summary>Add an indicator range</summary> public void AddIndicatorRange(RangeI range, Color colour) { System.Diagnostics.Debug.Assert(TotalRange.Contains(range), "Indicator range outside total range"); range = RangeI.Constrain(range, TotalRange); m_indicator_ranges.Add(new SubRange(range, colour)); }
public BuildCompleteEventArgs(RangeI new_range, int row_delta) { NewRange = new_range; RowDelta = row_delta; }
/// <summary>Restore the selection</summary> public void RestoreTextSelection(RangeI selection) { //System.Diagnostics.Trace.WriteLine($"Restoring Selection: [{selection.Begi},{ selection.Sizei}]"); Select(selection.Begi, selection.Sizei); //System.Diagnostics.Trace.WriteLine($"Selection is now: [{SelectionStart},{ SelectionLength}]"); }
public DataEventArgs(PriceData pd, RangeI index_range) : this(EUpdateType.Range, pd, index_range, null) { }