/** * Converts specified degenerate subpaths to squares. * Note: the list of degenerate subpaths should contain at least 2 elements. Otherwise * we can't determine the direction which the rotation of each square depends on. * * @param squareWidth Width of each constructed square. * @param sourcePath The path which dash pattern applied to. Needed to calc rotation angle of each square. * @return {@link java.util.List} consisting of squares constructed on given degenerated subpaths. */ private static IList <Subpath> ConvertToSquares(IList <Subpath> degenerateSubpaths, double squareWidth, Path sourcePath) { IList <Point2D> pathApprox = GetPathApproximation(sourcePath); if (pathApprox.Count < 2) { return(new List <Subpath>()); } IEnumerator <Point2D> approxIter = pathApprox.GetEnumerator(); approxIter.MoveNext(); Point2D approxPt1 = approxIter.Current; approxIter.MoveNext(); Point2D approxPt2 = approxIter.Current; StandardLine line = new StandardLine(approxPt1, approxPt2); IList <Subpath> squares = new List <Subpath>(degenerateSubpaths.Count); float widthHalf = (float)squareWidth / 2; for (int i = 0; i < degenerateSubpaths.Count; ++i) { Point2D point = degenerateSubpaths[i].GetStartPoint(); while (!line.Contains(point)) { approxPt1 = approxPt2; approxIter.MoveNext(); approxPt2 = approxIter.Current; line = new StandardLine(approxPt1, approxPt2); } float slope = line.GetSlope(); double angle; if (!float.IsPositiveInfinity(slope)) { angle = Math.Atan(slope); } else { angle = Math.PI / 2; } squares.Add(ConstructSquare(point, widthHalf, angle)); } return(squares); }
protected GameLine CreateLine( TrackWriter trk, Vector2d start, Vector2d end, bool inv, bool snapstart, bool snapend) { GameLine added = null; switch (Swatch.Selected) { case LineType.Blue: added = new StandardLine(start, end, inv); break; case LineType.Red: var red = new RedLine(start, end, inv) { Multiplier = Swatch.RedMultiplier }; red.CalculateConstants(); //multiplier needs to be recalculated added = red; break; case LineType.Scenery: added = new SceneryLine(start, end) { Width = Swatch.GreenMultiplier }; break; default: //In case no swatch is chosen select blue and make a blue line added = new StandardLine(start, end, inv); Swatch.Selected = LineType.Blue; break; } trk.AddLine(added); if (Swatch.Selected != LineType.Scenery) { if (snapstart) { SnapLineEnd(trk, added, added.Position); } if (snapend) { SnapLineEnd(trk, added, added.Position2); } } game.Track.Invalidate(); return(added); }
public void AddLine(StandardLine line) { if (_lines.ContainsKey(line.ID)) { LineChanged(line, false); return; } var color = line.GetColor(); var lineverts = CreateDecorationLine(line, color); int start = _linebuffer.AddLine(lineverts); _lines.Add(line.ID, start); }
protected bool LifeLock(TrackReader track, Timeline timeline, StandardLine line) { int offset = game.Track.Offset; int iteration = game.Track.IterationsOffset; if (offset == 0) { return(false); } var frame = timeline.GetFrame(offset, iteration); if (!frame.Crashed) { List <int> diagnosis = null; if (Settings.Editor.LifeLockNoFakie) { diagnosis = timeline.DiagnoseFrame(offset, iteration); foreach (var v in diagnosis) { //the next frame dies on something that isnt a fakie, so we cant stop here if (v < 0) { return(false); } } } if (Settings.Editor.LifeLockNoOrange) { if (diagnosis == null) { diagnosis = timeline.DiagnoseFrame(offset, iteration); } foreach (var v in diagnosis) { //the next frame dies on something that isnt a fakie, so we cant stop here if (v >= 0) { return(false); } } } if (timeline.IsLineHit(line.ID, game.Track.Offset)) { return(true); } } return(false); }
public void LineChanged(StandardLine line) { if (line == null) { return; } lock (SyncRoot) { linevertices lv; if (_lines.TryGetValue(line.ID, out lv)) { LineChangedFreeVertices(lv.coloredtrackline); var newcoloredline = DrawTrackLine(line, true); //chance the colored line could change in type, like 3x multiplier LineChangedFreeVertices(lv.blacktrackline); DrawBasicTrackLine((Vector2)line.Position, (Vector2)line.Position2, Settings.Default.NightMode ? Color.White : Color.Black); LineChangedFreeVertices(lv.knobs); RenderCircle((Vector2)line.Position, Settings.Default.NightMode ? Color.Black : Color.White, 0.75f, 100); RenderCircle((Vector2)line.Position2, Settings.Default.NightMode ? Color.Black : Color.White, 0.75f, 100); LineChangedFreeVertices(lv.redknobs); RenderCircle((Vector2)line.Position, Color.Red, 0.75f, 100); RenderCircle((Vector2)line.Position2, Color.Red, 0.75f, 100); Color linecolor = line.GetLineType() == LineType.Red ? Color.FromArgb(0xCC, 0, 0) : Color.FromArgb(0, 0x66, 0xFF); LineChangedFreeVertices(lv.hittestline); DrawBasicTrackLine((Vector2)line.Position, (Vector2)line.Position2, linecolor); LineChangedFreeVertices(lv.gwell); DrawGWell(line as StandardLine); if (lv.coloredtrackline.Count != newcoloredline.Count)//line indices changed, remind the vao { RequiresUpdate = true; lv.coloredtrackline = newcoloredline; _lines[line.ID] = lv; } } } }
public void AddLine(StandardLine line) { if (_lines.ContainsKey(line.ID)) { LineChanged(line); return; } var well = GetWell(line); _vbo.Bind(); var vertexbase = GetVertexBase(); _vbo.SetData(well, 0, vertexbase, wellsize); _vbo.Unbind(); _lines.Add(line.ID, vertexbase); }
protected GameLine CreateLine( TrackWriter trk, Vector2d start, Vector2d end, bool inv, bool snapstart, bool snapend) { GameLine added = null; switch (game.Canvas.ColorControls.Selected) { case LineType.Blue: added = new StandardLine(start, end, inv); break; case LineType.Red: var red = new RedLine(start, end, inv) { Multiplier = game.Canvas.ColorControls.RedMultiplier }; red.CalculateConstants(); //multiplier needs to be recalculated added = red; break; case LineType.Scenery: added = new SceneryLine(start, end) { Width = game.Canvas.ColorControls.GreenMultiplier }; break; } trk.AddLine(added); if (game.Canvas.ColorControls.Selected != LineType.Scenery) { if (snapstart) { SnapLineEnd(trk, added, added.Position); } if (snapend) { SnapLineEnd(trk, added, added.Position2); } } game.Track.Invalidate(); return(added); }
public static void DrawTrackLine(StandardLine line, Color color, bool drawwell, bool drawcolor) { var lv = new AutoArray <LineVertex>(24); var verts = new AutoArray <GenericVertex>(30); if (drawcolor) { if (line is RedLine redline) { verts.AddRange(LineAccelRenderer.GetAccelDecor(redline)); } lv.AddRange(LineColorRenderer.CreateDecorationLine(line, line.Color)); } lv.AddRange( LineRenderer.CreateTrackLine( line.Start, line.End, line.Width * 2, Utility.ColorToRGBA_LE(color))); if (drawwell) { verts.AddRange(WellRenderer.GetWell(line)); } var vao = GetLineVAO(); vao.Scale = Game.Track.Zoom; foreach (var v in lv.unsafe_array) { vao.AddVertex(v); } GameDrawingMatrix.Enter(); using (new GLEnableCap(EnableCap.Blend)) { if (verts.Count != 0) { GenericVAO gvao = new GenericVAO(); foreach (var v in verts.unsafe_array) { gvao.AddVertex(v); } gvao.Draw(PrimitiveType.Triangles); } vao.Draw(PrimitiveType.Triangles); } GameDrawingMatrix.Exit(); }
private void Multiline(int count) { SimulationCell multilines = GetMultiLines(false); using (var trk = _editor.CreateTrackWriter()) { var owner = (StandardLine)_ownerline; MakingChange(); // owner line doesn't count, but our min bounds is 1 var diff = (count - 1) - multilines.Count; if (diff < 0) { for (int i = 0; i > diff; i--) { trk.RemoveLine(multilines.First()); multilines.RemoveLine(multilines.First().ID); } } else if (diff > 0) { if (_ownerline is RedLine redline) { for (int i = 0; i < diff; i++) { var red = new RedLine(owner.Position, owner.Position2, owner.inv) { Multiplier = ((RedLine)owner).Multiplier }; red.CalculateConstants(); trk.AddLine(red); } } else if (_ownerline is StandardLine blueline) { for (int i = 0; i < diff; i++) { var blue = new StandardLine(owner.Position, owner.Position2, owner.inv); blue.CalculateConstants(); trk.AddLine(blue); } } } } _editor.NotifyTrackChanged(); }
public static GenericVertex[] GetWell(StandardLine line) { var angle = Angle.FromLine(line); angle.Radians += line.inv ? -1.5708 : 1.5708; //90 degrees var offset = angle.MovePoint(Vector2d.Zero, StandardLine.Zone); var wellcolor = Color.FromArgb(80, 80, 80, 80); var tl = new GenericVertex((Vector2)(line.Start), wellcolor); var tr = new GenericVertex((Vector2)(line.End), wellcolor); var bl = new GenericVertex((Vector2)(line.End + offset), wellcolor); var br = new GenericVertex((Vector2)(line.Start + offset), wellcolor); return(new GenericVertex[] { tl, tr, bl, bl, br, tl }); }
public void RemoveLine(StandardLine line) { lock (SyncRoot) { linevertices l; if (_lines.TryRemove(line.ID, out l)) { lines.Remove(line); FreeVertices(l.coloredtrackline); FreeVertices(l.hittestline); FreeVertices(l.blacktrackline); FreeVertices(l.knobs); FreeVertices(l.redknobs); FreeVertices(l.gwell); Invalidate(); } } }
public override void Render() { base.Render(); if (Active) { var diff = _end - _start; var x = diff.X; var y = diff.Y; Color c = Color.FromArgb(200, 150, 150, 150); if (Math.Abs(x) + Math.Abs(y) < MINIMUM_LINE) { c = Color.Red; var sz = 2f; if (Swatch.Selected == LineType.Scenery) { sz *= Swatch.GreenMultiplier; } GameRenderer.RenderRoundedLine(_start, _end, c, sz); } else { switch (Swatch.Selected) { case LineType.Blue: StandardLine sl = new StandardLine(_start, _end, _addflip); sl.CalculateConstants(); GameRenderer.DrawTrackLine(sl, c, Settings.Editor.RenderGravityWells, true); break; case LineType.Red: RedLine rl = new RedLine(_start, _end, _addflip); rl.Multiplier = Swatch.RedMultiplier; rl.CalculateConstants(); GameRenderer.DrawTrackLine(rl, c, Settings.Editor.RenderGravityWells, true); break; case LineType.Scenery: GameRenderer.RenderRoundedLine(_start, _end, c, 2 * Swatch.GreenMultiplier); break; } } } }
private linevertices CreateLine(StandardLine l) { linevertices lv = new linevertices(); lv.coloredtrackline = DrawTrackLine(l, true); lv.blacktrackline = DrawBasicTrackLine((Vector2)l.Position, (Vector2)l.Position2, Settings.Default.NightMode ? Color.White : Color.Black); lv.knobs = new List <int>(6 * 2); lv.knobs.AddRange(RenderCircle((Vector2)l.Position, Settings.Default.NightMode ? Color.Black : Color.White, 0.75f, 100)); lv.knobs.AddRange(RenderCircle((Vector2)l.Position2, Settings.Default.NightMode ? Color.Black : Color.White, 0.75f, 100)); lv.redknobs = new List <int>(6 * 2); lv.redknobs.AddRange(RenderCircle((Vector2)l.Position, Color.Red, 0.75f, 100)); lv.redknobs.AddRange(RenderCircle((Vector2)l.Position2, Color.Red, 0.75f, 100)); Color linecolor = l.GetLineType() == LineType.Red ? Color.FromArgb(0xCC, 0, 0) : Color.FromArgb(0, 0x66, 0xFF); lv.hittestline = DrawBasicTrackLine((Vector2)l.Position, (Vector2)l.Position2, linecolor); lv.gwell = DrawGWell(l); return(lv); }
public void LineChanged(StandardLine line, bool hit = false) { if (!hit) { if (line is RedLine red) { _lineaccelrenderer.LineChanged(red, false); } _linecolorrenderer.LineChanged(line, false); } else { if (line is RedLine red) { _lineaccelrenderer.RemoveLine(red); } _linecolorrenderer.RemoveLine(line); } _wellrenderer.LineChanged(line); }
private void UpdateAGWs(bool left, bool right) { StandardLine.Ext newExt = (StandardLine.Ext)((left ? 1 : 0) + (right ? 2 : 0)); var multilines = GetMultiLines(false); using (var trk = _editor.CreateTrackWriter()) { trk.DisableExtensionUpdating(); StandardLine cpy = (StandardLine)_ownerline.Clone(); cpy.Extension = newExt; UpdateOwnerLine(trk, cpy); foreach (var line in multilines) { StandardLine copy = (StandardLine)line.Clone(); copy.Extension = newExt; UpdateLine(trk, line, copy); } } }
protected GameLine CreateLine( //Creates a line from a pair of vectors (modified from Tool.cs) TrackWriter trk, Vector2d start, Vector2d end, LineType type, bool inv, int multiplier = 1, //Only applies to red lines (smh) float width = 1.0f) //Width only applicable to green lines { GameLine added = null; switch (type) { case LineType.Blue: added = new StandardLine(start, end, inv); break; case LineType.Red: var red = new RedLine(start, end, inv) { Multiplier = multiplier }; red.CalculateConstants(); //multiplier needs to be recalculated added = red; break; case LineType.Scenery: added = new SceneryLine(start, end) { Width = width }; break; } trk.AddLine(added); game.Track.Invalidate(); return(added); }
private List <int> DrawTrackLine(StandardLine line, bool colors) { List <int> ret = new List <int>((6 * 6) + 3); var type = line.GetLineType(); Color c = Settings.Default.NightMode ? Color.White : Color.Black; if (colors) { switch (type) { case LineType.Blue: { c = Color.FromArgb(0, 0x66, 0xFF); var l = line; var loc3 = (float)(l.Perpendicular.X > 0 ? (Math.Ceiling(l.Perpendicular.X)) : (Math.Floor(l.Perpendicular.X))); var loc4 = (float)(l.Perpendicular.Y > 0 ? (Math.Ceiling(l.Perpendicular.Y)) : (Math.Floor(l.Perpendicular.Y))); Vector2 p1 = new Vector2((float)l.Position.X + loc3, (float)l.Position.Y + loc4), p2 = new Vector2((float)l.Position2.X + loc3, (float)l.Position2.Y + loc4); ret.AddRange(DrawBasicTrackLine(p1, p2, c)); } break; case LineType.Red: { c = Color.FromArgb(0xCC, 0, 0); var l = line as RedLine; var loc3 = (float)(l.Perpendicular.X > 0 ? (Math.Ceiling(l.Perpendicular.X)) : (Math.Floor(l.Perpendicular.X))); var loc4 = (float)(l.Perpendicular.Y > 0 ? (Math.Ceiling(l.Perpendicular.Y)) : (Math.Floor(l.Perpendicular.Y))); for (int ix = 0; ix < l.Multiplier; ix++) { var angle = MathHelper.RadiansToDegrees(Math.Atan2(l.diff.Y, l.diff.X)); Turtle t = new Turtle(l.Position2); var basex = 8 + (ix * 2); t.Move(angle, -basex); var v0 = AddVertex(new Vertex((float)t.X, (float)t.Y, c)); t.Move(90, l.inv ? -8 : 8); var v1 = AddVertex(new Vertex((float)t.X, (float)t.Y, c)); t.Point = l.Position2; t.Move(angle, -(ix * 2)); var v2 = AddVertex(new Vertex((float)t.X, (float)t.Y, c)); ret.Add(v0); ret.Add(v1); ret.Add(v2); } Vector2 p1 = new Vector2((float)l.Position.X + loc3, (float)l.Position.Y + loc4), p2 = new Vector2((float)l.Position2.X + loc3, (float)l.Position2.Y + loc4); ret.AddRange(DrawBasicTrackLine(p1, p2, c)); } break; } } Color linecolor = Settings.Default.NightMode ? Color.White : Color.Black; var linep1 = line.Position; var linep2 = line.Position2; if (line.Trigger != null && line.Trigger.Enabled && colors) { linecolor = Color.FromArgb(0xFF, 0x95, 0x4F); } #if drawextension if (l.Extension != StandardLine.ExtensionDirection.None) { linerider.Tools.Angle angle = Tools.Angle.FromLine(l.Position, l.Position2); switch (l.Extension) { case StandardLine.ExtensionDirection.Left: { Turtle turtle = new Turtle(l.CompliantPosition); turtle.Move(angle.Degrees, l.inv ? 4 : -4); if (l.inv) { linep2 = turtle.Point; } else { linep1 = turtle.Point; } } break; case StandardLine.ExtensionDirection.Right: { Turtle turtle = new Turtle(l.CompliantPosition2); turtle.Move(angle.Degrees, !l.inv ? 4 : -4); if (l.inv) { linep1 = turtle.Point; } else { linep2 = turtle.Point; } } break; case StandardLine.ExtensionDirection.Both: { Turtle turtle = new Turtle(l.CompliantPosition); turtle.Move(angle.Degrees, -2); if (l.inv) { linep2 = turtle.Point; } else { linep1 = turtle.Point; } turtle = new Turtle(l.CompliantPosition2); turtle.Move(angle.Degrees, !l.inv ? 4 : -4); if (l.inv) { linep1 = turtle.Point; } else { linep2 = turtle.Point; } } break; } } #endif ret.AddRange(DrawBasicTrackLine((Vector2)linep1, (Vector2)linep2, linecolor)); return(ret); }
private static void MoveFrameRelative(List <LineSelection> selectedLines, int direction, bool isCompleteAction) { RiderFrame flag = window.Track.GetFlag(); int currentFrame = window.Track.Offset; if (flag == null || currentFrame <= flag.FrameID) { // Behavior only defined if flag is set and current frame is ahead of it return; } Rider flagFrameRider = flag.State; Rider flagNextFrameRider = window.Track.Timeline.ExtractFrame(flag.FrameID + 1).State; // Where the Rider was at the flag frame, and the frame after that // This establishes the initial frame of reference // // flagNextFrameRider is considered to be the frame with 0 relative velocity to the reference frame // All frames after will look as if the rider has started falling within the reference frame, because gravity. // // This is all if the user-configured relative speeds are (0, 0). If the user changes these speeds, // the lines will be drawn accordingly. Vector2d flagFramePos = Game.Rider.GetBounds(flagFrameRider).Vector; Vector2d flagNextFramePos = Game.Rider.GetBounds(flagNextFrameRider).Vector; // The difference between where the rider was on frames 0 and 1 establishes a reference speed to apply Vector2d firstFrameDiff = Vector2d.Subtract(flagNextFramePos, flagFramePos); // Add the user-configurable speed offsets firstFrameDiff = Vector2d.Add(firstFrameDiff, new Vector2d(Settings.animationRelativeVelX, Settings.animationRelativeVelY)); int framesElapsed = currentFrame - flag.FrameID; // Apply the speed vector to the number of elapsed frames, and add it to the initial reference frame // to get an expected position for the current frame Vector2d currentFrameExpectedPos = Vector2d.Add(Vector2d.Multiply(firstFrameDiff, framesElapsed), flagFramePos); // Same for the next frame Vector2d nextFrameExpectedPos = Vector2d.Add(Vector2d.Multiply(firstFrameDiff, framesElapsed + direction), flagFramePos); if (isCompleteAction) { window.Invalidate(); window.Track.UndoManager.BeginAction(); } TrackWriter trackWriter = window.Track.CreateTrackWriter(); List <GameLine> newLines = new List <GameLine>(); foreach (LineSelection selection in selectedLines) { GameLine selectedLine = selection.line; Vector2d p1 = selectedLine.Position; Vector2d p2 = selectedLine.Position2; Vector2d diff1 = Vector2d.Subtract(p1, currentFrameExpectedPos); Vector2d diff2 = Vector2d.Subtract(p2, currentFrameExpectedPos); Vector2d nextP1 = Vector2d.Add(nextFrameExpectedPos, diff1); Vector2d nextP2 = Vector2d.Add(nextFrameExpectedPos, diff2); // Add a new line in the same position, then move the existing line to maintain the selection GameLine newLine; if (!Settings.forwardLinesAsScenery && (direction > 0 || !Settings.recededLinesAsScenery)) { switch (selection.line.Type) { case LineType.Red: newLine = new RedLine(nextP1, nextP2, ((RedLine)selectedLine).inv); break; case LineType.Blue: newLine = new StandardLine(nextP1, nextP2, ((StandardLine)selectedLine).inv); break; case LineType.Scenery: newLine = new SceneryLine(nextP1, nextP2); break; default: newLine = new SceneryLine(nextP1, nextP2); break; } } else { newLine = new SceneryLine(nextP1, nextP2); } newLines.Add(newLine); } var selectTool = CurrentTools.SelectTool; foreach (GameLine newLine in newLines) { trackWriter.AddLine(newLine); } selectTool.SelectLines(newLines); if (isCompleteAction) { window.Track.UndoManager.EndAction(); window.Track.NotifyTrackChanged(); } }
public void RemoveLine(StandardLine line) { var colorindex = _lines[line.ID]; _linebuffer.RemoveLine(colorindex); }
public static void DrawTrackLine(StandardLine l, Color color, bool drawwell, bool drawcolor, bool drawknobs, bool redknobs = false) { color = Color.FromArgb(255, color); var thickness = 2; Color color2; var type = l.GetLineType(); switch (type) { case LineType.Blue: color2 = Color.FromArgb(0, 0x66, 0xFF); break; case LineType.Red: color2 = Color.FromArgb(0xCC, 0, 0); break; default: throw new Exception("Rendering Invalid Line"); } if (drawcolor) { var loc3 = l.Perpendicular.X > 0 ? (Math.Ceiling(l.Perpendicular.X)) : (Math.Floor(l.Perpendicular.X)); var loc4 = l.Perpendicular.Y > 0 ? (Math.Ceiling(l.Perpendicular.Y)) : (Math.Floor(l.Perpendicular.Y)); if (type == LineType.Red) { var redline = l as RedLine; GameDrawingMatrix.Enter(); GL.Color3(color2); GL.Begin(PrimitiveType.Triangles); var basepos = l.Position2; for (int ix = 0; ix < redline.Multiplier; ix++) { var angle = MathHelper.RadiansToDegrees(Math.Atan2(l.diff.Y, l.diff.X)); Turtle t = new Turtle(l.Position2); var basex = 8 + (ix * 2); t.Move(angle, -basex); GL.Vertex2(new Vector2((float)t.X, (float)t.Y)); t.Move(90, l.inv ? -8 : 8); GL.Vertex2(new Vector2((float)t.X, (float)t.Y)); t.Point = l.Position2; t.Move(angle, -(ix * 2)); GL.Vertex2(new Vector2((float)t.X, (float)t.Y)); } GL.End(); GameDrawingMatrix.Exit(); } RenderRoundedLine(new Vector2d(l.Position.X + loc3, l.Position.Y + loc4), new Vector2d(l.Position2.X + loc3, l.Position2.Y + loc4), color2, thickness); } RenderRoundedLine(l.Position, l.Position2, color, thickness, drawknobs, redknobs); if (drawwell) { using (new GLEnableCap(EnableCap.Blend)) { GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GameDrawingMatrix.Enter(); GL.Begin(PrimitiveType.Quads); GL.Color4(new Color4(150, 150, 150, 150)); var rect = StaticRenderer.GenerateThickLine((Vector2)l.Position, (Vector2)l.Position2, (float)(StandardLine.Zone * 2)); GL.Vertex2(l.Position); GL.Vertex2(l.Position2); GL.Vertex2(rect[l.inv ? 2 : 1]); GL.Vertex2(rect[l.inv ? 3 : 0]); GL.End(); GL.PopMatrix(); } } }
public static Track LoadTrack(string trackfile, string trackname) { var ret = new Track(); ret.Filename = trackfile; ret.Name = trackname; var addedlines = new Dictionary <int, StandardLine>(); var location = trackfile; var bytes = File.ReadAllBytes(location); using (var file = new MemoryStream(bytes)) { var br = new BinaryReader(file); int magic = br.ReadInt32(); if (magic == ('T' | 'R' << 8 | 'K' << 16 | 0xF2 << 24)) { byte version = br.ReadByte(); string[] features = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (version != 1) { throw new TrackIO.TrackLoadException("Unsupported version"); } bool redmultipier = false; bool scenerywidth = false; bool supports61 = false; bool songinfo = false; bool ignorabletrigger = false; for (int i = 0; i < features.Length; i++) { switch (features[i]) { case "REDMULTIPLIER": redmultipier = true; break; case "SCENERYWIDTH": scenerywidth = true; break; case "6.1": supports61 = true; break; case "SONGINFO": songinfo = true; break; case "IGNORABLE_TRIGGER": ignorabletrigger = true; break; case "ZEROSTART": ret.ZeroStart = true; break; default: throw new TrackIO.TrackLoadException("Unsupported feature"); } } if (supports61) { ret.SetVersion(61); } else { ret.SetVersion(62); } if (songinfo) { var song = br.ReadString(); try { var strings = song.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); var fn = Program.UserDirectory + "Songs" + Path.DirectorySeparatorChar + strings[0]; if (File.Exists(fn)) { if (AudioService.LoadFile(ref fn)) { Settings.Local.CurrentSong = new Song(Path.GetFileName(fn), float.Parse(strings[1])); Settings.Local.EnableSong = true; } else { Program.NonFatalError("An unknown error occured trying to load the song file"); } } } catch { // ignored } } ret.StartOffset = new Vector2d(br.ReadDouble(), br.ReadDouble()); var lines = br.ReadInt32(); for (var i = 0; i < lines; i++) { GameLine l; byte ltype = br.ReadByte(); var lt = (LineType)(ltype & 0x1F);//we get 5 bits var inv = (ltype >> 7) != 0; var lim = (ltype >> 5) & 0x3; var ID = -1; var prvID = -1; var nxtID = -1; var multiplier = 1; var linewidth = 1f; LineTrigger tr = ignorabletrigger ? new LineTrigger() : null; if (redmultipier) { if (lt == LineType.Red) { multiplier = br.ReadByte(); } } if (lt == LineType.Blue || lt == LineType.Red) { if (ignorabletrigger) { bool zoomtrigger = br.ReadBoolean(); if (zoomtrigger) { tr.Zoomtrigger = true; var target = br.ReadSingle(); var frames = br.ReadInt16(); tr.ZoomFrames = frames; tr.ZoomTarget = target; } else { tr = null; } } ID = br.ReadInt32(); if (lim != 0) { prvID = br.ReadInt32(); //ignored nxtID = br.ReadInt32(); //ignored } } if (lt == LineType.Scenery) { if (scenerywidth) { float b = br.ReadByte(); linewidth = b / 10f; } } var x1 = br.ReadDouble(); var y1 = br.ReadDouble(); var x2 = br.ReadDouble(); var y2 = br.ReadDouble(); switch (lt) { case LineType.Blue: var bl = new StandardLine(new Vector2d(x1, y1), new Vector2d(x2, y2), inv); bl.ID = ID; bl.Extension = (StandardLine.Ext)lim; l = bl; bl.Trigger = tr; break; case LineType.Red: var rl = new RedLine(new Vector2d(x1, y1), new Vector2d(x2, y2), inv); rl.ID = ID; rl.Extension = (StandardLine.Ext)lim; if (redmultipier) { rl.Multiplier = multiplier; } l = rl; rl.Trigger = tr; break; case LineType.Scenery: l = new SceneryLine(new Vector2d(x1, y1), new Vector2d(x2, y2)) { Width = linewidth }; break; default: throw new TrackIO.TrackLoadException("Invalid line type at ID " + ID); } if (l is StandardLine) { if (!addedlines.ContainsKey(l.ID)) { addedlines[ID] = (StandardLine)l; ret.AddLine(l); } } else { ret.AddLine(l); } } } } return(ret); }
private static void AddLine(Track track, line_json line) { switch (line.type) { case 0: { var add = new StandardLine( new Vector2d(line.x1, line.y1), new Vector2d(line.x2, line.y2), Convert.ToBoolean(line.flipped)); add.ID = line.id; add.Extension = (StandardLine.Ext)line.extended; if (Convert.ToBoolean(line.leftExtended)) { add.Extension |= StandardLine.Ext.Left; } if (Convert.ToBoolean(line.rightExtended)) { add.Extension |= StandardLine.Ext.Right; } track.AddLine(add); break; } case 1: { var add = new RedLine( new Vector2d(line.x1, line.y1), new Vector2d(line.x2, line.y2), Convert.ToBoolean(line.flipped)); add.ID = line.id; add.Extension = (StandardLine.Ext)line.extended; if (Convert.ToBoolean(line.leftExtended)) { add.Extension |= StandardLine.Ext.Left; } if (Convert.ToBoolean(line.rightExtended)) { add.Extension |= StandardLine.Ext.Right; } if (line.multiplier > 1) { add.Multiplier = line.multiplier; } track.AddLine(add); break; } case 2: { var add = new SceneryLine( new Vector2d(line.x1, line.y1), new Vector2d(line.x2, line.y2)); add.ID = line.id; track.AddLine(add); break; } default: throw new TrackIO.TrackLoadException( "Unknown line type"); } }
/** * Converts specified degenerate subpaths to squares. * Note: the list of degenerate subpaths should contain at least 2 elements. Otherwise * we can't determine the direction which the rotation of each square depends on. * * @param squareWidth Width of each constructed square. * @param sourcePath The path which dash pattern applied to. Needed to calc rotation angle of each square. * @return {@link java.util.List} consisting of squares constructed on given degenerated subpaths. */ private static IList<Subpath> ConvertToSquares(IList<Subpath> degenerateSubpaths, double squareWidth, Path sourcePath) { IList<Point2D> pathApprox = GetPathApproximation(sourcePath); if (pathApprox.Count < 2) { return new List<Subpath>(); } IEnumerator<Point2D> approxIter = pathApprox.GetEnumerator(); approxIter.MoveNext(); Point2D approxPt1 = approxIter.Current; approxIter.MoveNext(); Point2D approxPt2 = approxIter.Current; StandardLine line = new StandardLine(approxPt1, approxPt2); IList<Subpath> squares = new List<Subpath>(degenerateSubpaths.Count); float widthHalf = (float) squareWidth / 2; for (int i = 0; i < degenerateSubpaths.Count; ++i) { Point2D point = degenerateSubpaths[i].GetStartPoint(); while (!line.Contains(point)) { approxPt1 = approxPt2; approxIter.MoveNext(); approxPt2 = approxIter.Current; line = new StandardLine(approxPt1, approxPt2); } float slope = line.GetSlope(); double angle; if (!float.IsPositiveInfinity(slope)) { angle = Math.Atan(slope); } else { angle = Math.PI / 2; } squares.Add(ConstructSquare(point, widthHalf, angle)); } return squares; }
public static Track LoadTrack(sol_track trackdata) { var ret = new Track { Name = trackdata.name, Filename = trackdata.filename }; var buffer = (List <Amf0Object>)trackdata.get_property("data"); List <GameLine> lineslist = new List <GameLine>(buffer.Count); var addedlines = new Dictionary <int, StandardLine>(buffer.Count); var version = trackdata.data.First(x => x.name == "version").data as string; if (version == "6.1") { ret.SetVersion(61); } else { ret.SetVersion(62); } try { var options = (List <Amf0Object>)trackdata.get_property("trackData"); if (options.Count >= 2) { try { ret.ZeroStart = (bool)options.Find(x => x.name == "2").get_property("5"); } catch { //ignored } } } catch { //ignored } for (var i = buffer.Count - 1; i >= 0; --i) { var line = (List <Amf0Object>)buffer[i].data; var type = Convert.ToInt32(line[9].data, CultureInfo.InvariantCulture); switch (type) { case 0: { var l = new StandardLine( new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture), Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)), new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture), Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)), Convert.ToBoolean(line[5].data, CultureInfo.InvariantCulture)) { ID = Convert.ToInt32(line[8].data, CultureInfo.InvariantCulture) }; l.Extension = (StandardLine.Ext)( Convert.ToInt32( line[4].data, CultureInfo.InvariantCulture)); if (line[6].data != null) { var prev = Convert.ToInt32(line[6].data, CultureInfo.InvariantCulture); } if (line[7].data != null) { var next = Convert.ToInt32(line[7].data, CultureInfo.InvariantCulture); } if (!addedlines.ContainsKey(l.ID)) { lineslist.Add(l); addedlines[l.ID] = l; } } break; case 1: { var l = new RedLine( new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture), Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)), new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture), Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)), Convert.ToBoolean(line[5].data, CultureInfo.InvariantCulture)) { ID = Convert.ToInt32(line[8].data, CultureInfo.InvariantCulture) }; l.Extension = (StandardLine.Ext)( Convert.ToInt32( line[4].data, CultureInfo.InvariantCulture)); if (line[6].data != null) { var prev = Convert.ToInt32(line[6].data, CultureInfo.InvariantCulture); } if (line[7].data != null) { var next = Convert.ToInt32(line[7].data, CultureInfo.InvariantCulture); } if (!addedlines.ContainsKey(l.ID)) { lineslist.Add(l); addedlines[l.ID] = l; } } break; case 2: lineslist.Add( new SceneryLine( new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture), Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)), new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture), Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)))); break; default: throw new TrackIO.TrackLoadException("Unknown line type"); } } var startlineprop = trackdata.get_property("startLine"); var startline = startlineprop as List <Amf0Object>; if (startline == null && startlineprop is double) { var conv = Convert.ToInt32(startlineprop, CultureInfo.InvariantCulture); if (conv >= ret.Lines.Count || conv < 0) { startline = new List <Amf0Object>(); startline.Add(new Amf0Object { data = 100 }); startline.Add(new Amf0Object { data = 100 }); } } else if (startlineprop is double) { var conv = Convert.ToInt32(startlineprop, CultureInfo.InvariantCulture); startline = new List <Amf0Object>(); startline.Add(new Amf0Object { data = lineslist[conv].Position.X }); startline.Add(new Amf0Object { data = lineslist[conv].Position.Y - 50 * 0.5 }); } ret.StartOffset = new Vector2d( Convert.ToDouble(startline[0].data, CultureInfo.InvariantCulture), Convert.ToDouble(startline[1].data, CultureInfo.InvariantCulture)); foreach (var line in lineslist) { ret.AddLine(line); } return(ret); }
public static Track LoadTrack(string trackfile, string trackname) { var ret = new Track(); ret.Filename = trackfile; ret.Name = trackname; ret.Remount = false; var addedlines = new Dictionary <int, StandardLine>(); var location = trackfile; var bytes = File.ReadAllBytes(location); using (var file = new MemoryStream(bytes)) { var br = new BinaryReader(file); int magic = br.ReadInt32(); if (magic != ('T' | 'R' << 8 | 'K' << 16 | 0xF2 << 24)) { throw new TrackIO.TrackLoadException("File was read as .trk but it is not valid"); } byte version = br.ReadByte(); string[] features = ReadString(br).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (version != 1) { throw new TrackIO.TrackLoadException("Unsupported version"); } bool redmultipier = false; bool scenerywidth = false; bool supports61 = false; bool songinfo = false; bool ignorabletrigger = false; for (int i = 0; i < features.Length; i++) { switch (features[i]) { case TrackFeatures.redmultiplier: redmultipier = true; break; case TrackFeatures.scenerywidth: scenerywidth = true; break; case TrackFeatures.six_one: supports61 = true; break; case TrackFeatures.songinfo: songinfo = true; break; case TrackFeatures.ignorable_trigger: ignorabletrigger = true; break; case TrackFeatures.zerostart: ret.ZeroStart = true; break; case TrackFeatures.remount: ret.Remount = true; break; case TrackFeatures.frictionless: ret.frictionless = true; break; default: throw new TrackIO.TrackLoadException("Unsupported feature"); } } if (supports61) { ret.SetVersion(61); } else { ret.SetVersion(62); } if (songinfo) { var song = br.ReadString(); try { var strings = song.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); var fn = Program.UserDirectory + "Songs" + Path.DirectorySeparatorChar + strings[0]; if (File.Exists(fn)) { if (AudioService.LoadFile(ref fn)) { ret.Song = new Song(Path.GetFileName(fn), float.Parse(strings[1], Program.Culture)); } else { Program.NonFatalError("An unknown error occured trying to load the song file"); } } } catch { // ignored } } ret.StartOffset = new Vector2d(br.ReadDouble(), br.ReadDouble()); var lines = br.ReadInt32(); List <LineTrigger> linetriggers = new List <LineTrigger>(); for (var i = 0; i < lines; i++) { GameLine l; byte ltype = br.ReadByte(); var lt = (LineType)(ltype & 0x1F);//we get 5 bits var inv = (ltype >> 7) != 0; var lim = (ltype >> 5) & 0x3; var ID = -1; var prvID = -1; var nxtID = -1; var multiplier = 1; var linewidth = 1f; LineTrigger tr = null; if (redmultipier) { if (lt == LineType.Red) { multiplier = br.ReadByte(); } } if (lt == LineType.Blue || lt == LineType.Red) { if (ignorabletrigger) { tr = new LineTrigger(); bool zoomtrigger = br.ReadBoolean(); if (zoomtrigger) { tr.ZoomTrigger = true; var target = br.ReadSingle(); var frames = br.ReadInt16(); tr.ZoomFrames = frames; tr.ZoomTarget = target; } else { tr = null; } } ID = br.ReadInt32(); if (lim != 0) { prvID = br.ReadInt32(); //ignored nxtID = br.ReadInt32(); //ignored } } if (lt == LineType.Scenery) { if (scenerywidth) { float b = br.ReadByte(); linewidth = b / 10f; } } var x1 = br.ReadDouble(); var y1 = br.ReadDouble(); var x2 = br.ReadDouble(); var y2 = br.ReadDouble(); if (tr != null) { tr.LineID = ID; linetriggers.Add(tr); } switch (lt) { case LineType.Blue: var bl = new StandardLine(new Vector2d(x1, y1), new Vector2d(x2, y2), inv); bl.ID = ID; bl.Extension = (StandardLine.Ext)lim; l = bl; break; case LineType.Red: var rl = new RedLine(new Vector2d(x1, y1), new Vector2d(x2, y2), inv); rl.ID = ID; rl.Extension = (StandardLine.Ext)lim; if (redmultipier) { rl.Multiplier = multiplier; } l = rl; break; case LineType.Scenery: l = new SceneryLine(new Vector2d(x1, y1), new Vector2d(x2, y2)) { Width = linewidth }; break; default: throw new TrackIO.TrackLoadException("Invalid line type at ID " + ID); } if (l is StandardLine) { if (!addedlines.ContainsKey(l.ID)) { addedlines[ID] = (StandardLine)l; ret.AddLine(l); } } else { ret.AddLine(l); } } ret.Triggers = TriggerConverter.ConvertTriggers(linetriggers, ret); if (br.BaseStream.Position != br.BaseStream.Length) { var meta = br.ReadInt32(); if (meta == ('M' | 'E' << 8 | 'T' << 16 | 'A' << 24)) { ParseMetadata(ret, br); } else { throw new TrackIO.TrackLoadException("Expected metadata tag but got " + meta.ToString("X8")); } } } return(ret); }
public void init(StreamWriter st) { st.WriteLine("初期化開始"); pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel); st.WriteLine("デバイス作成の開始"); device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters() { BackBufferWidth = this.pictureBox1.ClientSize.Width, BackBufferHeight = this.pictureBox1.ClientSize.Height, Windowed = true, }); st.WriteLine("デバイス作成の終了"); Capabilities caps = device.Capabilities; st.WriteLine("adapterOrdinal:" + caps.AdapterOrdinal); st.WriteLine("DeviceType:" + caps.DeviceType); if (caps.VertexShaderVersion.Major < 3) { MessageBox.Show("VertexShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion); device.Dispose(); Environment.Exit(0); } else if (caps.PixelShaderVersion.Major < 3) { MessageBox.Show("PixelShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion); device.Dispose(); Environment.Exit(0); } st.WriteLine("DeviceContextの初期化"); DeviceContext.init(device); st.WriteLine("ZEnableの初期化"); device.SetRenderState(RenderState.ZEnable, true); st.WriteLine("cameraの初期化"); camera = new Camera(device); st.WriteLine("Floorの初期化"); floorMap = new FloorMap(device); // teapot = Mesh.CreateTeapot(device); // device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat); st.WriteLine("照明の初期化"); device.SetRenderState(RenderState.Lighting, true); device.SetLight(0, new Light() { Type = LightType.Directional, Diffuse = Color.White, Ambient = Color.Gray, Direction = new Vector3(1.0f, 1.0f, 0.0f), }); device.EnableLight(0,true); standardLine = new StandardLine(device); //射影変換 device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((float)(Math.PI / 4), (float)this.pictureBox1.ClientSize.Width / (float)this.pictureBox1.ClientSize.Height, 0.1f, 1500.0f)); //ビュー device.SetTransform(TransformState.View, camera.getLookAtLh()); device.SetTransform(TransformState.World, Matrix.Identity); st.WriteLine("FloorModelの初期化"); floorModel = new FloorModel(new MqoParser(device).parse(".\\projects\\sample\\model\\floor.mqo", new MqoModel())); st.WriteLine("初期化終了"); }