Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name">material description file name or "" for basic material</param>
        private Material(ICanyonShooterGame game, string name, InstancingType instancing)
        {
            this.game       = game;
            this.instancing = instancing;

            load(name, instancing);
            this.name = name;
        }
Exemplo n.º 2
0
 void IXmlSerializable.ReadXml(XmlReader reader)
 {
     IdentityType   = reader.ReadEnum <IdentityType>("idtype");
     ServerType     = reader.ReadEnum <ServerType>("servertype");
     InstancingType = reader.ReadEnum <InstancingType>("instancetype");
     ServiceName    = reader.ReadString("servicename");
     ExePath        = reader.ReadString("exepath");
     Identity       = reader.ReadString("identity");
     Permissions    = reader.ReadString("perms");
 }
Exemplo n.º 3
0
 private void LoadFromKey(RegistryKey key)
 {
     IdentityType   = (IdentityType)COMUtilities.ReadIntFromKey(key, null, "IdentityType");
     ServerType     = (ServerType)COMUtilities.ReadIntFromKey(key, null, "ServerType");
     InstancingType = (InstancingType)COMUtilities.ReadIntFromKey(key, null, "InstancingType");
     Identity       = COMUtilities.ReadStringFromKey(key, null, "Identity");
     ServiceName    = COMUtilities.ReadStringFromKey(key, null, "ServiceName");
     ExePath        = COMUtilities.ReadStringFromKey(key, null, "ExePath");
     Permissions    = string.Empty;
     byte[] permissions = key.GetValue("Permissions", new byte[0]) as byte[];
     Permissions = COMSecurity.GetStringSDForSD(permissions);
 }
Exemplo n.º 4
0
        static public Material Create(ICanyonShooterGame game, string name, InstancingType instancing)
        {
            foreach (Material material in materials)
            {
                if (material.name == name && material.instancing == instancing)
                {
                    return(material);
                }
            }
            Material n = new Material(game, name, instancing);

            materials.Add(n);
            return(n);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a model which is made of one or multiple meshes.
        /// meshes[i] will be drawn with materials[i]
        /// </summary>
        /// <param name="game">the owner</param>
        /// <param name="meshes">meshes to add to the new Model</param>
        /// <param name="materials">materials. each material in that array can be null to load a default materials</param>
        /// <param name="name">just to identify this</param>
        public Model(ICanyonShooterGame game, IMesh[] meshes, IMaterial[] materials, string name) : base(game, null)
        {
            this.game = game;

            if (meshes != null)
            {
                foreach (IMesh mesh in meshes)
                {
                    mesh.Parent = this;
                    this.meshes.Add(mesh);
                }
            }

            if (materials != null)
            {
                foreach (IMaterial material in materials)
                {
                    if (material != null)
                    {
                        this.materials.Add(material);
                    }
                    else
                    {
                        InstancingType instancing = InstancingType.None;

                        if (meshes[0] is ConstantsInstancingModelMeshAdapterMesh)
                        {
                            instancing = InstancingType.Constants;
                        }
                        else if (meshes[0] is HardwareInstancingModelMeshAdapterMesh)
                        {
                            instancing = InstancingType.Hardware;
                        }

                        this.materials.Add(Material.Create(game, "", instancing));
                    }
                }
            }

            this.name = name;
        }
Exemplo n.º 6
0
        public override void SetParameter(ModelRenderParameter p)
        {
            var param = p as GBufferModelRenderParameter;
            if (param == null)
            {
                return;
            }

            Shader.World = MathUtilXna.ToXnaMatrix(param.Transform);
            Shader.View = MathUtilXna.ToXnaMatrix(param.Camera.View);
            Shader.Projection = MathUtilXna.ToXnaMatrix(param.Camera.Projection);

            InstancingType = param.InstancingType;

            if (param.InstancingType == InstancingType.Instanced)
            {
                //LoadProfiler.Instance.BeginMark("GBufferToArray");

                Shader.InstanceTransforms = FrameCacheData.Instance.InstanceTransformsToArray(param.InstanceTransforms);

                //LoadProfiler.Instance.EndMark();
            }
        }
Exemplo n.º 7
0
 public override int GetHashCode()
 {
     return(IdentityType.GetHashCode() ^ ServerType.GetHashCode() ^ InstancingType.GetHashCode() ^
            ServiceName.GetSafeHashCode() ^ ExePath.GetSafeHashCode() ^ Permissions.GetSafeHashCode() ^
            Identity.GetSafeHashCode() ^ PackageId.GetSafeHashCode() ^ Source.GetHashCode());
 }
Exemplo n.º 8
0
        private void load(string name, InstancingType instancing)
        {
            if (name == "")
            {
                effect = new BasicEffect(game.Graphics.Device, null);
            }
            else
            {
                MaterialDescription desc = game.Content.Load <MaterialDescription>("Content\\Materials\\" + name);

                this.diffuseColor  = desc.DiffuseColor;
                this.specularColor = desc.SpecularColor;
                this.shininess     = desc.Shininess;
                this.emissiveColor = desc.EmissiveColor;

                if (desc.Effect == "")
                {
                    effect = game.Graphics.ShaderSelector.CreateEffect(desc.ShaderDescription, instancing);
                }
                else
                {
                    if (desc.Effect == "basic")
                    {
                        if (instancing != InstancingType.None)
                        {
                            throw new Exception("The basic shader does not support instancing.");
                        }

                        effect = new BasicEffect(game.Graphics.Device, null);
                    }
                    else
                    {
                        string shaderModel   = game.Graphics.ShaderModel3Supported ? "_3_0" : "_2_0";
                        string techniqueName = desc.Technique + shaderModel;
                        effect = game.Content.Load <Effect>("Content\\Effects\\" + desc.Effect);
                        bool set = false;
                        foreach (EffectTechnique technique in effect.Techniques)
                        {
                            if (technique.Name == techniqueName)
                            {
                                effect.CurrentTechnique = technique;
                                set = true;
                                break;
                            }
                        }
                        if (!set)
                        {
                            string techniqueName2 = desc.Technique + "_2_0";
                            foreach (EffectTechnique technique in effect.Techniques)
                            {
                                if (technique.Name == techniqueName2)
                                {
                                    effect.CurrentTechnique = technique;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (desc.Texture0 != "")
                {
                    textures[0] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture0);
                }
                if (desc.Texture1 != "")
                {
                    textures[1] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture1);
                }
                if (desc.Texture2 != "")
                {
                    textures[2] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture2);
                }
                if (desc.Texture3 != "")
                {
                    textures[3] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture3);
                }
                if (desc.Texture4 != "")
                {
                    textures[4] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture4);
                }
                if (desc.Texture5 != "")
                {
                    textures[5] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture5);
                }
                if (desc.Texture6 != "")
                {
                    textures[6] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture6);
                }
                if (desc.Texture7 != "")
                {
                    textures[7] = game.Content.Load <Texture>("Content\\Textures\\" + desc.Texture7);
                }
            }
            currentTechnique = effect.CurrentTechnique;

            this.name = name;
        }
