public void AddCacheType(string cacheName) { GameObjectCaching.GameComponentCache cache = GameObjectCaching.GetCacheByName(cacheName); if (cache == null) { return; } if (cacheTypeNames == null) { cacheTypeNames = new List <string>(); cacheTypes = new List <GameObjectCaching.GameComponentCache>(); } else if (cacheTypeNames.Contains(cacheName)) { return; } cacheTypeNames.Add(cacheName); cacheTypes.Add(cache); // Sadly, when we call this in the type constructor of a derived type we've already called AddChild for that type // in the GameComponent constructor so we can't put AddToCache there. cache.addFunction(this); }
/// <summary> /// Initializes a new instance of the <see cref="GameComponent"/> class, while adding it to the component manager. /// </summary> /// <param name="createNew">if set to <c>true</c> adds this component to the manager..</param> /// <param name="manager">The component manager to add the component to</param> public GameComponent(bool createNew, ComponentManager manager) { World = manager.World; lock (globalIdLock) { GlobalID = maxGlobalID; maxGlobalID++; } Parent = null; Children = new List <GameComponent>(); Name = "uninitialized"; IsVisible = true; IsActive = true; IsDead = false; if (createNew && Manager != null) { Manager.AddComponent(this); } Tags = new List <string>(); HasOwnRender = GameObjectCaching.HasOwnRender(this.GetType()); }
protected override void Initialize() { // Goes before anything else so we can track from the very start. GamePerformance.Initialize(this); // TODO: Find a more appropriate spot for this. GameObjectCaching.Initialize(); SpriteBatch = new SpriteBatch(GraphicsDevice); base.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="GameComponent"/> class. /// </summary> public GameComponent() { World = null; Children = new List <GameComponent>(); Name = "uninitialized"; IsVisible = true; IsActive = true; Tags = new List <string>(); HasOwnRender = GameObjectCaching.HasOwnRender(this.GetType()); }
public MinimapIcon(Body parent, ImageFrame icon) : base("Icon", parent, Matrix.Identity, Vector3.One, Vector3.Zero) { Icon = icon; IconScale = 1.0f; AddToCollisionManager = false; FrustrumCull = false; IsVisible = false; GameObjectCaching.AddMinimapIcon(this); }
public void RefreshCacheTypes() { if (cacheTypeNames == null) { return; } cacheTypes = new List <GameObjectCaching.GameComponentCache>(cacheTypeNames.Count); for (int i = 0; i < cacheTypeNames.Count; i++) { GameObjectCaching.GameComponentCache cache = GameObjectCaching.GetCacheByName(cacheTypeNames[i]); if (cache == null) { continue; } cacheTypes.Add(cache); cache.addFunction(this); } }
public override void Die() { GameObjectCaching.RemoveMinimapIcon(this); base.Die(); }
public void OnDeserialize(StreamingContext context) { GameObjectCaching.AddMinimapIcon(this); }
private void OnDeserialized(StreamingContext context) { AdditionMutex = new Mutex(); RemovalMutex = new Mutex(); Removals = new List <GameComponent>(); Additions = new List <GameComponent>(); World = (WorldManager)context.Context; Vector3 origin = new Vector3(World.WorldOrigin.X, 0, World.WorldOrigin.Y); Vector3 extents = new Vector3(1500, 1500, 1500); CollisionManager = new CollisionManager(new BoundingBox(origin - extents, origin + extents)); GameObjectCaching.Reset(); RootComponent.RefreshCacheTypesRecursive(); }