public void Render()
        {
            bool flag = false;

            DuckGame.Graphics.Clear(this.backgroundColor * DuckGame.Graphics.fade);
            for (int key = 0; key < this.currentObject; ++key)
            {
                if (this._states.ContainsKey(key))
                {
                    if (flag)
                    {
                        DuckGame.Graphics.screen.End();
                    }
                    RecorderFrameStateChange state = this._states[key];
                    flag = true;
                    MTEffect mtEffectFromIndex = Content.GetMTEffectFromIndex(state.effectIndex);
                    if (Layer.IsBasicLayerEffect(mtEffectFromIndex))
                    {
                        mtEffectFromIndex.effect.Parameters["fade"].SetValue((Vector3) new Vec3(DuckGame.Graphics.fade));
                        mtEffectFromIndex.effect.Parameters["add"].SetValue((Vector3) new Vec3(DuckGame.Graphics.fadeAdd));
                    }
                    DuckGame.Graphics.screen.Begin(state.sortMode, state.blendState, state.samplerState, state.depthStencilState, state.rasterizerState, Content.GetMTEffectFromIndex(state.effectIndex), state.camera);
                    DuckGame.Graphics.SetScissorRectangle(state.scissor);
                }
                DuckGame.Graphics.DrawRecorderItem(ref this.objects[key]);
            }
            if (!flag)
            {
                return;
            }
            DuckGame.Graphics.screen.End();
        }
Beispiel #2
0
 public bool IsBasicLayerEffect(MTEffect e)
 {
     if (e == null)
     {
         return(false);
     }
     return((int)e.effectIndex == (int)this._basicEffect.effectIndex || (int)e.effectIndex == (int)this._basicEffectAdd.effectIndex || (int)e.effectIndex == (int)this._basicEffectFade.effectIndex || (int)e.effectIndex == (int)this._basicEffectFadeAdd.effectIndex);
 }
Beispiel #3
0
 public void Begin(
     SpriteSortMode sortMode,
     BlendState blendState,
     SamplerState samplerState,
     DepthStencilState depthStencilState,
     RasterizerState rasterizerState,
     MTEffect effect)
 {
     this.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, Matrix.Identity);
 }
 public static void SetEffectAtIndex(short index, MTEffect e)
 {
     while ((int)index > DuckGame.Content._effectList.Count)
     {
         DuckGame.Content._effectList.Add((MTEffect)null);
         ++DuckGame.Content._currentEffectIndex;
     }
     DuckGame.Content._effectList[(int)index] = e;
     DuckGame.Content._effectMap[e.effect]    = e;
     DuckGame.Content._effects[e.effectName]  = e;
     e.SetEffectIndex(index);
 }
        public static MTEffect GetMTEffect(Effect e)
        {
            MTEffect mtEffect = (MTEffect)null;

            DuckGame.Content._effectMap.TryGetValue(e, out mtEffect);
            if (mtEffect == null)
            {
                mtEffect = new MTEffect(e, "", DuckGame.Content._currentEffectIndex);
                ++DuckGame.Content._currentEffectIndex;
                DuckGame.Content._effectList.Add(mtEffect);
                DuckGame.Content._effectMap[e] = mtEffect;
            }
            return(mtEffect);
        }
 public void StateChange(
     SpriteSortMode sortModeVal,
     BlendState blendStateVal,
     SamplerState samplerStateVal,
     DepthStencilState depthStencilStateVal,
     RasterizerState rasterizerStateVal,
     MTEffect effectVal,
     Matrix cameraVal,
     Rectangle sciss)
 {
     this._states[this.currentObject] = new RecorderFrameStateChange()
     {
         sortMode          = sortModeVal,
         blendState        = blendStateVal,
         samplerState      = samplerStateVal,
         depthStencilState = depthStencilStateVal,
         rasterizerState   = rasterizerStateVal,
         effectIndex       = effectVal != null ? effectVal.effectIndex : (short)-1,
         camera            = cameraVal,
         stateIndex        = DuckGame.Graphics.currentStateIndex,
         scissor           = sciss
     };
 }
