Пример #1
0
        public override void RenderInstance(NewInstanceData Instance, GraphicsDevice Device, Shader Effect, Camera Camera, InstanceRenderMode Mode)
        {
            if (Mode == InstanceRenderMode.SelectionBuffer && !RenderData.RenderInSelectionBuffer)
            {
                return;
            }
            if (InstanceCount >= InstanceQueueSize)
            {
                return;
            }

            Instances[InstanceCount] = new TiledInstancedVertex
            {
                Transform            = Instance.Transform,
                LightRamp            = Instance.LightRamp,
                SelectionBufferColor = Instance.SelectionBufferColor,
                VertexColorTint      = Instance.VertexColorTint,
                TileBounds           = GetTileBounds(Instance)
            };

            InstanceCount += 1;
            if (InstanceCount >= InstanceQueueSize)
            {
                Flush(Device, Effect, Camera, Mode);
            }
        }
Пример #2
0
 private static void DestroyGrassMote(WorldManager World, String Name, NewInstanceData Data)
 {
     World.NewInstanceManager.RemoveInstance(Data);
     //EntityFactory.InstanceManager.RemoveInstance(Name, Data);
     // Todo: Should this be automatically set whenever an instance is added or removed?
     //EntityFactory.InstanceManager.Instances[Name].HasSelectionBuffer = false;
 }
Пример #3
0
        private Vector4 GetTileBounds(NewInstanceData Instance)
        {
            if (Instance.AtlasCache != null)
            {
                return(Instance.AtlasCache.MapRectangleToUVBounds(Instance.SpriteBounds));
            }

            Gui.TileSheet sheet  = null;
            Texture2D     tex    = null;
            bool          exists = false;

            if (Instance.TextureAsset == null)
            {
                Instance.TextureAsset = "newgui/error";
            }
            exists = Atlas.TryGetValue(Instance.TextureAsset, out sheet);
            if (!exists)
            {
                tex = AssetManager.GetContentTexture(Instance.TextureAsset);
                if (tex == null)
                {
                    return(Vector4.Zero);             // Actually should never happen.
                }
                sheet = new Gui.TileSheet(tex.Width, tex.Height, new Rectangle(0, 0, tex.Width, tex.Height), tex.Width, tex.Height, false);
                Atlas.Add(Instance.TextureAsset, sheet);

                RebuildAtlas();
                NeedsRendered = true;
            }
            Instance.AtlasCache = sheet;
            return(sheet.MapRectangleToUVBounds(Instance.SpriteBounds));
        }
Пример #4
0
        public void RenderInstance(NewInstanceData Instance,
                                   GraphicsDevice Device, Shader Effect, Camera Camera, RenderMode Mode)
        {
            if (Instance.Type == null || !InstanceTypes.ContainsKey(Instance.Type))
            {
                return;
            }

            var group = InstanceTypes[Instance.Type];

            if (Mode == RenderMode.SelectionBuffer && !group.RenderData.RenderInSelectionBuffer)
            {
                return;
            }

            group.Instances[group.InstanceCount] = new InstancedVertex
            {
                Transform            = Instance.Transform,
                Color                = Instance.Color,
                SelectionBufferColor = Instance.SelectionBufferColor
            };

            group.InstanceCount += 1;
            if (group.InstanceCount == InstanceQueueSize)
            {
                Flush(group, Device, Effect, Camera, Mode);
            }
        }
Пример #5
0
 protected void OnDeserialized(StreamingContext context)
 {
     Instance = new NewInstanceData(
         ModelType,
         GlobalTransform,
         LightRamp);
     Instance.SelectionBufferColor = this.GetGlobalIDColor();
 }
Пример #6
0
 public InstanceMesh(ComponentManager Manager, string name, Matrix localTransform, string modelType, bool addToCollisionManager) :
     base(Manager, name, localTransform, Vector3.Zero, Vector3.Zero, addToCollisionManager)
 {
     ModelType = modelType;
     Instance  = new NewInstanceData(Manager.World.NewInstanceManager, ModelType,
                                     Vector3.One, GlobalTransform, Tint, true);
     Instance.SelectionBufferColor = this.GetGlobalIDColor();
 }
Пример #7
0
 public InstanceMesh(ComponentManager Manager, string name, Matrix localTransform, string modelType, Vector3 BoundingBoxExtents, Vector3 BoundingBoxPos) :
     base(Manager, name, localTransform, BoundingBoxExtents, BoundingBoxPos)
 {
     PropogateTransforms();
     UpdateBoundingBox();
     ModelType = modelType;
     Instance  = new NewInstanceData(ModelType, GlobalTransform, LightRamp);
     Instance.SelectionBufferColor = this.GetGlobalIDColor();
 }
Пример #8
0
 protected void OnDeserialized(StreamingContext context)
 {
     Instance = new NewInstanceData(
         (context.Context as WorldManager).NewInstanceManager,
         ModelType,
         Vector3.One,
         GlobalTransform,
         Tint,
         true);
     Instance.SelectionBufferColor = this.GetGlobalIDColor();
 }
