More code cleanup

Input is now handled by context

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-02-08 14:57:17 +01:00
parent a8ef45265c
commit 48a91ff297
12 changed files with 76 additions and 59 deletions

View File

@ -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

View File

@ -1,33 +1,8 @@
#include <FreeImage.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <SDL.h>
#include <csignal>
#include <filesystem>
#include <getopt.h>
#include <iostream>
#include <libgen.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#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;

View File

@ -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 <unistd.h>
@ -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

View File

@ -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"

View File

@ -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 ();
}

View File

@ -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;
};
}

View File

@ -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;
}

View File

@ -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;
};
}

View File

@ -52,12 +52,13 @@ int CustomXIOErrorHandler (Display* dsp)
return 0;
}
CRenderContext::CRenderContext (std::vector <std::string> screens, CVideoDriver& driver, CContainer& container, CWallpaperApplication& app) :
CRenderContext::CRenderContext (std::vector <std::string> 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

View File

@ -3,11 +3,12 @@
#include <vector>
#include <glm/vec4.hpp>
#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 <X11/Xlib.h>
using namespace WallpaperEngine::Application;
@ -33,13 +34,13 @@ namespace WallpaperEngine::Render
class CRenderContext
{
public:
CRenderContext (std::vector <std::string> screens, CVideoDriver& driver, CContainer& container, CWallpaperApplication& app);
CRenderContext (std::vector <std::string> 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 <std::string> m_screens;
std::vector <viewport> m_viewports;
CWallpaper* m_wallpaper;
CMouseInput* m_mouse;
CInputContext& m_input;
CContainer& m_container;
CWallpaperApplication& m_app;
CTextureCache* m_textureCache;

View File

@ -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
}

View File

@ -1,8 +1,8 @@
#pragma once
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
namespace WallpaperEngine::Render::Drivers
{