-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
182 lines (157 loc) · 6.28 KB
/
Program.cs
File metadata and controls
182 lines (157 loc) · 6.28 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System.Diagnostics;
using CEM.Core;
using CEM.Utils;
using CEM.World;
namespace CEM
{
/// <summary>
/// CEM
/// </summary>
internal static class Program
{
/// <summary>
/// Command Line Arguments
/// </summary>
public static CLIArgs Arguments { get; private set; }
/// <summary>
/// Positional Arguments
/// </summary>
public static string[] PositionalArguments { get; private set; }
/// <summary>
/// Configuration
/// </summary>
public static Config Config { get; private set; }
public static List<string> NifIgnorelist { get; private set; }
[STAThread]
public static void Main(string[] args)
{
Log.LOG_DEBUG = false;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
// Command & CVar core
Core.Core.Init();
// Parse Args
Arguments = new CLIArgs();
PositionalArguments = CommandLineArgs.ParseArguments(Arguments, Environment.GetCommandLineArgs().Skip(1).ToArray());
if (Arguments.Help)
return;
if (!Arguments.NormalPriority)
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
// Load the config file
if (!string.IsNullOrEmpty(Arguments.DaocRoot))
{
Config = new Config { CEM = { GamePath = Arguments.DaocRoot } };
}
else
{
string cfgFile = Path.Combine("..", Arguments.ConfigFile);
if (!File.Exists(cfgFile))
{
Log.Fatal("Config file not found: {0}", Arguments.ConfigFile);
return;
}
Config = Config.Load(cfgFile);
}
// Load nif whitelist
string ignorelistFile = Path.Combine("..", Arguments.IgnoreList);
if (!File.Exists(ignorelistFile))
{
Log.Warn("NIF ignorelist file not found: {0}", Arguments.IgnoreList);
NifIgnorelist = new List<string>();
}
else
{
NifIgnorelist = File.ReadAllLines(ignorelistFile).ToList();
}
BuildNavmeshes();
Log.Normal("---------------------------------------------------------------------------");
Log.Normal("All done.");
Console.ReadKey();
}
private static IEnumerable<Zone2> GetZonesToBuild()
{
// Zones
foreach (var zone in Arguments.RecastBuildZoneID.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
yield return World.WorldMgr.GetZone(int.Parse(zone));
// Regions
foreach (var region in Arguments.RecastBuildRegionID.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(r => World.WorldMgr.GetRegion(int.Parse(r))).Where(r => r != null))
{
foreach (var zone in region.Values)
yield return zone;
}
// All?
if (Arguments.RecastBuildAll)
{
foreach (var zone in World.WorldMgr.GetAllRegions().SelectMany(r => r.Values))
yield return zone;
}
}
private static void BuildNavmeshes()
{
World.WorldMgr.Init();
Log.Normal("-----------------------------------------------------------------------------");
Log.Normal("Building recast navmeshes!");
var zones = GetZonesToBuild().Distinct().Shuffle().ToArray();
Log.Normal("We will be creating {0} zones today. Right here. Right now.", zones.Length);
Log.Normal("-----------------------------------------------------------------------------");
Log.Normal("");
Console.Title = "NavGen";
int finishedZones = 0;
var po = new ParallelOptions() { MaxDegreeOfParallelism = Math.Max(1, Environment.ProcessorCount - 1) };
Parallel.Invoke(po, zones.Select(z => new Action(() =>
{
#if !DEBUG
try
{
#endif
NavmeshMgr.BuildNavMesh(z);
#if !DEBUG
}
catch (Exception ex)
{
Log.Error(ex);
}
#endif
int finished = Interlocked.Increment(ref finishedZones);
Console.Title = String.Format("[{2}%] NavGen {0}/{1}", finished, zones.Length, finished * 100 / zones.Length);
})).ToArray());
}
/// <summary>
/// Command Line Arguments
/// </summary>
internal class CLIArgs
{
/// <summary>
/// Default arguments
/// </summary>
public CLIArgs()
{
ConfigFile = "cem.json";
IgnoreList = "ignorelist.txt";
RecastBuildRegionID = "";
RecastBuildZoneID = "";
ExportObjOnly = false;
RecastBuildAll = false;
NormalPriority = false;
}
[Argument("config", Description = "Configuration File to use")]
public string ConfigFile { get; set; }
[Argument("daoc", Description = "DAoC Root Dir to use")]
public string DaocRoot { get; set; }
[Argument("ignorelist", Description = "NIF ignorelist file to use")]
public string IgnoreList { get; set; }
[Argument("help", Description = "Shows this help")]
public bool Help { get; set; }
[Argument("regions", Description = "Regions to build (recast navmesh), CSV")]
public string RecastBuildRegionID { get; set; }
[Argument("zones", Description = "Zones to build (recast navmesh), CSV")]
public string RecastBuildZoneID { get; set; }
[Argument("all", Description = "Build All Regions")]
public bool RecastBuildAll { get; set; }
[Argument("obj", Description = "Export obj only")]
public bool ExportObjOnly { get; set; }
[Argument("normal-priority", Description = "Run at normal priority")]
public bool NormalPriority { get; set; }
}
}
}