Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
[Toolkit.Yaml] Add new SharpDX.Toolkit.Yaml project that allows to lo…
Browse files Browse the repository at this point in the history
…ad Yaml files directly into .NET object using the ContentManager.
  • Loading branch information
xoofx committed Oct 22, 2013
1 parent 9fcab71 commit 2c069e7
Show file tree
Hide file tree
Showing 16 changed files with 1,287 additions and 7 deletions.
20 changes: 19 additions & 1 deletion Samples/SharpDXToolkitSamples.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld.Desktop", "Toolkit\Desktop\HelloWorld\HelloWorld.Desktop.csproj", "{05D111D6-C8FD-4DA4-B6C0-8C47E7081C3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomEffect.Desktop", "Toolkit\Desktop\CustomEffect\CustomEffect.Desktop.csproj", "{0C9A4884-6357-4392-9341-27B43E195456}"
Expand Down Expand Up @@ -71,6 +73,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShaderLinking.Desktop", "To
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ForegroundSwapChains.WinRT", "Toolkit\WinRT\ForegroundSwapChains\ForegroundSwapChains.WinRT.csproj", "{1855D2D9-0009-4825-A333-11230556445E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomDataLoading.Desktop", "Toolkit\Desktop\CustomDataLoading\CustomDataLoading.Desktop.csproj", "{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -826,6 +830,20 @@ Global
{1855D2D9-0009-4825-A333-11230556445E}.Release|x86.ActiveCfg = Release|x86
{1855D2D9-0009-4825-A333-11230556445E}.Release|x86.Build.0 = Release|x86
{1855D2D9-0009-4825-A333-11230556445E}.Release|x86.Deploy.0 = Release|x86
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|ARM.ActiveCfg = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|x64.ActiveCfg = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Debug|x86.ActiveCfg = Debug|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|Any CPU.Build.0 = Release|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|ARM.ActiveCfg = Release|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|x64.ActiveCfg = Release|Any CPU
{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 11 additions & 0 deletions Samples/Toolkit/Common/CustomDataLoading/Content/MyData.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
!MyData
Name: This text was loaded from MyData.yml
SimpleValue: 1.0
Color: { R: 128, G: 128, B: 128, A: 128}
Vectors:
- {X: 0, Y: 0, Z: 0, W: 1}
- {X: 1, Y: 0, Z: 0, W: 1}
- {X: 2, Y: 0, Z: 0, W: 1}
- {X: 3, Y: 0, Z: 0, W: 1}
- {X: 4, Y: 0, Z: 0, W: 1}
- {X: 5, Y: 0, Z: 0, W: 1}
111 changes: 111 additions & 0 deletions Samples/Toolkit/Common/CustomDataLoading/CustomDataLoadingGame.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System.Collections.Generic;

using SharpDX;
using SharpDX.Toolkit;
using SharpDX.Toolkit.Yaml;

namespace CustomLoadingData
{
// Use this namespace here in case we need to use Direct3D11 namespace as well, as this
// namespace will override the Direct3D11.
using SharpDX.Toolkit.Graphics;

/// <summary>
/// Simple CustomLoadingData application using SharpDX.Toolkit.
/// The purpose of this application is to demonstrate how to load YAML data into .NET objects
/// using the Content Manager.
/// </summary>
public class CustomLoadingDataGame : Game
{
private GraphicsDeviceManager graphicsDeviceManager;
private YamlManager yamlManager;
private MyData loadedMyData;

/// <summary>
/// Initializes a new instance of the <see cref="CustomLoadingDataGame" /> class.
/// </summary>
public CustomLoadingDataGame()
{
// Creates a graphics manager. This is mandatory.
graphicsDeviceManager = new GraphicsDeviceManager(this);
graphicsDeviceManager.PreferredDepthStencilFormat = DepthFormat.None;


// In order to support Yaml loading, we need to add the YamlManager
yamlManager = new YamlManager(this);
GameSystems.Add(yamlManager);

// Register that !MyData will map to our local type.
// We could have used YamlTagAttribute directly on our MyData type from YamlDotNet library.
yamlManager.RegisterTagMapping("MyData",typeof(MyData));

// Setup the relative directory to the executable directory
// for loading contents with the ContentManager
Content.RootDirectory = "Content";
}

protected override void Initialize()
{
Window.Title = "Yaml Data Loading";

base.Initialize();
}

protected override void LoadContent()
{
loadedMyData = Content.Load<MyData>("MyData.yml");
Window.Title = string.Format("Yaml Data Loading: [{0}]", loadedMyData.Name);

base.LoadContent();
}

protected override void Draw(GameTime gameTime)
{
// Clear the color using MyData
GraphicsDevice.Clear(loadedMyData.Color);

// Handle base.Draw
base.Draw(gameTime);
}


/// <summary>
/// A Simple type demonstrating how to load data from YAML to .NET object instance.
/// </summary>
public class MyData
{
public MyData()
{
Vectors = new List<Vector4>();
}

public string Name { get; set; }

public Color Color { get; set; }

public float SimpleValue { get; set; }

public List<Vector4> Vectors { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{72E1AFCD-4E5B-428A-A4C8-0B179F660BA6}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CustomDataLoading</RootNamespace>
<AssemblyName>CustomDataLoading.Desktop</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Common\CustomDataLoading\CustomDataLoadingGame.cs">
<Link>CustomDataLoadingGame.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\Common\CustomDataLoading\Content\MyData.yml">
<Link>Content\MyData.yml</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\..\SharpDX.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>
44 changes: 44 additions & 0 deletions Samples/Toolkit/Desktop/CustomDataLoading/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace CustomLoadingData
{
/// <summary>
/// Simple SpriteBatchAndFont application using SharpDX.Toolkit.
/// </summary>
class Program
{
/// <summary>
/// Defines the entry point of the application.
/// </summary>
#if NETFX_CORE
[MTAThread]
#else
[STAThread]
#endif
static void Main()
{
using (var program = new CustomLoadingDataGame())
program.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SpriteBatchAndFont")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpriteBatchAndFont")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("aa8e09eb-19f9-44df-a586-c0b424001031")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 2c069e7

Please sign in to comment.