Просмотр исходного кода

增加机器人模块,准备做服务器测试机器人

tanghai 13 лет назад
Родитель
Сommit
fddd8f30e5

+ 2 - 0
CSharp/App/Editor/Bootstrapper.cs

@@ -4,6 +4,7 @@ using Infrastructure;
 using Microsoft.Practices.Prism.MefExtensions;
 using Microsoft.Practices.Prism.Regions;
 using Modules.BehaviorTree;
+using Modules.Robot;
 
 namespace Editor
 {
@@ -14,6 +15,7 @@ namespace Editor
 			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (Bootstrapper).Assembly));
 			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (ViewExportAttribute).Assembly));
 			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (BehaviorTreeModule).Assembly));
+			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof (RobotModule).Assembly));
 		}
 
 		protected override void InitializeShell()

+ 4 - 0
CSharp/App/Editor/Editor.csproj

@@ -106,6 +106,10 @@
       <Project>{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3}</Project>
       <Name>Infrastructure</Name>
     </ProjectReference>
+    <ProjectReference Include="..\Modules\Robot\Robot.csproj">
+      <Project>{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}</Project>
+      <Name>Robot</Name>
+    </ProjectReference>
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />

+ 8 - 1
CSharp/App/Editor/Shell.xaml

@@ -3,6 +3,13 @@
         xmlns:prism="http://www.codeplex.com/prism" Title="Editor" Height="800" Width="1280"
         WindowStartupLocation="CenterScreen">
 	<Grid>
-		<ContentControl Name="treeCanvas" prism:RegionManager.RegionName="TreeCanvasRegion" />
+		<TabControl>
+			<TabItem Height="25" Width="80" Header="行为树">
+				<ContentControl Name="treeCanvas" prism:RegionManager.RegionName="TreeCanvasRegion" />
+			</TabItem>
+			<TabItem Height="25" Width="80" Header="机器人">
+				<ContentControl Name="robot" prism:RegionManager.RegionName="RobotRegion" />
+			</TabItem>
+		</TabControl>
 	</Grid>
 </Window>

+ 1 - 5
CSharp/App/Modules/BehaviorTree/BehaviorTreeModule.cs

@@ -3,15 +3,11 @@ using Microsoft.Practices.Prism.Modularity;
 
 namespace Modules.BehaviorTree
 {
-	[ModuleExport(typeof (BehaviorTreeModule))]
+	[ModuleExport(moduleType: typeof (BehaviorTreeModule))]
 	public class BehaviorTreeModule : IModule
 	{
-		#region IModule Members
-
 		public void Initialize()
 		{
 		}
-
-		#endregion
 	}
 }

+ 1 - 1
CSharp/App/Modules/BehaviorTree/BehaviorTreeViewModel.cs

