Reworked frame timing again; Reworked input
This commit is contained in:
parent
9fcd8240e4
commit
d628bbb184
@ -109,7 +109,7 @@
|
||||
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@ -135,7 +135,7 @@
|
||||
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -157,7 +157,7 @@
|
||||
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -183,7 +183,7 @@
|
||||
<AdditionalDependencies>nf.res;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
40
NFPackCreator/AssetBuild/CubeTest/models/cube.obj
Normal file
40
NFPackCreator/AssetBuild/CubeTest/models/cube.obj
Normal file
@ -0,0 +1,40 @@
|
||||
# Blender v2.93.3 OBJ File: ''
|
||||
# www.blender.org
|
||||
o Cube_Cube.001
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 -1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
v -1.000000 1.000000 1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v 1.000000 1.000000 1.000000
|
||||
vt 0.375000 0.003906
|
||||
vt 0.625000 0.253906
|
||||
vt 0.375000 0.253906
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.625000 1.000000
|
||||
vt 0.625000 0.003906
|
||||
vt 0.125000 0.750000
|
||||
vt 0.375000 1.000000
|
||||
s off
|
||||
f 2/1 3/2 1/3
|
||||
f 4/4 7/5 3/6
|
||||
f 8/7 5/8 7/5
|
||||
f 6/9 1/10 5/8
|
||||
f 7/5 1/11 3/12
|
||||
f 4/13 6/9 8/7
|
||||
f 2/1 4/14 3/2
|
||||
f 4/4 8/7 7/5
|
||||
f 8/7 6/9 5/8
|
||||
f 6/9 2/15 1/10
|
||||
f 7/5 5/8 1/11
|
||||
f 4/13 2/16 6/9
|
BIN
NFPackCreator/AssetBuild/CubeTest/textures/cube.png
Normal file
BIN
NFPackCreator/AssetBuild/CubeTest/textures/cube.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
@ -78,6 +78,7 @@ namespace nf {
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateInput();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
mainThread.join();
|
||||
@ -185,33 +186,40 @@ namespace nf {
|
||||
}
|
||||
}
|
||||
|
||||
void Application::updateInput() {
|
||||
for (unsigned int i = 0; i < 164; i++) {
|
||||
if (GetFocus() == m_window)
|
||||
m_input[i] = GetKeyState(i) & 0x8000;
|
||||
else
|
||||
m_input[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::runMainGameThread() {
|
||||
m_renderer = new Renderer(this);
|
||||
startIntroState();
|
||||
std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now();
|
||||
const std::chrono::duration<double> wait_time = std::chrono::nanoseconds(1000000000 / 60);
|
||||
auto next_time = start_time + wait_time;
|
||||
m_deltaTime = 0.0167;
|
||||
std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now();
|
||||
std::chrono::steady_clock::time_point lastFrame = std::chrono::steady_clock::now();
|
||||
while (m_running) {
|
||||
start_time = std::chrono::steady_clock::now();
|
||||
m_currentState->update(m_deltaTime);
|
||||
m_currentState->render(*m_renderer);
|
||||
m_renderer->doFrame();
|
||||
m_frames++;
|
||||
if (m_stateChange)
|
||||
doStateChange();
|
||||
currentTime = std::chrono::steady_clock::now();
|
||||
m_deltaTime = std::chrono::duration<double>(currentTime - lastFrame).count();
|
||||
if (m_deltaTime >= m_minFrametime) {
|
||||
lastFrame = std::chrono::steady_clock::now();
|
||||
m_currentState->update(m_deltaTime);
|
||||
m_currentState->render(*m_renderer);
|
||||
m_renderer->doFrame();
|
||||
m_frames++;
|
||||
if (m_stateChange)
|
||||
doStateChange();
|
||||
}
|
||||
m_fpsClock2 = std::chrono::steady_clock::now();
|
||||
m_fpsDuration = m_fpsClock2 - m_fpsClock1;
|
||||
if (m_fpsDuration.count() >= 1.0) {
|
||||
m_FPS = m_frames - 1;
|
||||
m_FPS = m_frames;
|
||||
m_frames = 0;
|
||||
Log("FPS: " + std::to_string(m_FPS));
|
||||
m_fpsClock1 = std::chrono::steady_clock::now();
|
||||
}
|
||||
std::this_thread::sleep_until(next_time);
|
||||
m_deltaTime = (double)(std::chrono::steady_clock::now() - start_time).count();
|
||||
next_time += wait_time;
|
||||
//TODO: Redo FPS AGAIN like how I did it in PongClone
|
||||
}
|
||||
m_currentState->onExit();
|
||||
delete m_renderer;
|
||||
@ -255,42 +263,6 @@ namespace nf {
|
||||
case WM_MENUCHAR: {
|
||||
return MNC_CLOSE << 16;
|
||||
}
|
||||
case WM_LBUTTONDOWN: {
|
||||
app->m_input[1] = true;
|
||||
return 0;
|
||||
}
|
||||
case WM_LBUTTONUP: {
|
||||
app->m_input[1] = false;
|
||||
return 0;
|
||||
}
|
||||
case WM_RBUTTONDOWN: {
|
||||
app->m_input[2] = true;
|
||||
return 0;
|
||||
}
|
||||
case WM_RBUTTONUP: {
|
||||
app->m_input[2] = false;
|
||||
return 0;
|
||||
}
|
||||
case WM_MBUTTONDOWN: {
|
||||
app->m_input[4] = true;
|
||||
return 0;
|
||||
}
|
||||
case WM_MBUTTONUP: {
|
||||
app->m_input[4] = false;
|
||||
return 0;
|
||||
}
|
||||
case WM_KEYDOWN: {
|
||||
if (wParam < 164 && !(lParam & (1 << 30))) {
|
||||
app->m_input[wParam] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_KEYUP: {
|
||||
if (wParam < 164) {
|
||||
app->m_input[wParam] = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_CLOSE: {
|
||||
DestroyWindow(hWnd);
|
||||
return 0;
|
||||
|
@ -70,7 +70,7 @@ namespace nf {
|
||||
|
||||
void Renderer::doFrame() {
|
||||
glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height);
|
||||
proj = glm::perspective(glm::radians(45.0f), (float)m_app->getConfig().width / (float)m_app->getConfig().height, 0.1f, 100.0f);
|
||||
proj = glm::perspective(glm::radians(45.0f), (float)m_app->getConfig().width / (float)m_app->getConfig().height, 0.1f, 100000.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
for (Entity* draw : m_lGame) {
|
||||
|
@ -35,6 +35,7 @@ namespace nf {
|
||||
RECT getWindowRect() const;
|
||||
void calculateNewWindowPos(int& x, int& y);
|
||||
void toggleFullscreen();
|
||||
void updateInput();
|
||||
void runMainGameThread();
|
||||
void startIntroState();
|
||||
void doStateChange();
|
||||
|
Reference in New Issue
Block a user