Repository navigation
Expand file tree
/
Copy pathApp.h
More file actions
111 lines (92 loc) · 3.17 KB
/
Copy pathApp.h
File metadata and controls
111 lines (92 loc) · 3.17 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
#pragma once
#include "Window.h"
#include "Tools/Timer.h"
#include "Tools/FixedStepClock.h"
#include "Tools/DungeonGenerator.h"
#include "Tools/json.hpp"
#include "Graphics/Camera.h"
#include "Graphics/Drawable/Box.h"
#include "Graphics/Drawable/CubeMap.h"
#include "Graphics/Drawable/Ground.h"
#include "Graphics/Drawable/Model.h"
#include "Graphics/Drawable/Primitive.h"
#include "Graphics/Lighting/DirectionalLight.h"
#include "Graphics/Lighting/PointLight.h"
#include "Graphics/Lighting/SpotLight.h"
#include "Graphics/Renderer.h"
#include "imgui/ImguiManager.h"
#include "Physics/Physics.h"
#include "Scene/Scene.h"
#include "Scene/GameObject.h"
#include "Components/Component.h"
#include "Components/DrawableComponent.h"
#include "Components/Animator.h"
#include "Components/Rigidbody.h"
#include "Components/Collider.h"
#include "Components/AudioClip.h"
#include "Audio/Audio.h"
// error logging macros (can be redefined by user to redirect to file or other logging system if desired)
#ifndef TE_LOG
#define TE_LOG(...) SPDLOG_INFO(__VA_ARGS__)
#endif
#ifndef TE_LOGERROR
#define TE_LOGERROR(...) SPDLOG_ERROR(__VA_ARGS__)
#endif
#ifndef TE_LOGWARNING
#define TE_LOGWARNING(...) SPDLOG_WARN(__VA_ARGS__)
#endif
class App
{
private:
struct Config
{
int width;
int height;
std::string title;
Config();
};
public:
App();
~App();
int Begin(); // handles message pump between windows and the app
private:
friend class AppPhysicsTestAccess;
void Update(float frameDelta); // advances fixed ticks and per-frame animation
void ResetFrameTiming() noexcept;
void RenderFrame(float alpha); // renders the frame, alpha for physics interpolation
void DrawPhysicsDebug();
void ResetSimulation(); // resets camera, light, and all drawables to initial state
void CacheSceneComponents() noexcept;
DirectX::SimpleMath::Ray BuildMouseRay(int mouseX, int mouseY) noexcept;
void HandleInput(float dt); // handles input per frame
private:
Config config;
Physics physics; // Outlives Scene; reject a second App before initializing UI/window state.
Audio audio; // Outlives Scene so component destructors may still submit audio commands.
ImguiManager imgui; // initializes imgui
Window wnd;
Timer timer;
Scene scene;
// Cameras for different modes
Camera editorCam;
std::vector<Camera*> gameCams;
Camera* activeCam = nullptr; // reference to currently active camera
std::vector<PointLight*> pointLights;
std::vector<SpotLight*> spotLights;
std::vector<DirectionalLight*> directionalLights;
Renderer renderer;
std::vector<DirectX::XMFLOAT3> physicsDebugVertices;
// Persistent game objects for inter-scene use (e.g. player character)
std::vector<GameObject*> persistentObjects;
// Simulation state
bool isPlayMode = false; // false = Edit Mode, true = Play Mode
bool isPaused = false; // true = Simulation Paused (while in Play Mode)
bool needsReset = false; // flag to indicate if simulation needs reset (used to defer reset until end of frame)
bool previousPlayMode = false;
bool previousPaused = false;
// Input state
int lastMouseX = 0;
int lastMouseY = 0;
static constexpr float dt = static_cast<float>(Physics::FixedTimeStep);
FixedStepClock fixedClock{ Physics::FixedTimeStep };
};