Example #1
0
        /// <summary>
        /// 更新する
        /// </summary>
        /// <param name="inputInfo">入力の情報</param>
        /// <param name="mouseInfo">マウスの情報</param>
        /// <param name="sound">サウンド</param>
        public void Update(InputInfoBase inputInfo, MouseInfo mouseInfo, ISound sound)
        {
            Sound = sound;
            if (previousScene != null)
            {
                previousScene.Dispose();
                if (!previousSceneResourceUsing && !PPDSetting.Setting.AllowedToUseMuchMemory && previousScene.ResourceManager != null)
                {
                    previousScene.ResourceManager.Dispose();
                }
                previousScene = null;
                device.GetModule <CharCacheManager>().ClearUnUsed();
            }
            if (nextScene != null)
            {
                if (LoadFinished)
                {
#if DEBUG
                    Console.WriteLine("LoadTime is:" + (Environment.TickCount - lastTime));
#if BENCHMARK
                    Benchmark.Instance.EndCategory();
#endif
#endif
                    loadingThread.Join();
                    loadingThread = null;
                    device.GetModule <CharCacheManager>().ClearUnUsed();
                    if (loadResult)
                    {
                        CurrentScene = nextScene;
                    }
                    else
                    {
                        previousScene = nextScene;
                        CurrentScene  = sceneStack.Pop();
                        CurrentScene.SceneStackPoped(new Dictionary <string, object>
                        {
                            { "Failed to initialize", "" }
                        });
                    }
                    nextScene = null;
                    if (LeaveLoading != null)
                    {
                        LeaveLoading.Invoke(this, EventArgs.Empty);
                    }
                }
            }
            if (CurrentScene != null)
            {
                CurrentScene.Update(inputInfo, mouseInfo);
            }
            if (loadingThread != null && LoadingScene != null)
            {
                LoadingScene.Update(inputInfo, mouseInfo);
            }
        }
Example #2
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="device"></param>
 /// <param name="c">文字</param>
 /// <param name="x">x</param>
 /// <param name="y">y</param>
 /// <param name="fontsize">フォントサイズ</param>
 /// <param name="facename">フォント名</param>
 /// <param name="color">色</param>
 public TextureChar(PPDDevice device, char c, float x, float y, float fontsize, string facename, Color4 color)
 {
     this.device   = device;
     Position      = new Vector2(x, y);
     this.c        = c;
     this.color    = color;
     fontsize      = PPDSetting.Setting.GetAdjustedFontSize(fontsize);
     this.facename = facename;
     isSpace       = CheckSpace();
     cci           = device.GetModule <CharCacheManager>().Get(fontsize, facename, this.c);
     vertices      = device.GetModule <ShaderCommon>().CreateVertex(4);
 }
Example #3
0
        /// <summary>
        /// 描画します
        /// </summary>
        /// <param name="alphaBlendContext">コンテキスト</param>
        /// <param name="startX">表示をはじめるピクセルのx座標(0からwidth)</param>
        /// <param name="endX">表示をおえるピクセルのx座標(0からwidthかつsx以上)</param>
        public void Draw(AlphaBlendContext alphaBlendContext, float startX, float endX)
        {
            if (Hidden || isSpace)
            {
                return;
            }

            if (prevPosition != Position || prevStartX != startX || prevEndX != endX)
            {
                prevPosition = Position;
                prevStartX   = startX;
                prevEndX     = endX;
                float posX0 = Position.X + startX, posX1 = Position.X + endX,
                      posY0 = Position.Y, posY1 = Position.Y + cci.Height;
                var rect = cci.GetActualUVRectangle(startX / (float)cci.Width, 0, endX / (float)cci.Width, 1);
                vertices.Write(new[] {
                    new ColoredTexturedVertex(new Vector3(posX0, posY0, 0.5f), rect.TopLeft),
                    new ColoredTexturedVertex(new Vector3(posX1, posY0, 0.5f), rect.TopRight),
                    new ColoredTexturedVertex(new Vector3(posX0, posY1, 0.5f), rect.BottomLeft),
                    new ColoredTexturedVertex(new Vector3(posX1, posY1, 0.5f), rect.BottomRight)
                });
            }
            alphaBlendContext.Texture = cci.Texture;
            alphaBlendContext.Vertex  = vertices;
            device.GetModule <AlphaBlend>().Draw(device, alphaBlendContext);
        }
