adding imputs system

This commit is contained in:
Kbz-8
2022-10-05 17:08:36 +02:00
commit 5df9b4d39f
15 changed files with 825 additions and 0 deletions

24
src/core/application.cpp git.filemode.normal_file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* application.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2022/10/05 16:58:11 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "application.h"
namespace mlx::core
{
void Application::run() noexcept
{
while(_in.is_running())
{
_in.update();
}
}
}

46
src/core/application.h git.filemode.normal_file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* application.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2022/10/05 16:58:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_APPLICATION__
#define __MLX_APPLICATION__
#include <vector>
#include <memory>
#include <utility>
#include <platform/inputs.h>
#include <platform/window.h>
namespace mlx::core
{
class Application
{
public:
Application() = default;
inline void new_window(std::size_t w, std::size_t h, std::string title)
{
_wins.emplace_back(std::make_unique<Window>(w, h, std::move(title)));
}
void run() noexcept;
~Application() = default;
private:
Input _in;
std::vector<std::unique_ptr<Window>> _wins;
bool _is_loop_running = false;
};
}
#endif // __MLX_APPLICATION__

42
src/core/bridge.cpp git.filemode.normal_file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bridge.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2022/10/05 14:02:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <SDL2/SDL.h>
#include "errors.h"
#include "application.h"
extern "C"
{
static std::unique_ptr<mlx::core::Application> __main_app = nullptr;
void mlx_init()
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
mlx::core::error::report(e_kind::fatal_error, "Unable to init the SDL2");
__main_app.reset(new mlx::core::Application());
}
void mlx_new_window(int w, int h, const char* title)
{
if(__main_app == nullptr)
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can create new windows");
__main_app->new_window(w, h, title);
}
int mlx_loop()
{
if(__main_app == nullptr)
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can run the main loop");
__main_app->run();
}
}

33
src/core/errors.cpp git.filemode.normal_file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:48:06 by maldavid #+# #+# */
/* Updated: 2022/10/04 21:18:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <cstdlib>
#include "errors.h"
namespace mlx::core::error
{
void report(e_kind kind, std::string msg)
{
switch(kind)
{
case e_kind::message: std::cout << "[MicroLibX] Message : " << msg << std::endl; break;
case e_kind::warning: std::cout << "[MicroLibX] Warning : " << msg << std::endl; break;
case e_kind::error: std::cerr << "[MicroLibX] Error : " << msg << std::endl; break;
case e_kind::fatal_error:
std::cerr << "[MicroLibX] Fatal Error : " << msg << std::endl;
std::exit(EXIT_SUCCESS);
break;
}
}
}

31
src/core/errors.h git.filemode.normal_file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:42:32 by maldavid #+# #+# */
/* Updated: 2022/10/04 21:51:42 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_ERRORS__
#define __MLX_ERRORS__
#include <string>
enum class e_kind
{
message,
warning,
error,
fatal_error
};
namespace mlx::core::error
{
void report(e_kind kind, std::string msg);
}
#endif // __MLX_ERRORS__