Beispiel #7
0
 public void Begin(
     SpriteSortMode sortMode,
     BlendState blendState,
     SamplerState samplerState,
     DepthStencilState depthStencilState,
     RasterizerState rasterizerState,
     MTEffect effect,
     Matrix transformMatrix)
 {
     DuckGame.Graphics.currentStateIndex = this._globalIndex;
     if (this._beginCalled)
     {
         throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
     }
     base.Begin();
     if (Recorder.currentRecording != null)
     {
         Recorder.currentRecording.StateChange(sortMode, blendState, samplerState, depthStencilState, rasterizerState, Layer.IsBasicLayerEffect(effect) ? Layer.basicLayerEffect : effect, transformMatrix, (Rectangle)this.GraphicsDevice.ScissorRectangle);
     }
     if (Recorder.globalRecording != null)
     {
         Recorder.globalRecording.StateChange(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix, (Rectangle)this.GraphicsDevice.ScissorRectangle);
     }
     this._sortMode          = sortMode;
     this._blendState        = blendState ?? BlendState.AlphaBlend;
     this._samplerState      = samplerState ?? SamplerState.LinearClamp;
     this._depthStencilState = depthStencilState ?? DepthStencilState.None;
     this._rasterizerState   = rasterizerState ?? RasterizerState.CullCounterClockwise;
     this._effect            = (Effect)effect;
     this._matrix            = transformMatrix;
     if (sortMode == SpriteSortMode.Immediate)
     {
         this.Setup();
     }
     this._beginCalled = true;
 }
 public static T Load <T>(string name)
 {
     if (typeof(T) == typeof(Tex2D))
     {
         Tex2D tex2D = (Tex2D)null;
         lock (DuckGame.Content._textures)
             DuckGame.Content._textures.TryGetValue(name, out tex2D);
         if (tex2D == null)
         {
             Texture2D tex  = (Texture2D)null;
             bool      flag = false;
             if (MonoMain.moddingEnabled && ModLoader.modsEnabled && (name.Length > 1 && name[1] == ':'))
             {
                 flag = true;
             }
             if (!flag)
             {
                 lock (DuckGame.Content._loadLock)
                 {
                     try
                     {
                         tex = DuckGame.Content._base.Load <Texture2D>(name);
                     }
                     catch
                     {
                         flag = MonoMain.moddingEnabled && ModLoader.modsEnabled;
                     }
                 }
             }
             if (flag)
             {
                 foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
                 {
                     if (accessibleMod.configuration != null && accessibleMod.configuration.content != null)
                     {
                         tex = accessibleMod.configuration.content.Load <Texture2D>(name);
                     }
                     if (tex != null)
                     {
                         break;
                     }
                 }
             }
             else if (tex == null)
             {
                 try
                 {
                     tex = ContentPack.LoadTexture2D(name);
                 }
                 catch (Exception ex)
                 {
                 }
             }
             if (tex == null)
             {
                 tex = (Texture2D)DuckGame.Content.invalidTexture;
                 Main.SpecialCode = "Couldn't load texture " + name;
             }
             lock (DuckGame.Content._loadLock)
             {
                 tex2D = new Tex2D(tex, name, DuckGame.Content._currentTextureIndex);
                 ++DuckGame.Content._currentTextureIndex;
                 DuckGame.Content._textureList.Add(tex2D);
                 DuckGame.Content._textures[name]            = tex2D;
                 DuckGame.Content._texture2DMap[(object)tex] = tex2D;
             }
         }
         return((T)(Object)tex2D);
     }
     if (typeof(T) == typeof(MTEffect))
     {
         MTEffect mtEffect = (MTEffect)null;
         lock (DuckGame.Content._effects)
             DuckGame.Content._effects.TryGetValue(name, out mtEffect);
         if (mtEffect == null)
         {
             Effect effect = (Effect)null;
             lock (DuckGame.Content._loadLock)
                 effect = DuckGame.Content._base.Load <Effect>(name);
             lock (DuckGame.Content._loadLock)
             {
                 mtEffect = new MTEffect(effect, name, DuckGame.Content._currentEffectIndex);
                 ++DuckGame.Content._currentEffectIndex;
                 DuckGame.Content._effectList.Add(mtEffect);
                 DuckGame.Content._effects[name]     = mtEffect;
                 DuckGame.Content._effectMap[effect] = mtEffect;
             }
         }
         return((T)(Object)mtEffect);
     }
     if (typeof(T) == typeof(SoundEffect))
     {
         SoundEffect soundEffect = (SoundEffect)null;
         lock (DuckGame.Content._loadLock)
         {
             try
             {
                 soundEffect = DuckGame.Content._base.Load <SoundEffect>(name);
             }
             catch
             {
             }
         }
         if (MonoMain.moddingEnabled && ModLoader.modsEnabled && soundEffect == null)
         {
             foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
             {
                 if (accessibleMod.configuration != null && accessibleMod.configuration.content != null)
                 {
                     soundEffect = accessibleMod.configuration.content.Load <SoundEffect>(name);
                 }
                 if (soundEffect != null)
                 {
                     break;
                 }
             }
         }
         return((T)(Object)soundEffect);
     }
     if (!(typeof(T) == typeof(Song)))
     {
         return(DuckGame.Content._base.Load <T>(name));
     }
     if (MonoMain.moddingEnabled && ModLoader.modsEnabled)
     {
         foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
         {
             if (accessibleMod.configuration != null && accessibleMod.configuration.content != null)
             {
                 Song song = accessibleMod.configuration.content.Load <Song>(name);
                 if (song != null)
                 {
                     return((T)(Object)song);
                 }
             }
         }
     }
     return(default(T));
 }
