private void LoadStatics() { foreach (ObjectsNode node in staticList) { switch (node.Shape) { case 1: HorizontalLine(node); break; case 2: RightTriangle(node); break; case 3: LeftTriangle(node); break; case 4: VerticalLine(node); break; } } /* Teleport Pipe */ Statics.Add(new TeleportPipe(new Vector2(2429, 410), new Vector2(3050, -480), "TeleportVerticalLargePipe", Direction.top)); Statics.Add(new TeleportPipe(new Vector2(3705, -170), new Vector2(6990, 410), "TeleportHorizontalSmallPipe", Direction.left)); /* Regular Pipe */ Statics.Add(new Pipe(new Vector2(3759, -170), "HighPipe")); Statics.Add(new Pipe(new Vector2(6958, 410), "SmallPipe")); Statics.Add(new Pipe(new Vector2(400, 410), "SmallPipe")); Statics.Add(new Pipe(new Vector2(1290, 410), "SmallPipe")); Statics.Add(new Pipe(new Vector2(1629, 410), "MiddlePipe")); Statics.Add(new Pipe(new Vector2(1961, 410), "LargePipe")); }
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); }); }
private void VerticalLine(ObjectsNode node) { Type t = Type.GetType(node.ObjectType); Vector2 position; position.X = node.Position.X; position.Y = node.Position.Y; for (int i = 0; i < node.Size; i++) { Statics.Add(CreateInstance(t, position, node.ItemType, node.ItemCount)); position.Y -= node.Width; } }
private void HorizontalLine(ObjectsNode node) { Type t = Type.GetType(node.ObjectType); Vector2 position; position.X = node.Position.X; position.Y = node.Position.Y; for (int i = 0; i < node.Size; i++) { Statics.Add(CreateInstance(t, position, node)); position.X += node.Width; } }
private void LeftTriangle(ObjectsNode node) { Type t = Type.GetType(node.ObjectType); Vector2 position; position.X = node.Position.X; position.Y = node.Position.Y; for (int i = 0; i < node.Size; i++) { for (int j = 0; j <= i; j++) { position.X = node.Position.X + i * node.Width; position.Y = node.Position.Y - j * node.Width; Statics.Add(CreateInstance(t, position, node.ItemType, node.ItemCount)); position.Y -= node.Width; } } }
public StaticModel GetStatic(WadStatic @static, bool maybeRebuildAll = true) { // Check if the data is already loaded // If yes attempt to use that one StaticModel model; if (Statics.TryGetValue(@static, out model)) { if (model.Version >= @static.Version) { return(model); } ReclaimTextureSpace(model); model.Dispose(); Statics.Remove(@static); } // The data is either new or has changed, unfortunately we need to reload it try { model = new StaticModel(GraphicsDevice); model.Meshes.Add(ObjectMesh.FromWad2(GraphicsDevice, @static.Mesh, AllocateTexture)); model.UpdateBuffers(); } catch (TextureAtlasFullException exc) { logger.Info(exc.Message); if (maybeRebuildAll) { logger.Info("Starting to rebuild the entire atlas."); Dispose(); return(GetStatic(@static, false)); } } Statics.Add(@static, model); return(model); }
private bool AddTypeImpl(Type type, int recursionLevel) { if (type == null) { return(false); } if (type.IsArray) { AddTypeImpl(type.GetElementType(), recursionLevel); return(false); } // Load type and stop if it is already loaded. if (!LoadTypeToScriptContext(type)) { return(false); } // Add static. if (!Statics.ContainsKey(type.Name)) { Statics.Add(type.Name, new Member { Name = type.Name, Type = type }); InstancesAndStaticsDirty = true; } if (recursionLevel-- > 0) { // Add static members. AddMembers(StaticMembers, type, BindingFlags.Static | BindingFlags.Public, recursionLevel); // Add instance members. AddMembers(InstanceMembers, type, BindingFlags.Instance | BindingFlags.Public, recursionLevel); } return(true); }