Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed Apr 11, 2017
1 parent 220f289 commit fb6b368
Show file tree
Hide file tree
Showing 28 changed files with 906 additions and 169 deletions.
4 changes: 2 additions & 2 deletions MAGE/FPS/src/core/FPS.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stdafx.h"

#include "script\fps_script.hpp"
#include "script\system_usage_script.hpp"
#include "script\stats_script.hpp"

using namespace mage;

Expand Down Expand Up @@ -90,7 +90,7 @@ class TestScene final : public Scene {
SharedPtr< BehaviorScript > script(new TestScript(model));
AddScript(script);

SharedPtr< BehaviorScript > stats(new SystemUsageScript(text));
SharedPtr< BehaviorScript > stats(new StatsScript(text));
AddScript(stats);
}
};
Expand Down
11 changes: 9 additions & 2 deletions MAGE/MAGE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ClInclude Include="MAGE\src\input\keyboard.hpp" />
<ClInclude Include="MAGE\src\input\mouse.hpp" />
<ClInclude Include="MAGE\src\light\point_light.hpp" />
<ClInclude Include="MAGE\src\logging\cpu_timer.hpp" />
<ClInclude Include="MAGE\src\logging\error.hpp" />
<ClInclude Include="MAGE\src\logging\logging.hpp" />
<ClInclude Include="MAGE\src\logging\progress_reporter.hpp" />
Expand Down Expand Up @@ -103,6 +104,7 @@
<ClInclude Include="MAGE\src\scripting\vs\vs_tokens.hpp" />
<ClInclude Include="MAGE\src\scripting\vs\vs_writer.hpp" />
<ClInclude Include="MAGE\src\script\fps_script.hpp" />
<ClInclude Include="MAGE\src\script\stats_script.hpp" />
<ClInclude Include="MAGE\src\script\system_usage_script.hpp" />
<ClInclude Include="MAGE\src\shader\cso\lambertian_PS.h" />
<ClInclude Include="MAGE\src\shader\cso\lambertian_VS.h" />
Expand All @@ -125,7 +127,9 @@
<ClInclude Include="MAGE\src\string\string.hpp" />
<ClInclude Include="MAGE\src\string\string_utils.hpp" />
<ClInclude Include="MAGE\src\string\writer.hpp" />
<ClInclude Include="MAGE\src\system\system.hpp" />
<ClInclude Include="MAGE\src\system\cpu_monitor.hpp" />
<ClInclude Include="MAGE\src\system\system_time.hpp" />
<ClInclude Include="MAGE\src\system\system_usage.hpp" />
<ClInclude Include="MAGE\src\texture\dds\dds_loader.hpp" />
<ClInclude Include="MAGE\src\texture\texture.hpp" />
<ClInclude Include="MAGE\src\texture\texture_loader.hpp" />
Expand All @@ -152,6 +156,7 @@
<ClCompile Include="MAGE\src\input\input_manager.cpp" />
<ClCompile Include="MAGE\src\input\keyboard.cpp" />
<ClCompile Include="MAGE\src\input\mouse.cpp" />
<ClCompile Include="MAGE\src\logging\cpu_timer.cpp" />
<ClCompile Include="MAGE\src\logging\error.cpp" />
<ClCompile Include="MAGE\src\logging\logging.cpp" />
<ClCompile Include="MAGE\src\logging\progress_reporter.cpp" />
Expand Down Expand Up @@ -185,6 +190,7 @@
<ClCompile Include="MAGE\src\scripting\vs\vs_reader.cpp" />
<ClCompile Include="MAGE\src\scripting\vs\vs_writer.cpp" />
<ClCompile Include="MAGE\src\script\fps_script.cpp" />
<ClCompile Include="MAGE\src\script\stats_script.cpp" />
<ClCompile Include="MAGE\src\script\system_usage_script.cpp" />
<ClCompile Include="MAGE\src\shader\empty_shader.cpp" />
<ClCompile Include="MAGE\src\shader\lambertian_shader.cpp" />
Expand All @@ -198,7 +204,8 @@
<ClCompile Include="MAGE\src\string\token.cpp" />
<ClCompile Include="MAGE\src\string\string_utils.cpp" />
<ClCompile Include="MAGE\src\string\writer.cpp" />
<ClCompile Include="MAGE\src\system\system.cpp" />
<ClCompile Include="MAGE\src\system\system_time.cpp" />
<ClCompile Include="MAGE\src\system\system_usage.cpp" />
<ClCompile Include="MAGE\src\texture\dds\dds_loader.cpp" />
<ClCompile Include="MAGE\src\texture\texture.cpp" />
<ClCompile Include="MAGE\src\texture\texture_loader.cpp" />
Expand Down
33 changes: 27 additions & 6 deletions MAGE/MAGE.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,6 @@
<ClInclude Include="MAGE\src\script\fps_script.hpp">
<Filter>Header Files\script</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\system\system.hpp">
<Filter>Header Files\system</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\script\system_usage_script.hpp">
<Filter>Header Files\script</Filter>
</ClInclude>
Expand All @@ -570,6 +567,21 @@
<ClInclude Include="MAGE\src\text\outline_sprite_text.hpp">
<Filter>Header Files\text</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\logging\cpu_timer.hpp">
<Filter>Header Files\logging</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\system\system_usage.hpp">
<Filter>Header Files\system</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\system\system_time.hpp">
<Filter>Header Files\system</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\system\cpu_monitor.hpp">
<Filter>Header Files\system</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\script\stats_script.hpp">
<Filter>Header Files\script</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MAGE\src\core\engine.cpp">
Expand Down Expand Up @@ -764,9 +776,6 @@
<ClCompile Include="MAGE\src\script\fps_script.cpp">
<Filter>Source Files\script</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\system\system.cpp">
<Filter>Source Files\system</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\script\system_usage_script.cpp">
<Filter>Source Files\script</Filter>
</ClCompile>
Expand All @@ -782,6 +791,18 @@
<ClCompile Include="MAGE\src\text\normal_sprite_text.cpp">
<Filter>Source Files\text</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\logging\cpu_timer.cpp">
<Filter>Source Files\logging</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\system\system_usage.cpp">
<Filter>Source Files\system</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\system\system_time.cpp">
<Filter>Source Files\system</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\script\stats_script.cpp">
<Filter>Source Files\script</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="MAGE\shaders\lambertian.fx">
Expand Down
4 changes: 2 additions & 2 deletions MAGE/MAGE/src/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ namespace mage {

void Engine::SetScene(SharedPtr< Scene > scene) {
if (m_scene) {
m_scene->Close();
m_scene->Uninitialize();
}

m_scene = scene;

if (m_scene) {
m_scene->Load();
m_scene->Initialize();
}
}

Expand Down
109 changes: 109 additions & 0 deletions MAGE/MAGE/src/logging/cpu_timer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//-----------------------------------------------------------------------------
// Engine Includes
//-----------------------------------------------------------------------------
#pragma region

#include "logging\cpu_timer.hpp"
#include "logging\error.hpp"
#include "parallel\parallel.hpp"
#include "system\system_time.hpp"

#pragma endregion

//-----------------------------------------------------------------------------
// Engine Definitions
//-----------------------------------------------------------------------------
namespace mage {

CPUTimer::CPUTimer()
: m_handle(GetCurrentProcess()), m_nb_processor_cores(NumberOfSystemCores()),
m_initial_kernel_mode_time(0), m_initial_user_mode_time(0),
m_last_kernel_mode_time(0), m_last_user_mode_time(0),
m_elapsed_kernel_mode_time(0.0), m_elapsed_user_mode_time(0.0),
m_running(false) {}

void CPUTimer::Start() {
if (m_running) {
return;
}

m_running = true;

UpdateInitialTime();
// Reset the elapsed time.
m_elapsed_kernel_mode_time = 0.0;
m_elapsed_user_mode_time = 0.0;
UpdateLastTime();
}

void CPUTimer::Stop() {
if (!m_running) {
return;
}

m_running = false;

UpdateElapsedTime();
}

void CPUTimer::Restart() {
m_running = false;
Start();
}

void CPUTimer::Resume() {
if (m_running) {
return;
}

m_running = true;

UpdateLastTime();
}

double CPUTimer::GetElapsedCoreTime() const {
if (m_running) {
UpdateElapsedTime();
}

return m_elapsed_kernel_mode_time + m_elapsed_user_mode_time;
}

double CPUTimer::GetElapsedKernelModeTime() const {
if (m_running) {
UpdateElapsedTime();
}

return m_elapsed_kernel_mode_time;
}

double CPUTimer::GetElapsedUserModeTime() const {
if (m_running) {
UpdateElapsedTime();
}

return m_elapsed_user_mode_time;
}

void CPUTimer::UpdateInitialTime() {
// Set the initial time stamp.
GetCoreTime(m_handle, &m_initial_kernel_mode_time, &m_initial_user_mode_time);
}

void CPUTimer::UpdateLastTime() const {
// Set the last time stamp.
GetCoreTime(m_handle, &m_last_kernel_mode_time, &m_last_user_mode_time);
}

void CPUTimer::UpdateElapsedTime() const {
uint64_t kernel_mode_time;
uint64_t user_mode_time;
GetCoreTime(m_handle, &kernel_mode_time, &user_mode_time);

m_elapsed_kernel_mode_time = 0.0000001 * (kernel_mode_time - m_last_kernel_mode_time);
m_elapsed_user_mode_time = 0.0000001 * (user_mode_time - m_last_user_mode_time);

m_last_kernel_mode_time = kernel_mode_time;
m_last_user_mode_time = user_mode_time;
}
}
Loading

0 comments on commit fb6b368

Please sign in to comment.