-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
90 lines (73 loc) · 2.43 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
82
83
84
85
86
87
88
89
90
#include "global.hpp"
#include <memory>
#include <sstream>
#include <cstdlib>
#include <ctime>
#define SDL_MAIN_HANDLED
#include "SDLRenderer.hpp"
#include "SDLTextFactory.hpp"
#include "Logger.hpp"
#include "Game.hpp"
#include "AppSettings.hpp"
#include "LuaAppSettingsFactory.hpp"
pen31ope::AppSettings defaultSettings = {
"scene.lua",
1024, 768,
pen31ope::WindowedMode::WINDOWED
};
int main (int argc, char** argv)
{
// INITIALIZE_BASIC_LOGGERS();
std::string settingsFile;
// Command-line args
if (argc >= 2)
{
settingsFile = argv[1];
}
if (settingsFile.empty())
{
settingsFile = "settings.lua";
}
pen31ope::AppSettings settings = defaultSettings;
{
// Load application settings from config script
std::unique_ptr<IAppSettingsFactory> settingsFactory = std::make_unique<LuaAppSettingsFactory>();
auto rc = settingsFactory->ReadFromFile(settingsFile);
if (!rc)
{
std::cerr << "Failed to load settings from file " << settingsFile << std::endl;
}
else
{
settings = *rc.value;
}
}
pen31ope::AppSettings::Validate(settings);
SDL_SetMainReady();
std::unique_ptr<SDLRenderer> pSDL = std::make_unique<SDLRenderer>(); // resources are freed at the end via RAII
pSDL->Initialize(argv[0], settings.screenWidth, settings.screenHeight);
// Setup text rendering
// std::unique_ptr<SDLTextFactory> pTextFactory = std::make_unique<SDLTextFactory>(pSDL->GetRenderer());
// pTextFactory->Initialize();
SDLTextFactory textFactory(pSDL->GetRenderer());
textFactory.Initialize();
// Inititalize RNGs
// srand(time(nullptr));
srand(0xff12ffcc);
// Initialize and run the game
// The block ensures that game-related resources are released as soon as the game
// finishes running. This is done via RAII.
int rc;
{
Game game;
// Configuration
game.SetRenderer(pSDL.get());
// game.SetTextRenderer(pTextFactory.get());
game.SetTextRenderer(&textFactory);
game.SetScreenWidthAndHeight(settings.screenWidth, settings.screenHeight);
// Go!
rc = game.Run();
}
// spdlog::drop_all(); // in Windows, this must be called before main finishes to workaround a known VS issue
return rc;
}