adding SDL initialisation and quit, improving inputs code readability

This commit is contained in:
2023-08-28 10:53:22 +02:00
parent d90ab27489
commit 7f7d197e42
5 changed files with 45 additions and 89 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2023/04/25 15:12:57 by maldavid ### ########.fr */
/* Updated: 2023/08/28 10:19:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,10 +14,17 @@
#include <renderer/images/texture.h>
#include <renderer/core/render_core.h>
#include <array>
#include <core/errors.h>
#include <utils/endian.h>
namespace mlx::core
{
Application::Application() : _in(std::make_unique<Input>())
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
}
void Application::run() noexcept
{
while(_in->is_running())
@@ -52,4 +59,9 @@ namespace mlx::core
Texture* texture = static_cast<Texture*>(ptr);
texture->destroy();
}
Application::~Application()
{
SDL_Quit();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2023/04/25 15:23:31 by maldavid ### ########.fr */
/* Updated: 2023/08/28 10:19:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,7 +30,7 @@ namespace mlx::core
class Application
{
public:
Application() : _in(std::make_unique<Input>()) {}
Application();
inline void getMousePos(int* x, int* y) noexcept;
inline void mouseMove(void* win, int x, int y) noexcept;
@@ -58,7 +58,7 @@ namespace mlx::core
void run() noexcept;
~Application() = default;
~Application();
private:
std::list<Texture> _textures;