public MainWindow() {
var args = System.Environment.GetCommandLineArgs();
if (args != null)
foreach (var arg in args)
{
if (arg == "/S") SCALABLE = true;
if (arg == "/A") SYNCHRONOUS = false;
};
this.Title = (SCALABLE) ? "SCALABLE" : "LOCKBASED";
this.Title += (SYNCHRONOUS) ? " SYNCHRONOUS" : " ASYNCHRONOUS";
BoidModels = new ModelVisual3D[NumBoids];
Timer = new DispatcherTimer();
boids = new Boid[NumBoids];
Space = new Rect3D(0.0, 0.0, 0.0, 600.0, 200.0, 800.0);
CurrentData = new Data[NumBoids];
InitializeComponent();
InitJoin();
// The color combinations to use for boids. At least one combination is necessary,
// but more can be added to get more variations.
var colorCombinations = new Tuple<Color, Color>[]
{
Tuple.Create(Colors.SeaGreen, Colors.Silver),
Tuple.Create(Colors.Pink, Colors.Purple),
Tuple.Create(Colors.Yellow, Colors.Gold),
Tuple.Create(Colors.Red, Colors.Tomato),
Tuple.Create(Colors.Blue,Colors.BlueViolet),
Tuple.Create(Colors.Green,Colors.LightGreen),
Tuple.Create(Colors.Aqua,Colors.Aquamarine)
};
for (var i = 0; i < NumBoids; i++) {
BoidModels[i] = new ModelVisual3D();
var content = (System.Windows.Media.Media3D.GeometryModel3D)boidMain.Content.Clone();
content.BackMaterial = new DiffuseMaterial(new SolidColorBrush(colorCombinations[i % colorCombinations.Length].Item2));
content.Material = new DiffuseMaterial(new SolidColorBrush(colorCombinations[i % colorCombinations.Length].Item1));
BoidModels[i].Content = content;
BoidModels[i].Transform = new TranslateTransform3D(CurrentData[i].position);
viewport3D.Children.Add(BoidModels[i]);
}
System.Threading.ThreadPool.QueueUserWorkItem(_ => {
while (true) {
var d = Tick();
Dispatcher.Invoke((Action<Data[]>) Animate,DispatcherPriority.Input, d);
}
});
}