diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b2f994..d897adc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,8 +78,10 @@ add_executable( src/WallpaperEngine/Audio/CAudioStream.cpp src/WallpaperEngine/Audio/CAudioStream.h - src/WallpaperEngine/Input/CMouseInput.h + src/WallpaperEngine/Input/CInputContext.cpp + src/WallpaperEngine/Input/CInputContext.h src/WallpaperEngine/Input/CMouseInput.cpp + src/WallpaperEngine/Input/CMouseInput.h src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp diff --git a/main.cpp b/main.cpp index 35e624b..e612b5a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,33 +1,8 @@ -#include -#include -#include -#include #include -#include -#include #include -#include -#include -#include -#include -#include "WallpaperEngine/Core/CProject.h" -#include "WallpaperEngine/Render/CRenderContext.h" -#include "WallpaperEngine/Render/CVideo.h" -#include "WallpaperEngine/Render/CWallpaper.h" - -#include "WallpaperEngine/Assets/CPackage.h" -#include "WallpaperEngine/Assets/CDirectory.h" -#include "WallpaperEngine/Assets/CVirtualContainer.h" -#include "WallpaperEngine/Assets/CCombinedContainer.h" -#include "WallpaperEngine/Assets/CPackageLoadException.h" - -#include "Steam/FileSystem/FileSystem.h" #include "WallpaperEngine/Application/CApplicationContext.h" #include "WallpaperEngine/Application/CWallpaperApplication.h" -#include "WallpaperEngine/Audio/CAudioContext.h" -#include "WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h" -#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" #include "common.h" WallpaperEngine::Application::CWallpaperApplication* appPointer; diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 1df162e..3c932bc 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -5,7 +5,6 @@ #include "WallpaperEngine/Core/CVideo.h" #include "WallpaperEngine/Logging/CLog.h" #include "WallpaperEngine/Render/CRenderContext.h" -#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" #include @@ -216,13 +215,13 @@ void CWallpaperApplication::show () // initialize sdl audio driver WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver; // initialize audio context - WallpaperEngine::Audio::CAudioContext audioContext (&audioDriver); + WallpaperEngine::Audio::CAudioContext audioContext (audioDriver); // initialize OpenGL driver WallpaperEngine::Render::Drivers::COpenGLDriver videoDriver (this->m_project->getTitle ().c_str ()); + // initialize the input subsystem + WallpaperEngine::Input::CInputContext inputContext (videoDriver); // initialize render context - WallpaperEngine::Render::CRenderContext context (this->m_context.screens, videoDriver, this->m_vfs, *this); - // initialize mouse support - context.setMouse (new CMouseInput (videoDriver.getWindow ())); + WallpaperEngine::Render::CRenderContext context (this->m_context.screens, videoDriver, inputContext, this->m_vfs, *this); // ensure the context knows what wallpaper to render context.setWallpaper ( WallpaperEngine::Render::CWallpaper::fromWallpaper (this->m_project->getWallpaper (), context, audioContext) @@ -232,6 +231,8 @@ void CWallpaperApplication::show () while (videoDriver.closeRequested () == false && g_KeepRunning == true) { + // update input information + inputContext.update (); // keep track of the previous frame's time g_TimeLast = g_Time; // calculate the current time value diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.h b/src/WallpaperEngine/Application/CWallpaperApplication.h index bd99b95..55e9d18 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.h +++ b/src/WallpaperEngine/Application/CWallpaperApplication.h @@ -1,6 +1,7 @@ #pragma once #include "CApplicationContext.h" +#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" #include "WallpaperEngine/Assets/CCombinedContainer.h" #include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Render/CWallpaper.h" diff --git a/src/WallpaperEngine/Audio/CAudioContext.cpp b/src/WallpaperEngine/Audio/CAudioContext.cpp index d610c00..f3af8cf 100644 --- a/src/WallpaperEngine/Audio/CAudioContext.cpp +++ b/src/WallpaperEngine/Audio/CAudioContext.cpp @@ -4,7 +4,7 @@ using namespace WallpaperEngine::Audio; using namespace WallpaperEngine::Audio::Drivers; -CAudioContext::CAudioContext (CAudioDriver* driver) : +CAudioContext::CAudioContext (CAudioDriver& driver) : m_driver (driver) { @@ -12,20 +12,20 @@ CAudioContext::CAudioContext (CAudioDriver* driver) : void CAudioContext::addStream (CAudioStream* stream) { - this->m_driver->addStream (stream); + this->m_driver.addStream (stream); } AVSampleFormat CAudioContext::getFormat () const { - return this->m_driver->getFormat (); + return this->m_driver.getFormat (); } int CAudioContext::getSampleRate () const { - return this->m_driver->getSampleRate (); + return this->m_driver.getSampleRate (); } int CAudioContext::getChannels () const { - return this->m_driver->getChannels (); + return this->m_driver.getChannels (); } \ No newline at end of file diff --git a/src/WallpaperEngine/Audio/CAudioContext.h b/src/WallpaperEngine/Audio/CAudioContext.h index 1e59811..c9f95b5 100644 --- a/src/WallpaperEngine/Audio/CAudioContext.h +++ b/src/WallpaperEngine/Audio/CAudioContext.h @@ -15,7 +15,7 @@ namespace WallpaperEngine::Audio class CAudioContext { public: - CAudioContext (Drivers::CAudioDriver* driver); + CAudioContext (Drivers::CAudioDriver& driver); void addStream (CAudioStream* stream); @@ -23,6 +23,6 @@ namespace WallpaperEngine::Audio int getSampleRate () const; int getChannels () const; private: - Drivers::CAudioDriver* m_driver; + Drivers::CAudioDriver& m_driver; }; } \ No newline at end of file diff --git a/src/WallpaperEngine/Input/CInputContext.cpp b/src/WallpaperEngine/Input/CInputContext.cpp new file mode 100644 index 0000000..cf97ccf --- /dev/null +++ b/src/WallpaperEngine/Input/CInputContext.cpp @@ -0,0 +1,20 @@ +#include "CInputContext.h" +#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" + +using namespace WallpaperEngine::Input; +using namespace WallpaperEngine::Render::Drivers; + +CInputContext::CInputContext (COpenGLDriver& videoDriver) : + m_mouse (videoDriver.getWindow ()) +{ +} + +void CInputContext::update () +{ + this->m_mouse.update (); +} + +const CMouseInput& CInputContext::getMouseInput () const +{ + return this->m_mouse; +} \ No newline at end of file diff --git a/src/WallpaperEngine/Input/CInputContext.h b/src/WallpaperEngine/Input/CInputContext.h new file mode 100644 index 0000000..44f0114 --- /dev/null +++ b/src/WallpaperEngine/Input/CInputContext.h @@ -0,0 +1,24 @@ +#pragma once + +#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h" +#include "CMouseInput.h" + +namespace WallpaperEngine::Render::Drivers +{ + class COpenGLDriver; +} + +namespace WallpaperEngine::Input +{ + class CInputContext + { + public: + CInputContext (Render::Drivers::COpenGLDriver& videoDriver); + void update (); + + const CMouseInput& getMouseInput () const; + + private: + CMouseInput m_mouse; + }; +} diff --git a/src/WallpaperEngine/Render/CRenderContext.cpp b/src/WallpaperEngine/Render/CRenderContext.cpp index da29901..a41e603 100644 --- a/src/WallpaperEngine/Render/CRenderContext.cpp +++ b/src/WallpaperEngine/Render/CRenderContext.cpp @@ -52,12 +52,13 @@ int CustomXIOErrorHandler (Display* dsp) return 0; } -CRenderContext::CRenderContext (std::vector screens, CVideoDriver& driver, CContainer& container, CWallpaperApplication& app) : +CRenderContext::CRenderContext (std::vector screens, CVideoDriver& driver, CInputContext& input, CContainer& container, CWallpaperApplication& app) : m_wallpaper (nullptr), m_screens (std::move (screens)), m_driver (driver), m_container (container), m_app (app), + m_input (input), m_textureCache (new CTextureCache (*this)) { this->initialize (); @@ -228,9 +229,6 @@ void CRenderContext::render () if (this->m_wallpaper == nullptr) return; - // ensure mouse information is up to date before drawing any frame - this->m_mouse->update (); - if (this->m_viewports.empty () == false) this->renderScreens (); else @@ -260,14 +258,9 @@ void CRenderContext::setWallpaper (CWallpaper* wallpaper) } } -CMouseInput* CRenderContext::getMouse () const +CInputContext& CRenderContext::getInputContext () const { - return this->m_mouse; -} - -void CRenderContext::setMouse (CMouseInput* mouse) -{ - this->m_mouse = mouse; + return this->m_input; } CWallpaper* CRenderContext::getWallpaper () const diff --git a/src/WallpaperEngine/Render/CRenderContext.h b/src/WallpaperEngine/Render/CRenderContext.h index c1dcab9..56ee581 100644 --- a/src/WallpaperEngine/Render/CRenderContext.h +++ b/src/WallpaperEngine/Render/CRenderContext.h @@ -3,11 +3,12 @@ #include #include -#include "WallpaperEngine/Input/CMouseInput.h" -#include "WallpaperEngine/Render/Drivers/CVideoDriver.h" -#include "WallpaperEngine/Application/CWallpaperApplication.h" #include "CTextureCache.h" #include "CWallpaper.h" +#include "WallpaperEngine/Application/CWallpaperApplication.h" +#include "WallpaperEngine/Input/CInputContext.h" +#include "WallpaperEngine/Input/CMouseInput.h" +#include "WallpaperEngine/Render/Drivers/CVideoDriver.h" #include using namespace WallpaperEngine::Application; @@ -33,13 +34,13 @@ namespace WallpaperEngine::Render class CRenderContext { public: - CRenderContext (std::vector screens, CVideoDriver& driver, CContainer& container, CWallpaperApplication& app); + CRenderContext (std::vector screens, CVideoDriver& driver, CInputContext& input, CContainer& container, CWallpaperApplication& app); ~CRenderContext (); void initialize (); void render (); void setWallpaper (CWallpaper* wallpaper); - CMouseInput* getMouse () const; + CInputContext& getInputContext () const; void setMouse (CMouseInput* mouse); CWallpaper* getWallpaper () const; const CContainer& getContainer () const; @@ -69,7 +70,7 @@ namespace WallpaperEngine::Render std::vector m_screens; std::vector m_viewports; CWallpaper* m_wallpaper; - CMouseInput* m_mouse; + CInputContext& m_input; CContainer& m_container; CWallpaperApplication& m_app; CTextureCache* m_textureCache; diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 400a514..c11739d 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -245,15 +245,15 @@ void CScene::renderFrame (glm::ivec4 viewport) void CScene::updateMouse (glm::ivec4 viewport) { // update virtual mouse position first - CMouseInput* mouse = this->getContext ().getMouse (); + glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position; // TODO: PROPERLY TRANSLATE THESE TO WHAT'S VISIBLE ON SCREEN (FOR BACKGROUNDS THAT DO NOT EXACTLY FIT ON SCREEN) // rollover the position to the last this->m_mousePositionLast = this->m_mousePosition; // calculate the current position of the mouse - this->m_mousePosition.x = glm::clamp ((mouse->position.x - viewport.x) / viewport.z, 0.0, 1.0); - this->m_mousePosition.y = glm::clamp ((mouse->position.y - viewport.y) / viewport.w, 0.0, 1.0); + this->m_mousePosition.x = glm::clamp ((position.x - viewport.x) / viewport.z, 0.0, 1.0); + this->m_mousePosition.y = glm::clamp ((position.y - viewport.y) / viewport.w, 0.0, 1.0); // screen-space positions have to be transposed to what the screen will actually show } diff --git a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h index 1e3af0a..1c38902 100644 --- a/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h +++ b/src/WallpaperEngine/Render/Drivers/COpenGLDriver.h @@ -1,8 +1,8 @@ #pragma once -#include "WallpaperEngine/Render/Drivers/CVideoDriver.h" #include #include +#include "WallpaperEngine/Render/Drivers/CVideoDriver.h" namespace WallpaperEngine::Render::Drivers {