Skip to content

Commit fc0b49e

Browse files
author
A
authored
Merge pull request #55 from nightingazer/refactor
Refactor
2 parents feb0f37 + b87ca19 commit fc0b49e

39 files changed

+345
-120
lines changed

.idea/codeStyles/Project.xml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AGE/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
2-
project(AGE VERSION 1.0.0 LANGUAGES C CXX)
2+
3+
project(AGE VERSION 1.0.0 LANGUAGES CXX)
34

45
set(CMAKE_CXX_STANDARD_REQUIRED 23)
56

67
add_library(age_core STATIC)
78

89
target_include_directories(age_core INTERFACE include PUBLIC src vendor/imgui vendor/glm/ vendor/stb_image)
910

10-
file(GLOB_RECURSE _AGE_CORE_SRCS src/agepch.h src/agepch.cpp src/Age/*.cpp src/Age/*.h vendor/stb_image/stb_image.cpp vendor/stb_image/stb_image.h)
11+
file(GLOB_RECURSE _AGE_CORE_SRCS src/agepch.cpp src/agepch.h src/Age/*.cpp src/Age/*.h vendor/stb_image/stb_image.cpp vendor/stb_image/stb_image.h)
1112
list(REMOVE_ITEM _AGE_CORE_SRCS ${REMOVE_CMAKE})
1213

1314
file(GLOB _IMGUI_SRCS vendor/imgui/*.cpp vendor/imgui/*.h)
1415

1516
target_sources(age_core PRIVATE ${_AGE_CORE_SRCS} ${_IMGUI_SRCS})
17+
target_precompile_headers(age_core PUBLIC src/agepch.h)
1618

1719
option(AGE_INCLUDE_OPENGL "If ON, OpenGL-specific implementations will be added to the project" ON)
1820
option(AGE_INCLUDE_VULCAN "If ON, Vulcan-specific implementations will be added to the project" OFF)
@@ -77,16 +79,23 @@ if (AGE_INCLUDE_OPENGL)
7779
message(STATUS "Including OpenGl")
7880
add_subdirectory(vendor/GLFW)
7981

82+
add_library(age_core_glad STATIC)
83+
8084
target_link_libraries(age_core PUBLIC glfw ${GLFW_LIBRARIES})
8185

8286
file(GLOB _IMGUI_BE vendor/imgui/backends/imgui_impl_opengl3* vendor/imgui/backends/imgui_impl_glfw.*)
83-
file(GLOB _AGE_OPENGL_PLATFORM_SRCS src/Platform/OpenGL/* vendor/GLAD/src/glad.c)
87+
file(GLOB _AGE_OPENGL_PLATFORM_SRCS src/Platform/OpenGL/*)
88+
file(GLOB _AGE_OPENGL_PLATFORM_C_SRCS vendor/GLAD/src/glad.c)
8489

8590
target_sources(age_core PRIVATE ${_IMGUI_BE} ${_AGE_OPENGL_PLATFORM_SRCS})
91+
target_sources(age_core_glad PRIVATE ${_AGE_OPENGL_PLATFORM_C_SRCS})
8692

87-
target_include_directories(age_core PUBLIC vendor/GLFW/include vendor/GLAD/include vendor/imgui vendor/GLAD/include)
93+
target_include_directories(age_core PUBLIC vendor/GLFW/include vendor/imgui)
94+
target_include_directories(age_core_glad PUBLIC vendor/GLAD/include)
8895

8996
target_compile_definitions(age_core PUBLIC AGE_INCLUDE_OPENGL)
97+
98+
target_link_libraries(age_core PUBLIC age_core_glad)
9099
endif ()
91100

92101
target_compile_definitions(age_core PUBLIC AGE_RENDER_PLATFORM_${AGE_RENDER_PLATFORM})

AGE/src/Age/Core/Application.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "Application.h"
88

9-
#include "Age/Debug/Assert.h"
109
#include "Age/Debug/DebugLayer.h"
1110
#include "Age/ImGui/ImGuiLayer.h"
1211
#include "Age/Renderer/Renderer.h"
@@ -106,4 +105,4 @@ namespace AGE {
106105

107106
return m_Timer.Uptime();
108107
}
109-
}// namespace AGE
108+
}// namespace AGE

AGE/src/Age/Core/Application.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ namespace AGE {
2626
void PushLayer(Layer* layer);
2727
void PushOverlay(Layer* layer);
2828

29-
Scope<AGE::Window>& Window();
29+
Scope <AGE::Window>& Window();
30+
Timestep Uptime();
3031

3132
static Application* Instance();
3233

33-
Timestep Uptime();
34-
3534
private:
3635
bool OnWindowClose(WindowCloseEvent& e);
3736

38-
Scope<AGE::Window> m_Window;
37+
private:
38+
Scope <AGE::Window> m_Window;
3939

4040
bool m_Running;
4141
LayerStack m_LayerStack;

AGE/src/Age/Core/Layer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//
22
// Created by alex on 29.08.22.
33
//
4+
#include "agepch.h"
45

56
#include "Layer.h"
67

78
namespace AGE {
89
Layer::Layer(const age_string_t& debugName) : m_DebugName(debugName) {}
910
Layer::~Layer() = default;
10-
}// namespace AGE
11+
}// namespace AGE

AGE/src/Age/Debug/DebugLayer.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,30 @@ namespace AGE {
1616
void DebugLayer::OnUpdate(Timestep ts) {
1717
AGE_PROFILE_FUNCTION();
1818

19-
float fps = 1000.0f / ts.Milliseconds();
19+
constexpr float fpsTextUpdateThresholdSeconds{0.1f};
20+
static float lastFpsUpdateSeconds{0.0f};
21+
static float lastFps{1000.0f / ts.Milliseconds()};
22+
23+
lastFpsUpdateSeconds += ts;
24+
if(lastFpsUpdateSeconds >= fpsTextUpdateThresholdSeconds) {
25+
lastFpsUpdateSeconds = 0.0f;
26+
lastFps = 1000.0f / ts.Milliseconds();
27+
}
2028

21-
m_FpsPlot.LastUpdate += ts.Seconds();
29+
m_FpsPlot.LastUpdateSeconds += ts.Seconds();
2230

23-
if (m_FpsPlot.LastUpdate >= m_FpsPlot.RefreshTime) {
24-
m_FpsPlot.LastUpdate = 0;
25-
m_FpsPlot.InsertNewFps(fps);
31+
if (m_FpsPlot.LastUpdateSeconds >= m_FpsPlot.RefreshTimeSeconds) {
32+
m_FpsPlot.LastUpdateSeconds = 0;
33+
m_FpsPlot.InsertNewFps(1000.0f / ts.Milliseconds());
2634
}
2735

2836
ImGui::Begin("Debug");
2937
Scope<Window>& window = Application::Instance()->Window();
30-
ImGui::Text("MainWindow: %s (%i, %i)", window->Title().c_str(), (int)window->Width(), (int)window->Height());
31-
ImGui::Text("FPS: %f", fps);
32-
ImGui::Text("Delta Time: %fs", ts.Seconds());
38+
ImGui::Text(
39+
"MainWindow: %s (%i, %i)", window->Title().c_str(), (int)window->Width(),
40+
(int)window->Height());
41+
ImGui::Text("FPS: %.2f", lastFps);
42+
ImGui::Text("Delta Time: %.2fms", ts.Milliseconds());
3343

3444
m_FpsPlot.Render();
3545

@@ -56,27 +66,27 @@ namespace AGE {
5666
m_MinValue = fps;
5767
}
5868

59-
if (m_LastInsertIndex >= m_Data.max_size()) {
69+
if (m_NextIndex >= m_Data.max_size()) {
6070
for (std::size_t i = 0; i < m_Data.max_size() - 1; i++) {
6171
m_Data[i] = m_Data[i + 1];
6272
}
6373

6474
m_Data[m_Data.max_size() - 1] = fps;
6575
} else {
66-
m_Data[m_LastInsertIndex] = fps;
67-
m_LastInsertIndex++;
76+
m_Data[m_NextIndex] = fps;
77+
m_NextIndex++;
6878
}
6979
}
7080

7181
void FpsPlot::Render() {
7282
AGE_PROFILE_FUNCTION();
7383

7484
float scaleMax = *std::max_element(m_Data.begin(), m_Data.end());
75-
ImGui::Text("Max FPS: %f", m_MaxValue);
76-
ImGui::Text("Min FPS: %f", m_MinValue);
85+
ImGui::Text("Max FPS: %.2f", m_MaxValue);
86+
ImGui::Text("Min FPS: %.2f", m_MinValue);
7787

7888

79-
ImGui::SliderFloat("Refresh Rate(sec)", &RefreshTime, 0.0f, 5.0f);
89+
ImGui::SliderFloat("Refresh Rate(sec)", &RefreshTimeSeconds, 0.0f, 5.0f);
8090
ImGui::PlotLines(
8191
"FPS",
8292
m_Data.data(),
@@ -88,4 +98,4 @@ namespace AGE {
8898
ImVec2(0, 50)
8999
);
90100
}
91-
}// namespace AGE
101+
}// namespace AGE

AGE/src/Age/Debug/DebugLayer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ namespace AGE {
1515
void InsertNewFps(float fps);
1616
void Render();
1717

18-
float LastUpdate{0};
19-
float RefreshTime{0.25f};
18+
float LastUpdateSeconds{0};
19+
float RefreshTimeSeconds{0.25f};
2020

2121
private:
2222
std::array<float, 60> m_Data;
23-
std::size_t m_LastInsertIndex{0};
23+
std::size_t m_NextIndex{0};
2424
float m_MaxValue{0};
2525
float m_MinValue{FLT_MAX};
2626
};

AGE/src/Age/Events/Event.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace AGE {
6060

6161
class EventDispatcher {
6262
public:
63-
EventDispatcher(Event& event) : event_{event} {}
63+
EventDispatcher(Event& event) : m_Event{event} {}
6464

6565
/**
6666
* @brief Dispatches event
@@ -72,16 +72,16 @@ namespace AGE {
7272
*/
7373
template<typename E, typename F>
7474
bool Dispatch(const F& func) {
75-
if (event_.EventType() == E::StaticType()) {
76-
event_.Handled |= func(static_cast<E&>(event_));
75+
if (m_Event.EventType() == E::StaticType()) {
76+
m_Event.Handled |= func(static_cast<E&>(m_Event));
7777
return true;
7878
}
7979

8080
return false;
8181
}
8282

8383
private:
84-
Event& event_;
84+
Event& m_Event;
8585
};
8686

8787
inline std::ostream& operator<<(std::ostream& os, const Event& e) {

AGE/src/Age/ImGui/ImGuiLayer.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010
#include "Age/ImGui/ImGuiLayer.h"
1111

1212
#include "Age/Core/Application.h"
13-
#include "Age/Core/Input.h"
1413

1514

1615
namespace AGE {
1716
bool ImGuiLayer::IsInitialized{false};
1817

1918
ImGuiLayer::ImGuiLayer(age_string_t name) : Layer(name) {}
2019

21-
ImGuiLayer::~ImGuiLayer() {
22-
}
23-
2420
void ImGuiLayer::OnAttach() {
2521
IMGUI_CHECKVERSION();
2622
ImGui::CreateContext();
@@ -77,4 +73,4 @@ namespace AGE {
7773
IsInitialized = true;
7874
}
7975
}
80-
}// namespace AGE
76+
}// namespace AGE

AGE/src/Age/ImGui/ImGuiLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace AGE {
2121
class ImGuiLayer : public Layer {
2222
public:
2323
ImGuiLayer(age_string_t name = "ImGui");
24-
~ImGuiLayer() override;
24+
~ImGuiLayer() override = default;
2525

2626
void OnAttach() override;
2727
void OnDetach() override;

AGE/src/Age/Renderer/Buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace AGE {
4040
uint32_t shader_data_size(ShaderDataType type);
4141

4242
/**
43-
* @brief Converts ShaderDataType objects to corresponding ShaderDataType but with only one component.
44-
* For example, Float4 will be converted to Float.
43+
* @brief Extracts a base type data from the ShaderDataType.
44+
* @details Removes data about count of elements in ShaderDataType. For example Float4 input will return Float.
4545
* @param type - type to be converted
4646
* @return The same ShaderDataType but with one component.
4747
*/

AGE/src/Age/Renderer/OrthographicCamera.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ namespace AGE {
3131
inline glm::vec3 Position() const { return m_Position; }
3232
inline float Rotation() const { return m_Rotation; }
3333

34-
inline const glm::mat4& GetProjectionMatrix() const { return m_ProjectionMatrix; }
35-
inline const glm::mat4& GetViewMatrix() const { return m_ViewMatrix; }
36-
inline const glm::mat4& GetViewProjectionMatrix() const { return m_ViewProjectionMatrix; }
34+
inline const glm::mat4& ProjectionMatrix() const { return m_ProjectionMatrix; }
35+
inline const glm::mat4& ViewMatrix() const { return m_ViewMatrix; }
36+
inline const glm::mat4& ViewProjectionMatrix() const { return m_ViewProjectionMatrix; }
3737

3838
private:
3939
void RecalculateViewMatrix();

AGE/src/Age/Renderer/OrthographicCameraController.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Created by alex on 18.10.22.
33
//
44

5+
#include "agepch.h"
6+
57
#include "OrthographicCameraController.h"
68
#include <glm/trigonometric.hpp>
79

@@ -89,4 +91,4 @@ namespace AGE {
8991
OnResize((float)e.Width(), (float)e.Height());
9092
return false;
9193
}
92-
} // AGE
94+
} // AGE

AGE/src/Age/Renderer/OrthographicCameraController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace AGE {
2828
OrthographicCamera& GetCamera() { return m_Camera; }
2929
const OrthographicCamera& GetCamera() const { return m_Camera; }
3030

31-
float GetZoomLevel() const { return m_ZoomLevel; }
31+
float ZoomLevel() const { return m_ZoomLevel; }
3232
void SetZoomLevel(float level) { m_ZoomLevel = level; }
3333

3434
private:

AGE/src/Age/Renderer/RenderAPI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "agepch.h"
66

7-
#include "Age/Debug/Assert.h"
87
#include "RenderAPI.h"
98

109
#ifdef AGE_INCLUDE_OPENGL
@@ -33,4 +32,4 @@ namespace AGE {
3332

3433
return nullptr;
3534
}
36-
} // AGE
35+
} // AGE

AGE/src/Age/Renderer/Renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace AGE {
1919
void Renderer::BeginScene(OrthographicCamera& camera) {
2020
AGE_PROFILE_FUNCTION();
2121

22-
s_SceneData->ViewProjectionMatrix = camera.GetViewProjectionMatrix();
22+
s_SceneData->ViewProjectionMatrix = camera.ViewProjectionMatrix();
2323
}
2424

2525
void Renderer::EndScene() {

0 commit comments

Comments
 (0)