Exemplo n.º 9
0
        protected void Load(string name, InstancingType instancing)
        {
            if (name == null || name == string.Empty)
            {
                return;
            }

            // load description
            ModelDescription desc = game.Content.Load <ModelDescription>(".\\Content\\Models\\" + name + "Desc");

            LocalRotation = Quaternion.CreateFromAxisAngle(desc.BaseRotationAxis, MathHelper.ToRadians(desc.BaseRotationAngle));

            // load fbx
            Microsoft.Xna.Framework.Graphics.Model model = game.Content.Load <Microsoft.Xna.Framework.Graphics.Model>(".\\Content\\Models\\" + desc.BaseFBX);

            // process meshes
            foreach (ModelMesh modelmesh in model.Meshes)
            {
                // wrap ModelMesh in adapter
                IMesh mesh;
                switch (instancing)
                {
                case InstancingType.None:
                    mesh = new ModelMeshAdapterMesh(game, modelmesh);
                    break;

                case InstancingType.Constants:
                    mesh = new ConstantsInstancingModelMeshAdapterMesh(game, modelmesh);
                    break;

                case InstancingType.Hardware:
                    mesh = new HardwareInstancingModelMeshAdapterMesh(game, modelmesh);
                    break;

                default:
                    throw new Exception();
                }
                mesh.Parent = this;
                meshes.Add(mesh);

                // get material name. prefer the one with the mesh's name before *
                string materialName = "";
                foreach (MeshMaterial matdesc in desc.Materials)
                {
                    if (matdesc.MeshName == modelmesh.Name)
                    {
                        materialName = matdesc.MaterialName;
                        break;
                    }
                    if (matdesc.MeshName == "*")
                    {
                        if (materialName == "")
                        {
                            materialName = matdesc.MaterialName;
                        }
                    }
                }

                // load material
                Material material = Material.Create(game, materialName, instancing);
                materials.Add(material);

                // tell the mesh which effect to use
                mesh.Effect = material.Effect;
            }

            // get weapon slots
            foreach (WeaponDescription weapon in desc.Weapons)
            {
                WeaponSlot slot = new WeaponSlot(
                    (WeaponType)Enum.Parse(typeof(WeaponType), weapon.WeaponType, false),
                    weapon.Position,
                    weapon.RotationAxis,
                    weapon.RotationAngle,
                    weapon.Scaling);

                weaponSlots.Add(slot);
            }

            // get collision shapes
            foreach (Box box in desc.CollisionShapes.Boxes)
            {
                BoxShapeData shape = new BoxShapeData();
                shape.Dimensions = box.Size;
                Matrix m = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(box.OffsetRotationAxis, box.OffsetRotationAngle));
                m.Translation             = box.OffsetPosition;
                shape.Offset              = m;
                shape.Material.Friction   = desc.Friction;
                shape.Material.Bounciness = desc.Bounciness;
                shape.Material.Hardness   = desc.Hardness;
                collisionShapes.Add(shape);
            }
            foreach (Capsule capsule in desc.CollisionShapes.Capsules)
            {
                CapsuleShapeData shape = new CapsuleShapeData();
                shape.Radius = capsule.Radius;
                shape.Length = capsule.Length;
                Matrix m = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(capsule.OffsetRotationAxis, capsule.OffsetRotationAngle));
                m.Translation             = capsule.OffsetPosition;
                shape.Offset              = m;
                shape.Material.Friction   = desc.Friction;
                shape.Material.Bounciness = desc.Bounciness;
                shape.Material.Hardness   = desc.Hardness;
                collisionShapes.Add(shape);
            }
            foreach (Sphere sphere in desc.CollisionShapes.Spheres)
            {
                SphereShapeData shape = new SphereShapeData();
                shape.Radius = sphere.Radius;
                Matrix m = Matrix.CreateTranslation(sphere.OffsetPosition);
                shape.Offset              = m;
                shape.Material.Friction   = desc.Friction;
                shape.Material.Bounciness = desc.Bounciness;
                shape.Material.Hardness   = desc.Hardness;
                collisionShapes.Add(shape);
            }

            wreckageModels = desc.Wreckages;

            // get particle effects
            if (game.World != null)
            {
                foreach (ParticleEffectDescription effect in desc.ParticleEffects)
                {
                    IEffect fx = game.Effects.CreateEffect(effect.EffectName);
                    fx.Parent        = this;
                    fx.LocalPosition = effect.Position;
                    fx.LocalRotation = Quaternion.CreateFromAxisAngle(effect.RotationAxis, effect.RotationAngle);
                    fx.LocalScale    = effect.Scaling;
                    game.World.AddEffect(fx);
                    particleEffects.Add(fx); // for calling Destroy() later
                    fx.Play();
                }
            }

            // afterburner
            foreach (AfterBurnerEffectDescription ab in desc.AfterBurnerEffects)
            {
                AfterBurner a = new AfterBurner(game);

                a.Parent = this;

                a.LocalPosition = ab.Position;
                a.LocalScale    = ab.Scaling;
                a.LocalRotation = Quaternion.CreateFromAxisAngle(ab.RotationAxis, ab.RotationAngle);

                a.LoadTheContent();

                afterBurnerEffects.Add(a);
            }

            // get animations
            foreach (MeshAnimation anim in desc.Animations)
            {
                foreach (IMesh mesh in meshes)
                {
                    if (mesh.Name == anim.MeshName)
                    {
                        mesh.Animation = anim;

                        break; // inner foreach
                    }
                }
            }

            // mass
            mass = desc.Mass;

            // base rotation
            LocalRotation = Quaternion.CreateFromAxisAngle(desc.BaseRotationAxis, desc.BaseRotationAngle);

            // save name
            this.name = name;
        }
