Example #1
0
 public EditorPortal(EditorScene editorScene)
     : base(editorScene)
 {
     Path = new PortalPath();
     IsPortalable = false;
     Initialize();
 }
Example #2
0
 public static List<EditorObject> Clone(IDeepClone source, EditorScene destination)
 {
     Debug.Assert(source != null);
     List<IDeepClone> sourceList = new List<IDeepClone>();
     sourceList.Add(source);
     return Clone(sourceList, destination);
 }
Example #3
0
 public static List<EditorObject> Clone(List<IDeepClone> source, EditorScene destination)
 {
     Debug.Assert(source != null);
     List<IDeepClone> cloned = DeepClone.Clone(source).Values.ToList();
     SetScene(cloned, destination);
     return cloned.OfType<EditorObject>().ToList();
 }
Example #4
0
 public Selection(EditorScene scene)
 {
     Scene = scene;
     /*_firstMarker = new Entity(Scene.Scene);
     _firstMarker.AddModel(ModelFactory.CreateCircle(new Vector3(), 0.08f, 10));
     _firstMarker.ModelList[0].SetColor(new Vector3(0f, 1f, 0f));
     _firstMarker.ModelList[0].Transform.Position = new Vector3(0, 0, DrawDepth.EntityActive);
     _firstMarker.DrawOverPortals = true;*/
 }
Example #5
0
 public static void Serialize(EditorScene scene, string filename)
 {
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     settings.NewLineOnAttributes = false;
     settings.OmitXmlDeclaration = true;
     using (XmlWriter writer = XmlWriter.Create(filename, settings))
     {
         GetSerializer().WriteObject(writer, scene);
     }
 }
Example #6
0
        public Tuple<EditorScene, EditorWall> CreateTestScene()
        {
            EditorPortal portal0, portal1;
            EditorScene scene = new EditorScene();
            EditorWall polygon = new EditorWall(scene, PolygonFactory.CreateRectangle(2, 2));

            portal0 = new EditorPortal(scene);
            portal1 = new EditorPortal(scene);
            portal0.SetTransform(polygon, new PolygonCoord(0, 0.5f));
            portal1.SetTransform(polygon, new PolygonCoord(1, 0.5f));

            return new Tuple<EditorScene, EditorWall>(scene, polygon);
        }
Example #7
0
        public void FloatPortal()
        {
            EditorPortal portal0, portal1;
            EditorScene scene = new EditorScene();
            EditorWall polygon = new EditorWall(scene, PolygonFactory.CreateRectangle(2, 2));

            portal0 = new EditorPortal(scene);
            portal1 = new EditorPortal(scene);
            portal0.SetTransform(new Transform2(new Vector2(-0.8f, 0)));
            portal1.SetTransform(new Transform2(new Vector2(0.8f, 0)));
            portal0.Linked = portal1;
            portal1.Linked = portal0;

            List<Clip.ClipModel> clipmodels = Clip.GetClipModels(polygon, scene.GetPortalList(), 2);
            Assert.IsTrue(clipmodels.Count == polygon.GetModels().Count + 2);
        }
Example #8
0
        public void FixturePortal()
        {
            EditorPortal portal0, portal1;
            EditorScene scene = new EditorScene();
            EditorWall polygon = new EditorWall(scene, PolygonFactory.CreateRectangle(2, 2));

            portal0 = new EditorPortal(scene);
            portal1 = new EditorPortal(scene);
            portal0.SetTransform(polygon, new PolygonCoord(0, 0.5f));
            portal1.SetTransform(polygon, new PolygonCoord(1, 0.5f));
            portal0.Linked = portal1;
            portal1.Linked = portal0;

            for (float i = 0; i < MathExt.TAU; i += 0.01f)
            {
                polygon.SetTransform(new Transform2(new Vector2(100000, -123), 1, i));
                List<Clip.ClipModel> clipmodels = Clip.GetClipModels(polygon, scene.GetPortalList(), 2);
                Assert.IsTrue(clipmodels.Count == polygon.GetModels().Count);
            }
        }
Example #9
0
 public static void SetScene(IEnumerable<IDeepClone> cloned, EditorScene destination)
 {
     /*Contract.Requires(cloned != null);
     Contract.*/
     /*Debug.Assert(cloned != null);
     Debug.Assert(destination != null);*/
     foreach (IDeepClone clone in cloned)
     {
         if (clone is EditorObject)
         {
             ((EditorObject)clone).SetScene(destination);
         }
         else if (clone is SceneNode)
         {
             SceneNode sceneNode = (SceneNode)clone;
             if (!cloned.Contains(sceneNode.Parent))
             {
                 //sceneNode.SetParent(destination.Scene.Root);
             }
         }
     }
 }
