public void SpawnDestroyedPart(NativeArray <SurfaceState> surface, NativeArray <SurfaceState> surfaceBackup) { Texture2D maskTexture = new Texture2D(_resolution, _resolution, TextureFormat.ARGB32, false); Color32[] colors = new Color32[GameSurface.SurfacePieceCount]; for (int x = 0; x < _resolution; x++) { for (int y = 0; y < _resolution; y++) { Color32 color = new Color32(0, 0, 0, 0); SurfaceState nodeNow = surface[x + (y * _resolution)]; SurfaceState nodeBefore = surfaceBackup[x + (y * _resolution)]; if ((nodeNow == SurfaceState.Destroyed) && (nodeBefore != SurfaceState.Destroyed)) { color = new Color32(255, 255, 255, 255); } colors[x + (y * _resolution)] = color; } } maskTexture.SetPixels32(colors); maskTexture.Apply(); GameSurface.Instance.SpawnDestroyedPart(maskTexture); }
protected IOSurfaceInfo DeclareOutput(SurfaceState state, string channel = "default") { var iosi = DeclareIO(SurfaceDirection.Output, channel, state.SurfaceDisposition); iosi.SurfaceFormat = state.SurfaceFormat; return(iosi); }
public override void Draw(SurfaceState state) { for (int i = 0; i < state.DrawInstances.Count; i++) { Draw(state, state.DrawInstances[i]); } }
private void CountAllConnectedIntactNodes(int indexAtPosition, ref int numberOfPiecesInGroup) { SurfaceState nodeState = Surface[indexAtPosition]; numberOfPiecesInGroup++; if (nodeState == SurfaceState.Intact) { for (int i = 0; i < 4; i++) { int offsetInArray = ConnectedPiecesKernel[i]; int connectionPosition = indexAtPosition + offsetInArray; if (InsideSurface(connectionPosition)) { SurfaceState connectedNodeState = Surface[connectionPosition]; int connectedNodeStateValidity = Validity[connectionPosition]; if ((connectedNodeState == SurfaceState.Intact) && (connectedNodeStateValidity < Timestamp)) { Validity[connectionPosition] = Timestamp; Enqueue(connectionPosition); } } } } }
public override void SetInputFormat(string channel, SurfaceState state) { CrunchNumbers(); var ss = new SurfaceState(new SurfaceFormat(outputSize), SurfaceDisposition.RenderTarget); DeclareOutput(ss, channel); }
public override void SetInputFormat(string channel, SurfaceState state) { //calculate integer scaling factors XIS = OutputSize.Width / state.SurfaceFormat.Size.Width; YIS = OutputSize.Height / state.SurfaceFormat.Size.Height; if (XIS == 0) { XIS = 1; } if (YIS == 0) { YIS = 1; } OutputSize = state.SurfaceFormat.Size; if (XIS <= 1 && YIS <= 1) { IsNop = true; } else { OutputSize.Width *= XIS; OutputSize.Height *= YIS; } var outState = new SurfaceState(); outState.SurfaceFormat = new SurfaceFormat(OutputSize); outState.SurfaceDisposition = SurfaceDisposition.RenderTarget; DeclareOutput(outState); }
void Update() { if (m_surfaceState == SurfaceState.Detected) { if (!TryGetTouchPosition(out Vector2 touchPosition)) { return; } if (m_raycastManager.Raycast(touchPosition, m_hits, TrackableType.PlaneWithinPolygon)) { foreach (var plane in m_detectedPlanes.Values) { if (plane.trackableId == m_hits[0].trackableId) { m_surfaceState = SurfaceState.Selected; UpdateSurfaceStateMsg(SurfaceState.Selected); CheckAndSetCurrentPlane(plane); DisableDetectedPlaneVisuals(plane.trackableId); break; } } } } }
public override void SetInputFormat(string channel, SurfaceState state) { Size inSize = state.SurfaceFormat.Size; if (_sp.ScaleTypeX == RetroShaderPreset.ScaleType.Absolute) { _outputSize.Width = (int)_sp.Scale.X; } if (_sp.ScaleTypeY == RetroShaderPreset.ScaleType.Absolute) { _outputSize.Width = (int)_sp.Scale.Y; } if (_sp.ScaleTypeX == RetroShaderPreset.ScaleType.Source) { _outputSize.Width = (int)(inSize.Width * _sp.Scale.X); } if (_sp.ScaleTypeY == RetroShaderPreset.ScaleType.Source) { _outputSize.Height = (int)(inSize.Height * _sp.Scale.Y); } DeclareOutput(new SurfaceState { SurfaceFormat = new SurfaceFormat(_outputSize), SurfaceDisposition = SurfaceDisposition.RenderTarget }); }
public override void SetInputFormat(string channel, SurfaceState state) { bool need = false; if (state.SurfaceFormat.Size != OutputSize) { need = true; } if (FilterOption != eFilterOption.None) { need = true; } if (!need) { nop = true; ContentSize = state.SurfaceFormat.Size; return; } FindInput().SurfaceDisposition = SurfaceDisposition.Texture; DeclareOutput(new SurfaceState(new SurfaceFormat(OutputSize), SurfaceDisposition.RenderTarget)); InputSize = state.SurfaceFormat.Size; LL = new LetterboxingLogic(Global.Config.DispFixAspectRatio, Global.Config.DispFixScaleInteger, OutputSize.Width, OutputSize.Height, InputSize.Width, InputSize.Height, TextureSize, VirtualTextureSize); ContentSize = new Size(LL.vw, LL.vh); }
public override void SetInputFormat(string channel, SurfaceState state) { Size insize = state.SurfaceFormat.Size; if (SP.ScaleTypeX == RetroShaderPreset.ScaleType.Absolute) { OutputSize.Width = (int)SP.Scale.X; } if (SP.ScaleTypeY == RetroShaderPreset.ScaleType.Absolute) { OutputSize.Width = (int)SP.Scale.Y; } if (SP.ScaleTypeX == RetroShaderPreset.ScaleType.Source) { OutputSize.Width = (int)(insize.Width * SP.Scale.X); } if (SP.ScaleTypeY == RetroShaderPreset.ScaleType.Source) { OutputSize.Height = (int)(insize.Height * SP.Scale.Y); } var outState = new SurfaceState(); outState.SurfaceFormat = new SurfaceFormat(OutputSize); outState.SurfaceDisposition = SurfaceDisposition.RenderTarget; DeclareOutput(outState); }
public override void SetInputFormat(string channel, SurfaceState state) { if (RenderCallback == null) { return; } DeclareOutput(state); }
public override void SetInputFormat(string channel, SurfaceState state) { var outputSize = state.SurfaceFormat.Size; outputSize.Width *= Scale; outputSize.Height *= Scale; var ss = new SurfaceState(new SurfaceFormat(outputSize), SurfaceDisposition.RenderTarget); DeclareOutput(ss, channel); }
public override void SetInputFormat(string channel, SurfaceState state) { bool need = false; if (state.SurfaceFormat.Size != OutputSize) { need = true; } if (FilterOption != eFilterOption.None) { need = true; } if (Flip) { need = true; } if (!need) { nop = true; ContentSize = state.SurfaceFormat.Size; return; } FindInput().SurfaceDisposition = SurfaceDisposition.Texture; DeclareOutput(new SurfaceState(new SurfaceFormat(OutputSize), SurfaceDisposition.RenderTarget)); InputSize = state.SurfaceFormat.Size; if (Config_PadOnly) { //TODO - redundant fix LL = new LetterboxingLogic(); LL.vx += Padding.Left; LL.vy += Padding.Top; LL.vw = InputSize.Width; LL.vh = InputSize.Height; LL.WidthScale = 1; LL.HeightScale = 1; } else { int ow = OutputSize.Width; int oh = OutputSize.Height; ow -= Padding.Horizontal; oh -= Padding.Vertical; LL = new LetterboxingLogic(Config_FixAspectRatio, Config_FixScaleInteger, ow, oh, InputSize.Width, InputSize.Height, TextureSize, VirtualTextureSize); LL.vx += Padding.Left; LL.vy += Padding.Top; } ContentSize = new Size(LL.vw, LL.vh); if (InputSize == OutputSize) //any reason we need to check vx and vy? { IsNop = true; } }
public void Execute(int i) { int rpcNumberOfNode = RpcNumberPerNode[i]; if (ReceivedRpcNumber >= rpcNumberOfNode) { SurfaceState surfacePiece = LocalStateSurface[i]; surfacePiece = SyncedStateSurface[i]; LocalStateSurface[i] = surfacePiece; } }
public Surface(IEnumerable <Event> events, Random random) { _random = random; _state = new SurfaceState(); foreach (var e in events) { var eventType = e.GetType(); var exists = ImplementedApplys.Exists(a => a == eventType); if (!exists) { throw new NotImplementedException($"Surface state does not implement handler for {eventType.Name}"); } _state.Apply((dynamic)e); } }
private void UpdateSurfaceStateMsg(SurfaceState surfaceState) { switch (surfaceState) { case SurfaceState.Detected: m_surfaceStateMsg.GetComponentInChildren <Text>().text = "Tap on any surface to select and lock surface."; break; case SurfaceState.Selected: m_surfaceStateMsg.SetActive(false); break; default: break; } }
void OnARPlanesChanged(ARPlanesChangedEventArgs args) { if (args.added.Count > 0) { foreach (var addedPlane in args.added) { if (addedPlane.alignment == PlaneAlignment.HorizontalUp) { AddPlane(addedPlane); if (m_surfaceState == SurfaceState.Initial) { m_surfaceState = SurfaceState.Detected; UpdateSurfaceStateMsg(SurfaceState.Detected); } } } } if (args.removed.Count > 0) { foreach (var removedPlane in args.removed) { RemovePlane(removedPlane); } } // Make sure we are not using any child planes if (m_detectedPlanes.Count > 0) { foreach (var plane in m_detectedPlanes.Values) { if (plane.subsumedBy != null) { RemovePlane(plane); AddPlane(GetTopMostPlane(plane)); } } } }
private void Draw(SurfaceState state, SurfaceDrawInstance inst) { float destX = inst.DestLocation.X; float destY = inst.DestLocation.Y; Rectangle srcRect = inst.GetSourceRect(SurfaceSize); SizeF displaySize = state.GetDisplaySize(srcRect.Size); PointF rotationCenter = state.GetRotationCenter(displaySize); bool alphaBlend = true; float mRotationCos = (float)Math.Cos(state.RotationAngle); float mRotationSin = (float)Math.Sin(state.RotationAngle); srcRect.X += mSrcRect.Left; srcRect.Y += mSrcRect.Top; if (displaySize.Width < 0) { destX -= displaySize.Width; rotationCenter.X += displaySize.Width; } if (displaySize.Height < 0) { destY -= displaySize.Height; rotationCenter.Y += displaySize.Height; } mDevice.Interpolation = InterpolationHint; SetVertsTextureCoordinates(mVerts, 0, srcRect); SetVertsColor(state.ColorGradient, mVerts, 0, 4); SetVertsPosition(mVerts, 0, new RectangleF(destX, destY, srcRect.Width * (float)state.ScaleWidth, srcRect.Height * (float)state.ScaleHeight), rotationCenter.X, rotationCenter.Y, state.DisplayAlignment, mRotationCos, mRotationSin); mDevice.DrawBuffer.CacheDrawIndexedTriangles(mVerts, mIndices, mTexture.Value, alphaBlend); }
public override void SetInputFormat(string channel, SurfaceState state) { bool need = false; if (state.SurfaceFormat.Size != OutputSize) { need = true; } if (FilterOption != eFilterOption.None) { need = true; } if (!need) { nop = true; ContentSize = state.SurfaceFormat.Size; return; } FindInput().SurfaceDisposition = SurfaceDisposition.Texture; DeclareOutput(new SurfaceState(new SurfaceFormat(OutputSize), SurfaceDisposition.RenderTarget)); InputSize = state.SurfaceFormat.Size; if (Config_PadOnly) { //TODO - redundant fix LL = new LetterboxingLogic(); LL.vx += Padding.Left; LL.vy += Padding.Top; LL.vw = InputSize.Width; LL.vh = InputSize.Height; } else { LL = new LetterboxingLogic(Config_FixAspectRatio, Config_FixScaleInteger, OutputSize.Width, OutputSize.Height, InputSize.Width, InputSize.Height, TextureSize, VirtualTextureSize); } ContentSize = new Size(LL.vw, LL.vh); }
private void ValidateAllConnectedSurfaces(int indexAtPosition) { SurfaceState nodeState = Surface[indexAtPosition]; if (nodeState != SurfaceState.Border) { for (int i = 0; i < 4; i++) { int offsetInArray = ConnectedPiecesKernel[i]; int connectionPosition = indexAtPosition + offsetInArray; if (InsideSurface(connectionPosition)) { SurfaceState connectedNodeState = Surface[connectionPosition]; int connectedNodeStateValidity = Validity[connectionPosition]; if ((connectedNodeState != SurfaceState.Destroyed) && (connectedNodeStateValidity < Timestamp)) { Validity[connectionPosition] = Timestamp; Enqueue(connectionPosition); } } } } }
public override void SetInputFormat(string channel, SurfaceState format) { DeclareOutput(SurfaceDisposition.Texture); }
public SurfacePiece(SurfaceState state = SurfaceState.Intact) { State = state; ValidAtTimestamp = 0; }
public void Execute() { Timestamp = 1; int groupID = 0; int biggestGroupID = 0; int biggestGroupCount = 0; int biggestGroupStartTile = 0; ClearQueue(); for (int x = 0; x < Resolution; x++) { for (int y = 0; y < Resolution; y++) { int indexOfNode = GetIndexAtPosition(x, y); if ((Surface[indexOfNode] == SurfaceState.Intact) && (Validity[indexOfNode] < Timestamp)) { int numberOfPiecesInGroup = 0; ClearQueue(); Validity[indexOfNode] = Timestamp; Enqueue(indexOfNode); while (HasQueuedPosition()) { int positionToValidate = Dequeue(); CountAllConnectedIntactNodes(positionToValidate, ref numberOfPiecesInGroup); } if (numberOfPiecesInGroup > biggestGroupCount) { biggestGroupCount = numberOfPiecesInGroup; biggestGroupStartTile = indexOfNode; } } } } Timestamp++; ClearQueue(); Validity[biggestGroupStartTile] = Timestamp; Enqueue(biggestGroupStartTile); while (HasQueuedPosition()) { int positionToValidate = Dequeue(); ValidateAllConnectedSurfaces(positionToValidate ); } bool anyNewDestroyedNodes = false; for (int i = 0; i < SurfacePieceCount; i++) { SurfaceState nodeState = Surface[i]; int validity = Validity[i]; if ((validity < Timestamp) && (nodeState != SurfaceState.Destroyed)) { anyNewDestroyedNodes = true; Surface[i] = SurfaceState.Destroyed; } } DidCutNewSurface[0] = anyNewDestroyedNodes; }
public override void SetInputFormat(string channel, SurfaceState state) { DeclareOutput(state); }
private void Draw(SurfaceState s, SurfaceDrawInstance inst) { mDisplay.CheckInFrame("Surface.Draw"); System.Diagnostics.Debug.Assert(mImage != null); Geometry.SizeF displaySize = s.GetDisplaySize(SurfaceSize); Geometry.PointF rotationCenter = s.GetRotationCenter(displaySize); Drawing_Display disp = Display.Impl as Drawing_Display; Graphics g = disp.FrameGraphics; GraphicsState state = g.Save(); Geometry.PointF translatePoint = Origin.CalcF(s.DisplayAlignment, displaySize); if (displaySize.Width < 0) { translatePoint.X += displaySize.Width; rotationCenter.X += displaySize.Width; } if (displaySize.Height < 0) { translatePoint.Y += displaySize.Height; rotationCenter.Y += displaySize.Height; } if (s.RotationAngle != 0) { // translate to rotation point, rotate, and translate back. // System.Drawing rotates Clockwise! So we must reverse the // rotation angle. g.TranslateTransform(-rotationCenter.X, -rotationCenter.Y, MatrixOrder.Append); g.RotateTransform(-(float)s.RotationAngleDegrees, MatrixOrder.Append); g.TranslateTransform(rotationCenter.X, rotationCenter.Y, MatrixOrder.Append); } g.TranslateTransform(inst.DestLocation.X - translatePoint.X, inst.DestLocation.Y - translatePoint.Y, MatrixOrder.Append); SetInterpolation(g); Geometry.Rectangle srcRect = inst.GetSourceRect(SurfaceSize); if (s.Color != Geometry.Color.White) { ImageAttributes imageAttributes = new ImageAttributes(); ColorMatrix colorMatrix = new ColorMatrix(new float[][] { new float[] { s.Color.R / 255.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, s.Color.G / 255.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, s.Color.B / 255.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, (float)s.Alpha, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)), srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, imageAttributes); } else { g.DrawImage(mImage, Interop.Convert(DestRect(0, 0, srcRect, s.ScaleWidth, s.ScaleHeight)), srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel); } g.Restore(state); }
public virtual void SetInputFormat(string channel, SurfaceState state) { }
public virtual void SetInputFormat(string channel, SurfaceState state) { } //TODO - why a different param order than DeclareOutput?
public override void SetInputFormat(string channel, SurfaceState state) { DeclareOutput(new SurfaceState(state.SurfaceFormat, SurfaceDisposition.Texture)); }