Exemplo n.º 1
0
        public void Render(Moment now, GraphicsDevice graphicsDevice, ISpriteBatch spriteBatch, TextureContent content, HolofunkView view)
        {
            if (RootNode != null) {
                RootNode.Render(now, graphicsDevice, spriteBatch, content, view, Transform.Identity, 0);
            }

            Spam.Graphics.WriteLine("End Render");
        }
Exemplo n.º 2
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice,
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            bool positionMirrored =
                SecondaryViewOption == SecondaryViewOption.PositionMirrored
                && view == HolofunkView.Secondary;

            Vector2 p0 = m_p0 + parentTransform.Translation;
            Vector2 p1 = m_p1 + parentTransform.Translation;

            if (positionMirrored) {
                p0 = new Vector2(spriteBatch.Viewport.X - p0.X, p0.Y);
                p1 = new Vector2(spriteBatch.Viewport.X - p1.X, p1.Y);
            }

            Vector2 diff = Vector2.Subtract(p1, p0);
            float angleRadians = (float)Math.Atan2(diff.Y, diff.X);
            float length = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y) / 2;

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                content.TinyDot,
                p0,
                null,
                Color,
                angleRadians,
                new Vector2(0f, 1f), // we pivot around the center of the left edge of the 2x2 square
                new Vector2(length, LocalTransform.Scale.Y),
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
Exemplo n.º 3
0
        internal TrackNode(
            AParentSceneNode parent,
            Transform transform,
            string label,
            TextureContent content,
            int id,
            SparseSampleByteStream videoStream,
            bool fillInEveryBeat,
            Func<float> levelRatioFunc,
            Func<Color> circleColorFunc,
            Func<Color> videoColorFunc,
            Func<Duration<Sample>> trackDurationFunc,
            Func<int> initialBeatFunc,
            Func<Color> beatColorFunc,
            Func<float> videoRateFunc)
            : base(parent, transform, label)
        {
            m_id = id;

            m_levelRatioFunc = levelRatioFunc;
            m_circleColorFunc = circleColorFunc;
            m_videoColorFunc = videoColorFunc;
            m_beatColorFunc = beatColorFunc;
            m_videoRateFunc = videoRateFunc;

            // create this first so it is Z-ordered behind m_soundNode
            m_selectNode = new SpriteNode(this, "TrackHighlight", content.FilledCircle);
            m_selectNode.Color = new Color((byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80);
            m_selectNode.Origin = new Vector2(0.5f);

            m_soundNode = new SpriteNode(this, "TrackSound", content.FilledCircle);
            m_soundNode.Color = Color.Blue;
            m_soundNode.Origin = new Vector2(0.5f);

            m_videoNode = new SpriteNode(this, "Headshot", content.NewDynamicTexture(MagicNumbers.HeadCaptureSize, MagicNumbers.HeadCaptureSize));
            m_videoNode.Origin = new Vector2(0.5f);
            m_videoNode.LocalTransform = new Transform(new Vector2(0), new Vector2(MagicNumbers.HeadRatio));
            m_videoNode.SetSecondaryViewOption(SecondaryViewOption.TextureMirrored);

            m_videoStream = videoStream;

            m_beatNode = new BeatNode(
                this,
                // move it down a bit from the sprite node
                new Transform(new Vector2(0, 75)),
                "TrackBeats",
                fillInEveryBeat,
                MagicNumbers.MeasureCircleScale,
                trackDurationFunc,
                initialBeatFunc,
                beatColorFunc);

            m_beatNode.SetSecondaryViewOption(SecondaryViewOption.PositionMirrored);

            // we always mirror track node position
            SetSecondaryViewOption(SecondaryViewOption.PositionMirrored);

            m_lastVideoFrame = default(Slice<Frame, byte>);
        }
Exemplo n.º 4
0
        protected override void DoRender(Moment now, GraphicsDevice graphicsDevice, ISpriteBatch spriteBatch, TextureContent content, HolofunkView view, Transform parentTransform, int depth)
        {
            m_videoRateCounter += m_videoRateFunc();
            if (m_videoRateCounter >= 1f) {
                m_videoRateCounter -= 1f;
                lock (this) {
                    if (VideoStream != null) {
                        s_totalRenders++;

                        Slice<Frame, byte> videoImage = VideoStream.GetClosestSliver(now.Time + MagicNumbers.LatencyCompensationDuration);

                        if (!videoImage.IsEmpty()) {
                            if (videoImage.Equals(m_lastVideoFrame)) {
                                // skip the setData
                                s_redundantSetDatas++;
                            }
                            else {
                                // blast the data in there with a single pointer-based memory copy
                                videoImage.RawAccess((array, offset, count) => m_videoNode.Texture.SetData(array, (int)offset, (int)count));
                                m_lastVideoFrame = videoImage;
                            }
                        }
                    }
                    else {
                        // ain't nothing to show
                        m_videoNode.Texture.SetData(BlankTextureData);
                    }
                }
            }

            base.DoRender(now, graphicsDevice, spriteBatch, content, view, parentTransform, depth);
        }
Exemplo n.º 5
0
        /// <summary>Render this AParentSceneNode by rendering all its children.</summary>
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform, 
            int depth)
        {
            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            if (view == HolofunkView.Secondary && SecondaryViewOption == SecondaryViewOption.PositionMirrored) {
                combinedTransform = new Transform(
                    new Vector2(
                        spriteBatch.Viewport.X - combinedTransform.Translation.X,
                        combinedTransform.Translation.Y),
                    combinedTransform.Scale);
            }

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform);

            // m_children must only be enumerated / mutated under lock (this)
            lock (this) {
                m_childSnapshot.AddRange(m_children);
            }

            for (int i = 0; i < m_childSnapshot.Count; i++) {
                m_childSnapshot[i].Render(now, graphicsDevice, spriteBatch, content, view, combinedTransform, depth + 1);
            }

            // note that clearing preserves the capacity in the list, so no reallocation on next render
            m_childSnapshot.Clear();
        }