Example #4
0
        /// <summary>
        /// ルーチンを実行します。
        /// </summary>
        public void Routine()
        {
            nextframe = gameTimer.ElapsedTickTime;
            PreventScreenSaver();
            long   last             = gameTimer.ElapsedTime;
            double beforeUpdateTime = gameTimer.ElapsedTickTime;

            Update();
            LastUpdateTime = (float)(gameTimer.ElapsedTickTime - beforeUpdateTime);
            long current = gameTimer.ElapsedTime;

            if ((double)current < nextframe + wait)
            {
                double beforeDrawTime = gameTimer.ElapsedTickTime;
                device.DrawStart();
                Draw();
                foreach (var rect in blackRectangles)
                {
                    rect.Draw();
                }
                device.GetModule <AlphaBlendContextCache>().Reset();
#if BENCHMARK
                Benchmark.Instance.EndLoop();
#endif
                DrawEnd();
                device.DrawEnd();
                LastDrawTime = (float)(gameTimer.ElapsedTickTime - beforeDrawTime);
                try
                {
                    //更新
                    var diff = (int)(lastPresentEndTime + wait - gameTimer.ElapsedTickTime - 1);
                    if (diff > 0)
                    {
                        Thread.Sleep(diff);
                    }
                    device.Present();
                    lastPresentEndTime = gameTimer.ElapsedTickTime;
                    presentCount++;
                    if (presentCount >= 60)
                    {
                        FPS = (float)(1000 / (lastPresentEndTime - presentStartTime) * 60);
                        if (ShowFPS)
                        {
                            CurrentFPS = String.Format("PPD FPS:{0}", FPS);
                        }
                        presentCount     = 0;
                        presentStartTime = lastPresentEndTime;
                    }
                }
                catch (SharpDXException e)
                {
                    if (e.ResultCode == SharpDX.Direct3D9.ResultCode.DeviceLost)
                    {
                        device.ResetDevice();
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// DirectXを初期化します。
        /// </summary>
        /// <returns></returns>
        public bool InitializeDirectX(int?width = 800, int?height = 450, int?expectedWidth = 800, int?expectedHeight = 450, float?expectedAspectRatio = 16f / 9)
        {
            try
            {
                if (width <= 0)
                {
                    width = 800;
                }
                if (height <= 0)
                {
                    height = 450;
                }
                Control.Size = new System.Drawing.Size(width.Value, height.Value);
                InitializeUI();

                device = PPDDevice.Initialize(Control.Handle, width.Value, height.Value, expectedWidth.Value, expectedHeight.Value, expectedAspectRatio.Value);
                device.RegisterModule(new AlphaBlendContextCache(1024));
                device.RegisterModule(new ShaderCommon(device));
                device.RegisterModule(new ColorTextureAllcator(device));
                device.RegisterModule(new CharCacheManager(device));
                device.RegisterModule(new AlphaBlend(device));
                device.RegisterModule(new GaussianFilter(device));
                device.RegisterModule(new ColorScreenFilter());
                device.RegisterModule(new GlassFilter(device));
                device.RegisterModule(new BorderFilter(device));
                device.RegisterModule(new MosaicFilter(device));
                device.GetModule <ShaderCommon>().InitializeScreenVertex(device);
                resourceManager = new PPDFramework.Resource.ResourceManager();
                blackRectangles = new RectangleComponent[2];
                for (var i = 0; i < blackRectangles.Length; i++)
                {
                    blackRectangles[i] = new RectangleComponent(device, resourceManager, PPDColors.Black);
                }
                var invScale = 1 / device.Scale.X;
                if (device.Offset.X == 0)
                {
                    blackRectangles[0].Position        = new Vector2(0, -device.Offset.Y * invScale);
                    blackRectangles[0].RectangleWidth  = width.Value * invScale;
                    blackRectangles[0].RectangleHeight = device.Offset.Y * invScale;
                    blackRectangles[1].Position        = new Vector2(0, device.ExpectedHeight);
                    blackRectangles[1].RectangleWidth  = width.Value * invScale;
                    blackRectangles[1].RectangleHeight = device.Offset.Y * invScale;
                }
                else
                {
                    blackRectangles[0].Position        = new Vector2(-device.Offset.X * invScale, 0);
                    blackRectangles[0].RectangleWidth  = device.Offset.X * invScale;
                    blackRectangles[0].RectangleHeight = height.Value * invScale;
                    blackRectangles[1].Position        = new Vector2(device.ExpectedWidth, 0);
                    blackRectangles[1].RectangleWidth  = device.Offset.X * invScale;
                    blackRectangles[1].RectangleHeight = height.Value * invScale;
                }
                blackRectangles[0].Update();
                blackRectangles[1].Update();
                return(true);
            }
#if DEBUG
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
                throw;
#else
            catch
            {
                //初期化失敗
                return(false);
#endif
            }
        }
Example #6
0
        /// <summary>
        /// 描画する
        /// </summary>
        public virtual void Draw()
        {
            var alphaBlendContext = device.GetModule <AlphaBlendContextCache>().Get();

            alphaBlendContext.Alpha     = Alpha;
            alphaBlendContext.BlendMode = BlendMode.Normal;
            Draw(alphaBlendContext, 0, 0);
        }
Example #7
0
 /// <summary>
 /// コンストラクタです。
 /// </summary>
 /// <param name="device"></param>
 /// <param name="resourceManager"></param>
 /// <param name="color"></param>
 public RectangleComponent(PPDDevice device, PPDFramework.Resource.ResourceManager resourceManager, Color4 color) : base(device)
 {
     this.resourceManager = resourceManager;
     UpdateResource(color);
     vertices = device.GetModule <ShaderCommon>().CreateVertex(4);
 }