Exemplo n.º 1
0
        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.");
            }
        }
Exemplo n.º 2
0
        // 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);
            });
        }
Exemplo n.º 3
0
        // 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);
            }
        }
Exemplo n.º 4
0
 public void AddMoveable(string symbol)
 {
     if (!Moveables.Contains(symbol))
     {
         Moveables.Add(symbol);
     }
 }
Exemplo n.º 5
0
 public virtual void PlaceMoveable(IMoveable moveable)
 {
     if (Moveables.Count != 0)
     {
         RemoveMoveable(Moveables.First());
     }
     Moveables.Add(moveable);
 }
Exemplo n.º 6
0
 public void RemoveMoveable(string nonTerminal)
 {
     if (!Moveables.Contains(nonTerminal))
     {
         return;
     }
     Moveables.Remove(nonTerminal);
 }
Exemplo n.º 7
0
        public void AddMoveable(IMoveable moveable)
        {
            var listener = new FloorChangeListener();

            listener.Subscribe(moveable);
            Listeners.Add(listener);

            Moveables.Add(moveable.Identifier, moveable);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
 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.");
     }
 }
Exemplo n.º 11
0
 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.");
     }
 }
Exemplo n.º 12
0
 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.");
     }
 }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 public void RemoveMoveable(IMoveable moveable)
 {
     Moveables.Remove(moveable);
 }
Exemplo n.º 17
0
 public void PlaceMoveable(IMoveable moveable)
 {
     Moveables.Add(moveable);
 }