@@ -3,7 +3,7 @@ using System.ComponentModel.Composition;
 
 namespace Modules.BehaviorTree
 {
-	[Export(typeof (BehaviorTreeViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
+	[Export(contractType: typeof (BehaviorTreeViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
 	internal class BehaviorTreeViewModel
 	{
 		private readonly ObservableCollection<TreeNodeViewModel> treeNodes = new ObservableCollection<TreeNodeViewModel>();

+ 6 - 0
CSharp/App/Modules/Robot/Packages.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="CommonServiceLocator" version="1.0" targetFramework="net45" />
+  <package id="Prism" version="4.1.0.0" targetFramework="net45" />
+  <package id="Prism.MEFExtensions" version="4.1.0.0" targetFramework="net45" />
+</packages>

+ 6 - 0
CSharp/App/Modules/Robot/Robot.cs

@@ -0,0 +1,6 @@
+namespace Modules.Robot
+{
+	public class Robot
+	{
+	}
+}

+ 100 - 0
CSharp/App/Modules/Robot/Robot.csproj

@@ -0,0 +1,100 @@
+<?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>{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Robot</RootNamespace>
+    <AssemblyName>Robot</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
+    <RestorePackages>true</RestorePackages>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Expression.Interactions.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Practices.Prism">
+      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Practices.Prism.Interactivity">
+      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.Interactivity.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Practices.Prism.MefExtensions">
+      <HintPath>..\..\..\packages\Prism.MEFExtensions.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.MefExtensions.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Practices.ServiceLocation">
+      <HintPath>..\..\..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
+    </Reference>
+    <Reference Include="NLog">
+      <HintPath>..\..\..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
+    </Reference>
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
+    <Reference Include="System" />
+    <Reference Include="System.ComponentModel.Composition" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\System.Windows.Interactivity.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Xaml" />
+    <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Robot.cs" />
+    <Compile Include="RobotModule.cs" />
+    <Compile Include="RobotViewModel.cs" />
+    <Compile Include="RobotView.xaml.cs">
+      <DependentUpon>RobotView.xaml</DependentUpon>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <Page Include="RobotView.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\Platform\Infrastructure\Infrastructure.csproj">
+      <Project>{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3}</Project>
+      <Name>Infrastructure</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Properties\" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Packages.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(SolutionDir)\.nuget\nuget.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>

+ 13 - 0
CSharp/App/Modules/Robot/RobotModule.cs

@@ -0,0 +1,13 @@
+using Microsoft.Practices.Prism.MefExtensions.Modularity;
+using Microsoft.Practices.Prism.Modularity;
+
+namespace Modules.Robot
+{
+	[ModuleExport(moduleType: typeof (RobotModule))]
+	public class RobotModule : IModule
+	{
+		public void Initialize()
+		{
+		}
+	}
+}

+ 15 - 0
CSharp/App/Modules/Robot/RobotView.xaml

@@ -0,0 +1,15 @@
+<UserControl x:Class="Modules.Robot.RobotView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Robot="clr-namespace:Modules.Robot"
+             mc:Ignorable="d" 
+             d:DesignHeight="600" d:DesignWidth="800" d:DataContext="{d:DesignInstance Robot:RobotViewModel}">
+	<Grid Height="597" Margin="1,1,1,4">
+		<StackPanel>
+			<Button Name="btnStart" Content="开始" Width="80" Height="25" Click="btnStart_Click" />
+			<TextBox Name="tbLog" Text="{Binding LogText, Mode=OneWay}" Height="700"
+					VerticalScrollBarVisibility="Visible" />
+		</StackPanel>
+	</Grid>
+</UserControl>

+ 37 - 0
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -0,0 +1,37 @@
+using System.ComponentModel.Composition;
+using System.Windows;
+using Infrastructure;
+
+namespace Modules.Robot
+{
+	/// <summary>
+	/// RobotView.xaml 的交互逻辑
+	/// </summary>
+	[ViewExport(RegionName = "RobotRegion"), PartCreationPolicy(CreationPolicy.NonShared)]
+	public partial class RobotView
+	{
+		public RobotView()
+		{
+			this.InitializeComponent();
+		}
+
+		[Import]
+		private RobotViewModel ViewModel
+		{
+			get
+			{
+				return this.DataContext as RobotViewModel;
+			}
+			set
+			{
+				this.DataContext = value;
+			}
+		}
+
+		private void btnStart_Click(object sender, RoutedEventArgs e)
+		{
+			this.ViewModel.Start();
+			this.tbLog.ScrollToEnd();
+		}
+	}
+}

+ 36 - 0
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -0,0 +1,36 @@
+using System;
+using System.ComponentModel.Composition;
+using Microsoft.Practices.Prism.ViewModel;
+using NLog;
+
+namespace Modules.Robot
+{
+	[Export(contractType: typeof (RobotViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
+	internal class RobotViewModel : NotificationObject
+	{
+		private static readonly Logger logger = LogManager.GetCurrentClassLogger();
+		private string logText = "";
+
+		public string LogText
+		{
+			get
+			{
+				return this.logText;
+			}
+			set
+			{
+				if (this.logText == value)
+				{
+					return;
+				}
+				this.logText = value;
+				this.RaisePropertyChanged("LogText");
+			}
+		}
+
+		public void Start()
+		{
+			this.LogText += "11111111111" + Environment.NewLine;
+		}
+	}
+}

+ 13 - 0
CSharp/CSharp.sln

@@ -24,6 +24,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThirdParty", "ThirdParty",
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enet", "ThirdParty\Enet\Enet.csproj", "{D0B4CFAC-A368-4742-9863-68776CFA9938}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robot", "App\Modules\Robot\Robot.csproj", "{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -74,6 +76,16 @@ Global
 		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
 		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{D0B4CFAC-A368-4742-9863-68776CFA9938}.Release|x86.ActiveCfg = Release|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|Any CPU.Build.0 = Release|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -83,6 +95,7 @@ Global
 		{C46F3337-0F48-4A72-84AD-8FDD1F159BB0} = {6E9D97F0-4243-452E-B832-1A855B8118EB}
 		{48A2E149-0DAC-41B4-BB54-DFBCCD6D42B3} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{6CD185D1-08E0-4729-A999-2D5B57BA8193} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
+		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{D0B4CFAC-A368-4742-9863-68776CFA9938} = {9173C593-D63F-49F6-AFA7-028425D13E4B}
 	EndGlobalSection
 EndGlobal

+ 3 - 1
CSharp/ThirdParty/Enet/Enet.csproj

@@ -53,7 +53,9 @@
     <Compile Include="PacketFlags.cs" />
     <Compile Include="Peer.cs" />
     <Compile Include="PeerState.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Properties\" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 5 - 4
CSharp/ThirdParty/Enet/Host.cs

@@ -79,14 +79,15 @@ namespace ENet
 			if (address != null)
 			{
 				Native.ENetAddress nativeAddress = address.Value.NativeData;
-				this.host = Native.enet_host_create(ref nativeAddress, (IntPtr) peerLimit, 
-					(IntPtr) channelLimit, incomingBandwidth, outgoingBandwidth);
+				this.host = Native.enet_host_create(
+				                                    ref nativeAddress, (IntPtr) peerLimit, (IntPtr) channelLimit, incomingBandwidth,
+				                                    outgoingBandwidth);
 			}
 			else
 			{
 				this.host = Native.enet_host_create(
-					null, (IntPtr) peerLimit, (IntPtr) channelLimit, 
-					incomingBandwidth, outgoingBandwidth);
+				                                    null, (IntPtr) peerLimit, (IntPtr) channelLimit, incomingBandwidth,
+				                                    outgoingBandwidth);
 			}
 			if (this.host == null)
 			{