Example #1
0
        public override void Update(DwarfTime GameTime)
        {
            // Todo: Limit update rate.

            foreach (var steamObject in Objects)
            {
                if (steamObject.HasMoved)
                {
                    steamObject.PropogateTransforms();
                    if (steamObject.GlobalTransform.Decompose(out Vector3 scale, out Quaternion rotation, out Vector3 translation))
                    {
                        steamObject.Orientation = OrientationHelper.DetectOrientationFromRotation(rotation);
                    }

                    steamObject.DetachFromNeighbors();
                    steamObject.AttachToNeighbors();
                    steamObject.Primitive = null;
                }

                if (steamObject.Generator)
                {
                    steamObject.SteamPressure = steamObject.GeneratedSteam;
                }
                else
                {
                    var total = steamObject.SteamPressure;
                    var count = 1.0f;
                    foreach (var neighbor in steamObject.NeighborPipes.Select(id => steamObject.Manager.FindComponent(id)).OfType <SteamPoweredObject>())
                    {
                        if (neighbor.CanSendSteam(steamObject) && steamObject.CanReceiveSteam(neighbor))
                        {
                            total += neighbor.SteamPressure;
                            count += 1;
                        }
                    }

                    steamObject.SteamPressure  = total / count;
                    steamObject.SteamPressure *= 0.995f;
                }
            }
        }
Example #2
0
 public override bool CanSendSteam(SteamPoweredObject Other)
 {
     return(Orientation == OrientationHelper.DetectOrientationFromVector(Other.Position - Position));
 }
Example #3
0
        override public void Render(DwarfTime gameTime, ChunkManager chunks, Camera camera, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, Shader effect, bool renderingForWater)
        {
            base.Render(gameTime, chunks, camera, spriteBatch, graphicsDevice, effect, renderingForWater);

            if (Debugger.Switches.DrawPipeNetwork)
            {
                foreach (var neighborConnection in NeighborPipes)
                {
                    var neighbor = Manager.FindComponent(neighborConnection);
                    if (neighbor == null)
                    {
                        Drawer3D.DrawLine(Position, Position + Vector3.UnitY, Color.CornflowerBlue, 0.1f);
                    }
                    else
                    {
                        Drawer3D.DrawLine(Position + new Vector3(0.0f, 0.5f, 0.0f), (neighbor as GameComponent).Position + new Vector3(0.0f, 0.5f, 0.0f), new Color(SteamPressure, 0.0f, 0.0f, 1.0f), 0.1f);
                    }
                }

                Drawer3D.DrawBox(GetBoundingBox(), Color.Red, 0.01f, false);
                Drawer3D.DrawLine(Position, Position + Vector3.Transform(new Vector3(1, 0, 0), Matrix.CreateRotationY((float)Math.PI / 2 * (float)Orientation)), new Color(0.0f, 1.0f, 1.0f), 0.03f);
            }

            if (!DrawPipes)
            {
                return;
            }

            if (Primitive == null)
            {
                var bounds = Vector4.Zero;
                var uvs    = Sheet.GenerateTileUVs(new Point(0, 0), out bounds);

                Primitive = new RawPrimitive();

                foreach (var connection in NeighborPipes)
                {
                    var neighbor = Manager.FindComponent(connection) as GameComponent;
                    if (neighbor == null)
                    {
                        continue;
                    }

                    var orientationToNeighbor = OrientationHelper.DetectOrientationFromVector(new Vector3(neighbor.Position.X - this.Position.X, 0.0f, neighbor.Position.Z - this.Position.Z));
                    var pipeAngle             = Math.PI * 0.5f * ((float)Orientation - (float)orientationToNeighbor);

                    Primitive.AddQuad(
                        Matrix.CreateTranslation(0.5f, 0.0f, 0.0f)
                        * Matrix.CreateScale(0.5f, 0.5f, 0.5f)
                        * Matrix.CreateRotationX((float)Math.PI * 0.5f)
                        //* Matrix.CreateTranslation(0.0f, 0.3f, -0.2f)
                        * Matrix.CreateRotationY((float)pipeAngle),
                        //* Matrix.CreateTranslation(bumperOffset + bumperGap),
                        Color.White, Color.White, uvs, bounds);
                }
            }

            if (Primitive.VertexCount == 0)
            {
                return;
            }

            var under = new VoxelHandle(chunks, GlobalVoxelCoordinate.FromVector3(Position));

            if (under.IsValid)
            {
                Color color = new Color(under.Sunlight ? 255 : 0, 255, 0);
                LightRamp = color;
            }
            else
            {
                LightRamp = new Color(200, 255, 0);
            }

            Color origTint = effect.VertexColorTint;

            if (!Active)
            {
                DoStipple(effect);
            }
            effect.VertexColorTint = VertexColor;
            effect.LightRamp       = LightRamp;
            effect.World           = GlobalTransform;

            effect.MainTexture = Sheet.GetTexture();


            effect.EnableWind = false;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Primitive.Render(graphicsDevice);
            }

            effect.VertexColorTint = origTint;
            if (!Active)
            {
                EndDraw(effect);
            }
        }