initialize the application with the given parameters.
71{
72
73 Logger::Get().
Log(
"Initializing application class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
74
75 try
76 {
77 char mouseString1[32], mouseString2[32], mouseString3[32];
78 char modelFilename[128], renderString[32];
79 char bitmapFilename[128];
80 char spriteFilename[128];
81 char fpsString[32];
82 bool result;
83 HRESULT Hresult;
84
85
86 entity_manager_ = std::make_unique<ecs::EntityManager>();
87
88 screen_width_ = screenWidth;
89 screen_height_ = screenHeight;
90
95
96
98 if (!direct_3d_)
99 {
100 Logger::Get().
Log(
"Could not create the Direct3D object", __FILE__, __LINE__, Logger::LogLevel::Error);
101 return false;
102 }
103
104 result = direct_3d_->
initialize(screen_width_, screen_height_, vsync_enabled_, hwnd, full_screen, screen_depth, screen_near);
105 if (!result)
106 {
107 Logger::Get().
Log(
"Could not initialize Direct3D", __FILE__, __LINE__, Logger::LogLevel::Error);
108 return false;
109 }
110
111
113 if (!camera_)
114 {
115 Logger::Get().
Log(
"Could not create the camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
116 return false;
117 }
118
120 if (!sun_camera_)
121 {
122 Logger::Get().
Log(
"Could not create the sun camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
123 return false;
124 }
125
130
131
136
137 active_camera_ = camera_;
138
139
141
142 result = font_shader_->initialize(direct_3d_->
get_device(), hwnd);
143 if (!result)
144 {
145 Logger::Get().
Log(
"Could not initialize the font shader object", __FILE__, __LINE__, Logger::LogLevel::Error);
146 return false;
147 }
148
149
151
153 if (!result)
154 {
155 Logger::Get().
Log(
"Could not initialize the font object", __FILE__, __LINE__, Logger::LogLevel::Error);
156 return false;
157 }
158
159
161
162 result = render_texture_->Initialize(direct_3d_->
get_device(), 256, 256, screen_depth, screen_near, 1);
163 if (!result)
164 {
165 Logger::Get().
Log(
"Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
166 return false;
167 }
168
169
170
171
173 result = scene_texture_->Initialize(direct_3d_->
get_device(), 256, 256, screen_depth, screen_near, 1);
174 if (!result)
175 {
176 Logger::Get().
Log(
"Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
177 return false;
178 }
179
180
182
183 result = display_plane_->Initialize(direct_3d_->
get_device(), 1.0f, 1.0f);
184 if (!result)
185 {
186 Logger::Get().
Log(
"Could not initialize the display plane object", __FILE__, __LINE__, Logger::LogLevel::Error);
187 return false;
188 }
189
190
191
192
193 strcpy_s(spriteFilename, "sprite_data_01.txt");
194
195
197
198 result = sprite_->Initialize(direct_3d_->
get_device(), direct_3d_->
get_device_context(), screenWidth, screenHeight, spriteFilename, 50, 50);
199 if (!result)
200 {
201 Logger::Get().
Log(
"Could not initialize the sprite object", __FILE__, __LINE__, Logger::LogLevel::Error);
202 return false;
203 }
204
205
206 strcpy_s(mouseString1, "Mouse X: 0");
207 strcpy_s(mouseString2, "Mouse Y: 0");
208 strcpy_s(mouseString3, "Mouse Button: No");
209
210
212
213 for (int i = 0; i < 3; i++)
214 {
215 int y = 10 + (i * 25);
216 result = mouse_strings_[i].Initialize(direct_3d_->
get_device(), direct_3d_->
get_device_context(), screenWidth, screenHeight, 32, font_, mouseString1, 10, y, 1.0f, 1.0f, 1.0f);
217 if (!result)
218 {
219 Logger::Get().
Log(
"Could not initialize the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error);
220 return false;
221 }
222 }
223
224
225 strcpy_s(bitmapFilename, "assets/Texture/stone01.tga");
226
227
229
230 result = bitmap_->initialize(direct_3d_->
get_device(), direct_3d_->
get_device_context(), screenWidth, screenHeight, bitmapFilename, 50, 50);
231 if (!result)
232 {
233 Logger::Get().
Log(
"Could not initialize the bitmap object", __FILE__, __LINE__, Logger::LogLevel::Error);
234 return false;
235 }
236
237
238 strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
239
240
241 std::vector<std::wstring> textureFilenames = {
242 L"assets/Texture/stone01.png"
243 };
244
246
247 for (const auto& textureFilename : textureFilenames)
248 {
249 ID3D11ShaderResourceView* texture = nullptr;
250 Hresult = DirectX::CreateWICTextureFromFile(direct_3d_->
get_device(), direct_3d_->
get_device_context(), textureFilename.c_str(),
nullptr, &texture);
251 if (FAILED(Hresult))
252 {
253 Logger::Get().
Log(
"Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
254 return false;
255 }
256 CubeTextures.diffuse.push_back(texture);
257 }
258
259
261
262
264 if (!result)
265 {
266 Logger::Get().
Log(
"Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error);
267 return false;
268 }
269
270
272
273 m_light_->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
274 m_light_->SetDirection(0.0f, 0.0f, -1.0f);
275 m_light_->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
276 m_light_->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
277 m_light_->SetSpecularPower(16.0f);
278
279
280 num_lights_ = 4;
281
282 lights_.resize(num_lights_);
283
285 lights_[0]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
286 lights_[0]->SetDirection(0.0f, 0.0f, -1.0f);
287 lights_[0]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
288 lights_[0]->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
289 lights_[0]->SetSpecularPower(16.0f);
290 lights_[0]->SetPosition(10.0f, 7.0f, -5.0f);
291
293 lights_[1]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f);
294 lights_[1]->SetDirection(0.0f, 0.0f, -1.0f);
295 lights_[1]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
296 lights_[1]->SetSpecularColor(1.0f, 0.0f, 0.0f, 1.0f);
297 lights_[1]->SetSpecularPower(16.0f);
298 lights_[1]->SetPosition(-10.0f, 7.0f, -5.0f);
299
301 lights_[2]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f);
302 lights_[2]->SetDirection(0.0f, 0.0f, -1.0f);
303 lights_[2]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
304 lights_[2]->SetSpecularColor(0.0f, 1.0f, 0.0f, 1.0f);
305 lights_[2]->SetSpecularPower(16.0f);
306 lights_[2]->SetPosition(10.0f, 7.0f, 5.0f);
307
309 lights_[3]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f);
310 lights_[3]->SetDirection(0.0f, 0.0f, -1.0f);
311 lights_[3]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
312 lights_[3]->SetSpecularColor(0.0f, 0.0f, 1.0f, 1.0f);
313 lights_[3]->SetSpecularPower(16.0f);
314 lights_[3]->SetPosition(-10.0f, 7.0f, 5.0f);
315
316
317
318
319
321 sun_light_->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
322 sun_light_->SetDirection(0.0f, -1.0f, 0.0f);
323 sun_light_->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
324 sun_light_->SetPosition(0.0f, 100.0f, 0.0f);
325 sun_light_->SetIntensity(1.0f);
326
327 sun_camera_->
set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
330
331
333
334 result = shader_manager_->initialize(direct_3d_->
get_device(), hwnd);
335 if (!result)
336 {
337 Logger::Get().
Log(
"Could not initialize the shader manager object", __FILE__, __LINE__, Logger::LogLevel::Error);
338 return false;
339 }
340
341
342 strcpy_s(renderString, "render Count: 0");
343
344
346
347 result = render_count_string_->Initialize(direct_3d_->
get_device(), direct_3d_->
get_device_context(), screenWidth, screenHeight, 32, font_, renderString, 10, 10, 1.0f, 1.0f, 1.0f);
348 if (!result)
349 {
350 Logger::Get().
Log(
"Could not initialize the render count string", __FILE__, __LINE__, Logger::LogLevel::Error);
351 return false;
352 }
353
354
356 model_list_->Initialize(25);
357
358
359 std::vector<std::wstring> bathTextures = {
360 L"assets/Texture/marble01.png"
361 };
362
364
365 textures.clear();
366 for (const auto& textureFilename : bathTextures)
367 {
368 ID3D11ShaderResourceView* texture = nullptr;
369 Hresult = DirectX::CreateWICTextureFromFile(direct_3d_->
get_device(), direct_3d_->
get_device_context(), textureFilename.c_str(),
nullptr, &texture);
370 if (FAILED(Hresult))
371 {
372 Logger::Get().
Log(
"Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
373 return false;
374 }
375 BathTextures.diffuse.push_back(texture);
376 }
377
378
379 strcpy_s(modelFilename, "assets/Model/TXT/bath.txt");
380
381
383
385 if (!result)
386 {
387 MessageBox(hwnd, L"Could not initialize the bath model object.", L"Error", MB_OK);
388 return false;
389 }
390
391
392 strcpy_s(modelFilename, "assets/Model/TXT/water.txt");
393
394 std::vector<std::wstring> waterTextures = {
395 L"assets/Texture/water01.png"
396 };
397
399
400 textures.clear();
401 for (const auto& textureFilename : waterTextures)
402 {
403 ID3D11ShaderResourceView* texture = nullptr;
404 Hresult = DirectX::CreateWICTextureFromFile(direct_3d_->
get_device(), direct_3d_->
get_device_context(), textureFilename.c_str(),
nullptr, &texture);
405 if (FAILED(Hresult))
406 {
407 Logger::Get().
Log(
"Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
408 return false;
409 }
410 WaterTextures.diffuse.push_back(texture);
411 }
412
413
415
417 if (!result)
418 {
419 MessageBox(hwnd, L"Could not initialize the water model object.", L"Error", MB_OK);
420 return false;
421 }
422
423
425
426 result = refraction_texture_->Initialize(direct_3d_->
get_device(), screenWidth, screenHeight, screen_depth, screen_near, 1);
427 if (!result)
428 {
429 MessageBox(hwnd, L"Could not initialize the refraction render texture object.", L"Error", MB_OK);
430 return false;
431 }
432
433
435
436 result = reflection_texture_->Initialize(direct_3d_->
get_device(), screenWidth, screenHeight, screen_depth, screen_near, 1);
437 if (!result)
438 {
439 MessageBox(hwnd, L"Could not initialize the reflection render texture object.", L"Error", MB_OK);
440 return false;
441 }
442
443
444 water_height_ = -9.25f;
445
446
447 water_translation_ = 100.0f;
448
449
451
452 result = timer_->Initialize();
453 if (!result)
454 {
455 Logger::Get().
Log(
"Could not initialize the timer object", __FILE__, __LINE__, Logger::LogLevel::Error);
456 return false;
457 }
458
459
461
462
464
465 fps_->Initialize();
466
467
468 previous_fps_ = -1;
469 strcpy_s(fpsString, "Fps: 0");
470
471
473
474 result = fps_string_->Initialize(direct_3d_->
get_device(), direct_3d_->
get_device_context(), screenWidth, screenHeight, 32, font_, fpsString, 10, 10, 0.0f, 1.0f, 0.0f);
475 if (!result)
476 {
477 Logger::Get().
Log(
"Could not initialize the fps string", __FILE__, __LINE__, Logger::LogLevel::Error);
478 return false;
479 }
480
482 if (!shadow_map_->initialize(direct_3d_->
get_device(), 2048, 2048))
483 {
484 Logger::Get().
Log(
"Could not initialize the shadow map object", __FILE__, __LINE__, Logger::LogLevel::Error);
485 return false;
486 }
487
488 stats_ =
new stats();
489 if (!stats_->initialize(this))
490 {
491 Logger::Get().
Log(
"Could not initialize the stats object", __FILE__, __LINE__, Logger::LogLevel::Error);
492 return false;
493 }
494
496
498
499
503
504 culling_active_ = true;
505 culling_thread_ = std::thread(&application_class::culling_thread_function, this);
506
507 }
508 catch (const std::exception& e)
509 {
510 Logger::Get().
Log(std::string(
"Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error);
511 return false;
512 }
513 Logger::Get().
Log(
"Application class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
514
515
516
517 return true;
518}
object * ConstructSkybox(application_class *app)
void Initialize(d_3d_class *d3dClassRef)
void set_windowed(bool windowed)
void physics_thread_function()
Thread function for handling physics updates. this function will run in a separate thread to handle p...
void set_screen_width(int screen_width)
void set_screen_height(int screen_height)
virtual bool initialize(int, int, bool, HWND, bool, float, float)
Initializes the Direct3D device and related resources.