示例#1
0
        public void Mount(SceneItem target, string targetLinkPoint, string linkPoint)
        {
            if (IsMounted)
            {
                throw new Exception("This object is already mounted to another SceneItem");
            }
            if (target == null)
            {
                throw new Exception("This target SceneItem is null");
            }
            //if((!target.IsTemplate && !this.IsTemplate))
            //  throw new Exception("You cannot mount a sceneitem if it is not a Template");

            _mountedTargetLinkPoint = target.GetLinkPoint(targetLinkPoint);
            _mountedLinkPoint       = GetLinkPoint(linkPoint);
            if (_mountedTargetLinkPoint == null)
            {
                throw new Exception("The target LinkPoint \"" + targetLinkPoint + "\" does not exists");
            }
            if (_mountedLinkPoint == null)
            {
                throw new Exception("The local LinkPoint \"" + linkPoint + "\" does not exists");
            }
            _mountedTargetLinkPoint.AddMountedChildLinkPoint(_mountedLinkPoint);
            _mountOwner = target;
        }
示例#2
0
        /// <summary>
        /// Creates a new instance of a given SceneItem using Reflection
        /// </summary>
        public SceneItem CreateNewInstaceCopyOf(SceneItem item)
        {
            SceneItem copy = (SceneItem)item.GetType().Assembly.CreateInstance(item.GetType().FullName);

            item.CopyValuesTo(copy);
            return(copy);
        }
示例#3
0
        /// <summary>
        /// Perform a deep copy of the object to the target
        /// </summary>
        /// <param name="target">The target that will receive all the values</param>
        public virtual void CopyValuesTo(SceneItem target)
        {
            target.BoundingRectSize     = this.BoundingRectSize;
            target.BoundingRect         = this.BoundingRect;
            target.Layer                = this.Layer;
            target.MarkForDelete        = this.MarkForDelete;
            target.Name                 = this.Name;
            target.ObjectType           = this.ObjectType;
            target.Position             = this.Position;
            target.Rotation             = this.Rotation;
            target.SceneParent          = this.SceneParent;
            target.Scale                = this.Scale;
            target.Pivot                = this.Pivot;
            target.Opacity              = this.Opacity;
            target.IsPivotRelative      = this.IsPivotRelative;
            target.LockedPosition       = this.LockedPosition;
            target.Visible              = this.Visible;
            target.IsTemplate           = this.IsTemplate;
            target.IgnoreCameraPosition = IgnoreCameraPosition;
            target.FlipHorizontal       = this.FlipHorizontal;
            target.FlipVertical         = this.FlipVertical;
            target.LinkPoints.Clear();
            target.Components.Clear();
            foreach (var item in Components)
            {
                target.AddComponent((IceComponent)item.GetCopy());
            }

            target.Tags.Clear();
            foreach (string tag in this.Tags)
            {
                target.Tags.Add(tag);
            }
            target.FactionId = this.FactionId;
        }
示例#4
0
 public LinkPoint(SceneItem owner, String name)
 {
     this.Owner  = owner;
     this.Name   = name;
     this.Offset = Vector2.Zero;
     Mounts      = new Dictionary <string, string>();
 }
示例#5
0
        public void UpdateChild(LinkPoint targetLinkPoint)
        {
            SceneItem targetChild = targetLinkPoint.Owner;

            targetChild.Position = this.Position - targetLinkPoint.Offset;
            targetChild.Rotation = this.Rotation;


            //targetChild.Position = GetWorldLinkPosition( this._mountedTo.Val.Position, this._mountedTo.Val.Rotation, this._mountedTo.Val.Offset);
        }
示例#6
0
 /// <summary>
 /// Registers a sceneitem in the scene at the end of this update.
 /// </summary>
 /// <param name="sceneItem"></param>
 public void RegisterSceneItem(SceneItem sceneItem)
 {
     if (sceneItem.Name.Equals(string.Empty))
     {
         throw new ArgumentException("Scene item must have a name set");
     }
     sceneItem.IsTemplate  = false;
     sceneItem.SceneParent = this;
     _itemsToRegister.Add(sceneItem);
 }