Exemplo n.º 10
0
 public ViewModelMappingAttribute(Type viewModelType,
                                  InstancingType instancing)
 {
     _viewModelType = viewModelType;
     _instancing    = instancing;
 }
Exemplo n.º 11
0
        public Effect CreateEffect(ShaderDescription shaderDescription, InstancingType instancing)
        {
            EffectTechniqueDescription sd = GetEffectTechniqueDescription(shaderDescription, instancing);

            return(CreateEffect(sd));
        }
Exemplo n.º 12
0
        public EffectTechniqueDescription GetEffectTechniqueDescription(ShaderDescription description, InstancingType instancing)
        {
            List <string> descParts = new List <string>();

            switch (description.SurfaceType)
            {
            case SurfaceType.Color:
                descParts.Add("color");
                break;

            case SurfaceType.Texture:
                descParts.Add("texture");
                break;

            case SurfaceType.Wireframe:
                descParts.Add("wireframe");
                break;
            }

            if (description.Light)
            {
                if (game.Graphics.ShaderModel3Supported)
                {
                    descParts.Add("light");

                    if (game.Graphics.ShadowMappingSupported)
                    {
                        if (description.ReceiveShadows)
                        {
                            descParts.Add("sunlightshadow");

                            if (description.NormalMapping)
                            {
                                descParts.Add("normalmapping");
                            }
                        }
                    }
                }
                else
                {
                    descParts.Add("light");
                }
            }

            if (description.WireframeOverlay)
            {
                descParts.Add("wireframeoverlay");
            }

            switch (instancing)
            {
            case InstancingType.Constants:
                descParts.Add("constantsinstancing");
                break;

            case InstancingType.Hardware:
                descParts.Add("hardwareinstancing");
                break;
            }

            return(GetEffectTechniqueDescription(descParts));
        }