Exemplo n.º 6
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform, 
            int depth)
        {
            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            spriteBatch.Begin();

            Vector2 textSize = content.SpriteFont.MeasureString(m_text);
            Vector2 origin = Vector2.Zero;

            if (Alignment == Alignment.Centered) {
                origin = textSize / 2;
            }
            else if (Alignment == Alignment.TopRight) {
                origin = new Vector2(textSize.X, 0);
            }

            spriteBatch.DrawString(
                content.SpriteFont,
                m_text,
                combinedTransform.Translation,
                Color,
                Rotation,
                origin,
                combinedTransform.Scale.X,
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
Exemplo n.º 7
0
        // Draw one of the squares at a grid coordinate.
        void DrawQuarterCircle(ISpriteBatch spriteBatch, TextureContent content, Rectangle rect, Vector2 gridOrigin, int beat, Color color, float filledness, int depth)
        {
            // we prefer beats to start at upper left, but left to this logic, they start at lower left

            // position of this measure
            Vector2 position = gridOrigin + new Vector2(((beat / 4) % 4) * rect.Width, (beat / 16) * rect.Height);

            Vector2 offset;
            switch (beat % 4)
            {
                case 0: offset = new Vector2(1, 1); break;
                case 1: offset = new Vector2(0, 1); break;
                case 2: offset = new Vector2(0, 0); break;
                case 3: offset = new Vector2(1, 0); break;
                default: offset = Vector2.Zero; break; // NOTREACHED
            }
            position += offset * new Vector2(rect.Width, rect.Height);

            Rectangle destRect = new Rectangle(
                rect.Left + (int)position.X,
                rect.Top + (int)position.Y,
                rect.Width,
                rect.Height);

            Spam.Graphics.WriteLine(new string(' ', depth * 4 + 4) + Label + ": beat " + beat + ", filledness " + filledness + ", destRect " + destRect.ToString());

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            Vector2 origin = new Vector2(0);

            // always draw a hollow quarter circle
            spriteBatch.Draw(
                content.QuarterHollowCircle,
                destRect,
                null,
                color,
                (float)((beat % 4 + 2) * Math.PI / 2),
                origin,
                SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically,
                0);

            // now maybe draw a filled circle
            Vector4 v = color.ToVector4();
            v *= filledness;
            color = new Color(v);

            spriteBatch.Draw(
                content.QuarterFilledCircle,
                destRect,
                null,
                color,
                (float)((beat % 4 + 2) * Math.PI / 2),
                origin,
                SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically,
                0);

            spriteBatch.End();
        }
Exemplo n.º 8
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice,
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            if (m_totalBeats == 0) {
                // there is no actual track here; we do not render
                return;
            }

            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            // How many measures?
            long measureCount = (m_totalBeats + 3) / 4;

            // note that the quarter-circle only takes up one quarter of quarterCircleRect; this is deliberate
            Rectangle quarterCircleRect = TextureRect(content.QuarterHollowCircle, combinedTransform.Scale * m_textureScale);

            Vector2 measuresOrigin = combinedTransform.Translation;
            measuresOrigin.X -= ((Math.Min(4, measureCount) * quarterCircleRect.Width) / 2);

            Color color = m_colorFunc();

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform + ", color " + color.ToString());

            for (int b = 0; b < m_totalBeats; b++) {
                float filledness;
                if (m_fillInEveryBeat) {
                    if (b < m_currentBeat) {
                        filledness = 1;
                    }
                    else if (b == m_currentBeat) {
                        filledness = (float)m_fractionalBeat;
                    }
                    else {
                        filledness = 0;
                    }
                }
                else {
                    if (b == m_currentBeat) {
                        filledness = (float)(1 - m_fractionalBeat);
                    }
                    else {
                        filledness = 0;
                    }
                }

                DrawQuarterCircle(spriteBatch, content, quarterCircleRect, measuresOrigin, b, color, filledness, depth);
            }
        }
