Skip to content

Commit

Permalink
merge to master (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 authored Feb 25, 2024
2 parents 7f8ec48 + f3de55d commit 420ba21
Show file tree
Hide file tree
Showing 77 changed files with 4,631 additions and 920 deletions.
2 changes: 1 addition & 1 deletion example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2024/01/26 11:59:34 by maldavid ### ########.fr */
/* Updated: 2024/02/24 01:07:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
4 changes: 2 additions & 2 deletions src/core/UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace mlx
{
static std::random_device random_device;
static std::mt19937_64 engine(random_device());
static std::uniform_int_distribution<uint64_t> uniform_distribution;
static std::uniform_int_distribution<std::uint64_t> uniform_distribution;

UUID::UUID() : _uuid(uniform_distribution(engine)) {}
UUID::UUID(uint64_t uuid) : _uuid(uuid) {}
UUID::UUID(std::uint64_t uuid) : _uuid(uuid) {}
}
6 changes: 3 additions & 3 deletions src/core/UUID.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace mlx
{
public:
UUID();
UUID(uint64_t uuid);
UUID(std::uint64_t uuid);

inline operator uint64_t() const { return _uuid; }
inline operator std::uint64_t() const { return _uuid; }

private:
uint64_t _uuid;
std::uint64_t _uuid;
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/01/26 11:56:34 by maldavid ### ########.fr */
/* Updated: 2024/02/25 07:52:04 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -40,7 +40,7 @@ namespace mlx::core

void Application::run() noexcept
{
while(_in->is_running())
while(_in->isRunning())
{
if(!_fps.update())
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ namespace mlx::core

inline void getScreenSize(void* win, int* w, int* h) noexcept;

inline void setFPSCap(uint32_t fps) noexcept;
inline void setFPSCap(std::uint32_t fps) noexcept;

inline void* newGraphicsSuport(std::size_t w, std::size_t h, const char* title);
inline void clearGraphicsSupport(void* win);
inline void destroyGraphicsSupport(void* win);

inline void pixelPut(void* win, int x, int y, uint32_t color) const noexcept;
inline void stringPut(void* win, int x, int y, uint32_t color, char* str);
inline void pixelPut(void* win, int x, int y, std::uint32_t color) const noexcept;
inline void stringPut(void* win, int x, int y, std::uint32_t color, char* str);

void* newTexture(int w, int h);
void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...)
inline void texturePut(void* win, void* img, int x, int y);
inline int getTexturePixel(void* img, int x, int y);
inline void setTexturePixel(void* img, int x, int y, uint32_t color);
inline void setTexturePixel(void* img, int x, int y, std::uint32_t color);
void destroyTexture(void* ptr);

inline void loopHook(int (*f)(void*), void* param);
Expand Down
8 changes: 4 additions & 4 deletions src/core/application.inl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace mlx::core
*h = DM.h;
}

void Application::setFPSCap(uint32_t fps) noexcept
void Application::setFPSCap(std::uint32_t fps) noexcept
{
_fps.setMaxFPS(fps);
}
Expand Down Expand Up @@ -120,14 +120,14 @@ namespace mlx::core
_graphics[*static_cast<int*>(win)].reset();
}

void Application::pixelPut(void* win, int x, int y, uint32_t color) const noexcept
void Application::pixelPut(void* win, int x, int y, std::uint32_t color) const noexcept
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
_graphics[*static_cast<int*>(win)]->pixelPut(x, y, color);
}

void Application::stringPut(void* win, int x, int y, uint32_t color, char* str)
void Application::stringPut(void* win, int x, int y, std::uint32_t color, char* str)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
Expand Down Expand Up @@ -176,7 +176,7 @@ namespace mlx::core
return texture->getPixel(x, y);
}

void Application::setTexturePixel(void* img, int x, int y, uint32_t color)
void Application::setTexturePixel(void* img, int x, int y, std::uint32_t color)
{
MLX_PROFILE_FUNCTION();
CHECK_IMAGE_PTR(img, return);
Expand Down
12 changes: 9 additions & 3 deletions src/core/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2024/01/19 05:35:38 by maldavid ### ########.fr */
/* Updated: 2024/02/23 22:37:24 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -120,7 +120,13 @@ extern "C"
int mlx_get_image_pixel(void* mlx, void* img, int x, int y)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
return static_cast<mlx::core::Application*>(mlx)->getTexturePixel(img, x, y);
int color = static_cast<mlx::core::Application*>(mlx)->getTexturePixel(img, x, y);
unsigned char color_bits[4];
color_bits[0] = (color & 0x000000FF);
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = (color & 0x00FF0000) >> 16;
color_bits[3] = (color & 0xFF000000) >> 24;
return *reinterpret_cast<int*>(color_bits);
}

void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color)
Expand Down Expand Up @@ -294,7 +300,7 @@ extern "C"
mlx::core::error::report(e_kind::error, "You cannot set a FPS cap to 0 (nice try)");
return 0;
}
static_cast<mlx::core::Application*>(mlx)->setFPSCap(static_cast<uint32_t>(fps));
static_cast<mlx::core::Application*>(mlx)->setFPSCap(static_cast<std::uint32_t>(fps));
return 0;
}
}
6 changes: 3 additions & 3 deletions src/core/fps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace mlx
void FpsManager::init()
{
_timer = SDL_GetTicks64();
_fps_before = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
_fps_now = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
_fps_before = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
_fps_now = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
}

bool FpsManager::update()
{
using namespace std::chrono_literals;
_fps_now = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
_fps_now = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());

if(SDL_GetTicks64() - _timer > 1000)
_timer += 1000;
Expand Down
12 changes: 6 additions & 6 deletions src/core/fps.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ namespace mlx

void init();
bool update();
inline void setMaxFPS(uint32_t fps) noexcept { _max_fps = fps; _ns = 1000000000.0 / fps; }
inline void setMaxFPS(std::uint32_t fps) noexcept { _max_fps = fps; _ns = 1000000000.0 / fps; }

~FpsManager() = default;

private:
double _ns = 1000000000.0 / 1'337'000.0;
uint64_t _timer = 0;
uint64_t _fps_before = 0;
uint64_t _fps_now = 0;
uint32_t _max_fps = 1'337'000;
uint32_t _fps_elapsed_time = 0;
std::uint64_t _timer = 0;
std::uint64_t _fps_before = 0;
std::uint64_t _fps_now = 0;
std::uint32_t _max_fps = 1'337'000;
std::uint32_t _fps_elapsed_time = 0;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace mlx

#ifdef GRAPHICS_MEMORY_DUMP
// dump memory to file every two seconds
static uint64_t timer = SDL_GetTicks64();
static std::uint64_t timer = SDL_GetTicks64();
if(SDL_GetTicks64() - timer > 2000)
{
Render_Core::get().getAllocator().dumpMemoryToJson();
Expand Down
4 changes: 2 additions & 2 deletions src/core/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace mlx
void render() noexcept;

inline void clearRenderData() noexcept;
inline void pixelPut(int x, int y, uint32_t color) noexcept;
inline void stringPut(int x, int y, uint32_t color, std::string str);
inline void pixelPut(int x, int y, std::uint32_t color) noexcept;
inline void stringPut(int x, int y, std::uint32_t color, std::string str);
inline void texturePut(Texture* texture, int x, int y);
inline void loadFont(const std::filesystem::path& filepath, float scale);

Expand Down
4 changes: 2 additions & 2 deletions src/core/graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace mlx
_texture_manager.clear();
}

void GraphicsSupport::pixelPut(int x, int y, uint32_t color) noexcept
void GraphicsSupport::pixelPut(int x, int y, std::uint32_t color) noexcept
{
MLX_PROFILE_FUNCTION();
_pixel_put_pipeline.setPixel(x, y, color);
}

void GraphicsSupport::stringPut(int x, int y, uint32_t color, std::string str)
void GraphicsSupport::stringPut(int x, int y, std::uint32_t color, std::string str)
{
MLX_PROFILE_FUNCTION();
std::pair<DrawableResource*, bool> res = _text_manager.registerText(x, y, color, str);
Expand Down
10 changes: 5 additions & 5 deletions src/platform/inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
/* Updated: 2024/01/16 07:59:15 by maldavid ### ########.fr */
/* Updated: 2024/02/23 22:27:30 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,7 +33,7 @@ namespace mlx
_yRel = _event.motion.yrel;
}

uint32_t id = _event.window.windowID;
std::uint32_t id = _event.window.windowID;
if(_events_hooks.find(id) == _events_hooks.end())
continue;
auto& hooks = _events_hooks[id];
Expand Down Expand Up @@ -123,19 +123,19 @@ namespace mlx
case SDL_WINDOWEVENT_FOCUS_GAINED:
{
if(win_hook.hook)
win_hook.hook(4, win_hook.param);
win_hook.hook(5, win_hook.param);
break;
}
case SDL_WINDOWEVENT_LEAVE:
{
if(win_hook.hook)
win_hook.hook(5, win_hook.param);
win_hook.hook(6, win_hook.param);
break;
}
case SDL_WINDOWEVENT_FOCUS_LOST:
{
if(win_hook.hook)
win_hook.hook(4, win_hook.param);
win_hook.hook(7, win_hook.param);
break;
}

Expand Down
10 changes: 5 additions & 5 deletions src/platform/inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
/* Updated: 2024/01/16 07:59:08 by maldavid ### ########.fr */
/* Updated: 2024/02/25 07:51:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,7 +44,7 @@ namespace mlx
inline int getXRel() const noexcept { return _xRel; }
inline int getYRel() const noexcept { return _yRel; }

inline bool is_running() const noexcept { return !_end; }
inline bool isRunning() const noexcept { return !_end; }
inline constexpr void finish() noexcept { _end = true; }

inline void addWindow(std::shared_ptr<MLX_Window> window)
Expand All @@ -53,7 +53,7 @@ namespace mlx
_events_hooks[window->getID()] = {};
}

inline void onEvent(uint32_t id, int event, int (*funct_ptr)(int, void*), void* param) noexcept
inline void onEvent(std::uint32_t id, int event, int (*funct_ptr)(int, void*), void* param) noexcept
{
_events_hooks[id][event].hook = funct_ptr;
_events_hooks[id][event].param = param;
Expand All @@ -62,8 +62,8 @@ namespace mlx
~Input() = default;

private:
std::unordered_map<uint32_t, std::shared_ptr<MLX_Window>> _windows;
std::unordered_map<uint32_t, std::array<Hook, 6>> _events_hooks;
std::unordered_map<std::uint32_t, std::shared_ptr<MLX_Window>> _windows;
std::unordered_map<std::uint32_t, std::array<Hook, 6>> _events_hooks;
SDL_Event _event;

int _x = 0;
Expand Down
16 changes: 8 additions & 8 deletions src/platform/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
namespace mlx
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
constexpr const uint32_t rmask = 0xff000000;
constexpr const uint32_t gmask = 0x00ff0000;
constexpr const uint32_t bmask = 0x0000ff00;
constexpr const uint32_t amask = 0x000000ff;
constexpr const std::uint32_t rmask = 0xff000000;
constexpr const std::uint32_t gmask = 0x00ff0000;
constexpr const std::uint32_t bmask = 0x0000ff00;
constexpr const std::uint32_t amask = 0x000000ff;
#else
constexpr const uint32_t rmask = 0x000000ff;
constexpr const uint32_t gmask = 0x0000ff00;
constexpr const uint32_t bmask = 0x00ff0000;
constexpr const uint32_t amask = 0xff000000;
constexpr const std::uint32_t rmask = 0x000000ff;
constexpr const std::uint32_t gmask = 0x0000ff00;
constexpr const std::uint32_t bmask = 0x00ff0000;
constexpr const std::uint32_t amask = 0xff000000;
#endif

MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
Expand Down
4 changes: 2 additions & 2 deletions src/platform/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace mlx
inline SDL_Window* getNativeWindow() const noexcept { return _win; }
inline int getWidth() const noexcept { return _width; }
inline int getHeight() const noexcept { return _height; }
inline uint32_t getID() const noexcept { return _id; }
inline std::uint32_t getID() const noexcept { return _id; }

void destroy() noexcept;

Expand All @@ -38,7 +38,7 @@ namespace mlx
SDL_Window* _win = nullptr;
int _width = 0;
int _height = 0;
uint32_t _id = -1;
std::uint32_t _id = -1;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/buffers/vk_ibo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace mlx
class C_IBO : public Buffer
{
public:
inline void create(uint32_t size, const uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
inline void create(std::uint32_t size, const std::uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
inline void bind(Renderer& renderer) noexcept { renderer.getActiveCmdBuffer().bindIndexBuffer(*this); }
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/buffers/vk_ubo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace mlx
{
void UBO::create(Renderer* renderer, uint32_t size, [[maybe_unused]] const char* name)
void UBO::create(Renderer* renderer, std::uint32_t size, [[maybe_unused]] const char* name)
{
MLX_PROFILE_FUNCTION();
_renderer = renderer;
Expand All @@ -37,16 +37,16 @@ namespace mlx
}
}

void UBO::setData(uint32_t size, const void* data)
void UBO::setData(std::uint32_t size, const void* data)
{
MLX_PROFILE_FUNCTION();
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<size_t>(size));
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<std::size_t>(size));
}

void UBO::setDynamicData(uint32_t size, const void* data)
void UBO::setDynamicData(std::uint32_t size, const void* data)
{
MLX_PROFILE_FUNCTION();
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<size_t>(size));
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<std::size_t>(size));
_buffers[_renderer->getActiveImageIndex()].flush();
}

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/buffers/vk_ubo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace mlx
class UBO
{
public:
void create(class Renderer* renderer, uint32_t size, const char* name);
void create(class Renderer* renderer, std::uint32_t size, const char* name);

void setData(uint32_t size, const void* data);
void setDynamicData(uint32_t size, const void* data);
void setData(std::uint32_t size, const void* data);
void setDynamicData(std::uint32_t size, const void* data);

void destroy() noexcept;

Expand Down
Loading

0 comments on commit 420ba21

Please sign in to comment.