Skip to content

Commit

Permalink
Merge pull request #48 from vilbeyli/dev
Browse files Browse the repository at this point in the history
Timer & FrameTime
  • Loading branch information
vilbeyli authored Jul 14, 2020
2 parents 5eb2df7 + aec9bbc commit 2f2d3b6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Libs/VQUtils
2 changes: 1 addition & 1 deletion Source/Application/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ namespace GeometryGenerator
{
for (int i = 0; i < (int)data.Indices.size(); i += 3)
{
int Indices[3] =
TIndex Indices[3] =
{
data.Indices[i + 0]
, data.Indices[i + 1]
Expand Down
11 changes: 7 additions & 4 deletions Source/Application/VQEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "Camera.h"

#include "Libs/VQUtils/Source/Multithreading.h"
#include "Libs/VQUtils/Source/Timer.h"

#include "Source/Renderer/Renderer.h"

#include <memory>
Expand Down Expand Up @@ -170,14 +172,14 @@ class VQEngine : public IWindowOwner
// PRE_UPDATE()
// - Updates timer
// - Updates input state reading from Main Thread's input queue
void UpdateThread_PreUpdate();
void UpdateThread_PreUpdate(float& dt);

// UPDATE()
// - Updates program state (init/load/sim/unload/exit)
// - Starts loading tasks
// - Animates loading screen
// - Updates scene data
void UpdateThread_UpdateAppState();
void UpdateThread_UpdateAppState(const float dt);

// POST_UPDATE()
// - Computes visibility per SceneView
Expand All @@ -189,6 +191,7 @@ class VQEngine : public IWindowOwner
private:
using BuiltinMeshArray_t = std::array<Mesh , EBuiltInMeshes::NUM_BUILTIN_MESHES>;
using BuiltinMeshNameArray_t = std::array<std::string, EBuiltInMeshes::NUM_BUILTIN_MESHES>;
using EventQueue_t = BufferedContainer<std::queue<std::unique_ptr<IEvent>>, std::unique_ptr<IEvent>>;

// threads
std::thread mRenderThread;
Expand Down Expand Up @@ -230,9 +233,9 @@ class VQEngine : public IWindowOwner
// input

// events
BufferedContainer<std::queue<std::unique_ptr<IEvent>>, std::unique_ptr<IEvent>> mWinEventQueue;

EventQueue_t mWinEventQueue;

Timer mTimer;


private:
Expand Down
2 changes: 1 addition & 1 deletion Source/Application/VQEngine_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ constexpr char* BUILD_CONFIG = "Debug";
#else
constexpr char* BUILD_CONFIG = "Release";
#endif
constexpr char* VQENGINE_VERSION = "v0.1.0";
constexpr char* VQENGINE_VERSION = "v0.2.0";


void VQEngine::MainThread_Tick()
Expand Down
30 changes: 26 additions & 4 deletions Source/Application/VQEngine_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ void VQEngine::UpdateThread_Main()
UpdateThread_Inititalize();

bool bQuit = false;
float dt = 0.0f;
while (!mbStopAllThreads && !bQuit)
{
UpdateThread_PreUpdate();
UpdateThread_PreUpdate(dt);

#if DEBUG_LOG_THREAD_SYNC_VERBOSE
Log::Info(/*"UpdateThread_Tick() : */"u%d (r=%llu)", mNumUpdateLoopsExecuted.load(), mNumRenderLoopsExecuted.load());
#endif

UpdateThread_UpdateAppState();
UpdateThread_UpdateAppState(dt);

UpdateThread_PostUpdate();

Expand All @@ -63,6 +64,9 @@ void VQEngine::UpdateThread_Inititalize()
mpWinMain->Show();
if (mpWinDebug)
mpWinDebug->Show();

mTimer.Reset();
mTimer.Start();
}

void VQEngine::UpdateThread_Exit()
Expand All @@ -85,18 +89,20 @@ void VQEngine::UpdateThread_SignalRenderThread()
mpSemRender->Signal();
}

void VQEngine::UpdateThread_PreUpdate()
void VQEngine::UpdateThread_PreUpdate(float& dt)
{
// update timer
dt = mTimer.Tick();

// update input

}

void VQEngine::UpdateThread_UpdateAppState()
void VQEngine::UpdateThread_UpdateAppState(const float dt)
{
assert(mbRenderThreadInitialized);


if (mAppState == EAppState::INITIALIZING)
{
// start loading
Expand Down Expand Up @@ -129,17 +135,33 @@ void VQEngine::UpdateThread_UpdateAppState()

else
{
const int NUM_BACK_BUFFERS = mRenderer.GetSwapChainBackBufferCount(mpWinMain->GetHWND());
const int FRAME_DATA_INDEX = mNumUpdateLoopsExecuted % NUM_BACK_BUFFERS;

// update scene data
mScene_MainWnd.mFrameData[FRAME_DATA_INDEX].TFCube.RotateAroundAxisRadians(YAxis, dt * 0.2f * PI);
}

}

void VQEngine::UpdateThread_PostUpdate()
{
if (mbLoadingLevel)
{
return;
}

// compute visibility

// extract scene view

// copy over state for next frame

const int NUM_BACK_BUFFERS = mRenderer.GetSwapChainBackBufferCount(mpWinMain->GetHWND());
const int FRAME_DATA_INDEX = mNumUpdateLoopsExecuted % NUM_BACK_BUFFERS;
const int FRAME_DATA_NEXT_INDEX = ((mNumUpdateLoopsExecuted % NUM_BACK_BUFFERS) + 1) % NUM_BACK_BUFFERS;

mScene_MainWnd.mFrameData[FRAME_DATA_NEXT_INDEX] = mScene_MainWnd.mFrameData[FRAME_DATA_INDEX];
}


Expand Down
2 changes: 1 addition & 1 deletion Source/Shaders/hello-cube.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ PSInput VSMain(float4 position : POSITION, float4 color : COLOR, float2 uv : TEX
float4 PSMain(PSInput input) : SV_TARGET
{
float3 ColorTex = texColor.SampleLevel(Sampler, input.uv, 0).rgb;
float3 ColorVert = input.color;
float3 ColorVert = input.color * 0.8f; // Dim the vert colors a bit... they're too bright and look uglier.
float3 Color = ColorVert * ColorTex;
return float4(Color, 1);
}

0 comments on commit 2f2d3b6

Please sign in to comment.