add basic ah physicsworld
This commit is contained in:
+53
-35
@@ -12,10 +12,12 @@
|
||||
|
||||
#include <Jolt/Jolt.h>
|
||||
|
||||
App::App() {
|
||||
App::App()
|
||||
{
|
||||
}
|
||||
|
||||
void App::init(const AppParams ¶ms) {
|
||||
void App::init(const AppParams& params)
|
||||
{
|
||||
m_params = params;
|
||||
|
||||
AssetFS::GetInstance().Init(params.exeDir);
|
||||
@@ -33,7 +35,8 @@ void App::init(const AppParams ¶ms) {
|
||||
SDL_WINDOW_VULKAN);
|
||||
|
||||
SDL_SetWindowResizable(window, SDL_TRUE);
|
||||
if (!window) {
|
||||
if (!window)
|
||||
{
|
||||
spdlog::error("Failed to create window. SDL Error: {}", SDL_GetError());
|
||||
std::exit(1);
|
||||
}
|
||||
@@ -48,7 +51,8 @@ void App::init(const AppParams ¶ms) {
|
||||
customInit();
|
||||
}
|
||||
|
||||
void App::run() {
|
||||
void App::run()
|
||||
{
|
||||
Time::GetInstance().Update(); // initialize delta timing
|
||||
|
||||
const float fixedDt = static_cast<float>(Time::GetInstance().FixedDeltaTime());
|
||||
@@ -56,14 +60,16 @@ void App::run() {
|
||||
float accumulator = 0.0f;
|
||||
|
||||
isRunning = true;
|
||||
while (isRunning) {
|
||||
while (isRunning)
|
||||
{
|
||||
// ---- Update timing ---
|
||||
Time::GetInstance().Update();
|
||||
float dt = static_cast<float>(Time::GetInstance().DeltaTime());
|
||||
|
||||
if (dt > 0.25f) dt = 0.25f;
|
||||
|
||||
if (dt > 0.0f) {
|
||||
if (dt > 0.0f)
|
||||
{
|
||||
float newFPS = 1.0f / dt;
|
||||
avgFPS = std::lerp(avgFPS, newFPS, 0.1f);
|
||||
}
|
||||
@@ -75,16 +81,21 @@ void App::run() {
|
||||
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
imguiPass.handleEvent(event);
|
||||
if (event.type == SDL_QUIT) {
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
isRunning = false;
|
||||
break;
|
||||
}
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
case SDL_WINDOWEVENT_RESIZED: {
|
||||
if (event.type == SDL_WINDOWEVENT)
|
||||
{
|
||||
switch (event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
{
|
||||
resizePending = true;
|
||||
lastResizeTime = std::chrono::steady_clock::now();
|
||||
break;
|
||||
@@ -92,22 +103,24 @@ void App::run() {
|
||||
}
|
||||
}
|
||||
const bool mouseEvent =
|
||||
event.type == SDL_MOUSEBUTTONDOWN ||
|
||||
event.type == SDL_MOUSEBUTTONUP ||
|
||||
event.type == SDL_MOUSEMOTION ||
|
||||
event.type == SDL_MOUSEWHEEL;
|
||||
event.type == SDL_MOUSEBUTTONDOWN ||
|
||||
event.type == SDL_MOUSEBUTTONUP ||
|
||||
event.type == SDL_MOUSEMOTION ||
|
||||
event.type == SDL_MOUSEWHEEL;
|
||||
|
||||
const bool keyboardEvent =
|
||||
event.type == SDL_KEYDOWN ||
|
||||
event.type == SDL_KEYUP ||
|
||||
event.type == SDL_TEXTINPUT;
|
||||
event.type == SDL_KEYDOWN ||
|
||||
event.type == SDL_KEYUP ||
|
||||
event.type == SDL_TEXTINPUT;
|
||||
|
||||
const bool capturedByImgui =
|
||||
(mouseEvent && imguiPass.wantsMouse()) ||
|
||||
(keyboardEvent && imguiPass.wantsKeyboard());
|
||||
(mouseEvent && imguiPass.wantsMouse()) ||
|
||||
(keyboardEvent && imguiPass.wantsKeyboard());
|
||||
|
||||
if (!capturedByImgui) {
|
||||
if (InputManager::GetInstance().ProcessEvent(event)) {
|
||||
if (!capturedByImgui)
|
||||
{
|
||||
if (InputManager::GetInstance().ProcessEvent(event))
|
||||
{
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
@@ -123,13 +136,12 @@ void App::run() {
|
||||
|
||||
imguiPass.endFrame();
|
||||
int steps = 0;
|
||||
while (accumulator >= fixedDt && steps < maxSteps) {
|
||||
while (accumulator >= fixedDt && steps < maxSteps)
|
||||
{
|
||||
// physics.Update(fixedDt);
|
||||
|
||||
SDL_SetWindowTitle(
|
||||
window,
|
||||
fmt::format("{} - FPS: {:.2f}", m_params.windowTitle, avgFPS).c_str()
|
||||
);
|
||||
customFixedUpdate(fixedDt);
|
||||
// physics.Step(fixedDt);
|
||||
// physics.SyncTransforms();
|
||||
|
||||
accumulator -= fixedDt;
|
||||
steps++;
|
||||
@@ -138,11 +150,13 @@ void App::run() {
|
||||
|
||||
const float alpha = accumulator / fixedDt;
|
||||
|
||||
if (gfxDevice.needsSwapchainRecreate() || resizePending) {
|
||||
if (gfxDevice.needsSwapchainRecreate() || resizePending)
|
||||
{
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
if (resizePending &&
|
||||
now - lastResizeTime < std::chrono::milliseconds(100)) {
|
||||
now - lastResizeTime < std::chrono::milliseconds(100))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -150,7 +164,8 @@ void App::run() {
|
||||
int h = 0;
|
||||
SDL_Vulkan_GetDrawableSize(window, &w, &h);
|
||||
|
||||
if (w == 0 || h == 0) {
|
||||
if (w == 0 || h == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -166,9 +181,11 @@ void App::run() {
|
||||
customDraw();
|
||||
|
||||
|
||||
if (frameLimit) {
|
||||
if (frameLimit)
|
||||
{
|
||||
auto sleepTime = Time::GetInstance().SleepDuration();
|
||||
if (sleepTime.count() > 0) {
|
||||
if (sleepTime.count() > 0)
|
||||
{
|
||||
std::this_thread::sleep_for(sleepTime);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +194,8 @@ void App::run() {
|
||||
gfxDevice.waitIdle();
|
||||
}
|
||||
|
||||
void App::cleanup() {
|
||||
void App::cleanup()
|
||||
{
|
||||
spdlog::info("Cleaning up");
|
||||
customCleanup();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user