Example #1
0
        public override void CreateCosmeticChildren(ComponentManager Manager)
        {
            base.CreateCosmeticChildren(Manager);

            if (SharedPrimitive == null)
            {
                var spriteSheet = new NamedImageFrame("Entities\\Furniture\\bookshelf");
                SharedPrimitive = new OldBoxPrimitive(DwarfGame.GuiSkin.Device, 0.625f, 1.0f, 0.25f,
                                                      new OldBoxPrimitive.BoxTextureCoords(spriteSheet.SafeGetImage().Width, spriteSheet.SafeGetImage().Height,
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(0, 20, 20, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(28, 20, 20, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(20, 0, 8, 20), false),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(0, 0, 1, 1), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(20, 20, 8, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(20, 52, 8, 32), true)));
            }

            AddChild(new PrimitiveComponent(Manager,
                                            Matrix.CreateTranslation(new Vector3(-0.25f, 0.0f, 0.35f - 0.15f)),
                                            new Vector3(0.5f, 0.5f, 0.5f),
                                            new Vector3(0.0f, 0.0f, 0.0f),
                                            SharedPrimitive,
                                            "Entities\\Furniture\\bookshelf"))
            .SetFlag(Flag.ShouldSerialize, false);

            AddChild(new GenericVoxelListener(Manager, Matrix.Identity, new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.5f, 0.0f), (changeEvent) =>
            {
                if (changeEvent.Type == VoxelChangeEventType.VoxelTypeChanged && changeEvent.NewVoxelType == 0)
                {
                    Die();
                }
            })).SetFlag(Flag.ShouldSerialize, false).SetFlag(Flag.RotateBoundingBox, true);
        }
