diff --git a/src/asset/image.cpp b/src/asset/image.cpp deleted file mode 100644 index 656d838..0000000 --- a/src/asset/image.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "image.hpp" - -asset::image::image(const std::vector &data) - : Image(LoadImageFromMemory(".png", - data.data(), static_cast(data.size()))) -{ -} - -asset::image::image(const Image &img) - : Image(img) -{ -} diff --git a/src/asset/image.hpp b/src/asset/image.hpp deleted file mode 100644 index b27a51b..0000000 --- a/src/asset/image.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "raylib.h" - -#include - -namespace asset -{ - class image: public Image - { - public: - explicit image(const std::vector &data); - - explicit image(const Image &img); - }; -} diff --git a/src/asset/tileset.cpp b/src/asset/tileset.cpp index bf8f1a9..5f5fe9d 100644 --- a/src/asset/tileset.cpp +++ b/src/asset/tileset.cpp @@ -7,7 +7,7 @@ asset::tileset::tileset(const std::vector &data) size = texture.get_height(); } -auto asset::tileset::at(int i) const -> asset::image +auto asset::tileset::at(int i) const -> chirp::image { auto size_f = static_cast(size); Rectangle rect{ @@ -15,7 +15,14 @@ auto asset::tileset::at(int i) const -> asset::image size_f, size_f, }; - return asset::image(ImageFromImage(image, rect)); + int size; + const auto r_image = ImageFromImage(*image.data(), rect); + + auto *data = ExportImageToMemory(r_image, ".png", &size); + const std::vector buffer(data, data + size); + + RL_FREE(data); + return chirp::image(buffer); } void asset::tileset::draw(float x, float y, int i, float rotation, float scale) const @@ -25,7 +32,7 @@ void asset::tileset::draw(float x, float y, int i, float rotation, float scale) void asset::tileset::flip_horizontal() { - ImageFlipHorizontal(&image); + image.flip_horizontal(); texture = ce::texture(image); } diff --git a/src/asset/tileset.hpp b/src/asset/tileset.hpp index 63c311c..719858e 100644 --- a/src/asset/tileset.hpp +++ b/src/asset/tileset.hpp @@ -11,7 +11,7 @@ namespace asset public: explicit tileset(const std::vector &data); - auto at(int index) const -> asset::image; + auto at(int index) const -> chirp::image; void draw(float x, float y, int index, float rotation, float scale) const; @@ -23,7 +23,7 @@ namespace asset /** Total size for each tile */ int size = 0; - asset::image image; + chirp::image image; ce::texture texture; }; } diff --git a/src/engine/assets.cpp b/src/engine/assets.cpp index 10806fb..2b70ea7 100644 --- a/src/engine/assets.cpp +++ b/src/engine/assets.cpp @@ -31,9 +31,9 @@ auto ce::assets::font(const std::string &path, const int font_size) const -> chi return chirp::font(open("fonts", path), font_size); } -auto ce::assets::image(const std::string &path) const -> asset::image +auto ce::assets::image(const std::string &path) const -> chirp::image { - return asset::image(open("images", path)); + return chirp::image(open("images", path)); } auto ce::assets::tileset(const std::string &path) const -> asset::tileset diff --git a/src/engine/assets.hpp b/src/engine/assets.hpp index 1c9137a..2199c7a 100644 --- a/src/engine/assets.hpp +++ b/src/engine/assets.hpp @@ -1,13 +1,13 @@ #pragma once -#include "asset/image.hpp" #include "asset/level.hpp" #include "asset/sound.hpp" #include "asset/tileset.hpp" -#include "chirp/assets.hpp" -#include "chirp/font.hpp" -#include "chirp/music.hpp" +#include +#include +#include +#include namespace ce { @@ -25,7 +25,7 @@ namespace ce auto font(const std::string &path, int font_size) const -> chirp::font; - auto image(const std::string &path) const -> asset::image; + auto image(const std::string &path) const -> chirp::image; auto tileset(const std::string &path) const -> asset::tileset; diff --git a/src/engine/sprite.cpp b/src/engine/sprite.cpp index 07ce48a..2713ceb 100644 --- a/src/engine/sprite.cpp +++ b/src/engine/sprite.cpp @@ -6,7 +6,7 @@ ce::sprite::sprite(const ce::texture &texture) { } -ce::sprite::sprite(const asset::image &image) +ce::sprite::sprite(const chirp::image &image) : ce::sprite(ce::texture(image)) { } diff --git a/src/engine/sprite.hpp b/src/engine/sprite.hpp index da70a8e..2ea1940 100644 --- a/src/engine/sprite.hpp +++ b/src/engine/sprite.hpp @@ -19,7 +19,7 @@ namespace ce /** * New sprite from image */ - explicit sprite(const asset::image &image); + explicit sprite(const chirp::image &image); void draw(); diff --git a/src/engine/texture.cpp b/src/engine/texture.cpp index 28c422f..881fa53 100644 --- a/src/engine/texture.cpp +++ b/src/engine/texture.cpp @@ -1,7 +1,7 @@ #include "texture.hpp" -ce::texture::texture(const asset::image &image) - : r_texture(LoadTextureFromImage(image)) +ce::texture::texture(const chirp::image &image) + : r_texture(LoadTextureFromImage(*image.data())) { } diff --git a/src/engine/texture.hpp b/src/engine/texture.hpp index 0a0008a..ba1d4d2 100644 --- a/src/engine/texture.hpp +++ b/src/engine/texture.hpp @@ -1,16 +1,15 @@ #pragma once #include "raylib.h" -#include "asset/image.hpp" -#include +#include namespace ce { class texture { public: - explicit texture(const asset::image &image); + explicit texture(const chirp::image &image); /** * Draw entire texture at position diff --git a/src/engine/window.cpp b/src/engine/window.cpp index 02fdf07..3ddfd3e 100644 --- a/src/engine/window.cpp +++ b/src/engine/window.cpp @@ -37,9 +37,9 @@ void ce::window::close() CloseWindow(); } -void ce::window::set_icon(const asset::image &image) +void ce::window::set_icon(const chirp::image &image) { - SetWindowIcon(image); + SetWindowIcon(*image.data()); } auto ce::window::size() -> chirp::vector2i diff --git a/src/engine/window.hpp b/src/engine/window.hpp index 3a10eeb..125a564 100644 --- a/src/engine/window.hpp +++ b/src/engine/window.hpp @@ -1,8 +1,8 @@ #pragma once #include "raylib.h" -#include "asset/image.hpp" +#include #include #include @@ -24,7 +24,7 @@ namespace ce void end() const; static void close(); - static void set_icon(const asset::image &image); + static void set_icon(const chirp::image &image); static auto size() -> chirp::vector2i;