/// <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); }
public LinkPoint(SceneItem owner, String name) { this.Owner = owner; this.Name = name; this.Offset = Vector2.Zero; Mounts = new Dictionary <string, string>(); }
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; }
/// <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((SquidComponent)item.GetCopy()); } }
/// <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); }
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); }
internal void RegisterItems() { for (int i = 0; i < _itemsToRegister.Count; i++) { SceneItem item = _itemsToRegister[i]; AddToSceneItems(item); item.OnRegister(); _itemsToRegister.RemoveAt(i); i--; } }
/// <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); } }
private static void InitializeScene(SquidScene _scene) { _scene.InitializeContent(Game.Instance.Services); // 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 (SquidFont _font in _scene.Fonts) { _font.Font = _scene._content.Load <SpriteFont>(_font.Filename.Replace(".spritefont", "")); } #if !XNATOUCH foreach (SquidEffect _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 (SquidSceneComponent _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(); } } }
//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++) { SquidComponent _component = item.Components[i]; if (_component.Enabled == true) { _component.Update(SquidEngine.Game.Instance.Elapsed); } } }
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); } } } }
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; }
/// <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); }
internal void AddToSceneItems(SceneItem item) { item.id = GetNewID(); SceneItems.Add(item); }
/// <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 UpdateSquidEngine(float elapsed) { if (SceneManager.ActiveScene == null || !SceneManager.ActiveScene.Enabled) { return; } // Unload the scenes in the queue (this will prevent a flicker from happening when unloading // scenes during update if (SceneManager.ScenesToUnload.Count > 0) { foreach (SquidScene oldScene in SceneManager.ScenesToUnload) { oldScene.Unload(); oldScene.ContentManager.Unload(); oldScene.ContentManager.Dispose(); SceneManager.Scenes.Remove(oldScene); if (oldScene == SceneManager.ActiveScene) { SceneManager.ActiveScene = null; } if (SceneManager.ActiveScene == null && SceneManager.Scenes.Count > 0) //Pick the top scene { SceneManager.ActiveScene = SceneManager.Scenes[SceneManager.Scenes.Count - 1]; } } SceneManager.ScenesToUnload.Clear(); } SquidProfiler.StartProfiling(SquidProfilerNames.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++) { SquidSceneComponent comp = SceneManager.ActiveScene.SceneComponents[i]; if (comp.Enabled == false) { continue; } comp.Update(elapsed); if (activeSceneChanged == true) { SquidProfiler.StopProfiling(SquidProfilerNames.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) { SquidProfiler.StopProfiling(SquidProfilerNames.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); //} SquidProfiler.StopProfiling(SquidProfilerNames.ICE_CORE_MAIN_UPDATE); }