예제 #1
0
        static void Run(string sourceName)
        {
            var path = ExtractAndCompile(sourceName);

            try
            {
                Assembly assembly;

                using (var host = new PeReader.DefaultHost())
                    using (var pdbStream = File.OpenRead(Path.ChangeExtension(path, ".pdb")))
                    {
                        var pdbreader     = new PdbReader(pdbStream, host);
                        var loaded        = host.LoadAssembly(new AssemblyIdentity(host.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(path)), null, new Version(), null, path));
                        var dynamicLoader = new DynamicLoader(pdbreader, pdbreader);
                        assembly = dynamicLoader.Load(loaded);
                    }

                var type   = assembly.GetTypes().Single(t => t.Name == sourceName && Attribute.GetCustomAttribute(t, typeof(CompilerGeneratedAttribute)) == null);
                var foo    = Activator.CreateInstance(type);
                var method = type.GetMethod("Run");
                var action = (Action)Delegate.CreateDelegate(typeof(Action), foo, method);
                action();
            }
            finally
            {
                File.Delete(path);
            }
        }
예제 #2
0
 public void Update(GameTime gameTime)
 {
     dynamicLoader.Load(game.Camera.RightBound + LoadMargin); // We set the load range to 100.
     if (Mario.Position.X < game.Camera.LeftBound)
     {
         Mario.Position = new Vector2(game.Camera.LeftBound, Mario.Position.Y);
     }
     for (int i = (StaticObjects.Count - 1); i >= 0 && i < StaticObjects.Count; i--)
     {
         IStatic obj = StaticObjects[i];
         BoundaryCheck(obj);
         obj.Update(gameTime);
         if (obj.ObjState == ObjectState.Destroy)
         {
             DestroyFromManager(obj);
         }
         if (obj.ObjState == ObjectState.NonCollidable)
         {
             MoveToNonCollidable(obj);
         }
     }
     for (int i = (DynamicObjects.Count - 1); i >= 0 && i < DynamicObjects.Count; i--)
     {
         IDynamic obj = DynamicObjects[i];
         BoundaryCheck(obj);
         obj.Update(gameTime);
         if (obj.ObjState == ObjectState.Destroy)
         {
             DestroyFromManager(obj);
         }
         if (obj.ObjState == ObjectState.NonCollidable)
         {
             MoveToNonCollidable(obj);
         }
     }
     for (int i = (NonCollidableObjects.Count - 1); i >= 0 && i < NonCollidableObjects.Count; i--)
     {
         BoundaryCheck(NonCollidableObjects[i]);
         IObject obj;
         if (NonCollidableObjects[i] is IStatic)
         {
             obj = (IStatic)NonCollidableObjects[i];
             ((IStatic)obj).Update(gameTime);
         }
         else
         {
             obj = (IDynamic)NonCollidableObjects[i];
             ((IDynamic)obj).Update(gameTime);
         }
         if (obj.ObjState == ObjectState.Destroy)
         {
             DestroyFromNonCollidable(obj);
         }
         if (obj.ObjState == ObjectState.Normal)
         {
             MoveToCollidable(obj);
         }
     }
 }