Exemplo n.º 9
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            // no texture = no-op
            if (m_texture == null) {
                return;
            }

            int left = -(int)((float)m_texture.Width * m_origin.X);
            int top = -(int)((float)m_texture.Height * m_origin.Y);
            Rectangle rect = new Rectangle(left, top, m_texture.Width, m_texture.Height);

            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            Rectangle transformedRect = rect * combinedTransform;

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform + "; start rect " + rect.FormatToString() + "; transformedRect " + transformedRect.FormatToString());

            Texture2D texture = m_texture;
            SpriteEffects effects = SpriteEffects.None;

            if (view == HolofunkView.Secondary) {
                if ((SecondaryViewOption & SecondaryViewOption.TextureMirrored) != 0) {
                    effects = SpriteEffects.FlipHorizontally;
                }

                if ((SecondaryViewOption & SecondaryViewOption.PositionMirrored) != 0) {
                    // need to flip transformedRect around center of viewport
                    int newLeft = (int)spriteBatch.Viewport.X - transformedRect.Right;

                    transformedRect = new Rectangle(newLeft, transformedRect.Y, transformedRect.Width, transformedRect.Height);
                }

                if ((SecondaryViewOption & SecondaryViewOption.SecondTexture) != 0) {
                    HoloDebug.Assert(m_secondaryTexture != null);
                    texture = m_secondaryTexture;
                }
            }

            Color color = m_color;
            if (view == HolofunkView.Secondary && m_secondaryColor.HasValue) {
                color = m_secondaryColor.Value;
            }

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                texture,
                transformedRect,
                null,
                color,
                0,
                m_origin,
                effects,
                0);

            spriteBatch.End();
        }