port from perforce
This commit is contained in:
133
aiwaz/Aiwaz.Common/Aiwaz.Common.csproj
Normal file
133
aiwaz/Aiwaz.Common/Aiwaz.Common.csproj
Normal file
@@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0F7D7168-08C1-45AE-AAE3-80506939D7E6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Aiwaz.Common</RootNamespace>
|
||||
<AssemblyName>Aiwaz.Common</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<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|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>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Ionic.Zip, Version=1.8.4.29, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Ionic.Zip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Animations\AnimateableAttribute.cs" />
|
||||
<Compile Include="Animations\Animation.cs" />
|
||||
<Compile Include="Animations\AnimationManager.cs" />
|
||||
<Compile Include="Animations\CosineValueAnimation.cs" />
|
||||
<Compile Include="Animations\Event.cs" />
|
||||
<Compile Include="Animations\LinearValueAnimation.cs" />
|
||||
<Compile Include="FileSystem.cs" />
|
||||
<Compile Include="HiPerfTimer.cs" />
|
||||
<Compile Include="Win32Console.cs" />
|
||||
<Compile Include="Timeline.cs" />
|
||||
<Compile Include="Animations\ValueAnimation.cs" />
|
||||
<Compile Include="Pair.cs" />
|
||||
<Compile Include="ObjectFactory.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Aiwaz.Contracts\Aiwaz.Contracts.csproj">
|
||||
<Project>{DE4D6FE6-D1FB-41A1-8ABA-19635B8FFD7A}</Project>
|
||||
<Name>Aiwaz.Contracts</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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
aiwaz/Aiwaz.Common/Aiwaz.Common.csproj.user
Normal file
13
aiwaz/Aiwaz.Common/Aiwaz.Common.csproj.user
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishUrlHistory />
|
||||
<InstallUrlHistory />
|
||||
<SupportUrlHistory />
|
||||
<UpdateUrlHistory />
|
||||
<BootstrapperUrlHistory />
|
||||
<ErrorReportUrlHistory />
|
||||
<FallbackCulture>en-US</FallbackCulture>
|
||||
<VerifyUploadedFiles>false</VerifyUploadedFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
12
aiwaz/Aiwaz.Common/Animations/AnimateableAttribute.cs
Normal file
12
aiwaz/Aiwaz.Common/Animations/AnimateableAttribute.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class Animateable : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
16
aiwaz/Aiwaz.Common/Animations/Animation.cs
Normal file
16
aiwaz/Aiwaz.Common/Animations/Animation.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
abstract public class Animation
|
||||
{
|
||||
public double StartTime { get; set; }
|
||||
public double EndTime { get; set; }
|
||||
public string AnimationName;
|
||||
|
||||
public Animation()
|
||||
{
|
||||
AnimationName = "Erroneous";
|
||||
}
|
||||
|
||||
public abstract void Animate(double time, uint userData);
|
||||
}
|
||||
}
|
||||
164
aiwaz/Aiwaz.Common/Animations/AnimationManager.cs
Normal file
164
aiwaz/Aiwaz.Common/Animations/AnimationManager.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
struct AnimationInterval
|
||||
{
|
||||
public AnimationInterval(double argBegin, double argEnd)
|
||||
{
|
||||
begin = argBegin;
|
||||
end = argEnd;
|
||||
}
|
||||
|
||||
public double begin;
|
||||
public double end;
|
||||
}
|
||||
|
||||
class ForwardComparer : IComparer<AnimationInterval>
|
||||
{
|
||||
public int Compare(AnimationInterval a, AnimationInterval b)
|
||||
{
|
||||
return a.begin < b.begin ? -1 : (a.begin > b.begin ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
class BackwardComparer : IComparer<AnimationInterval>
|
||||
{
|
||||
public int Compare(AnimationInterval a, AnimationInterval b)
|
||||
{
|
||||
return a.end > b.end ? -1 : (a.end > b.end ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnimationManager
|
||||
{
|
||||
private static SortedList<AnimationInterval, List<Pair<Animation, uint>>> forwardSortedAnimations = new SortedList<AnimationInterval, List<Pair<Animation, uint>>>(new ForwardComparer());
|
||||
private static SortedList<AnimationInterval, List<Pair<Animation, uint>>> backwardSortedAnimations = new SortedList<AnimationInterval, List<Pair<Animation, uint>>>(new BackwardComparer());
|
||||
private static SortedList<AnimationInterval, List<Pair<Animation, uint>>> realTimeAnimations = new SortedList<AnimationInterval, List<Pair<Animation, uint>>>(new ForwardComparer());
|
||||
private static SortedList<double, List<Pair<Event, uint>>> demoTimeEvents = new SortedList<double, List<Pair<Event, uint>>>();
|
||||
private static SortedList<double, List<Pair<Event, uint>>> realTimeEvents = new SortedList<double, List<Pair<Event, uint>>>();
|
||||
|
||||
private static double previousDemoTime;
|
||||
private static double previousRealTime;
|
||||
|
||||
public static void AddDemoTimeAnimation(double argBeginTime, double argEndTime, Animation argAnimation, uint argUserData)
|
||||
{
|
||||
forwardSortedAnimations[new AnimationInterval(argBeginTime, argEndTime)].Add(new Pair<Animation, uint>(argAnimation, argUserData));
|
||||
backwardSortedAnimations[new AnimationInterval(argBeginTime, argEndTime)].Add(new Pair<Animation, uint>(argAnimation, argUserData));
|
||||
}
|
||||
|
||||
public static void AddRealTimeAnimation(double argBeginTime, double argEndTime, Animation argAnimation, uint argUserData)
|
||||
{
|
||||
realTimeAnimations[new AnimationInterval(argBeginTime, argEndTime)].Add(new Pair<Animation, uint>(argAnimation, argUserData));
|
||||
}
|
||||
|
||||
public static void AddDemoTimeEvent(double argTime, Event argEvent, uint argUserData)
|
||||
{
|
||||
demoTimeEvents[argTime].Add(new Pair<Event, uint>(argEvent, argUserData));
|
||||
}
|
||||
|
||||
public static void AddRealTimeEvent(double argTime, Event argEvent, uint argUserData)
|
||||
{
|
||||
realTimeEvents[argTime].Add(new Pair<Event, uint>(argEvent, argUserData));
|
||||
}
|
||||
|
||||
public static void Animate()
|
||||
{
|
||||
double demoTime = Timeline.DemoTime;
|
||||
double realTime = Timeline.RealTime;
|
||||
|
||||
// Gather all active animations, they are the ones that started before now and end after now.
|
||||
// Do this for both the demo time and real time.
|
||||
List<Pair<Pair<Animation, uint>, double>> lk_ActiveAnimations = new List<Pair<Pair<Animation, uint>, double>>();
|
||||
|
||||
// Demo time animations: Demo time can go backwards, so search from both directions
|
||||
if (Timeline.SpeedAndDirection > 0)
|
||||
{
|
||||
foreach (var entry in forwardSortedAnimations)
|
||||
{
|
||||
if (entry.Key.begin <= demoTime && entry.Key.end >= demoTime)
|
||||
{
|
||||
foreach (var animation in entry.Value)
|
||||
{
|
||||
lk_ActiveAnimations.Add(new Pair<Pair<Animation, uint>, double>(animation, (demoTime - entry.Key.begin) / (entry.Key.end - entry.Key.begin)));
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.Key.begin > demoTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Timeline.SpeedAndDirection < 0)
|
||||
{
|
||||
foreach (var entry in backwardSortedAnimations)
|
||||
{
|
||||
if (entry.Key.end >= demoTime && entry.Key.begin <= demoTime)
|
||||
{
|
||||
foreach (var animation in entry.Value)
|
||||
{
|
||||
lk_ActiveAnimations.Add(new Pair<Pair<Animation, uint>, double>(animation, (demoTime - entry.Key.begin) / (entry.Key.end - entry.Key.begin)));
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.Key.end < demoTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Real time animations: The time that we know doesn't allow us to travel to the past, so just check into the future:
|
||||
foreach (var entry in realTimeAnimations)
|
||||
{
|
||||
if (entry.Key.begin <= demoTime && entry.Key.end >= demoTime)
|
||||
{
|
||||
foreach (var animation in entry.Value)
|
||||
{
|
||||
lk_ActiveAnimations.Add(new Pair<Pair<Animation, uint>, double>(animation, (demoTime - entry.Key.begin) / (entry.Key.end - entry.Key.begin)));
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.Key.begin > demoTime)
|
||||
break;
|
||||
}
|
||||
|
||||
// Now that we know what animations correspond to this time, animate them!
|
||||
foreach (var anim in lk_ActiveAnimations)
|
||||
{
|
||||
anim.First.First.Animate(anim.Second, anim.First.Second);
|
||||
}
|
||||
|
||||
// Fire all events that happened since last time:
|
||||
foreach (var entry in demoTimeEvents)
|
||||
{
|
||||
double time = entry.Key;
|
||||
|
||||
foreach (var evt in entry.Value)
|
||||
{
|
||||
if ((Timeline.SpeedAndDirection > 0) && (time >= previousDemoTime && time <= demoTime))
|
||||
{
|
||||
evt.First.Do(evt.Second);
|
||||
}
|
||||
else if ((Timeline.SpeedAndDirection < 0) && (time <= previousDemoTime && time >= demoTime))
|
||||
{
|
||||
evt.First.Undo(evt.Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entry in realTimeEvents)
|
||||
{
|
||||
double time = entry.Key;
|
||||
|
||||
foreach (var evt in entry.Value)
|
||||
{
|
||||
if (time >= previousDemoTime && time <= demoTime)
|
||||
{
|
||||
evt.First.Do(evt.Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousDemoTime = demoTime;
|
||||
previousRealTime = realTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
aiwaz/Aiwaz.Common/Animations/CosineValueAnimation.cs
Normal file
22
aiwaz/Aiwaz.Common/Animations/CosineValueAnimation.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
public class CosineValueAnimation : ValueAnimation
|
||||
{
|
||||
public CosineValueAnimation()
|
||||
: base()
|
||||
{
|
||||
AnimationName = "Cosine";
|
||||
}
|
||||
|
||||
protected override float Calculate(double NormalizedTime)
|
||||
{
|
||||
float Interpolant = (float)((1.0 - Math.Cos(NormalizedTime * Math.PI)) / 2.0);
|
||||
return (StartValue * (1.0f - Interpolant) + EndValue * Interpolant);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
aiwaz/Aiwaz.Common/Animations/Event.cs
Normal file
13
aiwaz/Aiwaz.Common/Animations/Event.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
abstract public class Event
|
||||
{
|
||||
abstract public Action<uint> Do { get; }
|
||||
abstract public Action<uint> Undo { get; }
|
||||
}
|
||||
}
|
||||
21
aiwaz/Aiwaz.Common/Animations/LinearValueAnimation.cs
Normal file
21
aiwaz/Aiwaz.Common/Animations/LinearValueAnimation.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
public class LinearValueAnimation : ValueAnimation
|
||||
{
|
||||
public LinearValueAnimation()
|
||||
: base()
|
||||
{
|
||||
AnimationName = "Linear";
|
||||
}
|
||||
|
||||
protected override float Calculate(double NormalizedTime)
|
||||
{
|
||||
return (float)(StartValue * (1.0 - NormalizedTime) + EndValue * NormalizedTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
aiwaz/Aiwaz.Common/Animations/ValueAnimation.cs
Normal file
40
aiwaz/Aiwaz.Common/Animations/ValueAnimation.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common.Animations
|
||||
{
|
||||
abstract public class ValueAnimation : Animation
|
||||
{
|
||||
public float StartValue { get; set; }
|
||||
public float EndValue { get; set; }
|
||||
|
||||
public Func<float> ValueGetter;
|
||||
public Action<float> ValueSetter;
|
||||
public Func<string> ValueNamer;
|
||||
|
||||
public float Value
|
||||
{
|
||||
get { return ValueGetter(); }
|
||||
set { ValueSetter(value); }
|
||||
}
|
||||
|
||||
public ValueAnimation()
|
||||
: base()
|
||||
{
|
||||
AnimationName = "Erroneous (Value)";
|
||||
}
|
||||
|
||||
public override void Animate(double time, uint userData)
|
||||
{
|
||||
if (time < StartTime || time > EndTime)
|
||||
return;
|
||||
|
||||
double Time = (time - StartTime) / (EndTime - StartTime);
|
||||
Value = Calculate(Time);
|
||||
}
|
||||
|
||||
protected abstract float Calculate(double NormalizedTime);
|
||||
}
|
||||
}
|
||||
120
aiwaz/Aiwaz.Common/FileSystem.cs
Normal file
120
aiwaz/Aiwaz.Common/FileSystem.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Ionic.Zip;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public class FileSystem : IDisposable
|
||||
{
|
||||
private Dictionary<string, Action<Stream>> attachedFiles = new Dictionary<string, Action<Stream>>();
|
||||
private ZipFile zipFile;
|
||||
private FileSystemWatcher watcher;
|
||||
private string directory;
|
||||
public FileSystem()
|
||||
{
|
||||
directory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
|
||||
this.watcher = new FileSystemWatcher(directory);
|
||||
this.watcher.NotifyFilter = NotifyFilters.LastWrite;
|
||||
this.watcher.IncludeSubdirectories = true;
|
||||
this.watcher.Changed += watcher_Changed;
|
||||
this.watcher.EnableRaisingEvents = true;
|
||||
if (File.Exists(Path.Combine(directory, "data.pak")))
|
||||
{
|
||||
zipFile = ZipFile.Read(Path.Combine(directory, "data.pak"));
|
||||
}
|
||||
}
|
||||
|
||||
void watcher_Changed(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
foreach (var entry in attachedFiles)
|
||||
{
|
||||
if (e.FullPath == entry.Key)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = new FileStream(e.FullPath, FileMode.Open);
|
||||
entry.Value(stream);
|
||||
break;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~FileSystem()
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
public void Attach(string argFileName, Action<Stream> onLoaded)
|
||||
{
|
||||
if (File.Exists(Path.Combine(directory, argFileName)))
|
||||
{
|
||||
Stream fileStream = new FileStream(Path.Combine(directory, argFileName), FileMode.Open);
|
||||
if (fileStream != null && onLoaded != null)
|
||||
{
|
||||
var fullPath = Path.Combine(directory, argFileName).Replace('/', '\\');
|
||||
attachedFiles[fullPath] = onLoaded;
|
||||
onLoaded(fileStream);
|
||||
}
|
||||
}
|
||||
else if (zipFile != null)
|
||||
{
|
||||
var file = zipFile[argFileName];
|
||||
if (file != null)
|
||||
{
|
||||
Stream outputStream = new MemoryStream();
|
||||
file.Extract(outputStream);
|
||||
if (onLoaded != null)
|
||||
onLoaded(outputStream);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FileNotFoundException(argFileName);
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (zipFile != null)
|
||||
{
|
||||
zipFile.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class BinaryReaderExtensions
|
||||
{
|
||||
public static string ReadNullTerminatedString(this BinaryReader reader)
|
||||
{
|
||||
string result = string.Empty;
|
||||
char readChar = '\0';
|
||||
do
|
||||
{
|
||||
readChar = reader.ReadChar();
|
||||
if (readChar != '\0')
|
||||
result += readChar;
|
||||
}
|
||||
while (readChar != '\0');
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
44
aiwaz/Aiwaz.Common/HiPerfTimer.cs
Normal file
44
aiwaz/Aiwaz.Common/HiPerfTimer.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public static class HiPerfTimer
|
||||
{
|
||||
[DllImport("Kernel32.dll")]
|
||||
private static extern bool QueryPerformanceCounter(out long performanceCount);
|
||||
[DllImport("Kernel32.dll")]
|
||||
private static extern bool QueryPerformanceFrequency(out long frequency);
|
||||
private static double? startTime;
|
||||
private static double lastTime;
|
||||
|
||||
public static double LastDeltaTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public static double ElapsedTime
|
||||
{
|
||||
get
|
||||
{
|
||||
long frequency, performanceCount;
|
||||
QueryPerformanceFrequency(out frequency);
|
||||
QueryPerformanceCounter(out performanceCount);
|
||||
double thisTime = performanceCount / (double)frequency;
|
||||
if (!startTime.HasValue)
|
||||
{
|
||||
startTime = thisTime;
|
||||
lastTime = thisTime;
|
||||
return 0.0;
|
||||
}
|
||||
LastDeltaTime = thisTime - lastTime;
|
||||
lastTime = thisTime;
|
||||
return thisTime - startTime.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
70
aiwaz/Aiwaz.Common/ObjectFactory.cs
Normal file
70
aiwaz/Aiwaz.Common/ObjectFactory.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public class ObjectFactory
|
||||
{
|
||||
private Dictionary<Type, Type> m_Patterns = new Dictionary<Type, Type>();
|
||||
private Dictionary<Type, Dictionary<string, object>> m_StoredObjects = new Dictionary<Type, Dictionary<string, object>>();
|
||||
|
||||
public void RegisterPattern<O>()
|
||||
{
|
||||
var patternObject = typeof(O);
|
||||
var patternInterface = patternObject.GetInterface("I" + patternObject.Name);
|
||||
m_Patterns.Add(patternInterface, patternObject);
|
||||
}
|
||||
|
||||
public void RegisterPattern<I, O>()
|
||||
{
|
||||
m_Patterns.Add(typeof(I), typeof(O));
|
||||
}
|
||||
|
||||
public T CreateInstance<T>(params object[] args)
|
||||
{
|
||||
var creationType = m_Patterns.First(argPattern => argPattern.Key == typeof(T)).Value;
|
||||
Type[] creationArguments = null;
|
||||
if (args != null && args.Length > 0)
|
||||
creationArguments = args.Select(arg => arg.GetType()).ToArray();
|
||||
|
||||
var constructor = creationType.GetConstructor(creationArguments == null ?
|
||||
System.Type.EmptyTypes : creationArguments);
|
||||
|
||||
var construct = (T)constructor.Invoke(args);
|
||||
return construct;
|
||||
}
|
||||
|
||||
public T CreateNamedInstance<T>(string argName, params object[] args)
|
||||
{
|
||||
var construct = CreateInstance<T>(args);
|
||||
|
||||
var storage = m_StoredObjects.FirstOrDefault(type => type.Key == typeof(T)).Value;
|
||||
if (storage == null)
|
||||
{
|
||||
m_StoredObjects.Add(typeof(T), new Dictionary<string, object>());
|
||||
storage = m_StoredObjects.FirstOrDefault(type => type.Key == typeof(T)).Value;
|
||||
}
|
||||
storage.Add(argName, construct);
|
||||
|
||||
return construct;
|
||||
}
|
||||
|
||||
public T FindNamedInstance<T>(string argName)
|
||||
{
|
||||
var storage = m_StoredObjects.FirstOrDefault(type => type.Key == typeof(T)).Value;
|
||||
if (storage == null || !storage.ContainsKey(argName))
|
||||
return default(T);
|
||||
return (T)storage[argName];
|
||||
}
|
||||
|
||||
public void RemoveNamedInstance<T>(string argName)
|
||||
{
|
||||
var storage = m_StoredObjects.FirstOrDefault(type => type.Key == typeof(T)).Value;
|
||||
if (storage == null)
|
||||
return;
|
||||
storage.Remove(argName);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
aiwaz/Aiwaz.Common/Pair.cs
Normal file
23
aiwaz/Aiwaz.Common/Pair.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public class Pair<T, U>
|
||||
{
|
||||
public Pair()
|
||||
{
|
||||
}
|
||||
|
||||
public Pair(T first, U second)
|
||||
{
|
||||
this.First = first;
|
||||
this.Second = second;
|
||||
}
|
||||
|
||||
public T First { get; set; }
|
||||
public U Second { get; set; }
|
||||
}
|
||||
}
|
||||
36
aiwaz/Aiwaz.Common/Properties/AssemblyInfo.cs
Normal file
36
aiwaz/Aiwaz.Common/Properties/AssemblyInfo.cs
Normal file
@@ -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("AiwazCommon")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("AiwazCommon")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[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("e686f0df-9858-4478-a7fb-dea091646ff0")]
|
||||
|
||||
// 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")]
|
||||
22
aiwaz/Aiwaz.Common/Timeline.cs
Normal file
22
aiwaz/Aiwaz.Common/Timeline.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Aiwaz.Common.Animations;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public static class Timeline
|
||||
{
|
||||
private static double realTime;
|
||||
public static double RealTime { get { return realTime; } }
|
||||
private static double demoTime;
|
||||
public static double DemoTime { get { return demoTime; } }
|
||||
public static double SpeedAndDirection { get; set; }
|
||||
private static double lastRealDeltaTime;
|
||||
|
||||
public static void Advance(double argSeconds)
|
||||
{
|
||||
lastRealDeltaTime = argSeconds;
|
||||
realTime += argSeconds;
|
||||
demoTime += argSeconds * SpeedAndDirection;
|
||||
AnimationManager.Animate();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
aiwaz/Aiwaz.Common/Win32Console.cs
Normal file
42
aiwaz/Aiwaz.Common/Win32Console.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace Aiwaz.Common
|
||||
{
|
||||
public class Win32Console : IDisposable
|
||||
{
|
||||
[DllImport("kernel32.dll", EntryPoint = "FreeConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int FreeConsole();
|
||||
[DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
private static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
[DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
private static extern int AllocConsole();
|
||||
|
||||
private const int STD_OUTPUT_HANDLE = -11;
|
||||
private const int MY_CODE_PAGE = 437;
|
||||
|
||||
public Win32Console()
|
||||
{
|
||||
AllocConsole();
|
||||
IntPtr stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, true);
|
||||
FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write);
|
||||
Encoding encoding = System.Text.Encoding.GetEncoding(MY_CODE_PAGE);
|
||||
StreamWriter standardOutput = new StreamWriter(fileStream, encoding);
|
||||
standardOutput.AutoFlush = true;
|
||||
Console.SetOut(standardOutput);
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
FreeConsole();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Common.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Common.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Common.pdb
Normal file
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Common.pdb
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Contracts.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Contracts.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Contracts.pdb
Normal file
BIN
aiwaz/Aiwaz.Common/bin/Debug/Aiwaz.Contracts.pdb
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/Debug/Ionic.Zip.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/Debug/Ionic.Zip.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/Debug/SlimDX.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/Debug/SlimDX.dll
Normal file
Binary file not shown.
43576
aiwaz/Aiwaz.Common/bin/Debug/SlimDX.xml
Normal file
43576
aiwaz/Aiwaz.Common/bin/Debug/SlimDX.xml
Normal file
File diff suppressed because it is too large
Load Diff
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Common.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Common.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Common.pdb
Normal file
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Common.pdb
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Contracts.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Contracts.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Contracts.pdb
Normal file
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Aiwaz.Contracts.pdb
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Ionic.Zip.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/Ionic.Zip.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/SlimDX.dll
Normal file
BIN
aiwaz/Aiwaz.Common/bin/x86/Debug/SlimDX.dll
Normal file
Binary file not shown.
43576
aiwaz/Aiwaz.Common/bin/x86/Debug/SlimDX.xml
Normal file
43576
aiwaz/Aiwaz.Common/bin/x86/Debug/SlimDX.xml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\Debug\ResolveAssemblyReference.cache
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Common.dll
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Common.pdb
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Contracts.dll
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Contracts.pdb
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\Debug\Aiwaz.Common.dll
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\Debug\Aiwaz.Common.pdb
|
||||
D:\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Ionic.Zip.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Common.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Common.pdb
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Contracts.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Ionic.Zip.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\SlimDX.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\Aiwaz.Contracts.pdb
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\Debug\SlimDX.xml
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\Debug\Aiwaz.Common.csprojResolveAssemblyReference.cache
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\Debug\Aiwaz.Common.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\Debug\Aiwaz.Common.pdb
|
||||
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/obj/Debug/Aiwaz.Common.dll
Normal file
BIN
aiwaz/Aiwaz.Common/obj/Debug/Aiwaz.Common.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/obj/Debug/Aiwaz.Common.pdb
Normal file
BIN
aiwaz/Aiwaz.Common/obj/Debug/Aiwaz.Common.pdb
Normal file
Binary file not shown.
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/obj/Debug/Refactor/Aiwaz.Common.dll
Normal file
BIN
aiwaz/Aiwaz.Common/obj/Debug/Refactor/Aiwaz.Common.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/obj/Debug/ResolveAssemblyReference.cache
Normal file
BIN
aiwaz/Aiwaz.Common/obj/Debug/ResolveAssemblyReference.cache
Normal file
Binary file not shown.
Binary file not shown.
0
aiwaz/Aiwaz.Common/obj/Release/build.force
Normal file
0
aiwaz/Aiwaz.Common/obj/Release/build.force
Normal file
@@ -0,0 +1,10 @@
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\Aiwaz.Common.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\Aiwaz.Common.pdb
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\Aiwaz.Contracts.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\Ionic.Zip.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\SlimDX.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\Aiwaz.Contracts.pdb
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\bin\x86\Debug\SlimDX.xml
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\x86\Debug\Aiwaz.Common.csprojResolveAssemblyReference.cache
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\x86\Debug\Aiwaz.Common.dll
|
||||
D:\Private\Frank\Code\blu-flame.org\aiwaz\Aiwaz.Common\obj\x86\Debug\Aiwaz.Common.pdb
|
||||
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/obj/x86/Debug/Aiwaz.Common.dll
Normal file
BIN
aiwaz/Aiwaz.Common/obj/x86/Debug/Aiwaz.Common.dll
Normal file
Binary file not shown.
BIN
aiwaz/Aiwaz.Common/obj/x86/Debug/Aiwaz.Common.pdb
Normal file
BIN
aiwaz/Aiwaz.Common/obj/x86/Debug/Aiwaz.Common.pdb
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user