Compare commits

..

No commits in common. "5d20018faea982495f8b78b6cbbc0a0512a0f5d4" and "debc5b219be6fee9f3055d395d2e0d521bd45d76" have entirely different histories.

2 changed files with 18 additions and 24 deletions

View File

@ -3,8 +3,7 @@
#include "../World/DbgCube.hpp" #include "../World/DbgCube.hpp"
#include "../World/Tank.hpp" #include "../World/Tank.hpp"
//#define DISABLE_AABB_CLIPPING //#define DISABLE_INVISIBLE_VERTICES
//#define DISABLE_TRIANGLE_CLIPPING
// Rendering pipeline: // Rendering pipeline:
@ -114,7 +113,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
// Object outside frustrum clipping // Object outside frustrum clipping
projAABB.Transform(projAABB, oTMat); projAABB.Transform(projAABB, oTMat);
M3D_ContainmentType objInFrustrum = camFrustrum.Contains(projAABB); M3D_ContainmentType objInFrustrum = camFrustrum.Contains(projAABB);
#ifndef DISABLE_AABB_CLIPPING #ifndef DISABLE_INVISIBLE_VERTICES
if (objInFrustrum != DISJOINT) if (objInFrustrum != DISJOINT)
#endif #endif
{ {
@ -141,12 +140,10 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
break; break;
// Triangle clipping // Triangle clipping
#ifndef DISABLE_TRIANGLE_CLIPPING //TODO: scissor/clipping depending of how many vertices are outside/inside the clipspace, implement complete Cohen-Sutherland algo or similar
//TODO: scissor/clipping depending of how many vertices are outside/inside the clipspace, implement complete Cohen-Sutherland algo or CyrusBeck one
if (VertexClipTest(projVertices[indicePtr[i]], mRTSize, 2.5f) && if (VertexClipTest(projVertices[indicePtr[i]], mRTSize, 2.5f) &&
VertexClipTest(projVertices[indicePtr[i+1]], mRTSize, 2.5f) && VertexClipTest(projVertices[indicePtr[i+1]], mRTSize, 2.5f) &&
VertexClipTest(projVertices[indicePtr[i+2]], mRTSize, 2.5f)) VertexClipTest(projVertices[indicePtr[i+2]], mRTSize, 2.5f))
#endif
{ {
M3D_VECTOR V1 = M3D_V4LoadF4(&projVertices[indicePtr[i]]); M3D_VECTOR V1 = M3D_V4LoadF4(&projVertices[indicePtr[i]]);

View File

@ -52,24 +52,19 @@ Game::Game(std::shared_ptr<sf::RenderWindow> mainWnd, bool dbgFlag) : mbDbgModeE
GAME_STATUS Game::Tick() { GAME_STATUS Game::Tick() {
static std::vector<double> msTicksMonitoring; static std::vector<double> msTicksMonitoring;
static double mPrevdelta = 0;
static double mLastCycleSleepDelta = 0; static double mLastCycleSleepDelta = 0;
static unsigned int mFrameCnt = 0; static unsigned int mFrameCnt = 0;
double mDelta = mSysTimer.GetDeltaTimeUs();
// Debug performance computations // Debug performance computations
if (mDbgUI != nullptr && mPerfsTimer != nullptr) { if (mDbgUI != nullptr && mPerfsTimer != nullptr) {
msTicksMonitoring.push_back(((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) * TARGET_FPS / 1000000.f); msTicksMonitoring.push_back(((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) * TARGET_FPS / 1000000.f);
if (mPerfsTimer->GetDeltaTime() >= 1000) { // Every 1s if (mPerfsTimer->GetDeltaTime() >= 1000) { // Every 1s
// This average CPU/cycle_time method can monitor when CPU is in overload state (>0%) or in underload one (<0%) // This average CPU/cycle_time method can monitor when CPU is in overload state (>0%) or in underload one (<0%)
double cpuUsage = 100 * std::accumulate(msTicksMonitoring.begin(), msTicksMonitoring.end(), static_cast<double>(0)) / msTicksMonitoring.size(); double cpuUsage = 200 * std::accumulate(msTicksMonitoring.begin(), msTicksMonitoring.end(), static_cast<double>(0)) / msTicksMonitoring.size() - 100;
mDbgUI->UpdateDebugData( mDbgUI->UpdateDebugData(cpuUsage, (((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) / 1000), ((-mPrevdelta + mSysTimer.GetDeltaTimeUs()) / 1000), mFrameCnt, (PerfsGetVirtMem() / 1000), (PerfsGetPhysMem() / 1000));
cpuUsage,
((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) / 1000,
1000.f / TARGET_FPS,
mFrameCnt,
PerfsGetVirtMem() / 1000,
PerfsGetPhysMem() / 1000
);
mFrameCnt = 0; mFrameCnt = 0;
msTicksMonitoring.clear(); msTicksMonitoring.clear();
@ -80,20 +75,22 @@ GAME_STATUS Game::Tick() {
// Update game stats and internal stuff // Update game stats and internal stuff
Update(); Update();
// Loop the timer when reached the target FPS // Ugly way to wait for next frame... Maybe create a separate thread for rendering?
if ((mSysTimer.GetDeltaTime() >= (1000/TARGET_FPS))) { //while(time.GetDeltaTime() < (1000/TARGET_FPS)) {}
mSysTimer.Reset();
mFrameCnt++;
// Process to the final rendering if the window have the focus // Process to the final rendering if the window have the focus
if (mMainWindow->hasFocus()) if (mSysTimer.GetDeltaTime() >= (1000/TARGET_FPS) && mMainWindow->hasFocus()) {
Render(); Render();
mFrameCnt++;
mSysTimer.Reset();
mDelta = -mDelta;
} }
mPrevdelta = mDelta;
// Sleep for remaining time to avoid useless CPU usage // Sleep for remaining time to avoid useless CPU usage
mLastCycleSleepDelta = (1000000.f / TARGET_FPS) - mSysTimer.GetDeltaTimeUs(); mLastCycleSleepDelta = (1000000.f / TARGET_FPS) - (-mPrevdelta + mSysTimer.GetDeltaTimeUs());
if (mLastCycleSleepDelta > 0) if (mLastCycleSleepDelta > 0)
sf::sleep(sf::microseconds(mLastCycleSleepDelta + (1000000.f / TARGET_FPS * 0.02f))); sf::sleep(sf::microseconds(mLastCycleSleepDelta));
else else
mLastCycleSleepDelta = 0; mLastCycleSleepDelta = 0;