[Agate-svn-commit] SF.net SVN: agate:[1487] trunk
Status: Alpha
Brought to you by:
kanato
From: <ka...@us...> - 2014-08-31 00:41:39
|
Revision: 1487 http://sourceforge.net/p/agate/code/1487 Author: kanato Date: 2014-08-31 00:41:35 +0000 (Sun, 31 Aug 2014) Log Message: ----------- Clean up models for windows store apps. Modified Paths: -------------- trunk/AgateLib/ApplicationModels/AgateAppModel.cs trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SceneModel.cs trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SerialModel.cs trunk/AgateLib.Platform.WindowsPhone/AgateLib.Platform.WindowsPhone.csproj trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SceneModel.cs trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferWindow.cs trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Display.cs trunk/AgateLib.Platform.WindowsStoreCommon/Resources/Basic2Dpixel.fxo trunk/AgateLib.Platform.WindowsStoreCommon/Resources/Basic2Dvert.fxo trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainBackgroundPanelAdapter.cs trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainPanelAdapter.cs trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs Added Paths: ----------- trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SerialModel.cs trunk/AgateLib.Platform.WindowsStoreCommon/ApplicationModels/WindowsStoreSerialModel.cs Modified: trunk/AgateLib/ApplicationModels/AgateAppModel.cs =================================================================== --- trunk/AgateLib/ApplicationModels/AgateAppModel.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib/ApplicationModels/AgateAppModel.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -89,12 +89,13 @@ /// </summary> public void Exit() { - Instance = null; QuitModel = true; SceneStack.Clear(); Dispose(); + + Instance = null; } /// <summary> Modified: trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SceneModel.cs =================================================================== --- trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SceneModel.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SceneModel.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -35,6 +35,8 @@ context.DeviceReset += context_DeviceReset; Parameters.RenderTarget.BindContextToRenderTarget(context); + + SDX_Display.PauseWhenNotRendering = false; } void context_DeviceReset(object sender, DeviceResetEventArgs e) Modified: trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SerialModel.cs =================================================================== --- trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SerialModel.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsMetro/ApplicationModels/SerialModel.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -10,86 +10,19 @@ namespace AgateLib.Platform.WindowsMetro.ApplicationModels { - public class SerialModel : EntryPointAppModelBase + public class SerialModel : WindowsStoreSerialModel { - SharpDXContext context; - - IAsyncAction gameThread; - bool exit; - bool threadRunning; - int retval; - public SerialModel(WindowsStoreSerialModelParameters parameters) : base(parameters) { } - public new WindowsStoreSerialModelParameters Parameters { get { return (WindowsStoreSerialModelParameters)base.Parameters; } } - protected override void InitializeImpl() { WindowsInitializer.Initialize(Parameters.RenderTarget, Parameters.AssetLocations); - context = SDX_Display.InitializerContext; - context.Render += context_Render; - context.DeviceReset += context_DeviceReset; - - Parameters.RenderTarget.BindContextToRenderTarget(context); - - SDX_Display.PauseWhenNotRendering = true; + InitWindowsStoreCommon(); } - void context_DeviceReset(object sender, DeviceResetEventArgs e) - { - } - - void context_Render(object sender, EventArgs e) - { - SDX_Display.RenderingFrame = true; - - while (SDX_Display.RenderingFrame) ; - } - - int ExecuteEntry(Func<int> entryPoint) - { - try - { - threadRunning = true; - - try - { - return entryPoint(); - } - catch (ExitGameException) - { - return 0; - } - } - finally - { - threadRunning = false; - } - } - - protected override int BeginModel(Func<int> entryPoint) - { - gameThread = Windows.System.Threading.ThreadPool.RunAsync( - (workItem) => { retval = ExecuteEntry(entryPoint); }); - - return 0; - } - - public override void KeepAlive() - { - if (exit) - throw new ExitGameException(); - - base.KeepAlive(); - } - - protected override void window_Closing(object sender, ref bool cancel) - { - exit = true; - } } } Modified: trunk/AgateLib.Platform.WindowsPhone/AgateLib.Platform.WindowsPhone.csproj =================================================================== --- trunk/AgateLib.Platform.WindowsPhone/AgateLib.Platform.WindowsPhone.csproj 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsPhone/AgateLib.Platform.WindowsPhone.csproj 2014-08-31 00:41:35 UTC (rev 1487) @@ -98,6 +98,7 @@ </ItemGroup> <ItemGroup> <Compile Include="ApplicationModels\SceneModel.cs" /> + <Compile Include="ApplicationModels\SerialModel.cs" /> <Compile Include="Factories\WindowsPhoneFactory.cs" /> <Compile Include="Factories\WPPlatformFactory.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> Modified: trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SceneModel.cs =================================================================== --- trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SceneModel.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SceneModel.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -35,6 +35,8 @@ context.DeviceReset += context_DeviceReset; Parameters.RenderTarget.BindContextToRenderTarget(context); + + SDX_Display.PauseWhenNotRendering = false; } void context_DeviceReset(object sender, DeviceResetEventArgs e) Added: trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SerialModel.cs =================================================================== --- trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SerialModel.cs (rev 0) +++ trunk/AgateLib.Platform.WindowsPhone/ApplicationModels/SerialModel.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -0,0 +1,24 @@ +using AgateLib.Platform.WindowsStore.ApplicationModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AgateLib.Platform.WindowsPhone.ApplicationModels +{ + public class SerialModel : WindowsStoreSerialModel + { + public SerialModel(WindowsStoreSerialModelParameters parameters) + : base(parameters) + { + } + + protected override void InitializeImpl() + { + WindowsPhoneInitializer.Initialize(Parameters.RenderTarget, Parameters.AssetLocations); + + InitWindowsStoreCommon(); + } + } +} Modified: trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsStoreCommon/AgateLib.Platform.WindowsStoreCommon.csproj 2014-08-31 00:41:35 UTC (rev 1487) @@ -51,6 +51,7 @@ <None Include="Resources\fxc.bat" /> </ItemGroup> <ItemGroup> + <Compile Include="ApplicationModels\WindowsStoreSerialModel.cs" /> <Compile Include="ApplicationModels\WindowsStoreSerialModelParameters.cs" /> <Compile Include="DisplayImplementation\D3DDevice.cs" /> <Compile Include="DisplayImplementation\DrawBuffer.cs" /> Added: trunk/AgateLib.Platform.WindowsStoreCommon/ApplicationModels/WindowsStoreSerialModel.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/ApplicationModels/WindowsStoreSerialModel.cs (rev 0) +++ trunk/AgateLib.Platform.WindowsStoreCommon/ApplicationModels/WindowsStoreSerialModel.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -0,0 +1,141 @@ +using AgateLib.ApplicationModels; +using AgateLib.Platform.WindowsStore.DisplayImplementation; +using SharpDX.SimpleInitializer; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Foundation; + +namespace AgateLib.Platform.WindowsStore.ApplicationModels +{ + public abstract class WindowsStoreSerialModel : EntryPointAppModelBase + { + SharpDXContext mContext; + + IAsyncAction gameThread; + bool exit; + bool threadRunning; + int retval; + + public WindowsStoreSerialModel(WindowsStoreSerialModelParameters parameters) + : base(parameters) + { + } + + public new WindowsStoreSerialModelParameters Parameters { get { return (WindowsStoreSerialModelParameters)base.Parameters; } } + + protected SharpDXContext Context + { + get { return mContext; } + set + { + DetachContextEvents(); + mContext = value; + AttachContextEvents(); + } + } + + protected void InitWindowsStoreCommon() + { + Context = SDX_Display.InitializerContext; + + Parameters.RenderTarget.BindContextToRenderTarget(Context); + SDX_Display.FrameCount = 0; + + SDX_Display.PauseWhenNotRendering = true; + + Parameters.RenderTarget.Disposed += RenderTarget_Disposed; + } + + protected override void Dispose(bool disposing) + { + KillThread(); + + base.Dispose(disposing); + } + void RenderTarget_Disposed(object sender, EventArgs e) + { + KillThread(); + } + + private void AttachContextEvents() + { + Context.Render += context_Render; + Context.DeviceReset += context_DeviceReset; + } + + private void DetachContextEvents() + { + if (mContext != null) + { + Context.Render -= context_Render; + Context.DeviceReset -= context_DeviceReset; + } + } + + void context_DeviceReset(object sender, DeviceResetEventArgs e) + { + } + + void context_Render(object sender, EventArgs e) + { + SDX_Display.RenderingFrame = true; + + while (threadRunning && SDX_Display.RenderingFrame && SDX_Display.WaitingForMainThread) ; + } + + int ExecuteEntry(Func<int> entryPoint) + { + try + { + threadRunning = true; + + try + { + return entryPoint(); + } + catch (ExitGameException) + { + return 0; + } + } + finally + { + threadRunning = false; + } + } + + protected override int BeginModel(Func<int> entryPoint) + { + gameThread = Windows.System.Threading.ThreadPool.RunAsync( + (workItem) => { retval = ExecuteEntry(entryPoint); }); + + return 0; + } + + public override void KeepAlive() + { + if (exit) + throw new ExitGameException(); + + base.KeepAlive(); + } + + protected override void window_Closing(object sender, ref bool cancel) + { + KillThread(); + } + + private void KillThread() + { + exit = true; + + while (threadRunning) + { + SDX_Display.RenderingFrame = true; + } + } + } +} Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferWindow.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferWindow.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/FrameBufferWindow.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -88,10 +88,8 @@ { if (SDX_Display.PauseWhenNotRendering) { - while (SDX_Display.RenderingFrame == false) - { - - } + SDX_Display.WaitingForMainThread = true; + while (SDX_Display.RenderingFrame == false && SDX_Display.WaitingForMainThread) ; } mContext.D3DContext.OutputMerger.SetTargets( @@ -102,6 +100,7 @@ public override void EndRender() { SDX_Display.RenderingFrame = false; + SDX_Display.WaitingForMainThread = false; } public override AgateLib.DisplayLib.DisplayWindow AttachedWindow Modified: trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Display.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Display.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsStoreCommon/DisplayImplementation/SDX_Display.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -227,17 +227,26 @@ #region --- BeginFrame stuff and DeltaTime --- + public bool InFrame { get; private set; } + protected override void OnBeginFrame() { + if (mRenderTarget is FrameBufferWindow) + FrameCount++; + mRenderTarget.BeginRender(); SetClipRect(new AgateLib.Geometry.Rectangle(new AgateLib.Geometry.Point(0, 0), mRenderTarget.Size)); mDevice.DeviceContext.OutputMerger.SetDepthStencilState(mDepthStencilState); + + InFrame = true; } protected override void OnEndFrame() { mDevice.DrawBuffer.Flush(); mRenderTarget.EndRender(); + + InFrame = false; } #endregion @@ -813,5 +822,9 @@ InitializeDeviceWrapper(); } + + public static int FrameCount { get; set; } + + public static bool WaitingForMainThread { get; set; } } } \ No newline at end of file Modified: trunk/AgateLib.Platform.WindowsStoreCommon/Resources/Basic2Dpixel.fxo =================================================================== (Binary files differ) Modified: trunk/AgateLib.Platform.WindowsStoreCommon/Resources/Basic2Dvert.fxo =================================================================== (Binary files differ) Modified: trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainBackgroundPanelAdapter.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainBackgroundPanelAdapter.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainBackgroundPanelAdapter.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -15,8 +15,20 @@ public SwapChainBackgroundPanelAdapter(SwapChainBackgroundPanel renderTarget) { mRenderTarget = renderTarget; + renderTarget.Unloaded += renderTarget_Unloaded; } + void renderTarget_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) + { + OnDisposed(); + } + + private void OnDisposed() + { + if (Disposed != null) + Disposed(this, EventArgs.Empty); + } + public SwapChainBackgroundPanel RenderTarget { get { return mRenderTarget; } } public DisplayLib.DisplayWindow Owner { get; set; } Modified: trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainPanelAdapter.cs =================================================================== --- trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainPanelAdapter.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Platform.WindowsStoreCommon/SwapChainPanelAdapter.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -24,6 +24,7 @@ AttachEvents(); } + public SwapChainPanel RenderTarget { get { return mRenderTarget; } } public DisplayLib.DisplayWindow Owner { get; set; } @@ -54,8 +55,21 @@ mRenderTarget.KeyDown += mRenderTarget_KeyDown; mRenderTarget.KeyUp += mRenderTarget_KeyUp; + + mRenderTarget.Unloaded += renderTarget_Unloaded; } + void renderTarget_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) + { + OnDisposed(); + } + + private void OnDisposed() + { + if (Disposed != null) + Disposed(this, EventArgs.Empty); + } + void mRenderTarget_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) { } Modified: trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs =================================================================== --- trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs 2014-08-30 23:55:55 UTC (rev 1486) +++ trunk/AgateLib.Tests/Tests.WindowsPhone/TestContainer.xaml.cs 2014-08-31 00:41:35 UTC (rev 1487) @@ -33,7 +33,7 @@ } public TestInfo Info { get; set;} - SceneModel model; + AgateAppModel model; /// <summary> /// Invoked when this page is about to be displayed in a Frame. @@ -47,26 +47,45 @@ IAgateTest t = (IAgateTest)Activator.CreateInstance(Info.Class); if (t is ISceneModelTest) - { RunTest((ISceneModelTest)t); - } + else if (t is ISerialModelTest) + RunTest((ISerialModelTest)t); } protected override void OnNavigatedFrom(NavigationEventArgs e) { AgateAppModel.Instance.Exit(); } + private void RunTest(ISerialModelTest t) + { + var parameters = new WindowsStoreSerialModelParameters(new SwapChainPanelAdapter(RenderTarget)); + + SetAssetPath(t, parameters.AssetLocations); + + t.ModifyModelParameters(parameters); + + var smodel = new SerialModel(parameters); + model = smodel; + smodel.Run(new Action(t.EntryPoint)); + } private void RunTest(ISceneModelTest t) { - var assemblyName = t.GetType().GetTypeInfo().Assembly.GetName().Name; - var parameters = new WindowsStoreSceneModelParameters(new SwapChainPanelAdapter(RenderTarget)); - parameters.AssetLocations.Path = "ms-appx:///" + assemblyName + "/Assets"; + SetAssetPath(t, parameters.AssetLocations); + t.ModifyModelParameters(parameters); - model = new SceneModel(parameters); - model.Run(t.StartScene); + var smodel = new SceneModel(parameters); + model = smodel; + smodel.Run(t.StartScene); } + + private static void SetAssetPath(IAgateTest t, AssetLocations assets) + { + var assemblyName = t.GetType().GetTypeInfo().Assembly.GetName().Name; + assets.Path = "ms-appx:///" + assemblyName + "/Assets"; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |