Ejemplo n.º 1
0
        public void RemovePointLight(LightPoint lp)
        {
            if (!PointLights.Contains(lp))
            {
                return;
            }

            foreach (GameObject obj in lp.AffectedObjects)
            {
                obj.LightsAffecting.Remove(lp);
            }

            PointLights.Remove(lp);
            PhysicsManager.Instance.RemoveCollider(lp.MyCollider);
            PhysicsManager.Instance.RemovePhysicalObject(lp);
        }
Ejemplo n.º 2
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.MoveToContent();
            reader.ReadStartElement();

            ResourceManager.Instance.CurrentScene.ObjectsDictionary = new Dictionary <uint, GameObject>();
            ResourceManager.Instance.CurrentScene.PointLights       = new List <LightPoint>();
            DirectionalLights = new LightDirectional[ResourceManager.DIRECTIONAL_MAX_LIGHTS];

            if (reader.Name == "SceneParams")
            {
                Params = new SceneParams(0, "null");
                (Params as IXmlSerializable).ReadXml(reader);
            }

            if (reader.Name == "AmbientLight")
            {
                AmbientLight = new LightAmbient(0, "null");
                (AmbientLight as IXmlSerializable).ReadXml(reader);
            }

            int ctr = 0;

            reader.ReadStartElement("DirectionalLights");
            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                if (reader.Name == "DirectionalLight")
                {
                    reader.ReadStartElement();
                    if (reader.Name != "null")
                    {
                        LightDirectional obj = new LightDirectional(0, "");
                        (obj as IXmlSerializable).ReadXml(reader);
                        DirectionalLights[ctr] = obj;
                        ++ctr;
                    }
                    else
                    {
                        reader.ReadElementString("null", "");
                        reader.ReadEndElement();
                        ++ctr;
                    }
                }
            }
            reader.ReadEndElement();

            reader.ReadStartElement("PointLights");
            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                if (reader.Name == "PointLight")
                {
                    reader.ReadStartElement();
                    LightPoint pl = new LightPoint(0, "");
                    ResourceManager.Instance.CurrentScene.PointLights.Add(pl);
                    (pl as IXmlSerializable).ReadXml(reader);

                    if (pl.CastShadows)
                    {
                        pl.SetupShadowRender();
                    }
                    reader.ReadEndElement();
                }
                else
                {
                    reader.ReadElementString("null", "");
                }
            }
            reader.ReadEndElement();

            reader.ReadStartElement("ObjectsDictionary");
            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                if (reader.Name == "GameObject")
                {
                    reader.ReadStartElement();
                    GameObject obj = null;
                    uint       key = (uint)reader.ReadElementContentAsInt("GameObjectKey", "");
                    if (ResourceManager.Instance.CurrentScene.ObjectsDictionary.TryGetValue(key, out obj))
                    {
                        Debug.Log("GameObject successfully loaded - " + obj.Name);
                        GameObject tmp = null;
                        (tmp as IXmlSerializable).ReadXml(reader);
                    }
                    else
                    {
                        obj = new GameObject(0, "");
                        ResourceManager.Instance.CurrentScene.ObjectsDictionary.Add(key, obj);
                        (obj as IXmlSerializable).ReadXml(reader);
                        Debug.Log("New Gameobject successfully loaded - " + obj.Name);
                    }
                }
                reader.ReadEndElement();
            }
            reader.ReadEndElement();

            if (reader.Name == "Camera")
            {
                Cam = new Camera(0, "null", Vector3.Zero, Vector3.Zero, Vector3.Zero, Vector3.Zero, MathHelper.Pi / 3.0f, 1.0f, 0.1f, 2000.0f);
                reader.ReadStartElement();
                (Cam as IXmlSerializable).ReadXml(reader);
            }

            ObjectsDictionary = ResourceManager.Instance.CurrentScene.ObjectsDictionary;
            PointLights       = ResourceManager.Instance.CurrentScene.PointLights;

            reader.ReadEndElement();
        }