-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectxIntroduction.cpp
More file actions
176 lines (141 loc) · 6.31 KB
/
Copy pathDirectxIntroduction.cpp
File metadata and controls
176 lines (141 loc) · 6.31 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
// ===========================================================================
/// <summary>
/// DirectXIntroduction.cpp
/// DirectXIntroduction
/// created by Mehrdad Soleimanimajd on 17.07.2019
/// </summary>
/// <created>ʆϒʅ, 17.07.2019</created>
/// <changed>ʆϒʅ, 04.07.2023</changed>
// ===========================================================================
#include "Utilities.h" // string + s,f streams + exception + threads + list + Windows standards
#include "Shared.h"
#include "Game.h"
// references:
// http://www.rastertek.com/
// https://docs.microsoft.com/
// https://bell0bytes.eu/
// http://www.cplusplus.com/
// https://en.cppreference.com/
// https://www.braynzarsoft.net/
// needed for application's exceptions handling check (simply copy to place to to throw)
//long long* anArray = new long long [1000000000000000000]; // throwing a standard exception on memory allocation
bool running {false};
std::wstring gameState {L"uninitialized"};
// main function (application entry point)
int WINAPI WinMain (_In_ HINSTANCE hInstance, // generated instance handle by Windows for the program
_In_opt_ HINSTANCE hPrevInstance, // obsolete plus backward compatibility (https://bell0bytes.eu/hello-world/)
// a long pointer to a string, similar to the command-line parameters of the standard C/C++ main function.
_In_ LPSTR lpCmdLine,
_In_ int nShowCmd) // indicates how the main window is to be opened (minimized, maximized)
{
try
{
std::shared_ptr<theException> anException {new (std::nothrow) theException ()};
PointerProvider::exceptionProvider (anException);
std::shared_ptr<Logger<toFile>> fileLoggerEngine (new (std::nothrow) Logger<toFile> ());
PointerProvider::fileLoggerProvider (fileLoggerEngine);
std::shared_ptr<Configurations> settings (new (std::nothrow) Configurations ());
PointerProvider::configurationProvider (settings);
if ((anException) && (settings))
running = true;
else
{
// failure, shut down the game properly
if (anException)
{
PointerProvider::exceptionProvider (nullptr);
anException.reset ();
}
PointerProvider::getException ()->set ("appSone");
throw* PointerProvider::getException ();
}
if (fileLoggerEngine)
{
PointerProvider::getFileLogger ()->push (logType::info, std::this_thread::get_id (), L"mainThread",
L"Exception, file logger and configuration providers are successfully initialized.");
} else
{
// failure, shut down the game properly
if (anException)
{
PointerProvider::exceptionProvider (nullptr);
anException.reset ();
}
if (settings)
{
PointerProvider::configurationProvider (nullptr);
settings.reset ();
}
PointerProvider::getException ()->set ("appDebug");
throw* PointerProvider::getException ();
}
settings->isDebug () = true;
settings->initialize ();
Game game (hInstance);
if (!game.isReady ())
{
game.shutdown (); // failure, try to save all the logs, while shutting down properly.
PointerProvider::getFileLogger ()->push (logType::error, std::this_thread::get_id (), L"mainThread",
L"The game initialization failed!");
PointerProvider::getException ()->set ("appStwo");
throw* PointerProvider::getException ();
}
gameState = L"initialized";
PointerProvider::getFileLogger ()->push (logType::warning, std::this_thread::get_id (), L"mainThread",
L"Entering the game loop...");
bool failure {false};
if (!game.run ())
{
failure = true;
PointerProvider::getFileLogger ()->push (logType::warning, std::this_thread::get_id (), L"mainThread",
L"Game failed to run!");
}
game.shutdown (); // failure or success, try to save all the logs, while shutting down properly.
if (anException)
{
PointerProvider::exceptionProvider (nullptr);
anException.reset ();
}
if (fileLoggerEngine)
{
PointerProvider::getFileLogger ()->push (logType::info, std::this_thread::get_id (), L"mainThread",
L"The logging engine is set to shut down...");
std::this_thread::sleep_for (std::chrono::milliseconds {100});
PointerProvider::fileLoggerProvider (nullptr);
fileLoggerEngine.reset ();
}
if (settings)
{
PointerProvider::configurationProvider (nullptr);
settings.reset ();
}
gameState = L"uninitialized";
if (failure)
return EXIT_FAILURE;
else
return EXIT_SUCCESS;
} catch (const std::exception& ex)
{
if (ex.what () == "appSone")
MessageBoxA (NULL, "The Game could not be started...", "Error", MB_OK | MB_ICONERROR);
else
if (ex.what () == "appDebug")
MessageBoxA (NULL, "The debug service failed to start.", "Error", MB_OK | MB_ICONERROR);
else
if (ex.what () == "appStwo")
{
MessageBoxA (NULL, "The Game functionality failed to start...", "Critical-Error", MB_OK | MB_ICONERROR);
} else
{
MessageBoxA (NULL, ex.what (), "Error", MB_OK | MB_ICONERROR);
if (PointerProvider::getFileLogger ())
{
PointerProvider::getFileLogger ()->push (logType::error, std::this_thread::get_id (), L"mainThread",
Converter::strConverter (ex.what ()));
std::this_thread::sleep_for (std::chrono::milliseconds {100});
}
}
return EXIT_FAILURE;
}
}