-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathice.d
111 lines (92 loc) · 3.15 KB
/
ice.d
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
// Copyright Ferdinand Majerech 2010 - 2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
/**
* $(BIG ICE API documentation)
*
* Introduction:
*
* This is the complete API documentation for ICE. It describes
* all classes, structs, interfaces, functions and so on.
* This API documentation is intended to serve developers who want to
* improve the ICE engine, as well as those who want to modify it for
* their own needs.
*/
///Program entry point.
module main.ice;
import core.stdc.stdlib: exit;
import std.stdio: writeln, File, stdout;
import std.typecons;
import dgamevfs._;
import formats.cli;
import ice.exceptions;
import ice.ice;
import util.unittests;
import memory.allocator;
import memory.memory;
///Program entry point.
void main(string[] args)
{
memory.memory.suspendMemoryDebugRecording = false;
version(Windows)
{
stdout = File("iceLog.txt", "wb");
}
scope(exit)
{
stdout.flush();
}
writeln("Started main()...");
//will add -h/--help and generate usage info by itself
auto cli = new CLI();
cli.description = "ICE 0.1.0\n"
"Top-down scrolling shooter written in D.\n"
"Copyright (C) 2010-2012 Ferdinand Majerech, Libor Malis, David Horvath, Tomas Nguyen";
cli.epilog = "Report errors at <[email protected]> (in English, Czech or Slovak).";
string root = "./data";
string user = "./user_data";
//Root data and user data MUST be specified at startup
cli.addOption(CLIOption("root_data").shortName('R').target(&root));
cli.addOption(CLIOption("user_data").shortName('U').target(&user));
if(!cli.parse(args)){return;}
scope(exit) writeln("Main exit");
try
{
auto rootFS = new FSDir("root_data", root, No.writable);
auto userFS = new FSDir("user_data", user, Yes.writable);
//Create userFS if it doesn't exist. rootFS not existing is an error.
userFS.create();
auto rootStack = new StackDir("root_data");
auto userStack = new StackDir("user_data");
auto gameDir = new StackDir("root");
rootStack.mount(rootFS.dir("main"));
auto userMain = userFS.dir("main");
userMain.create();
userStack.mount(userMain);
gameDir.mount(rootStack);
gameDir.mount(userStack);
writeln("Initialized VFS...");
memory.memory.outputDir = gameDir;
auto ice = new Ice(gameDir);
// This is here due to an unknown std.regex 32bit bug.
// It should be moved back to the start later.
runUnitTests();
writeln("Initialized ICE...");
scope(exit){clear(ice);}
writeln("Going to run ICE...");
ice.run();
}
catch(GameStartupException e)
{
writeln("Game failed to start: ", e.msg);
exit(-1);
}
catch(VFSException e)
{
writeln("Game failed due to a file system error "
"(maybe data directory is missing?): ", e.msg);
exit(-1);
}
memory.allocator.freeUnusedBuffers.emit();
}