From 2059e4b7db987a00e275d3cafc56e7131f93aea0 Mon Sep 17 00:00:00 2001 From: "Grayson Riffe (Desktop)" Date: Tue, 2 Nov 2021 22:49:22 -0500 Subject: [PATCH] Minor fixes and changes --- Game/src/MainState.cpp | 2 +- NothinFancy/src/Application.cpp | 26 ++++++++++++-------------- NothinFancy/src/AudioEngine.cpp | 2 +- NothinFancy/src/Renderer/Renderer.cpp | 5 ++--- NothinFancy/src/include/Application.h | 6 +++--- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index b063661..5bd32ea 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -80,7 +80,7 @@ void MainState::update(float deltaTime) { sound2.stop(); } - if (app->isMouseClicked(NFI_LEFTMOUSE) || app->isMouseHeld(NFI_RIGHTMOUSE)) { + if (camera->getType() == nf::Camera::Type::FIRST_PERSON && (app->isMouseClicked(NFI_LEFTMOUSE) || app->isMouseHeld(NFI_RIGHTMOUSE))) { entities.push_back(new nf::Entity); entities.back()->create(nf::BaseAssets::sphere, nf::Entity::Type::DYNAMIC); entities.back()->setPosition(camera->getPosition() + camera->getRotation() * 5.0); diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp index 271613d..b729078 100644 --- a/NothinFancy/src/Application.cpp +++ b/NothinFancy/src/Application.cpp @@ -31,15 +31,14 @@ namespace nf { int y = 0; calculateNewWindowPos(x, y); m_window = CreateWindowEx(NULL, m_wclassName, toWide(m_currentConfig.title).data(), WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, x, y, windowSize.right, windowSize.bottom, NULL, NULL, m_hInst, NULL); - m_defaultWindowStyle = GetWindowLong(m_window, GWL_STYLE); SetProp(m_window, L"App", this); if (m_currentConfig.fullscreen) toggleFullscreen(); } - void Application::setWindowIcon(HANDLE hIcon) { + void Application::setWindowIcon(HICON hIcon) { m_customWindowIconSet = true; + m_windowIcon = hIcon; SendMessage(m_window, WM_SETICON, ICON_BIG, (LPARAM)hIcon); - SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } //TODO: Test these top-level features void Application::setWindowCursor(HCURSOR hCursor) { @@ -104,7 +103,7 @@ namespace nf { mainThread.join(); } - bool Application::isCustomWindowIcon() { + bool Application::hasCustomWindowIcon() { return m_customWindowIconSet; } @@ -255,6 +254,7 @@ namespace nf { else { SetWindowLong(m_window, GWL_STYLE, wndStyle | WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX); SetWindowPos(m_window, HWND_TOP, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); + SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)m_windowIcon); } } @@ -373,16 +373,14 @@ namespace nf { return 0; } case WM_SYSKEYDOWN: { - if (GetKeyState(VK_RETURN) & 0x8000) { - if (!(lParam & (1 << 30))) { - if (!app->m_currentConfig.fullscreen) { - app->m_altWidth = app->m_currentConfig.width; - app->m_altHeight = app->m_currentConfig.height; - } - app->changeConfig({ app->m_currentConfig.width, app->m_currentConfig.height, !app->m_currentConfig.fullscreen, app->m_currentConfig.title }); - if (!app->m_currentConfig.fullscreen) { - app->changeConfig({ app->m_altWidth, app->m_altHeight, app->m_currentConfig.fullscreen, app->m_currentConfig.title }); - } + if (GetKeyState(VK_RETURN) & 0x8000 && !(lParam & (1 << 30))) { + if (!app->m_currentConfig.fullscreen) { + app->m_altWidth = app->m_currentConfig.width; + app->m_altHeight = app->m_currentConfig.height; + } + app->changeConfig({ app->m_currentConfig.width, app->m_currentConfig.height, !app->m_currentConfig.fullscreen, app->m_currentConfig.title }); + if (!app->m_currentConfig.fullscreen) { + app->changeConfig({ app->m_altWidth, app->m_altHeight, app->m_currentConfig.fullscreen, app->m_currentConfig.title }); } return 0; } diff --git a/NothinFancy/src/AudioEngine.cpp b/NothinFancy/src/AudioEngine.cpp index 15aa5bb..6d62ceb 100644 --- a/NothinFancy/src/AudioEngine.cpp +++ b/NothinFancy/src/AudioEngine.cpp @@ -58,7 +58,7 @@ namespace nf { SetThreadDescription(GetCurrentThread(), L"Audio Thread"); #endif //Wait to initialize stuff until the master voice is created if it hasn't been already - while (!m_isActive) { + while (m_threadRunning && !m_isActive) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index 5f6854f..ff134a5 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -89,7 +89,7 @@ namespace nf { m_pointDepthTexSize = 2048; createShadowMaps(); - if (!m_app->isCustomWindowIcon()) { + if (!m_app->hasCustomWindowIcon()) { ATexture& windowTex = *(ATexture*)m_baseAP["defaultwindowicon.png"]; int width, height, nChannels; unsigned char* tex = stbi_load_from_memory((const unsigned char*)windowTex.data, (unsigned int)windowTex.size, &width, &height, &nChannels, 0); @@ -102,8 +102,7 @@ namespace nf { } stbi_image_free(tex); HICON windowIcon = CreateIcon(GetModuleHandle(NULL), width, height, 1, 32, NULL, &pixels[0]); - SendMessage(m_app->getWindow(), WM_SETICON, ICON_BIG, (LPARAM)windowIcon); - SendMessage(m_app->getWindow(), WM_SETICON, ICON_SMALL, (LPARAM)windowIcon); + m_app->setWindowIcon(windowIcon); } float quadVB[] = { diff --git a/NothinFancy/src/include/Application.h b/NothinFancy/src/include/Application.h index 7f9a3bc..01d324c 100644 --- a/NothinFancy/src/include/Application.h +++ b/NothinFancy/src/include/Application.h @@ -22,7 +22,7 @@ namespace nf { Application() = delete; Application(Application& other) = delete; - void setWindowIcon(HANDLE hIcon); + void setWindowIcon(HICON hIcon); void setWindowCursor(HCURSOR hCursor); AudioEngine* getAudioEngine() const; PhysicsEngine* getPhysicsEngine() const; @@ -30,7 +30,7 @@ namespace nf { void setDefaultState(const std::string& stateName); const std::string& getDefaultState(); void run(); - bool isCustomWindowIcon(); + bool hasCustomWindowIcon(); void changeState(const std::string& stateName); Gamestate* getCurrentState(); void showWindow(bool show); @@ -69,7 +69,7 @@ namespace nf { LPCWSTR m_wclassName; HWND m_window; bool m_customWindowIconSet; - LONG m_defaultWindowStyle; + HICON m_windowIcon; unsigned int m_altWidth, m_altHeight; std::chrono::duration m_fpsDuration;