Пример #9
0
        public void UpdateInstance(NewInstanceData InstanceData)
        {
            if (CurrentAnimation == null || CurrentAnimation.Frames.Count <= CurrentFrame || CurrentFrame < 0)
            {
                return;
            }
            var sheet = CurrentAnimation.SpriteSheet;
            var frame = CurrentAnimation.Frames[CurrentFrame];

            InstanceData.SpriteBounds = new Rectangle(sheet.FrameWidth * frame.X, sheet.FrameHeight * frame.Y, sheet.FrameWidth, sheet.FrameHeight);
            InstanceData.TextureAsset = sheet.AssetName;
        }
Пример #10
0
        private static NewInstanceData GenerateGrassMote(WorldManager World, Vector3 Position, Color Color, float Scale, String Name)
        {
            var mote = new NewInstanceData(
                World.NewInstanceManager,
                Name,
                Vector3.One / 2,
                Matrix.CreateScale(Scale) * Matrix.CreateRotationY(Scale * Scale)
                * Matrix.CreateTranslation(Position), Color, true);

            //EntityFactory.InstanceManager.AddInstance(Name, mote);
            return(mote);
        }
Пример #11
0
        public void RenderInstance(
            NewInstanceData Instance,
            GraphicsDevice Device, Shader Effect, Camera Camera, InstanceRenderMode Mode)
        {
            if (Instance.Type == null || !InstanceTypes.ContainsKey(Instance.Type))
            {
                return;
            }

            InstanceTypes[Instance.Type].RenderInstance(Instance, Device, Effect, Camera, Mode);

            _instanceCounter += 1;
        }
Пример #12
0
        private void PrepareInstanceData(Camera Camera)
        {
            if (InstanceData == null)
            {
                InstanceData = new NewInstanceData(Manager.World.Renderer.InstanceRenderer.PrepareCombinedTiledInstance(), Matrix.Identity, Color.White);
            }

            InstanceData.Transform            = GetWorldMatrix(Camera);
            InstanceData.LightRamp            = LightRamp;
            InstanceData.VertexColorTint      = VertexColorTint;
            InstanceData.SelectionBufferColor = this.GetGlobalIDColor();
            if (Stipple)
            {
                InstanceData.VertexColorTint.A = 256 / 2;
            }
            AnimPlayer.UpdateInstance(InstanceData);
        }
Пример #13
0
        private void PrepareInstanceData(Camera Camera)
        {
            if (InstanceData == null)
            {
                InstanceData = new NewInstanceData(Manager.World.Renderer.InstanceRenderer.PrepareCombinedTiledInstance(), Matrix.Identity, Color.White);
            }

            InstanceData.Transform            = GetWorldMatrix(Camera);
            InstanceData.LightRamp            = LightRamp;
            InstanceData.SpriteBounds         = new Rectangle(Sheet.FrameWidth * Frame.X, Sheet.FrameHeight * Frame.Y, Sheet.FrameWidth, Sheet.FrameHeight);
            InstanceData.TextureAsset         = Sheet.AssetName; // Todo: Cache the raw texture info so the renderer doesn't need to look it up all the time.
            InstanceData.SelectionBufferColor = this.GetGlobalIDColor();
            InstanceData.VertexColorTint      = VertexColorTint;
            if (Stipple)
            {
                InstanceData.VertexColorTint.A = 200;
            }
        }
Пример #14
0
        private Vector4 GetTileBounds(NewInstanceData Instance)
        {
            if (Instance.AtlasCache != null)
            {
                return(Instance.AtlasCache.MapRectangleToUVBounds(Instance.SpriteBounds));
            }

            if (Instance.TextureAsset == null)
            {
                Instance.TextureAsset = "newgui/error";
            }

            var exists = Atlas.TryGetValue(Instance.TextureAsset, out var sheet); // Need to give them dynamic names generated from asset and palette?

            if (!exists)
            {
                Texture2D tex = null;
                if (Instance.CachedSpriteSheet != null)
                {
                    tex = Instance.CachedSpriteSheet.GetTexture();
                }
                else
                {
                    tex = AssetManager.GetContentTexture(Instance.TextureAsset);
                }

                if (tex == null)
                {
                    return(Vector4.Zero);             // Actually should never happen.
                }
                sheet = new InstanceTileSheet
                {
                    Sheet   = new Gui.TileSheet(tex.Width, tex.Height, new Rectangle(0, 0, tex.Width, tex.Height), tex.Width, tex.Height, false),
                    Texture = tex
                };
                Atlas.Add(Instance.TextureAsset, sheet);

                RebuildAtlas();
                NeedsRendered = true;
            }
            Instance.AtlasCache = sheet.Sheet;
            return(sheet.Sheet.MapRectangleToUVBounds(Instance.SpriteBounds));
        }
Пример #15
0
 public abstract void RenderInstance(NewInstanceData Instance, GraphicsDevice Device, Shader Effect, Camera Camera, InstanceRenderMode Mode);
Пример #16
0
        public void AddInstance(NewInstanceData Instance)
        {
            var box = new BoundingBox(Instance.Position - Instance.HalfSize, Instance.Position + Instance.HalfSize);

            OctTree.AddItem(Instance, box);
        }