Example #2
0
        public override void CreateCosmeticChildren(ComponentManager Manager)
        {
            base.CreateCosmeticChildren(Manager);

            if (SharedPrimitive == null)
            {
                var spriteSheet = new NamedImageFrame("Terrain\\terrain_tiles");
                SharedPrimitive = new OldBoxPrimitive(DwarfGame.GuiSkin.Device, 0.9f, 0.9f, 0.9f,
                                                      new OldBoxPrimitive.BoxTextureCoords(spriteSheet.SafeGetImage().Width, spriteSheet.SafeGetImage().Height,
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(224, 0, 32, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(224, 0, 32, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(256, 0, 32, 32), false),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(224, 0, 32, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(224, 0, 32, 32), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(224, 0, 32, 32), true)));
            }

            AddChild(new PrimitiveComponent(Manager,
                                            Matrix.CreateRotationY(MathFunctions.Rand(-0.25f, 0.25f)),
                                            new Vector3(1.0f, 1.0f, 1.0f),
                                            new Vector3(0.5f, 0.5f, 0.5f),
                                            SharedPrimitive,
                                            "Terrain\\terrain_tiles"))
            .SetFlag(Flag.ShouldSerialize, false);
        }
Example #3
0
        public void Rebuild(GraphicsDevice g)
        {
            if (g == null || g.IsDisposed)
            {
                return;
            }

            GeometricPrimitive primitive = null;

            if (Debugger.Switches.UseNewVoxelGeoGen)
            {
                primitive = Voxels.GeometryBuilder.CreateFromChunk(this, Manager.World);
            }
            else
            {
                primitive = new VoxelListPrimitive();
                (primitive as VoxelListPrimitive).InitializeFromChunk(this, Manager.World);
            }

            PrimitiveMutex.WaitOne();
            if (Primitive != null)
            {
                Primitive.Dispose();
            }
            Primitive = primitive;
            PrimitiveMutex.ReleaseMutex();
        }
Example #4
0
 public PrimitiveComponent(
     ComponentManager Manager,
     Matrix localTransform,
     Vector3 boundingBoxExtents,
     Vector3 boundingBoxPos,
     GeometricPrimitive Primitive,
     String Asset) :
     base(Manager, "primitive", localTransform, boundingBoxExtents, boundingBoxPos)
 {
     this.Primitive = Primitive;
     this.Asset     = Asset;
 }
Example #5
0
        public void DiscardPrimitive()
        {
            PrimitiveMutex.WaitOne();
            if (Primitive != null)
            {
                Primitive.Dispose();
            }
            Primitive = null;
            for (var y = 0; y < VoxelConstants.ChunkSizeY; ++y)
            {
                Data.SliceCache[y] = null;
                MoteRecords[y]     = null;
            }

            PrimitiveMutex.ReleaseMutex();
        }
Example #6
0
        public FixedInstanceArray(string name, GeometricPrimitive model, Texture2D texture, int numInstances, BlendState blendMode)
        {
            CullDistance = (GameSettings.Default.ChunkDrawDistance * GameSettings.Default.ChunkDrawDistance) - 40;
            Name         = name;
            Model        = model;
            Data         = new List <InstanceData>();
            Additions    = new List <InstanceData>();
            Removals     = new List <InstanceData>();

            SortedData   = new MinBag <InstanceData>(numInstances);
            NumInstances = numInstances;

            ShouldRebuild = true;
            Texture       = texture;
            DataLock      = new Mutex();

            BlendMode = blendMode;
        }
Example #7
0
        public FixedInstanceArray(string name, GeometricPrimitive model, Texture2D texture, int numInstances, BlendState blendMode)
        {
            CullDistance = (GameSettings.Default.ChunkDrawDistance * GameSettings.Default.ChunkDrawDistance) - 40;
            Name = name;
            Model = model;
            Data = new List<InstanceData>();
            Additions = new List<InstanceData>();
            Removals = new List<InstanceData>();

            SortedData = new MinBag<InstanceData>(numInstances);
            NumInstances = numInstances;

            ShouldRebuild = true;
            Texture = texture;
            DataLock = new Mutex();

            BlendMode = blendMode;
        }
Example #8
0
        public override void CreateCosmeticChildren(ComponentManager Manager)
        {
            base.CreateCosmeticChildren(Manager);

            if (SharedPrimitive == null)
            {
                var spriteSheet = new NamedImageFrame("Entities\\Furniture\\bedtex");
                SharedPrimitive = new OldBoxPrimitive(DwarfGame.GuiSkin.Device, 0.8f, 0.5f, 1.8f,
                                                      new OldBoxPrimitive.BoxTextureCoords(spriteSheet.SafeGetImage().Width, spriteSheet.SafeGetImage().Height,
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(0, 24, 24, 16), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(72, 24, 24, 16), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(24, 0, 48, 24), false),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(0, 0, 1, 1), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(24, 24, 48, 16), true),
                                                                                           new OldBoxPrimitive.FaceData(new Rectangle(24, 40, 48, 16), true)));
            }

            AddChild(new PrimitiveComponent(Manager,
                                            Matrix.CreateTranslation(-0.40f, 0.00f, -0.45f) * Matrix.CreateRotationY((float)Math.PI * 0.5f),
                                            new Vector3(1.0f, 1.0f, 2.0f),
                                            new Vector3(0.0f, 0.0f, 0.0f),
                                            SharedPrimitive,
                                            "Entities\\Furniture\\bedtex"))
            .SetFlag(Flag.ShouldSerialize, false)
            .SetFlag(Flag.RotateBoundingBox, true);

            AddChild(new GenericVoxelListener(Manager,
                                              Matrix.Identity,
                                              new Vector3(1.5f, 0.5f, 0.75f), // Position just below surface.
                                              new Vector3(0.5f, -0.30f, 0.0f),
                                              (v) =>
            {
                if (v.Type == VoxelChangeEventType.VoxelTypeChanged &&
                    v.NewVoxelType == 0)
                {
                    Die();
                }
            }))
            .SetFlag(Flag.ShouldSerialize, false)
            .SetFlag(Flag.RotateBoundingBox, true);
        }