-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
81 lines (69 loc) · 1.59 KB
/
Main.cpp
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
#include "PCHeader.h"
#include "BattleCity/Framework/Framework.h"
#include "BattleCity/Framework/Screen.h"
#include "BattleCity/Game/Game.h"
#include "BattleCity/Engine/Texture/TexturePathLibrary.h"
namespace
{
void ShowUsage()
{
std::cout
<< "Usage: " << "BattleCity.exe\n"
<< "Options:\n"
<< "\t-w, -window 800x600\tSpecify window size"
<< std::endl;
}
void IsValidArgCount(const int argc)
{
if (argc != 3)
{
throw std::invalid_argument("Invalid argument count");
}
}
void IsValidWindowArg(std::string_view arg)
{
const bool correctArg = arg == "-w" || arg == "-window";
if(!correctArg)
{
throw std::invalid_argument("Invalid first argument");
}
}
void IsValidSizeArg(std::string_view arg, int& w, int& h)
{
char delim;
std::istringstream argv2(arg.data());
argv2 >> w;
argv2.get(delim);
argv2 >> h;
if (!argv2 || !argv2.eof() || delim != 'x')
{
throw std::invalid_argument("Invalid third argument");
}
}
}
int main(const int argc, const char* argv[])
{
int width = 800, height = 600;
bool fullScreen = true;
if (argc != 1)
{
try
{
IsValidArgCount(argc);
IsValidWindowArg(argv[1]);
IsValidSizeArg(argv[2], width, height);
}
catch (const std::invalid_argument& ex)
{
std::cerr << ex.what() << "\n";
ShowUsage();
return 0;
}
fullScreen = false;
}
NSFramework::Screen screen(width, height, fullScreen);
BattleCity::Engine::Texture::PathLibrary pathLibrary;
pathLibrary.CreateData(R"(.\data)");
const auto framework = std::make_unique<BattleCity::Game::Game>(screen, pathLibrary);
return run(framework.get());
}