Added RecordingSample (working but ugly), some fixes in RecordingMouse

This commit is contained in:
SND\simsmaster_cp 2011-12-08 17:18:05 +00:00
parent 7d2de05ea0
commit 1d61c78f88
9 changed files with 393 additions and 14 deletions

View File

@ -115,6 +115,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.InputSystem.Recording",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.RenderSystem.Windows.Metro", "RenderSystems\ANX.RenderSystem.Windows.Metro\ANX.RenderSystem.Windows.Metro.csproj", "{FF0AB665-2796-4354-9630-76C2751DB3C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecordingSample", "RecordingSample\RecordingSample\RecordingSample.csproj", "{160150D5-38E6-482D-97F5-2624F322A854}"
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
@ -397,6 +399,16 @@ Global
{FF0AB665-2796-4354-9630-76C2751DB3C2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{FF0AB665-2796-4354-9630-76C2751DB3C2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{FF0AB665-2796-4354-9630-76C2751DB3C2}.Release|x86.ActiveCfg = Release|Any CPU
{160150D5-38E6-482D-97F5-2624F322A854}.Debug|Any CPU.ActiveCfg = Debug|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Debug|Mixed Platforms.Build.0 = Debug|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Debug|x86.ActiveCfg = Debug|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Debug|x86.Build.0 = Debug|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Release|Any CPU.ActiveCfg = Release|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Release|Mixed Platforms.ActiveCfg = Release|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Release|Mixed Platforms.Build.0 = Release|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Release|x86.ActiveCfg = Release|x86
{160150D5-38E6-482D-97F5-2624F322A854}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -420,6 +432,7 @@ Global
{71378D2F-0DCD-4413-8DE0-3FEC0BA04E27} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{41E6C2CF-51EA-4D8E-96AE-739CA3951766} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{57097B7A-A283-4409-8AAC-35BF0F458657} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{160150D5-38E6-482D-97F5-2624F322A854} = {9B0DD48B-3912-4F33-AF3F-691AF02B73F9}
{E5D69E75-D77C-493F-BBDA-6F9E73B82549} = {7AD65E6B-2A48-437F-81D9-4CA9C9A85C64}
{60D08399-244F-46A3-91F1-4CFD26D961A3} = {7AD65E6B-2A48-437F-81D9-4CA9C9A85C64}
{5CA3CDF5-4D2C-42AC-AD08-641BD3992B75} = {7AD65E6B-2A48-437F-81D9-4CA9C9A85C64}

View File

@ -85,6 +85,9 @@ namespace ANX.InputSystem.Recording
/// </summary>
protected void Initialize(Stream bufferStream)
{
if (!bufferStream.CanRead || !bufferStream.CanWrite)
throw new ArgumentException("The stream must support read and write opearions!", "bufferStream");
recordStream = bufferStream;
isInitialized = true;
@ -98,6 +101,10 @@ namespace ANX.InputSystem.Recording
if (RecordingState == RecordingState.Recording)
return;
//Reset the stream if we can seek
if(recordStream.CanSeek)
recordStream.Position = 0;
RecordingState = RecordingState.Recording;
}
@ -117,6 +124,10 @@ namespace ANX.InputSystem.Recording
if (RecordingState == RecordingState.Recording)
throw new InvalidOperationException("Recording is currently running for this device.");
//Reset the stream if we can seek
if (recordStream.CanSeek)
recordStream.Position = 0;
RecordingState = RecordingState.Playback;
}

View File

@ -99,15 +99,15 @@ namespace ANX.InputSystem.Recording
protected IMouse realMouse;
protected MouseRecordInfo recordInfo;
public IntPtr WindowHandle
{
get { return realMouse.WindowHandle; }
public IntPtr WindowHandle
{
get { return realMouse.WindowHandle; }
set { realMouse.WindowHandle = value; }
}
public MouseState GetState() //The main recording/playback logic is placed here
{
switch(RecordingState)
switch (RecordingState)
{
case RecordingState.None:
return realMouse.GetState();
@ -117,7 +117,7 @@ namespace ANX.InputSystem.Recording
if (stateData == null) //No input at this position
return new MouseState();
byte readOffset = 0;
ButtonState left, right, middle, x1, x2;
int scrollWheel, xPos, yPos;
@ -136,17 +136,26 @@ namespace ANX.InputSystem.Recording
left = right = middle = x1 = x2 = ButtonState.Released;
if (recordInfo.HasFlag(MouseRecordInfo.ScrollWheel))
scrollWheel = BitConverter.ToInt32(stateData, readOffset++);
{
scrollWheel = BitConverter.ToInt32(stateData, readOffset);
readOffset += 4;
}
else
scrollWheel = 0;
if (recordInfo.HasFlag(MouseRecordInfo.XPosition))
xPos = BitConverter.ToInt32(stateData, readOffset++);
{
xPos = BitConverter.ToInt32(stateData, readOffset);
readOffset += 4;
}
else
xPos = 0;
if (recordInfo.HasFlag(MouseRecordInfo.YPosition))
yPos = BitConverter.ToInt32(stateData, readOffset++);
{
yPos = BitConverter.ToInt32(stateData, readOffset);
readOffset += 4;
}
else
yPos = 0;
@ -168,13 +177,22 @@ namespace ANX.InputSystem.Recording
}
if (recordInfo.HasFlag(MouseRecordInfo.ScrollWheel))
Array.ConstrainedCopy(BitConverter.GetBytes(state.ScrollWheelValue), 0, buffer, writeOffset++, 4); //int is always 4 byte long.
{
Array.ConstrainedCopy(BitConverter.GetBytes(state.ScrollWheelValue), 0, buffer, writeOffset, 4); //int is always 4 byte long.
writeOffset += 4;
}
if(recordInfo.HasFlag(MouseRecordInfo.XPosition))
Array.ConstrainedCopy(BitConverter.GetBytes(state.X), 0, buffer, writeOffset++, 4); //int is always 4 byte long.
if (recordInfo.HasFlag(MouseRecordInfo.XPosition))
{
Array.ConstrainedCopy(BitConverter.GetBytes(state.X), 0, buffer, writeOffset, 4); //int is always 4 byte long.
writeOffset += 4;
}
if(recordInfo.HasFlag(MouseRecordInfo.YPosition))
Array.ConstrainedCopy(BitConverter.GetBytes(state.Y), 0, buffer, writeOffset++, 4); //int is always 4 byte long.
if (recordInfo.HasFlag(MouseRecordInfo.YPosition))
{
Array.ConstrainedCopy(BitConverter.GetBytes(state.Y), 0, buffer, writeOffset, 4); //int is always 4 byte long.
writeOffset += 4;
}
WriteState(buffer);
@ -226,7 +244,6 @@ namespace ANX.InputSystem.Recording
public void Initialize(MouseRecordInfo info, Stream bufferStream, IMouse mouse)
{
realMouse = mouse;
realMouse.WindowHandle = WindowHandle;
recordInfo = info;
PacketLenght = GetPaketSize(info);

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,138 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using ANX.Framework;
using ANX.Framework.Graphics;
using ANX.Framework.Input;
using ANX.Framework.NonXNA;
using ANX.InputSystem.Recording;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace RecordingSample
{
/// <summary>
/// Sample, showing the use of the RecordingSystem (currently only the Mouse).
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D logo;
RecordingMouse mouse;
KeyboardState oldState;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "SampleContent";
}
protected override void Initialize()
{
Window.Title = "Use Mouse to move arround, press r to record, p for playback and n for none";
mouse = (RecordingMouse)AddInSystemFactory.Instance.GetCreator<IInputSystemCreator>("Recording").Mouse;
mouse.Initialize(MouseRecordInfo.Position);
mouse.WindowHandle = Window.Handle;
mouse.EndOfPlaybackReached += new EventHandler((sender, args) => mouse.StopPlayback());
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
logo = Content.Load<Texture2D>(@"Textures/ANX.Framework.Logo_459x121");
oldState = Keyboard.GetState();
}
protected override void Update(GameTime gameTime)
{
KeyboardState newState = Keyboard.GetState();
if (oldState.IsKeyUp(Keys.R) && newState.IsKeyDown(Keys.R))
mouse.StartRecording();
if (oldState.IsKeyUp(Keys.P) && newState.IsKeyDown(Keys.P))
{
if (mouse.RecordingState == RecordingState.Recording)
mouse.StopRecording();
mouse.StartPlayback();
}
if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N))
{
if (mouse.RecordingState == RecordingState.Recording)
mouse.StartRecording();
mouse.StopPlayback();
}
oldState = newState;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(logo, new Rectangle(mouse.GetState().X, mouse.GetState().Y, 115, 30), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -0,0 +1,21 @@
using System;
namespace RecordingSample
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
#endif
}

View File

@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über den folgenden
// Satz von Attributen kontrolliert. Ändern Sie diese Attributwerte, um die mit einer Assembly
// verbundenen Informationen zu ändern.
[assembly: AssemblyTitle("RecordingSample")]
[assembly: AssemblyProduct("RecordingSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Bei Einstellung von ComVisible auf falsch sind die Typen in dieser Assembly für
// COM-Komponenten nicht sichtbar. Wenn Sie von COM aus auf einen Typ in dieser Assembly
// zugreifen müssen, stellen Sie das Attribut ComVisible bei diesem Typ auf wahr ein. Nur Windows-
// Assemblys unterstützen COM.
[assembly: ComVisible(false)]
// Auf Windows gilt die folgende GUID für die ID von typelib, wenn dieses
// COM ausgesetzt ist. Auf anderen Plattformen identifiziert sie den
// Titelspeichercontainer bei Bereitstellung dieser Assembly auf dem Gerät eindeutig.
[assembly: Guid("199e53b1-c103-417e-9c77-c650504fd35f")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Größere Version
// Kleinere Version
// Build-Nummer
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{160150D5-38E6-482D-97F5-2624F322A854}</ProjectGuid>
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RecordingSample</RootNamespace>
<AssemblyName>RecordingSample</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
<XnaProfile>Reach</XnaProfile>
<XnaCrossPlatformGroupID>7c7cc1e8-47d2-4253-8ab6-15ca8305b8e2</XnaCrossPlatformGroupID>
<XnaOutputType>Game</XnaOutputType>
<ApplicationIcon>Game.ico</ApplicationIcon>
<Thumbnail>GameThumbnail.png</Thumbnail>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\x86\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>false</XnaCompressContent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\x86\Release</OutputPath>
<DefineConstants>TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>true</XnaCompressContent>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Net" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Game1.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Game.ico" />
<Content Include="GameThumbnail.png">
<XnaPlatformSpecific>true</XnaPlatformSpecific>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ANX.Framework\ANX.Framework.csproj">
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\..\InputSystems\ANX.InputSystem.Recording\ANX.InputSystem.Recording.csproj">
<Project>{DB88DDEB-7281-405D-8FCA-5681B6B2BD7A}</Project>
<Name>ANX.InputSystem.Recording</Name>
</ProjectReference>
<ProjectReference Include="..\..\InputSystems\ANX.InputSystem.Windows.XInput\ANX.InputSystem.Windows.XInput.csproj">
<Project>{60D08399-244F-46A3-91F1-4CFD26D961A3}</Project>
<Name>ANX.InputSystem.Windows.XInput</Name>
</ProjectReference>
<ProjectReference Include="..\..\RenderSystems\ANX.Framework.Windows.DX10\ANX.Framework.Windows.DX10.csproj">
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
<Name>ANX.Framework.Windows.DX10</Name>
</ProjectReference>
<ProjectReference Include="..\..\Samples\SampleContent\SampleContent.contentproj">
<Project>{FA6E229D-4504-47B1-8A23-2D3FCC13F778}</Project>
<Name>SampleContent</Name>
<XnaReferenceType>Content</XnaReferenceType>
</ProjectReference>
<ProjectReference Include="..\..\SoundSystems\ANX.SoundSystem.Windows.XAudio\ANX.SoundSystem.Windows.XAudio.csproj">
<Project>{6A582788-C4D2-410C-96CD-177F75712D65}</Project>
<Name>ANX.SoundSystem.Windows.XAudio</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 und x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Xna.Framework.4.0">
<Visible>False</Visible>
<ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" />
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>