Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (56 loc) · 2.57 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (56 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using CAI;
using Spectre.Console;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
namespace NeuralLife
{
internal class Program
{
private static AppInterface BukashkiInterface;
private static App BukashkiApp = null;
private static void Main(string[] args)
{
Thread appThread = new(() => { BukashkiApp = new(); BukashkiApp.Run(); });
appThread.Start();
BukashkiInterface = new("Neural Life", isCatchExceptions: true);
#region Commands
BukashkiInterface.AddCommand(new("stats", "show simulation stats and settings values",
() => { LockAndExecute(BukashkiApp, ShowSettings); }));
BukashkiInterface.AddCommand(new("exit", "exit simulation",
() => { LockAndExecute(BukashkiApp, ExitSimulation); }));
BukashkiInterface.AddCommand(new("restart", "restart simulation",
() => { LockAndExecute(BukashkiApp, BukashkiApp.StartSimulation); }));
BukashkiInterface.AddCommand<bool>(new("fdisp", "is food dispawn?",
(isDispawn) => { SimulationSettings.EnableFoodDispawn = isDispawn; }, "fdisp [true/false]"));
BukashkiInterface.AddCommand<bool>(new("autodiv", "are cells divide when they want it?",
(doAutoDivide) => { SimulationSettings.EnableAutoDivide = doAutoDivide; }, "autodiv [true/false]"));
#endregion
BukashkiInterface.Start();
appThread.Join();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void LockAndExecute<T>(T lockObject, Action method)
{
lock(lockObject)
{
method();
}
}
private static void ShowSettings()
{
Table settingsTable = new Table().AddColumns("name", "value");
settingsTable.AddRow("EnableFoodDispawn", SimulationSettings.EnableFoodDispawn.ToString());
settingsTable.AddRow("FoodLifeTime", SimulationSettings.FoodLifeTime.ToString());
settingsTable.AddRow("FoodSpawnCount", SimulationSettings.FoodSpawnCount.ToString());
settingsTable.AddRow("AllowColonialism", SimulationSettings.AllowColonialism.ToString());
settingsTable.AddRow("EnableAutoDivide", SimulationSettings.EnableAutoDivide.ToString());
BukashkiInterface.WriteInfo(settingsTable);
}
private static void ExitSimulation()
{
BukashkiApp.Stop();
BukashkiInterface.Quit();
}
}
}