Skip to content

Commit

Permalink
#17 add: Change Resolution feature, UniformRandom [SeedWriter], Pixel…
Browse files Browse the repository at this point in the history
…-Perfect
  • Loading branch information
Art-Stea1th committed Apr 30, 2017
1 parent af7a2a7 commit eb3c5fa
Show file tree
Hide file tree
Showing 37 changed files with 495 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@
<ItemGroup>
<Compile Include="Algorithms\RandomMixer.cs" />
<Compile Include="Algorithms\TheGameOfLife.cs" />
<Compile Include="Controllers\ApplicationStateMachine.cs" />
<Compile Include="Controllers\GenerationStateMachine.cs" />
<Compile Include="BindingExtensions\SettingsExtension.cs" />
<Compile Include="Extensions\Extensions.cs" />
<Compile Include="Interfaces\IFrameSequenceGenerator.cs" />
<Compile Include="Interfaces\IMatrix.cs" />
<Compile Include="Interfaces\IMatrixMutator.cs" />
<Compile Include="Interfaces\IMainController.cs" />
<Compile Include="Interfaces\IMatrixGenerator.cs" />
<Compile Include="DataProviders\UniformRandomDataProvider.cs" />
<Compile Include="Interfaces\IFPSGenerator.cs" />
<Compile Include="Interfaces\IMutationAlgorithm.cs" />
<Compile Include="Interfaces\IGenerationController.cs" />
<Compile Include="Interfaces\IApplicationFacade.cs" />
<Compile Include="Interfaces\ISeedGenerator.cs" />
<Compile Include="MVVM\RelayCommand.cs" />
<Compile Include="MVVM\BindableBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
Expand All @@ -96,8 +96,9 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Services\CryptoRandomService.cs" />
<Compile Include="Services\FrameGenerationService.cs" />
<Compile Include="SeedGenerators\UniformRandom.cs" />
<Compile Include="Services\FPSGenerationService.cs" />
<Compile Include="Services\ApplicationFacade.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\Settings.settings">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace ASD.CellUniverse.Infrastructure.Algorithms {
using Interfaces;
using MVVM;

public class RandomMixer : BindableBase, IMatrixMutator {
public class RandomMixer : BindableBase, IMutationAlgorithm {

private Random random;
public string Name => "Random Mixer";

public override string ToString() => Name;

private Random random;
public RandomMixer() => random = new Random();

public byte[,] Mutate(byte[,] prev) {
Expand All @@ -39,7 +39,6 @@ private IEnumerable<int> RandomIndexesFrom(byte[,] field, int dimension) {
yield return columnsIndexes[i];
columnsIndexes.RemoveAt(i);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ namespace ASD.CellUniverse.Infrastructure.Algorithms {
using Interfaces;
using MVVM;

public sealed class TheGameOfLife : BindableBase, IMatrixMutator {
public sealed class TheGameOfLife : BindableBase, IMutationAlgorithm {

public string Name => "The Game Of Life";
private byte alive = 255, dead = 0;

public string Name => "The Game Of Life";
public override string ToString() => Name;

public byte[,] Mutate(byte[,] prev) {
return NextGeneration(prev);
}

private byte alive = 255, dead = 0;

public byte[,] NextGeneration(byte[,] cells) {

var nextGeneration = new byte[cells.GetLength(0), cells.GetLength(1)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@ namespace ASD.CellUniverse.Infrastructure.Controllers {
using MVVM;
using Interfaces;

public sealed class ApplicationStateMachine : BindableBase, IMainController {
internal sealed class GenerationStateMachine : BindableBase, IGenerationController {

private object shared = new object();

public State State { get; private set; }
private State state;

private StateMachineCommand playCommand, pauseCommand, resumeCommand, stopCommand, resetCommand, dummyCommand;
private StateMachineCommand playPauseResumeCommand, stopResetCommand;

public event Action Started, Paused, Resumed, Stopped, Reseted;
public event Action<State> StateChanged;

public State State {
get => state;
private set => Set(ref state, value);
}

public ICommand Start {
get => playPauseResumeCommand;
private set => SetProperty(ref playPauseResumeCommand, value as StateMachineCommand);
private set => Set(ref playPauseResumeCommand, value as StateMachineCommand);
}

public ICommand Stop {
get => stopResetCommand;
private set => SetProperty(ref stopResetCommand, value as StateMachineCommand);
private set => Set(ref stopResetCommand, value as StateMachineCommand);
}

public ApplicationStateMachine() => InitializeCommands();
internal GenerationStateMachine() => InitializeCommands();

private void InitializeCommands() {

playCommand = new StateMachineCommand(
"PLAY",
"START",
(o) => ChangeState(State.Started, pauseCommand, stopCommand, Started),
(o) => State == State.Stopped);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Security.Cryptography;

namespace ASD.CellUniverse.Infrastructure.DataProviders {

internal sealed class UniformRandomDataProvider : IDisposable {

private RNGCryptoServiceProvider crypto;

public UniformRandomDataProvider() => crypto = new RNGCryptoServiceProvider();

public byte NextByte() {
var next = new byte[1];
crypto.GetBytes(next);
return next[0];
}

public void Dispose() => crypto?.Dispose();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media;

namespace ASD.CellUniverse.Infrastructure.Interfaces {

public interface IApplicationFacade : INotifyPropertyChanged {

byte[,] Matrix { get; }

int GenerationWidth { get; set; }
int GenerationHeight { get; set; }
bool MatrixReadyToChange { get; }
bool MatrixReadyToMutate { get; }

ISeedGenerator SeedWriter { get; set; }
ICommand WriteSeed { get; }
IMutationAlgorithm Algorithm { get; set; }

DoubleCollection FPSCollection { get; }
double MinFPS { get; }
double MaxFPS { get; }
double FPS { get; set; }

State State { get; }
ICommand Start { get; }
ICommand Stop { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Windows.Media;

namespace ASD.CellUniverse.Infrastructure.Interfaces {

internal interface IFPSGenerator {

DoubleCollection FPSCollection { get; }

double FPS { get; set; }

event Action NextFrameTime;
void Start();
void Stop();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace ASD.CellUniverse.Infrastructure.Interfaces {

public enum State { Started, Paused, Stopped }

public interface IMainController : INotifyPropertyChanged {
internal interface IGenerationController : INotifyPropertyChanged {

event Action Started, Paused, Resumed, Stopped, Reseted;
State State { get; }

event Action<State> StateChanged;

State State { get; }
event Action Started, Paused, Resumed, Stopped, Reseted;

ICommand Start { get; }
ICommand Stop { get; }
Expand Down
15 changes: 0 additions & 15 deletions Application/ASD.CellUniverse.Infrastructure/Interfaces/IMatrix.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ASD.CellUniverse.Infrastructure.Interfaces {

public interface IMatrixMutator {
public interface IMutationAlgorithm {

string Name { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ASD.CellUniverse.Infrastructure.Interfaces {

public interface ISeedGenerator {

string Name { get; }

byte[,] GenerateNew(int width, int height, object parameter = null);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class BindableBase : INotifyPropertyChanged, IDisposable {

protected BindableBase() { }

protected void SetProperty<T>(ref T oldValue, T newValue, [CallerMemberName] string propertyName = null) {
protected void Set<T>(ref T oldValue, T newValue, [CallerMemberName] string propertyName = null) {
oldValue = newValue; RaisePropertyChanged(propertyName);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Value Profile="(Default)">Normal</Value>
</Setting>
<Setting Name="ShellWidth" Type="System.Double" Scope="User">
<Value Profile="(Default)">970</Value>
<Value Profile="(Default)">974</Value>
</Setting>
<Setting Name="ShellHeight" Type="System.Double" Scope="User">
<Value Profile="(Default)">540</Value>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace ASD.CellUniverse.Infrastructure.SeedGenerators {

using DataProviders;
using Interfaces;

public class UniformRandom : ISeedGenerator {

public string Name => "Uniform Random";
public override string ToString() => Name;

public byte[,] GenerateNew(int width, int height, object parameter = null) {
var result = new byte[width, height];

using (var random = new UniformRandomDataProvider()) {
for (var x = 0; x < width; ++x) {
for (var y = 0; y < height; ++y) {
result[x, y] = (byte)(random.NextByte() % 2 == 0 ? 0 : 255);
}
}
}
return result;
}
}
}
Loading

0 comments on commit eb3c5fa

Please sign in to comment.