示例#7
0
 internal void RegisterItems()
 {
     for (int i = 0; i < _itemsToRegister.Count; i++)
     {
         SceneItem item = _itemsToRegister[i];
         AddToSceneItems(item);
         item.OnRegister();
         _itemsToRegister.RemoveAt(i);
         i--;
     }
 }
示例#8
0
        private static void InitializeScene(IceScene _scene)
        {
            _scene.InitializeContent(Game.Instance.Services);
            _scene.ContentManager.RootDirectory = GlobalDataHolder.ContentFolderPath;

            // Create a default full sized camera
            Camera camera = new Camera();

            camera.Position = Vector2.Zero;
            camera.Update(1 / 60f);
            _scene.ActiveCameras.Add(camera);

            // Load Materials
            foreach (Material _material in _scene.Materials)
            {
                _material.Texture = _scene._content.Load <Texture2D>(_material.Filename.Substring(0, _material.Filename.Length - 4));
                _material.Scope   = AssetScope.Local;
            }
            // Load Fonts
            foreach (IceFont _font in _scene.Fonts)
            {
                _font.Font = _scene._content.Load <SpriteFont>(_font.Filename.Replace(".spritefont", ""));
            }
                        #if !XNATOUCH
            foreach (IceEffect _effect in _scene.Effects)
            {
                if (_effect.Effects != null)
                {
                    continue;
                }
                // removing ".fx" from the name
                string name = _effect.Filename.Substring(0, _effect.Filename.Length - 3);
                _effect.Load(GlobalDataHolder.ContentManager, new string[] { name });
            }
            #endif
            //Load Scene Components
            foreach (IceSceneComponent _comp in _scene.SceneComponents)
            {
                _comp.SetOwner(_scene);
                _comp.OnRegister();
            }
            //Register Scene Items
            for (int i = 0; i < _scene.SceneItems.Count; i++)
            {
                SceneItem item = _scene.SceneItems[i];
                item.SceneParent = _scene;
                if (item.IsRegistered == false)
                {
                    item.OnRegister();
                }
            }
        }
示例#9
0
        /// <summary>
        /// Creates a copy of a template with the given name
        /// </summary>
        /// <param name="name">The name of the template to copy</param>
        /// <returns>A copied SceneItem, if the Template is not found, null is returned</returns>
        public SceneItem CreateCopy(string name)
        {
            SceneItem item = GetTemplate(name);

            if (item != null)
            {
                return((SceneItem)CreateNewInstaceCopyOf(item));
            }
            else
            {
                return(null);
            }
        }
示例#10
0
        //private static void UpdateNetworkToSend(float elapsed)
        //{
        //    NetworkSession session = SceneManager.networkSession;
        //    if (SceneManager.IsNetworkOwner)
        //    {
        //        //foreach (var item in SceneManager.ActiveScene.SceneItems)
        //        //{
        //        //    packetWriter.Write((int)NetworkDataType.UpdateSceneItem);
        //        //    packetWriter.Write(item.Position);
        //        //}
        //        //LocalNetworkGamer server = (LocalNetworkGamer)session.Host;
        //        //server.SendData(packetWriter, SendDataOptions.InOrder);
        //    }
        //    session.Update();
        //}

        private static void UpdateItemsComponents(SceneItem item)
        {
            if (item.Components == null)
            {
                return;
            }
            for (int i = 0; i < item.Components.Count; i++)
            {
                IceComponent _component = item.Components[i];
                if (_component.Enabled == true)
                {
                    _component.Update(IceCream.Game.Instance.Elapsed);
                }
            }
        }
示例#11
0
 public void SetupLinkFuses()
 {
     //Trying something out with loading linkpoints
     foreach (var item in LinkPoints)
     {
         foreach (var mount in item.Mounts)
         {
             SceneItem sceneitem = SceneParent.GetTemplate(mount.Key);
             if (sceneitem != null)
             {
                 sceneitem.Mount(this, item.Name, mount.Value);
             }
         }
     }
 }
