public void Add(IWadObjectId newId, IWadObject wadObject) { // Change id if necessary if (newId != wadObject.Id) { var property = wadObject.GetType().GetProperty("Id"); property.SetValue(wadObject, newId); } // Add object if (newId is WadMoveableId) { Moveables.Add((WadMoveableId)newId, (WadMoveable)wadObject); } else if (newId is WadStaticId) { Statics.Add((WadStaticId)newId, (WadStatic)wadObject); } else if (newId is WadSpriteSequenceId) { SpriteSequences.Add((WadSpriteSequenceId)newId, (WadSpriteSequence)wadObject); } else { throw new ArgumentException("Argument not of a valid type."); } }
// This method is optional. By sorting the wad textures it may result ahead of time // we may have better texture space efficency. public void PreloadReplaceWad(IEnumerable <WadMoveable> newMoveables, IEnumerable <WadStatic> newStatics) { Dispose(); try { PreloadReplaceTextures(newMoveables, newStatics); } catch (TextureAtlasFullException) { logger.Error("Unable to preload wad because the texture atlas became too full!"); return; } // Create moveable models Parallel.ForEach(newMoveables, moveable => { var model = AnimatedModel.FromWadMoveable(GraphicsDevice, moveable, AllocateTexture); lock (Moveables) Moveables.Add(moveable, model); }); // Create static meshes Parallel.ForEach(newStatics, @static => { var model = new StaticModel(GraphicsDevice); model.Meshes.Add(ObjectMesh.FromWad2(GraphicsDevice, @static.Mesh, AllocateTexture)); model.UpdateBuffers(); lock (Statics) Statics.Add(@static, model); }); }
// removes GameObject from all lists depending on type public void Remove(GameObject go) { GameObjects.Remove(go); var item = go as ICollidable; if (item != null) { Collidables.Remove(item); } var moveable = go as IMoveable; if (moveable != null) { Moveables.Remove(moveable); } var renderable = go as IRenderable; if (renderable != null) { Renderables.Remove(renderable); } }
public void AddMoveable(string symbol) { if (!Moveables.Contains(symbol)) { Moveables.Add(symbol); } }
public virtual void PlaceMoveable(IMoveable moveable) { if (Moveables.Count != 0) { RemoveMoveable(Moveables.First()); } Moveables.Add(moveable); }
public void RemoveMoveable(string nonTerminal) { if (!Moveables.Contains(nonTerminal)) { return; } Moveables.Remove(nonTerminal); }
public void AddMoveable(IMoveable moveable) { var listener = new FloorChangeListener(); listener.Subscribe(moveable); Listeners.Add(listener); Moveables.Add(moveable.Identifier, moveable); }
public void GenerateInitialRulesFromDerivedRules() { if (!LandingSites.Any() || !Moveables.Any()) { return; } var initialRules = ruleNumberDictionary.Values.ToList(); var derivedRules = initialRules.Where(x => !x.IsInitialRule()).ToList(); var toRemove = derivedRules.ToList(); foreach (var item in toRemove) { DeleteRule(item); } }
public void Dispose() { Texture?.Dispose(); Texture = null; CreateTexturePacker(); foreach (var obj in Moveables.Values) { obj.Dispose(); } Moveables.Clear(); foreach (var obj in Statics.Values) { obj.Dispose(); } Statics.Clear(); }
public bool Contains(IWadObject wadObject) { if (wadObject is WadMoveable) { return(Moveables.Any(obj => obj.Value == (WadMoveable)wadObject)); } else if (wadObject is WadStatic) { return(Statics.Any(obj => obj.Value == (WadStatic)wadObject)); } else if (wadObject is WadSpriteSequence) { return(SpriteSequences.Any(obj => obj.Value == (WadSpriteSequence)wadObject)); } else { throw new ArgumentException("Argument not of a valid type."); } }
public IWadObject TryGet(IWadObjectId wadObjectId) { if (wadObjectId is WadMoveableId) { return(Moveables.TryGetOrDefault((WadMoveableId)wadObjectId)); } else if (wadObjectId is WadStaticId) { return(Statics.TryGetOrDefault((WadStaticId)wadObjectId)); } else if (wadObjectId is WadSpriteSequenceId) { return(SpriteSequences.TryGetOrDefault((WadSpriteSequenceId)wadObjectId)); } else { throw new ArgumentException("Argument not of a valid type."); } }
public void Remove(IWadObjectId wadObjectId) { if (wadObjectId is WadMoveableId) { Moveables.Remove((WadMoveableId)wadObjectId); } else if (wadObjectId is WadStaticId) { Statics.Remove((WadStaticId)wadObjectId); } else if (wadObjectId is WadSpriteSequenceId) { SpriteSequences.Remove((WadSpriteSequenceId)wadObjectId); } else { throw new ArgumentException("Argument not of a valid type."); } }
private void AddToList(GameObject go) { var item = go as ICollidable; if (item != null) { Collidables.Add(item); } var moveable = go as IMoveable; if (moveable != null) { Moveables.Add(moveable); } var renderable = go as IRenderable; if (renderable != null) { Renderables.Add(renderable); } }
public void GenerateDerivedRulesFromSchema() { if (!LandingSites.Any() || !Moveables.Any()) { return; } var toAdd = new List <Rule>(); foreach (var moveable in Moveables) { var pop1 = new Rule(1, moveable, new[] { Epsilon }, 0, 0); pop1.Name.Stack = new NonTerminalStack(moveable); toAdd.Add(pop1); foreach (var landingSiteNonTerminal in LandingSites) { var push = new Rule(1, landingSiteNonTerminal, new[] { moveable, landingSiteNonTerminal }, 1, 1); push.Name.Stack = new NonTerminalStack("."); push.Production[1].Stack = new NonTerminalStack("."); push.Production[1].Stack = push.Production[1].Stack.Push(moveable); toAdd.Add(push); } var pop2 = new Rule(1, "IP", new[] { moveable, "VP" }, 1, 1); pop2.Name.Stack = new NonTerminalStack("."); pop2.Name.Stack = pop2.Name.Stack.Push(moveable); pop2.Production[0].Stack = new NonTerminalStack(moveable); pop2.Production[1].Stack = new NonTerminalStack("."); toAdd.Add(pop2); } foreach (var item in toAdd) { AddRule(item); } }
public AnimatedModel GetMoveable(WadMoveable moveable, bool maybeRebuildAll = true) { // Check if the data is already loaded // If yes attempt to use that one AnimatedModel model; if (Moveables.TryGetValue(moveable, out model)) { if (model.Version >= moveable.Version) { return(model); } ReclaimTextureSpace(model); model.Dispose(); Moveables.Remove(moveable); } // The data is either new or has changed, unfortunately we need to reload it try { model = AnimatedModel.FromWadMoveable(GraphicsDevice, moveable, AllocateTexture); } catch (TextureAtlasFullException exc) { logger.Info(exc.Message); if (maybeRebuildAll) { logger.Info("Starting to rebuild the entire atlas."); Dispose(); return(GetMoveable(moveable, false)); } } Moveables.Add(moveable, model); return(model); }
public void RemoveMoveable(IMoveable moveable) { Moveables.Remove(moveable); }
public void PlaceMoveable(IMoveable moveable) { Moveables.Add(moveable); }