Example #10
0
        /// <summary>
        /// Creates a Scene from an EditorScene.  Scene is intended for gameplay use.
        /// </summary>
        public static Scene Export(EditorScene level, Controller controller)
        {
            Scene scene = new Scene();
            /*if (level.GetAll().OfType<EditorPlayer>().Count() > 0)
            {
                Camera2 camera = new Camera2(scene);
                camera.SetTransform(new Transform2(new Vector2(), 10, 0));
                scene.SetActiveCamera(camera);
                if (level.ActiveCamera != null)
                {
                    camera.Aspect = level.ActiveCamera.Aspect;
                }
            }
            else*/
            {
                if (level.ActiveCamera != null)
                {
                    ControllerCamera camera = level.ActiveCamera.ShallowClone();
                    camera.Scene = scene;
                    scene.SetActiveCamera(camera);
                }
            }

            #region create background
            Model background = Game.ModelFactory.CreatePlane();
            background.Texture = level.Renderer.GetTexture("grid.png");
            background.SetColor(new Vector3(1, 1, 0.5f));
            background.Transform.Position = new Vector3(0, 0, -5f);
            float size = 50;
            background.Transform.Scale = new Vector3(size, size, size);
            background.TransformUv.Size = size;
            Entity back = new Entity(scene, new Vector2(0f, 0f));
            back.Name = "Background";
            back.AddModel(background);
            back.IsPortalable = false;
            #endregion

            Dictionary<EditorObject, SceneNode> dictionary = new Dictionary<EditorObject, SceneNode>();
            AnimationDriver animation = new AnimationDriver();
            scene.SceneObjectList.Add(animation);

            List<EditorObject> editorObjects = level.GetAll().OfType<EditorObject>().ToList();
            foreach (EditorObject e in editorObjects)
            {
                if (e is EditorPortal)
                {
                    EditorPortal cast = (EditorPortal)e;

                    Entity entity = new Entity(scene);
                    entity.IsPortalable = false;
                    entity.AddModel(ModelFactory.CreatePortal());
                    entity.ModelList[0].Transform.Position += new Vector3(0, 0, -2);

                    if (cast.OnEdge)
                    {
                        FixturePortal portal = new FixturePortal(scene);
                        portal.Name = cast.Name;
                        dictionary.Add(cast, portal);

                        entity.SetParent(portal);
                    }
                    else
                    {
                        FloatPortal portal = new FloatPortal(scene);
                        portal.Name = cast.Name;
                        portal.SetTransform(cast.GetTransform());
                        dictionary.Add(cast, portal);

                        entity.SetParent(portal);

                        if (cast.AnimatedTransform != null)
                        {
                            animation.Add(portal, cast.AnimatedTransform);
                            portal.SetTransform(cast.AnimatedTransform.GetTransform(0));
                        }
                        else
                        {
                            portal.SetTransform(cast.GetTransform());
                        }
                    }
                }
                else if (e is EditorEntity)
                {
                    EditorEntity cast = (EditorEntity)e;
                    Entity clone = new Entity(scene);
                    clone.Name = cast.Name;
                    clone.AddModelRange(cast.Models);

                    dictionary.Add(cast, clone);

                    if (cast.AnimatedTransform != null)
                    {
                        animation.Add(clone, cast.AnimatedTransform);
                        clone.SetTransform(cast.AnimatedTransform.GetTransform(0));
                    }
                    else
                    {
                        clone.SetTransform(cast.GetTransform());
                    }
                }
                else if (e is IWall)
                {
                    EditorObject cast = e;

                    Transform2 t = cast.GetTransform();
                    Actor actor = new Actor(scene, ((IWall)e).Vertices, t);
                    actor.Name = cast.Name;
                    Transform2 tEntity = new Transform2();
                    Entity entity = new Entity(scene, tEntity);
                    entity.Name = cast.Name;
                    entity.SetParent(actor);
                    if (e is EditorWall)
                    {
                        EditorWall castWall = (EditorWall)e;
                        actor.SetBodyType(BodyType.Static);
                        //actor.Vertices = castWall.Vertices;
                        entity.AddModel(Game.ModelFactory.CreatePolygon(castWall.Vertices));
                        //entity.AddModel(Game.ModelFactory.CreateActorDebug(actor));
                        dictionary.Add(castWall, actor);
                    }
                    else if (e is EditorActor)
                    {
                        //actor.SetVelocity(new Transform2(new Vector2(0.2f, 0)));
                        EditorActor castActor = (EditorActor)e;
                        //actor.Vertices = castActor.Vertices;
                        entity.AddModel(castActor.GetActorModel(castActor));
                        //entity.AddModel(Game.ModelFactory.CreateActorDebug(actor));
                        dictionary.Add(castActor, actor);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                    if (cast.AnimatedTransform != null)
                    {
                        animation.Add(actor, cast.AnimatedTransform);
                        actor.SetTransform(cast.AnimatedTransform.GetTransform(0));
                        actor.SetBodyType(BodyType.Kinematic);
                    }
                    else
                    {
                        actor.SetTransform(cast.GetTransform());
                    }
                }
                else if (e is EditorPlayer)
                {
                    EditorPlayer cast = (EditorPlayer)e;
                    Player player = new Player(controller);
                    Vector2[] polygon = PolygonFactory.CreateNGon(6, 0.5f, new Vector2());
                    Actor actor = new Actor(scene, polygon);
                    player.SetActor(actor);
                    actor.SetTransform(new Transform2(cast.GetWorldTransform().Position));

                    //player.Camera = (Camera2)scene.ActiveCamera;

                    Entity entity = new Entity(scene, new Transform2());
                    entity.Name = cast.Name;
                    entity.SetParent(actor);
                    entity.AddModel(Game.ModelFactory.CreatePolygon(polygon));

                    scene.SceneObjectList.Add(player);
                    dictionary.Add(cast, player.Actor);
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            foreach (EditorObject e in editorObjects)
            {
                SceneNode parent = e.Parent == null ? null : dictionary[e.Parent];
                SceneNode clone = dictionary[e];
                clone.SetParent(parent);
                if (clone is IPortal)
                {
                    if (clone is FixturePortal)
                    {
                        FixturePortal cast = (FixturePortal)clone;

                        cast.SetPosition((IWall)parent, ((EditorPortal)e).PolygonTransform, e.GetTransform().Size, e.GetTransform().MirrorX);
                        Debug.Assert(((IWall)parent).Vertices.Count > 0);

                        IPortal portalEditor = (IPortal)e;
                        if (portalEditor.Linked != null)
                        {
                            cast.Linked = (IPortal)dictionary[(EditorPortal)portalEditor.Linked];
                        }
                    }
                    else if (clone is FloatPortal)
                    {
                        FloatPortal cast = (FloatPortal)clone;

                        IPortal portalEditor = (IPortal)e;
                        if (portalEditor.Linked != null)
                        {
                            cast.Linked = (IPortal)dictionary[(EditorPortal)portalEditor.Linked];
                        }
                    }
                }
            }

            PortalCommon.UpdateWorldTransform(scene);

            return scene;
        }
Example #11
0
 public static List<EditorObject> Clone(EditorScene source, EditorScene destination)
 {
     return Clone(new List<IDeepClone>(source._children), destination);
 }
Example #12
0
 public EditorActor(EditorScene editorScene)
     : this(editorScene, PolygonFactory.CreateRectangle(1, 1))
 {
 }
Example #13
0
        public void LevelLoad(string filepath)
        {
            SceneStop();
            SetTool(null);
            EditorScene load = Serializer.Deserialize(filepath);
            load.ActiveCamera.Controller = this;
            load.ActiveCamera.InputExt = Input;
            Renderer.AddLayer(load);
            Renderer.RemoveLayer(Level);
            Level = load;
            selection = new Selection(Level);

            LevelLoaded(this, filepath);
            LevelChanged(this, filepath);
            TimeChanged(this, Level.Time);
        }
Example #14
0
        public void LevelCreate()
        {
            //SceneStop();
            SetTool(null);
            Renderer.RemoveLayer(Hud);
            Renderer.RemoveLayer(Level);
            Hud = new Scene();
            Level = new EditorScene(Renderer);
            Renderer.AddLayer(Level);
            Renderer.AddLayer(Hud);

            selection = new Selection(Level);
            StateList = new StateList();

            CamControl = new ControllerCamera(this, Input, Level);
            Transform2.SetSize(CamControl, 10);
            Hud.SetActiveCamera(CamControl);
            Level.ActiveCamera = CamControl;

            LevelCreated(this, null);
            LevelChanged(this, null);
            TimeChanged(this, Level.Time);
        }
Example #15
0
 public EditorWall(EditorScene scene, IList<Vector2> vertices)
     : base(scene)
 {
     Vertices = new List<Vector2>(vertices);
     Initialize();
 }
Example #16
0
 public Doodad(EditorScene scene)
     : this()
 {
     scene.Doodads.Add(this);
 }
Example #17
0
 public void Initialize()
 {
     stateList = new StateList();
     scene = new EditorScene();
 }
Example #18
0
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Clipboard = new EditorScene();

            LevelCreate();
            Hud.SetActiveCamera(new Camera2(Hud, new Transform2(new Vector2(CanvasSize.Width / 2, CanvasSize.Height / 2), CanvasSize.Width), CanvasSize.Width / (float)CanvasSize.Height));

            PortalCommon.UpdateWorldTransform(Hud);
            PortalCommon.UpdateWorldTransform(Level);

            InitTools();
            SceneStop();
        }
Example #19
0
 public void Init()
 {
     _scene = new EditorScene();
     _clipboard = new EditorScene();
 }
Example #20
0
 public EditorEntity(EditorScene editorScene)
     : base(editorScene)
 {
 }
Example #21
0
 public EditorActor(EditorScene editorScene, IList<Vector2> vertices)
     : base(editorScene)
 {
     Vertices = vertices;
 }
Example #22
0
 public EditorPlayer(EditorScene editorScene)
     : base(editorScene)
 {
 }