示例#12
0
 public void UnMount()
 {
     if (IsMounted == false)
     {
         throw new Exception("This object is not mounted to a SceneItem");
     }
     if (_mountOwner == null)
     {
         throw new Exception("The Mount Owner of this object is null");
     }
     if (_mountedTargetLinkPoint == null)
     {
         throw new Exception("The Mount Owner target LinkPoint is null");
     }
     if (_mountedLinkPoint == null)
     {
         throw new Exception("The local mounted LinkPoint is null");
     }
     _mountedTargetLinkPoint.RemoveMountedChildLinkPoint(_mountedLinkPoint);
     _mountedTargetLinkPoint = null;
     _mountedLinkPoint       = null;
     _mountOwner             = null;
 }
示例#13
0
        /// <summary>
        /// Calls Update on all enabled SceneItems and their Corresponding Components along with the SceneComponents
        /// </summary>
        /// <param name="elapsed">The elapsed game time since the last Update</param>
        internal static void UpdateIceCream(float elapsed)
        {
            if (SceneManager.ActiveScene == null || !SceneManager.ActiveScene.Enabled)
            {
                return;
            }

            IceProfiler.StartProfiling(IceProfilerNames.ICE_CORE_MAIN_UPDATE);
            // Differentiate between being in Milkshake and a running game
            if (SceneManager.ActiveScene.isInGame == false)
            {
                SceneManager.ActiveScene.isInGame = true;
            }
            if (SceneManager.ActiveScene._hasBeenUpdatedOnce == false)
            {
                SceneManager.ActiveScene._hasBeenUpdatedOnce = true;
            }
            SceneManager.ActiveScene.RemoveItems();
            SceneManager.ActiveScene.RegisterItems();

            //Pump input
            Input.InputCore.Update(elapsed);

            //First update any scene components
            for (int i = 0; i < SceneManager.ActiveScene.SceneComponents.Count; i++)
            {
                IceSceneComponent comp = SceneManager.ActiveScene.SceneComponents[i];
                if (comp.Enabled == false)
                {
                    continue;
                }
                comp.Update(elapsed);
                if (activeSceneChanged == true)
                {
                    IceProfiler.StopProfiling(IceProfilerNames.ICE_CORE_MAIN_UPDATE);
                    return;
                }
            }

            // Physics.CollisionManager.CheckAndProcessCollisions();
            // Update Spatial Data
            for (int i = 0; i < SceneManager.ActiveScene.SceneItems.Count; i++)
            {
                SceneItem _item = SceneManager.ActiveScene.SceneItems[i];
                if (_item.IsTemplate == true)
                {
                    continue;
                }
                _item.Update(elapsed);
            }

            for (int i = 0; i < SceneManager.ActiveScene.SceneItems.Count; i++)
            {
                SceneItem _item = SceneManager.ActiveScene.SceneItems[i];
                if (_item.IsTemplate == true)
                {
                    continue;
                }
                // Update all its components
                UpdateItemsComponents(_item);
                if (_item.MarkForDelete == true)
                {
                    _itemsToDelete.Add(_item);
                }
                if (activeSceneChanged == true)
                {
                    IceProfiler.StopProfiling(IceProfilerNames.ICE_CORE_MAIN_UPDATE);
                    return;
                }
            }

            for (int i = 0; i < SceneManager.ActiveScene.ActiveCameras.Count; i++)
            {
                SceneManager.ActiveScene.ActiveCameras[i].Update(elapsed);
            }

            //if(SceneManager.networkSession != null)
            //{
            //UpdateNetworkToSend(elapsed);
            //}

            IceProfiler.StopProfiling(IceProfilerNames.ICE_CORE_MAIN_UPDATE);
        }
示例#14
0
 /// <summary>
 /// Adds a template sceneitem to the templates collection
 /// </summary>
 /// <param name="sceneItem">The scene item to add</param>
 public void AddTemplate(SceneItem sceneItem)
 {
     sceneItem.IsTemplate = true;
     TemplateItems.Add(sceneItem);
 }
示例#15
0
 internal void AddToSceneItems(SceneItem item)
 {
     item.id = GetNewID();
     SceneItems.Add(item);
 }