Beispiel #9
0
        public void InitializeLayers()
        {
            Layer.lightingTwoPointOh = false;
            this._layers.Add(new Layer("PARALLAX", 100));
            this._parallax = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("VIRTUAL", 95));
            this._virtual = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("BACKGROUND", 90));
            this._background = this._layers[this._layers.Count - 1];
            this._background.enableCulling = true;
            this._layers.Add(new Layer("GAME"));
            this._game = this._layers[this._layers.Count - 1];
            this._game.enableCulling = false;
            this._layers.Add(new Layer("BLOCKS", -18));
            this._blocks = this._layers[this._layers.Count - 1];
            this._blocks.enableCulling = true;
            this._layers.Add(new Layer("FOREGROUND", -80));
            this._foreground = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("HUD", -90));
            this._hud = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("CONSOLE", -100, new Camera((float)DuckGame.Graphics.width, (float)DuckGame.Graphics.height)));
            this._console = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("GLOW", -20));
            this._glow = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("LIGHTING", Layer.lightingTwoPointOh ? -19 : -10, targetLayer: true, targetSize: new Vec2((float)DuckGame.Graphics.width, (float)DuckGame.Graphics.height)));
            this._lighting = this._layers[this._layers.Count - 1];
            this._layers.Add(new Layer("LIGHTING2", -15, targetLayer: true, targetSize: new Vec2((float)DuckGame.Graphics.width, (float)DuckGame.Graphics.height)));
            this._lighting2 = this._layers[this._layers.Count - 1];
            BlendState blendState = new BlendState();

            blendState.ColorSourceBlend      = Blend.Zero;
            blendState.ColorDestinationBlend = Blend.SourceColor;
            blendState.ColorBlendFunction    = BlendFunction.Add;
            blendState.AlphaSourceBlend      = Blend.Zero;
            blendState.AlphaDestinationBlend = Blend.SourceAlpha;
            blendState.AlphaBlendFunction    = BlendFunction.Add;
            this._glow.blend           = BlendState.Additive;
            this._lighting.targetBlend = BlendState.Additive;
            this._lighting.targetBlend = new BlendState()
            {
                ColorSourceBlend      = Blend.One,
                ColorDestinationBlend = Blend.One,
                ColorBlendFunction    = BlendFunction.Add,
                AlphaSourceBlend      = Blend.One,
                AlphaDestinationBlend = Blend.One,
                AlphaBlendFunction    = BlendFunction.Add
            };
            this._lighting.blend                  = blendState;
            this._lighting.targetClearColor       = new Color(150, 150, 150, 0);
            this._lighting.targetDepthStencil     = DepthStencilState.None;
            this._lighting.flashAddClearInfluence = 1f;
            this._lighting2.targetBlend           = BlendState.Additive;
            this._lighting2.blend                 = BlendState.Additive;
            this._lighting2.targetClearColor      = new Color(0, 0, 0);
            this._lighting2.targetDepthStencil    = DepthStencilState.None;
            this._lighting2.shareDrawObjects      = this._lighting;
            this._lighting2.targetFade            = 0.3f;
            this._layers = this._layers.OrderBy <Layer, int>((Func <Layer, int>)(l => - l.depth)).ToList <Layer>();
            Layer.Parallax.flashAddInfluence = 1f;
            Layer.HUD.flashAddInfluence      = 1f;
            if (this._basicEffect == null)
            {
                this._itemSpawnEffect         = Content.Load <MTEffect>("Shaders/wireframeTex");
                this._basicWireframeEffect    = Content.Load <MTEffect>("Shaders/wireframe");
                this._basicWireframeEffectTex = Content.Load <MTEffect>("Shaders/wireframeTex");
                this._basicEffect             = Content.Load <MTEffect>("Shaders/basic");
                this._basicEffectFade         = Content.Load <MTEffect>("Shaders/basicFade");
                this._basicEffectAdd          = Content.Load <MTEffect>("Shaders/basicAdd");
                this._basicEffectFadeAdd      = Content.Load <MTEffect>("Shaders/basicFadeAdd");
            }
            this.ResetLayers();
        }