mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 13:22:23 +08:00
More code cleanup
Input is now handled by context Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
a8ef45265c
commit
48a91ff297
@ -78,8 +78,10 @@ add_executable(
|
|||||||
src/WallpaperEngine/Audio/CAudioStream.cpp
|
src/WallpaperEngine/Audio/CAudioStream.cpp
|
||||||
src/WallpaperEngine/Audio/CAudioStream.h
|
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.cpp
|
||||||
|
src/WallpaperEngine/Input/CMouseInput.h
|
||||||
|
|
||||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h
|
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h
|
||||||
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp
|
src/WallpaperEngine/Render/Shaders/Variables/CShaderVariable.cpp
|
||||||
|
25
main.cpp
25
main.cpp
@ -1,33 +1,8 @@
|
|||||||
#include <FreeImage.h>
|
|
||||||
#include <GL/glew.h>
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <filesystem>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <iostream>
|
#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/CApplicationContext.h"
|
||||||
#include "WallpaperEngine/Application/CWallpaperApplication.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"
|
#include "common.h"
|
||||||
|
|
||||||
WallpaperEngine::Application::CWallpaperApplication* appPointer;
|
WallpaperEngine::Application::CWallpaperApplication* appPointer;
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "WallpaperEngine/Core/CVideo.h"
|
#include "WallpaperEngine/Core/CVideo.h"
|
||||||
#include "WallpaperEngine/Logging/CLog.h"
|
#include "WallpaperEngine/Logging/CLog.h"
|
||||||
#include "WallpaperEngine/Render/CRenderContext.h"
|
#include "WallpaperEngine/Render/CRenderContext.h"
|
||||||
#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -216,13 +215,13 @@ void CWallpaperApplication::show ()
|
|||||||
// initialize sdl audio driver
|
// initialize sdl audio driver
|
||||||
WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver;
|
WallpaperEngine::Audio::Drivers::CSDLAudioDriver audioDriver;
|
||||||
// initialize audio context
|
// initialize audio context
|
||||||
WallpaperEngine::Audio::CAudioContext audioContext (&audioDriver);
|
WallpaperEngine::Audio::CAudioContext audioContext (audioDriver);
|
||||||
// initialize OpenGL driver
|
// initialize OpenGL driver
|
||||||
WallpaperEngine::Render::Drivers::COpenGLDriver videoDriver (this->m_project->getTitle ().c_str ());
|
WallpaperEngine::Render::Drivers::COpenGLDriver videoDriver (this->m_project->getTitle ().c_str ());
|
||||||
|
// initialize the input subsystem
|
||||||
|
WallpaperEngine::Input::CInputContext inputContext (videoDriver);
|
||||||
// initialize render context
|
// initialize render context
|
||||||
WallpaperEngine::Render::CRenderContext context (this->m_context.screens, videoDriver, this->m_vfs, *this);
|
WallpaperEngine::Render::CRenderContext context (this->m_context.screens, videoDriver, inputContext, this->m_vfs, *this);
|
||||||
// initialize mouse support
|
|
||||||
context.setMouse (new CMouseInput (videoDriver.getWindow ()));
|
|
||||||
// ensure the context knows what wallpaper to render
|
// ensure the context knows what wallpaper to render
|
||||||
context.setWallpaper (
|
context.setWallpaper (
|
||||||
WallpaperEngine::Render::CWallpaper::fromWallpaper (this->m_project->getWallpaper (), context, audioContext)
|
WallpaperEngine::Render::CWallpaper::fromWallpaper (this->m_project->getWallpaper (), context, audioContext)
|
||||||
@ -232,6 +231,8 @@ void CWallpaperApplication::show ()
|
|||||||
|
|
||||||
while (videoDriver.closeRequested () == false && g_KeepRunning == true)
|
while (videoDriver.closeRequested () == false && g_KeepRunning == true)
|
||||||
{
|
{
|
||||||
|
// update input information
|
||||||
|
inputContext.update ();
|
||||||
// keep track of the previous frame's time
|
// keep track of the previous frame's time
|
||||||
g_TimeLast = g_Time;
|
g_TimeLast = g_Time;
|
||||||
// calculate the current time value
|
// calculate the current time value
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CApplicationContext.h"
|
#include "CApplicationContext.h"
|
||||||
|
#include "WallpaperEngine/Render/Drivers/COpenGLDriver.h"
|
||||||
#include "WallpaperEngine/Assets/CCombinedContainer.h"
|
#include "WallpaperEngine/Assets/CCombinedContainer.h"
|
||||||
#include "WallpaperEngine/Core/CProject.h"
|
#include "WallpaperEngine/Core/CProject.h"
|
||||||
#include "WallpaperEngine/Render/CWallpaper.h"
|
#include "WallpaperEngine/Render/CWallpaper.h"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
using namespace WallpaperEngine::Audio;
|
using namespace WallpaperEngine::Audio;
|
||||||
using namespace WallpaperEngine::Audio::Drivers;
|
using namespace WallpaperEngine::Audio::Drivers;
|
||||||
|
|
||||||
CAudioContext::CAudioContext (CAudioDriver* driver) :
|
CAudioContext::CAudioContext (CAudioDriver& driver) :
|
||||||
m_driver (driver)
|
m_driver (driver)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -12,20 +12,20 @@ CAudioContext::CAudioContext (CAudioDriver* driver) :
|
|||||||
|
|
||||||
void CAudioContext::addStream (CAudioStream* stream)
|
void CAudioContext::addStream (CAudioStream* stream)
|
||||||
{
|
{
|
||||||
this->m_driver->addStream (stream);
|
this->m_driver.addStream (stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
AVSampleFormat CAudioContext::getFormat () const
|
AVSampleFormat CAudioContext::getFormat () const
|
||||||
{
|
{
|
||||||
return this->m_driver->getFormat ();
|
return this->m_driver.getFormat ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAudioContext::getSampleRate () const
|
int CAudioContext::getSampleRate () const
|
||||||
{
|
{
|
||||||
return this->m_driver->getSampleRate ();
|
return this->m_driver.getSampleRate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAudioContext::getChannels () const
|
int CAudioContext::getChannels () const
|
||||||
{
|
{
|
||||||
return this->m_driver->getChannels ();
|
return this->m_driver.getChannels ();
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ namespace WallpaperEngine::Audio
|
|||||||
class CAudioContext
|
class CAudioContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CAudioContext (Drivers::CAudioDriver* driver);
|
CAudioContext (Drivers::CAudioDriver& driver);
|
||||||
|
|
||||||
void addStream (CAudioStream* stream);
|
void addStream (CAudioStream* stream);
|
||||||
|
|
||||||
@ -23,6 +23,6 @@ namespace WallpaperEngine::Audio
|
|||||||
int getSampleRate () const;
|
int getSampleRate () const;
|
||||||
int getChannels () const;
|
int getChannels () const;
|
||||||
private:
|
private:
|
||||||
Drivers::CAudioDriver* m_driver;
|
Drivers::CAudioDriver& m_driver;
|
||||||
};
|
};
|
||||||
}
|
}
|
20
src/WallpaperEngine/Input/CInputContext.cpp
Normal file
20
src/WallpaperEngine/Input/CInputContext.cpp
Normal 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;
|
||||||
|
}
|
24
src/WallpaperEngine/Input/CInputContext.h
Normal file
24
src/WallpaperEngine/Input/CInputContext.h
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
@ -52,12 +52,13 @@ int CustomXIOErrorHandler (Display* dsp)
|
|||||||
return 0;
|
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_wallpaper (nullptr),
|
||||||
m_screens (std::move (screens)),
|
m_screens (std::move (screens)),
|
||||||
m_driver (driver),
|
m_driver (driver),
|
||||||
m_container (container),
|
m_container (container),
|
||||||
m_app (app),
|
m_app (app),
|
||||||
|
m_input (input),
|
||||||
m_textureCache (new CTextureCache (*this))
|
m_textureCache (new CTextureCache (*this))
|
||||||
{
|
{
|
||||||
this->initialize ();
|
this->initialize ();
|
||||||
@ -228,9 +229,6 @@ void CRenderContext::render ()
|
|||||||
if (this->m_wallpaper == nullptr)
|
if (this->m_wallpaper == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// ensure mouse information is up to date before drawing any frame
|
|
||||||
this->m_mouse->update ();
|
|
||||||
|
|
||||||
if (this->m_viewports.empty () == false)
|
if (this->m_viewports.empty () == false)
|
||||||
this->renderScreens ();
|
this->renderScreens ();
|
||||||
else
|
else
|
||||||
@ -260,14 +258,9 @@ void CRenderContext::setWallpaper (CWallpaper* wallpaper)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CMouseInput* CRenderContext::getMouse () const
|
CInputContext& CRenderContext::getInputContext () const
|
||||||
{
|
{
|
||||||
return this->m_mouse;
|
return this->m_input;
|
||||||
}
|
|
||||||
|
|
||||||
void CRenderContext::setMouse (CMouseInput* mouse)
|
|
||||||
{
|
|
||||||
this->m_mouse = mouse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CWallpaper* CRenderContext::getWallpaper () const
|
CWallpaper* CRenderContext::getWallpaper () const
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
|
|
||||||
#include "WallpaperEngine/Input/CMouseInput.h"
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
|
||||||
#include "WallpaperEngine/Application/CWallpaperApplication.h"
|
|
||||||
#include "CTextureCache.h"
|
#include "CTextureCache.h"
|
||||||
#include "CWallpaper.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>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
using namespace WallpaperEngine::Application;
|
using namespace WallpaperEngine::Application;
|
||||||
@ -33,13 +34,13 @@ namespace WallpaperEngine::Render
|
|||||||
class CRenderContext
|
class CRenderContext
|
||||||
{
|
{
|
||||||
public:
|
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 ();
|
~CRenderContext ();
|
||||||
|
|
||||||
void initialize ();
|
void initialize ();
|
||||||
void render ();
|
void render ();
|
||||||
void setWallpaper (CWallpaper* wallpaper);
|
void setWallpaper (CWallpaper* wallpaper);
|
||||||
CMouseInput* getMouse () const;
|
CInputContext& getInputContext () const;
|
||||||
void setMouse (CMouseInput* mouse);
|
void setMouse (CMouseInput* mouse);
|
||||||
CWallpaper* getWallpaper () const;
|
CWallpaper* getWallpaper () const;
|
||||||
const CContainer& getContainer () const;
|
const CContainer& getContainer () const;
|
||||||
@ -69,7 +70,7 @@ namespace WallpaperEngine::Render
|
|||||||
std::vector <std::string> m_screens;
|
std::vector <std::string> m_screens;
|
||||||
std::vector <viewport> m_viewports;
|
std::vector <viewport> m_viewports;
|
||||||
CWallpaper* m_wallpaper;
|
CWallpaper* m_wallpaper;
|
||||||
CMouseInput* m_mouse;
|
CInputContext& m_input;
|
||||||
CContainer& m_container;
|
CContainer& m_container;
|
||||||
CWallpaperApplication& m_app;
|
CWallpaperApplication& m_app;
|
||||||
CTextureCache* m_textureCache;
|
CTextureCache* m_textureCache;
|
||||||
|
@ -245,15 +245,15 @@ void CScene::renderFrame (glm::ivec4 viewport)
|
|||||||
void CScene::updateMouse (glm::ivec4 viewport)
|
void CScene::updateMouse (glm::ivec4 viewport)
|
||||||
{
|
{
|
||||||
// update virtual mouse position first
|
// 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)
|
// 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
|
// rollover the position to the last
|
||||||
this->m_mousePositionLast = this->m_mousePosition;
|
this->m_mousePositionLast = this->m_mousePosition;
|
||||||
|
|
||||||
// calculate the current position of the mouse
|
// 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.x = glm::clamp ((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.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
|
// screen-space positions have to be transposed to what the screen will actually show
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include "WallpaperEngine/Render/Drivers/CVideoDriver.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Render::Drivers
|
namespace WallpaperEngine::Render::Drivers
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user