diff --git a/assets/game/objects/mimik.png b/assets/game/objects/mimik.png new file mode 100644 index 0000000000000000000000000000000000000000..c5e50d7b9498a04315051951bd3796330c502e6b Binary files /dev/null and b/assets/game/objects/mimik.png differ diff --git a/assets/player.png b/assets/player.png deleted file mode 100644 index c84d047f428c2c2dadeff99120314ec06d313048..0000000000000000000000000000000000000000 Binary files a/assets/player.png and /dev/null differ diff --git a/assets/textures/Cube_Air.png b/assets/textures/Cube_Air.png deleted file mode 100644 index ed6b8e0766c45ad7800bcd2a972db9bd9ce8e979..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Air.png and /dev/null differ diff --git a/assets/textures/Cube_Black.png b/assets/textures/Cube_Black.png deleted file mode 100644 index c16e826571abf5b30be7c3365d62b1b8c8538ab0..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Black.png and /dev/null differ diff --git a/assets/textures/Cube_Blue.png b/assets/textures/Cube_Blue.png deleted file mode 100644 index 507f300138b6411b10e78bad4cc2a83b3aaba7da..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Blue.png and /dev/null differ diff --git a/assets/textures/Cube_Blue_Outlined.png b/assets/textures/Cube_Blue_Outlined.png deleted file mode 100644 index 7b9880a482b09a1df76a7df636e288472e224130..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Blue_Outlined.png and /dev/null differ diff --git a/assets/textures/Cube_Brown.png b/assets/textures/Cube_Brown.png deleted file mode 100644 index 020f8148945580c16561cc7b2b95e763ff718ffa..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Brown.png and /dev/null differ diff --git a/assets/textures/Cube_Cyan.png b/assets/textures/Cube_Cyan.png deleted file mode 100644 index 13773ab71faba09930bdb840951eaa60571b0f9d..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Cyan.png and /dev/null differ diff --git a/assets/textures/Cube_GLab_1.png b/assets/textures/Cube_GLab_1.png deleted file mode 100644 index dde2eea7829efe08f4841cd5e0c2f832fb243d6c..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_GLab_1.png and /dev/null differ diff --git a/assets/textures/Cube_GLab_2.png b/assets/textures/Cube_GLab_2.png deleted file mode 100644 index 5529901db2254ea4a144a954502f548275c7c47e..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_GLab_2.png and /dev/null differ diff --git a/assets/textures/Cube_GLab_3.png b/assets/textures/Cube_GLab_3.png deleted file mode 100644 index 5d5da902f3a75d14435bc76d5c0cb9fc7d2a4fdc..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_GLab_3.png and /dev/null differ diff --git a/assets/textures/Cube_Grass.png b/assets/textures/Cube_Grass.png deleted file mode 100644 index cdf1c247f553a7bac65b41a60a90ba387e72e327..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Grass.png and /dev/null differ diff --git a/assets/textures/Cube_Gray.png b/assets/textures/Cube_Gray.png deleted file mode 100644 index d1f106c214c46328ab91ca74b87a8561286239bb..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Gray.png and /dev/null differ diff --git a/assets/textures/Cube_Green.png b/assets/textures/Cube_Green.png deleted file mode 100644 index fcf9d95475e3f448c86c6bf73678eee864e84000..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Green.png and /dev/null differ diff --git a/assets/textures/Cube_Lava.png b/assets/textures/Cube_Lava.png deleted file mode 100644 index 064c841716d1f8629cd93615e4bc81c8a6e7749e..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Lava.png and /dev/null differ diff --git a/assets/textures/Cube_Light_Red.png b/assets/textures/Cube_Light_Red.png deleted file mode 100644 index 19358f477e5c40c303c41af9a48e25a12bfe1616..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Light_Red.png and /dev/null differ diff --git a/assets/textures/Cube_Orange.png b/assets/textures/Cube_Orange.png deleted file mode 100644 index 3507d1817b1ce103382da1a2c0fc64aa0d84ae0b..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Orange.png and /dev/null differ diff --git a/assets/textures/Cube_Pink.png b/assets/textures/Cube_Pink.png deleted file mode 100644 index ba27564cbc49fd9b80963fe86a3e7b60035718d5..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Pink.png and /dev/null differ diff --git a/assets/textures/Cube_Purple.png b/assets/textures/Cube_Purple.png deleted file mode 100644 index ee44d1c36dc3d41ddcc29ae14f87b7a0ac54346e..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Purple.png and /dev/null differ diff --git a/assets/textures/Cube_Red.png b/assets/textures/Cube_Red.png deleted file mode 100644 index 0a74973acf3f347737254a42611fadb532695d1f..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Red.png and /dev/null differ diff --git a/assets/textures/Cube_Red2.png b/assets/textures/Cube_Red2.png deleted file mode 100644 index 56f33155d5b904a8d0f2fec48a951ee55433a741..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Red2.png and /dev/null differ diff --git a/assets/textures/Cube_Sepia.png b/assets/textures/Cube_Sepia.png deleted file mode 100644 index 6c1088662450d67d9c75dcffb3b13b81bd70e372..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Sepia.png and /dev/null differ diff --git a/assets/textures/Cube_Test.png b/assets/textures/Cube_Test.png deleted file mode 100644 index 673ea5b784babacfdb93ea407c2db77aed95f6ac..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Test.png and /dev/null differ diff --git a/assets/textures/Cube_Void.png b/assets/textures/Cube_Void.png deleted file mode 100644 index 9743f77ea12dda6388eb70707aa02019ad0a7f89..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Void.png and /dev/null differ diff --git a/assets/textures/Cube_White.png b/assets/textures/Cube_White.png deleted file mode 100644 index 7a051769c27b4638b734fbf8271301b351245541..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_White.png and /dev/null differ diff --git a/assets/textures/Cube_Yellow.png b/assets/textures/Cube_Yellow.png deleted file mode 100644 index 0101f31b955bc6fac43581e556bbeea94b9f03a9..0000000000000000000000000000000000000000 Binary files a/assets/textures/Cube_Yellow.png and /dev/null differ diff --git a/assets/textures/Image_Test.png b/assets/textures/Image_Test.png deleted file mode 100644 index 428fbc85ff234275126068eed22a3f0536537b91..0000000000000000000000000000000000000000 Binary files a/assets/textures/Image_Test.png and /dev/null differ diff --git a/assets/textures/Neera.png b/assets/textures/Neera.png deleted file mode 100644 index 01d777dca4146f5ff1d41da072aa59c744c5cc5b..0000000000000000000000000000000000000000 Binary files a/assets/textures/Neera.png and /dev/null differ diff --git a/assets/textures/Tile_Test.png b/assets/textures/Tile_Test.png deleted file mode 100644 index c113642b3f04ce076c806252f8a3f93109b54b5a..0000000000000000000000000000000000000000 Binary files a/assets/textures/Tile_Test.png and /dev/null differ diff --git a/assets/textures/Tile_Test_2.png b/assets/textures/Tile_Test_2.png deleted file mode 100644 index 6193471ba9f044adff524fb9b3afa01ee664c806..0000000000000000000000000000000000000000 Binary files a/assets/textures/Tile_Test_2.png and /dev/null differ diff --git a/assets/textures/Tile_Test_3.png b/assets/textures/Tile_Test_3.png deleted file mode 100644 index 5b6bb5cbd73647990fa99bac0513a38665b877c3..0000000000000000000000000000000000000000 Binary files a/assets/textures/Tile_Test_3.png and /dev/null differ diff --git a/assets/textures/Tile_Test_4.png b/assets/textures/Tile_Test_4.png deleted file mode 100644 index b5db7d7c8c3da0f2ec9178caf6403d59193535d8..0000000000000000000000000000000000000000 Binary files a/assets/textures/Tile_Test_4.png and /dev/null differ diff --git a/assets/textures/letters.png b/assets/textures/letters.png deleted file mode 100644 index 7ae52871e931f300419edcd0971ee378ddd0c9f0..0000000000000000000000000000000000000000 Binary files a/assets/textures/letters.png and /dev/null differ diff --git a/assets/tilemap.png b/assets/tilemap.png deleted file mode 100644 index 49ffb3925e40fe5195012608f088696ccd8bd4de..0000000000000000000000000000000000000000 Binary files a/assets/tilemap.png and /dev/null differ diff --git a/source/engine/graphics/back/textures/Texture.hpp b/source/engine/graphics/back/textures/Texture.hpp index c58c0132a4d289bbbbd7c8d192404b1d0b563442..aabf735e384b293c3ac1f3000100923d202fed7b 100644 --- a/source/engine/graphics/back/textures/Texture.hpp +++ b/source/engine/graphics/back/textures/Texture.hpp @@ -39,7 +39,7 @@ namespace megu { void bind() const; void bind(GLuint) const; - inline GLint width() const {return this->_width;} + inline GLint width() const {return this->_width;} inline GLint height() const {return this->_height;} inline GLuint slot() const {return this->_slot;} diff --git a/source/engine/graphics/front.hpp b/source/engine/graphics/front.hpp new file mode 100644 index 0000000000000000000000000000000000000000..85ac870234eadbdaa3f90c79799f975dd1b4a252 --- /dev/null +++ b/source/engine/graphics/front.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "front/engine/Engine.hpp" +#include "front/engine/FrameBufferMerger.hpp" +#include "front/engine/Layer.hpp" +#include "front/engine/Renderer.hpp" +#include "front/engine/TextureArray.hpp" + +#include "front/geometry/Quads.hpp" +#include "front/geometry/Plane.hpp" + +#include "front/module/Quad_Module.hpp" + +#include "front/object/Image.hpp" +#include "front/object/Sprite.hpp" +#include "front/object/TileArray.hpp" \ No newline at end of file diff --git a/source/engine/graphics/front/engine/Engine.hpp b/source/engine/graphics/front/engine/Engine.hpp index 38dce9fde7967b660bb902945f75d2bb011b8f9b..5a3b7532b9e2c74a70b1fdceff4936da8a28483f 100644 --- a/source/engine/graphics/front/engine/Engine.hpp +++ b/source/engine/graphics/front/engine/Engine.hpp @@ -23,10 +23,6 @@ namespace megu { return this->_layers[layer_priority].get()->push<T>(object_priority, object, modul); } - /*void push(Priority layer_priority, Priority object_priority, Renderable & renderable) { - this->_layers[layer_priority].get()->push(object_priority, renderable); - }*/ - void remove(Priority); void remove(const Identifiable &); diff --git a/source/engine/graphics/front/module/Quad_Module.hpp b/source/engine/graphics/front/module/Quad_Module.hpp index 5822de04afe111811c6a51352138eddcb991ce92..5ec48d8dadc4fa90ff46ce065012ba878e5a6b22 100644 --- a/source/engine/graphics/front/module/Quad_Module.hpp +++ b/source/engine/graphics/front/module/Quad_Module.hpp @@ -2,11 +2,10 @@ #include "Image_Module.hpp" #include "Sprite_Module.hpp" -#include "Text_Module.hpp" #include "TileArray_Module.hpp" namespace megu { - class Quad_Module : public Image_Module, public Sprite_Module, public Text_Module, public TileArray_Module { + class Quad_Module : public Image_Module, public Sprite_Module, public TileArray_Module { // ... }; } \ No newline at end of file diff --git a/source/engine/graphics/front/module/Sprite_Module.cpp b/source/engine/graphics/front/module/Sprite_Module.cpp index e95ba8dfa0b7ff9f8d4094b05f64b9858f2d4192..b63d53607e911a356d9669173ee2e525b6b6ef2f 100644 --- a/source/engine/graphics/front/module/Sprite_Module.cpp +++ b/source/engine/graphics/front/module/Sprite_Module.cpp @@ -38,7 +38,7 @@ namespace megu { std::vector<std::reference_wrapper<const Texture>>::iterator it = std::find(textures.begin(), textures.end(), image.get().texture()); if(it != textures.end()) { uModels.push_back(image.get().transformation().model()); - uFrames.push_back(image.get().frame()); + uFrames.push_back(image.get().getFrame()); uSizes.push_back({it->get().width(), it->get().height()}); uTextures.push_back(static_cast<GLint>(it - textures.begin())); @@ -63,7 +63,7 @@ namespace megu { uTextures.push_back(static_cast<GLint>(textures.size()-1)); uModels.push_back(image.get().transformation().model()); - uFrames.push_back(image.get().frame()); + uFrames.push_back(image.get().getFrame()); uSizes.push_back({image.get().texture().width(), image.get().texture().height()}); } } diff --git a/source/engine/graphics/front/module/Text_Module.cpp b/source/engine/graphics/front/module/Text_Module.cpp deleted file mode 100644 index 9ccf73b216478cdd95abe1425137c132982bb324..0000000000000000000000000000000000000000 --- a/source/engine/graphics/front/module/Text_Module.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "Text_Module.hpp" - -#include <engine/graphics/back/cameras/Camera.hpp> -#include <engine/utility/array_generator.hpp> - -namespace megu { - Text_Module::Text_Module() - : _vbo(this->_vao, Text::Layout(), Text::Vertices(), EditMode::STATIC) { - Source vert_source("assets/shaders/Text.vert", Source::Categorie::VERTEX); - this->_program << vert_source; - - Source frag_source("assets/shaders/Text.frag", Source::Categorie::FRAGMENT); - this->_program << frag_source; - - this->_program.link(); - vert_source.release(); - frag_source.release(); - } - - void Text_Module::draw(const Text & text, const Camera & camera, const Window &) const { - this->_vao.bind(); - this->_program.use(); - - text.texture().bind(); - this->_program.setUniform("uSampler", 0); - - glm::vec4 glyphFrame = text['w']; - - this->_program.setUniform("uSize", glm::vec2{text.texture().width(), text.texture().height()}); - this->_program.setUniform("uGlyphFrame", glyphFrame); - - glDrawArrays(Quads::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size())); - } -} \ No newline at end of file diff --git a/source/engine/graphics/front/module/Text_Module.hpp b/source/engine/graphics/front/module/Text_Module.hpp deleted file mode 100644 index 71aacd0a5da7815074d804708b8dade68a6a0504..0000000000000000000000000000000000000000 --- a/source/engine/graphics/front/module/Text_Module.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "Module.hpp" - -#include <engine/graphics/back/buffers/VertexArray.hpp> -#include <engine/graphics/back/buffers/VerticeBuffer.hpp> -#include <engine/graphics/back/shaders/Program.hpp> - -#include <engine/graphics/front/object/Text.hpp> -#include <engine/utility/ref_set.hpp> - -namespace megu { - class Text_Module : public Module<Text> { - public: - Text_Module(); - - virtual void draw(const Text &, const Camera &, const Window &) const override; - - private: - VertexArray _vao; - VerticeBuffer _vbo; - Program _program; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/module/TileArray_Module.cpp b/source/engine/graphics/front/module/TileArray_Module.cpp index cdc258fba5b57477d0256c5bd4f8e091b21095ff..efb6e0b65fe3c86cddd18cbd3a3bc932c18eb512 100644 --- a/source/engine/graphics/front/module/TileArray_Module.cpp +++ b/source/engine/graphics/front/module/TileArray_Module.cpp @@ -34,15 +34,15 @@ namespace megu { size_t count = 0; - for(size_t x = 0; x < vertexArray.width(); ++x) { - for(size_t y = 0; y < vertexArray.height(); ++y) { + for(size_t x = 0; x < vertexArray.row(); ++x) { + for(size_t y = 0; y < vertexArray.collumn(); ++y) { uOffsets.push_back(glm::translate(glm::mat4(1.f), {x, y, 0.f})); uUvs.push_back(vertexArray.uvs()[x][y]); if(count > 128) { this->_program.setUniform("uOffsets", uOffsets); this->_program.setUniform("uUvs", uUvs); - glDrawArraysInstanced(TileArray::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(vertexArray.width() * vertexArray.height())); + glDrawArraysInstanced(TileArray::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(vertexArray.row() * vertexArray.collumn())); uOffsets.clear(); uUvs.clear(); @@ -56,7 +56,7 @@ namespace megu { this->_program.setUniform("uOffsets", uOffsets); this->_program.setUniform("uUvs", uUvs); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glDrawArraysInstanced(TileArray::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(vertexArray.width() * vertexArray.height())); + glDrawArraysInstanced(TileArray::Primitive(), 0, static_cast<GLsizei>(this->_vbo.size()), static_cast<GLsizei>(vertexArray.row() * vertexArray.collumn())); //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } } diff --git a/source/engine/graphics/front/object/Image.cpp b/source/engine/graphics/front/object/Image.cpp index 1dc161947f2703d95a7ca710ad2624d999d2bb4c..0570661dbe3b4675f6fc88897ddd5e4bc65503f6 100644 --- a/source/engine/graphics/front/object/Image.cpp +++ b/source/engine/graphics/front/object/Image.cpp @@ -30,12 +30,12 @@ namespace megu { } void Image::load(const TextureBuffer & buffer) { - this->setSize({buffer.width(), buffer.height()}); + this->setSize(static_cast<float>(buffer.width()), static_cast<float>(buffer.height())); this->_texture.store(buffer); } void Image::link(const Texture & texture) { - this->setSize({texture.width(), texture.height()}); + this->setSize(static_cast<float>(texture.width()), static_cast<float>(texture.height())); this->_texture = texture; } } \ No newline at end of file diff --git a/source/engine/graphics/front/object/Image.hpp b/source/engine/graphics/front/object/Image.hpp index 715408df9643f0fd18e81db20fbff2da05c0ab6d..95c5b6fc2450e87e08fc8423dcab7a6463efa365 100644 --- a/source/engine/graphics/front/object/Image.hpp +++ b/source/engine/graphics/front/object/Image.hpp @@ -19,26 +19,24 @@ namespace megu { Image(const Image &) = default; Image operator=(const Image &); Image operator=(const Image &&); - ~Image() = default; + virtual ~Image() = default; inline Vec2 getPosition() const {return Vec2(this->_transformation.x(), this->_transformation.y());} inline Vec2 getOrigine() const {return Vec2(this->_transformation.origine().x, this->_transformation.origine().y);} inline Vec2 getSize() const {return Vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} inline float getRotation() const {return this->_transformation.roll();} - inline float getLayer() const {return this->_transformation.z();} inline const Texture & texture() const {return this->_texture;} inline const Transformable & transformation() const {return this->_transformation;} - inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} - inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} - inline void setSize(const Vec2 & size) {this->_transformation.setScaling(size.x, size.y);} + inline void setPosition(float x, float y) {this->_transformation.setPosition(x, y);} + inline void setOrigine(float x, float y) {this->_transformation.setOrigine(x, y);} + inline void setSize(float w, float h) {this->_transformation.setScaling(w, h);} inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} - inline void setLayer(float l) {this->_transformation.setZ(l);} - inline void move(const Vec2 & pos) {this->_transformation.move({pos.x, pos.y, 0.f});} - inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} - inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} + inline void move(float x, float y) {this->_transformation.move({x, y, 0.f});} + inline void scale(float w, float h) {this->_transformation.scale({w, h, 0.f});} + inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} void load(const std::filesystem::path &, bool = false); void load(const TextureBuffer &); diff --git a/source/engine/graphics/front/object/Sprite.cpp b/source/engine/graphics/front/object/Sprite.cpp index d9dd26c1084e14d70e7a6af5514b3233298a624e..ef85ab713c1be323b02fc4637ee198bc5db1d3de 100644 --- a/source/engine/graphics/front/object/Sprite.cpp +++ b/source/engine/graphics/front/object/Sprite.cpp @@ -1,6 +1,9 @@ #include "Sprite.hpp" namespace megu { + Sprite::Sprite() + : _frame(0, 0, 0, 0) {} + Sprite::Sprite(const std::filesystem::path & path, bool flip) : _frame(0, 0, 0, 0) { this->load(path, flip); @@ -18,12 +21,12 @@ namespace megu { } void Sprite::load(const TextureBuffer & buffer) { - this->setSize({buffer.width(), buffer.height()}); + this->setSize(static_cast<float>(buffer.width()), static_cast<float>(buffer.height())); this->_texture.store(buffer); } void Sprite::link(const Texture & texture) { - this->setSize({texture.width(), texture.height()}); + this->setSize(static_cast<float>(texture.width()), static_cast<float>(texture.height())); this->_texture = texture; } } \ No newline at end of file diff --git a/source/engine/graphics/front/object/Sprite.hpp b/source/engine/graphics/front/object/Sprite.hpp index a0b5b23075888188c6548e92a0ba3a19672684d6..777eef34bcb225bf9ad75286e7c082296c777c12 100644 --- a/source/engine/graphics/front/object/Sprite.hpp +++ b/source/engine/graphics/front/object/Sprite.hpp @@ -13,34 +13,31 @@ namespace megu { public: using Frame = glm::vec4; + Sprite(); Sprite(const std::filesystem::path &, bool = true); Sprite(const std::filesystem::path &, const Frame &, bool = true); + virtual ~Sprite() = default; - inline void setFrame(const Frame & frame) {this->_frame = frame;} + inline const Vec2 & getPosition() const {return Vec2(this->_transformation.x(), this->_transformation.y());} + inline const Vec2 & getOrigine() const {return Vec2(this->_transformation.origine().x, this->_transformation.origine().y);} + inline const Vec2 & getSize() const {return Vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} + inline const Frame & getFrame() const {return this->_frame;} + inline float getrotation() const {return this->_transformation.rotation().z;} - inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} - inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} - inline void setSize(const Vec2 & size) {this->_transformation.setScaling(size.x, size.y);} + inline const Texture & texture() const {return this->_texture;} + inline const Transformable & transformation() const {return this->_transformation;} + + inline void setPosition(float x, float y) {this->_transformation.setPosition(x, y);} + inline void setOrigine(float x, float y) {this->_transformation.setOrigine(x, y);} + inline void setSize(float w, float h) {this->_transformation.setScaling(w, h);} inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} + inline void setFrame(const Frame & frame) {this->_frame = frame;} - inline const Vec3 & position() const {return this->_transformation.position();} - inline const Vec3 & origine() const {return this->_transformation.origine();} - inline const Vec3 & rotation() const {return this->_transformation.rotation();} - inline const Vec2 & size() const {return Vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} + inline void setFrame(float x, float y, float w, float h) {this->_frame = Frame(x, y, w ,h);} - inline float x() const {return this->_transformation.x();} - inline float y() const {return this->_transformation.y();} - inline float z() const {return this->_transformation.z();} - - inline void move(const Vec2 & pos) {this->_transformation.move({pos.x, pos.y, 0.f});} - inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} - inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} - - inline void setSize(float w, float h) {this->_transformation.setScaling(w, h);} - - inline const Frame & frame() const {return this->_frame;} - inline const Texture & texture() const {return this->_texture;} - inline const Transformable & transformation() const {return this->_transformation;} + inline void move(float x, float y) {this->_transformation.move({x, y, 0.f});} + inline void scale(float w, float h) {this->_transformation.scale({w, h, 0.f});} + inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} void load(const std::filesystem::path &, bool = false); void load(const TextureBuffer &); diff --git a/source/engine/graphics/front/object/Text.cpp b/source/engine/graphics/front/object/Text.cpp deleted file mode 100644 index 6b16ea6d12983b4ef57776d8c470f42e436895ef..0000000000000000000000000000000000000000 --- a/source/engine/graphics/front/object/Text.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "Text.hpp" - -#include <exception> -#include <iostream> - -namespace megu { - Text::Text(const std::string & text) - : _text(text) {} - - Text::Text(const Text & src) - : _text(src._text), _characters(src._characters), _transformation(src._transformation) {} - - Text & Text::operator=(const Text & src) { - this->_text = src._text; - this->_characters = src._characters; - this->_transformation = src._transformation; - return *this; - } - - void Text::loadFont(const std::filesystem::path & file, bool smoothing) { - if(!std::filesystem::exists(file) || std::filesystem::is_directory(file)) { - throw std::runtime_error("Cannot load font file" + file.string() + "."); - } - - TextureBuffer buffer(file); - this->_texture.store(buffer); - } -} diff --git a/source/engine/graphics/front/object/Text.hpp b/source/engine/graphics/front/object/Text.hpp deleted file mode 100644 index 7fd1df31aa1fa2c1e9fbae9492b41d05de9bdc27..0000000000000000000000000000000000000000 --- a/source/engine/graphics/front/object/Text.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include <utility/Identifiable.hpp> - -#include <string> -#include <filesystem> -#include <map> - -#include <engine/graphics/back/geometry/Transformable.hpp> -#include <engine/graphics/back/textures/Texture.hpp> -#include <engine/graphics/front/geometry/Quads.hpp> -#include <engine/utility/type.hpp> - -namespace megu { - class Text : public Quads { - public: - using Frame = Vec4Int; - using CharacterMap = std::map<unsigned char, Frame>; - - Text(const std::string & = ""); - Text(const Text &); - Text & operator=(const Text &); - ~Text() = default; - - inline Vec2 getPosition() const {return Vec2(this->_transformation.x(), this->_transformation.y());} - inline Vec2 getOrigine() const {return Vec2(this->_transformation.origine().x, this->_transformation.origine().y);} - inline Vec2 getSize() const {return Vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} - inline float getRotation() const {return this->_transformation.roll();} - inline float getLayer() const {return this->_transformation.z();} - - inline const Texture & texture() const {return this->_texture;} - inline const Transformable & transformation() const {return this->_transformation;} - inline const std::string & text() const {return this->_text;} - inline const CharacterMap & characters() const {return this->_characters;} - - inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} - inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} - inline void setSize(const Vec2 & size) {this->_transformation.setScaling(size.x, size.y);} - inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} - inline void setLayer(float l) {this->_transformation.setZ(l);} - - inline void move(const Vec2 & pos) {this->_transformation.move({pos.x, pos.y, 0.f});} - inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} - inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} - - inline void addGlyph(unsigned char c, Frame f) {this->_characters.insert(std::pair<unsigned char, Frame>(c, f));} - inline void removeGlyph(unsigned char c) {this->_characters.erase(c);} - inline void clearGlyph() {return this->_characters.clear();} - - void loadFont(const std::filesystem::path &, bool = true); - - inline const Frame & operator[](unsigned char c) const {return this->_characters.at(c);} - - private: - std::string _text; - Texture _texture; - CharacterMap _characters; - Transformable _transformation; - }; -} \ No newline at end of file diff --git a/source/engine/graphics/front/object/TileArray.cpp b/source/engine/graphics/front/object/TileArray.cpp index 78953d5c33c07c542ba22949a5b88ad26e48cbef..e54216ade5e67470a74ec1177a426bd8fc7c492f 100644 --- a/source/engine/graphics/front/object/TileArray.cpp +++ b/source/engine/graphics/front/object/TileArray.cpp @@ -3,17 +3,17 @@ #include <iostream> namespace megu { - TileArray::TileArray(const std::filesystem::path & path, size_t width, size_t height, float tileSize, size_t lenght) - : _width(width), _height(height), _tileSize(tileSize) { + TileArray::TileArray(const std::filesystem::path & path, size_t row, size_t col, float tileSize, size_t lenght) + : _row(row), _col(col), _tileSize(tileSize) { megu::TextureBuffer buffer(path); this->_texture.store(buffer); float twidth = static_cast<float>(this->_texture.width()); float theight = static_cast<float>(this->_texture.height()); - for(size_t x = 0; x < width; ++x) { + for(size_t x = 0; x < row; ++x) { std::vector<glm::vec4> rows; - for(size_t y = 0; y < height; ++y) { + for(size_t y = 0; y < col; ++y) { rows.push_back({0.f, this->_texture.height() - lenght, lenght, lenght}); } this->_uvs.push_back(rows); diff --git a/source/engine/graphics/front/object/TileArray.hpp b/source/engine/graphics/front/object/TileArray.hpp index b8862f5da55eb2e6926da3132fb0f768ede3022f..e90c92279e37ce7c8619dde541cd84302cb11f97 100644 --- a/source/engine/graphics/front/object/TileArray.hpp +++ b/source/engine/graphics/front/object/TileArray.hpp @@ -13,35 +13,45 @@ namespace megu { class TileArray : public Quads { public: + TileArray() = delete; TileArray(const std::filesystem::path &, size_t, size_t, float, size_t); + virtual ~TileArray() = default; - inline void setPosition(const Vec2 & pos) {this->_transformation.setPosition(pos.x, pos.y);} - inline void setOrigine(const Vec2 & pos) {this->_transformation.setOrigine(pos.x, pos.y);} - inline void setSize(const Vec2 & size) {this->_transformation.setScaling(size.x, size.y);} + inline Vec2 getPosition() const {return Vec2(this->_transformation.x(), this->_transformation.y());} + inline Vec2 getOrigine() const {return Vec2(this->_transformation.origine().x, this->_transformation.origine().y);} + inline Vec2 getSize() const {return Vec2(this->_transformation.scaling().x, this->_transformation.scaling().y);} + inline float getrotation() const {return this->_transformation.rotation().z;} + + inline void setPosition(float x, float y) {this->_transformation.setPosition(x, y);} + inline void setOrigine(float x, float y) {this->_transformation.setOrigine(x, y);} + inline void setSize(float w, float h) {this->_transformation.setScaling(w, h);} inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);} inline void setLayer(float l) {this->_transformation.setZ(l);} - inline void move(const Vec2 & pos) {this->_transformation.move({pos.x, pos.y, 0.f});} - inline void scale(const Vec2 & size) {this->_transformation.scale({size.x, size.y, 0.f});} - inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} + inline void move(float x, float y) {this->_transformation.move(x, y);} + inline void scale(float w, float h) {this->_transformation.scale(w, h);} + inline void rotate(float a) {this->_transformation.rotate(a, Transformable::Axis::Z);} - inline size_t width() const {return this->_width;} - inline size_t height() const {return this->_height;} - inline float getTileSize() const {return this->_tileSize;} - inline const Vec3 & getSize() const {return this->_transformation.scaling();} + inline size_t row() const {return this->_row;} + inline size_t collumn() const {return this->_col;} + inline float tileSize() const {return this->_tileSize;} inline void setUv(size_t x, size_t y, const glm::vec4 & uv) {this->_uvs[y][x] = uv;} + inline const glm::vec4 & getUv(size_t x, size_t y) const {return this->_uvs[y][x];} inline const Transformable & transformation() const {return this->_transformation;} inline const Texture & texture() const {return this->_texture;} + inline GLint getTextureWidth() const {return this->_texture.width();} + inline GLint getTextureHeight() const {return this->_texture.height();} + inline const std::vector<std::vector<glm::vec4>> & uvs() const {return this->_uvs;} std::vector<glm::vec4> & operator[](size_t index) {return this->_uvs[index];} private: Transformable _transformation; Texture _texture; - size_t _width, _height; + size_t _row, _col; float _tileSize; std::vector<std::vector<glm::vec4>> _uvs; }; diff --git a/source/engine/physic/back/Position.cpp b/source/engine/physic/back/Position.cpp index 540929210aa9e7731cdbf0f46bc81f71691cf999..a823329af8f8bc89281c52b81e46e5cb13729a6c 100644 --- a/source/engine/physic/back/Position.cpp +++ b/source/engine/physic/back/Position.cpp @@ -18,10 +18,6 @@ namespace megu { return *this; } - void Position::setPosition(const glm::vec3 & position) { - this->_position = position; - } - void Position::move(const glm::vec3 & direction) { this->_position.x += direction.x; this->_position.y += direction.y; diff --git a/source/engine/physic/back/Position.hpp b/source/engine/physic/back/Position.hpp index 334a9681cd2480bb6e14ff8f21689636365f9d73..fef03d3dceacc2c75b410f3a3cffbcf34e8f5d81 100644 --- a/source/engine/physic/back/Position.hpp +++ b/source/engine/physic/back/Position.hpp @@ -10,15 +10,14 @@ namespace megu { Position(const glm::vec3 &); Position(const Position &); Position operator=(const Position &); + virtual ~Position() = default; inline float x() const {return this->_position.x;} inline float y() const {return this->_position.y;} inline float z() const {return this->_position.z;} - inline const glm::vec3 & position() const {return this->_position;} - - void setPosition(const glm::vec3 &); - inline void setPosition(float x, float y, float z) {this->setPosition({x, y, z});} + inline void set(const glm::vec3 & position) {this->_position = position;} + inline void set(float x, float y, float z) {this->set({x, y, z});} void move(const glm::vec3 &); inline void move(float x, float y, float z) {this->move({x, y, z});} diff --git a/source/engine/physic/back/SquareBox.cpp b/source/engine/physic/back/SquareBox.cpp index 13927a5991530f51f8fe78cf177d46344cd983cf..58c8629fd6a8500c52f9683ab71fe40eff64e8e2 100644 --- a/source/engine/physic/back/SquareBox.cpp +++ b/source/engine/physic/back/SquareBox.cpp @@ -15,27 +15,13 @@ namespace megu { return *this; } - Cube SquareBox::asCube() const { - return { - this->_position, - this->_position + Position(this->_dimension.x, 0.f, 0.f), - this->_position + Position(0.f, 0.f, this->_dimension.z), - this->_position + Position(this->_dimension.x, 0.f, this->_dimension.z), - - this->_position + Position(0.f, this->_dimension.y, 0.f), - this->_position + Position(this->_dimension.x, this->_dimension.y, 0.f), - this->_position + Position(0.f, this->_dimension.y, this->_dimension.z), - this->_position + Position(this->_dimension.x, this->_dimension.y, this->_dimension.z) - }; - } - void SquareBox::move(const Direction & direction) { this->_position.move(direction.x(), direction.y(), direction.z()); } bool SquareBox::intersect(const SquareBox & squareBox) const { - const Position & a = squareBox.position(); - const Dimension & as = squareBox.dimension(); + const Position & a = squareBox._position; + const Dimension & as = squareBox._dimension; const Position & b = this->_position; const Dimension & bs = this->_dimension; @@ -57,4 +43,8 @@ namespace megu { bool SquareBox::operator!=(const SquareBox & squareBox) const { return !(*this == squareBox); } + + bool SquareBox::operator|(const SquareBox & squareBox) const { + return this->intersect(squareBox); + } } \ No newline at end of file diff --git a/source/engine/physic/back/SquareBox.hpp b/source/engine/physic/back/SquareBox.hpp index 47afd297c6c8d8801e0e1dceb44127dee7cb1b4f..5f16f4d5d0928aa298d495a536ca5cf25db9b38a 100644 --- a/source/engine/physic/back/SquareBox.hpp +++ b/source/engine/physic/back/SquareBox.hpp @@ -5,8 +5,7 @@ #include "Position.hpp" namespace megu { - using Dimension = glm::vec3; - using Cube = std::array<Position, 8>; + using Dimension = glm::vec3; class SquareBox { public: @@ -15,23 +14,31 @@ namespace megu { SquareBox(const SquareBox &); SquareBox operator=(const SquareBox &); - inline const Position & position() const {return this->_position;} - inline const Dimension & dimension() const {return this->_dimension;} + inline const Position & getPosition() const {return this->_position;} + inline const Dimension & getDimension() const {return this->_dimension;} + + inline float x() const {return this->_position.x();} + inline float y() const {return this->_position.y();} + inline float z() const {return this->_position.z();} inline float width() const {return this->_dimension.x;} inline float height() const {return this->_dimension.y;} inline float depth() const {return this->_dimension.z;} inline void setPosition(const Position & position) {this->_position = position;} - inline void setDimension(const Dimension & dimension) {this->_dimension = dimension;} + inline void setPosition(float x, float y, float z = 0.f) {this->_position = Position(x, y, z);} - Cube asCube() const; + inline void setDimension(const Dimension & dimension) {this->_dimension = dimension;} + inline void setDimension(float x, float y, float z = 0.f) {this->_dimension = Dimension(x, y, z);} void move(const Direction &); + inline void move(float x, float y, float z = 0.f) {this->move(Direction(x, y, z));} + bool intersect(const SquareBox &) const; bool operator==(const SquareBox &) const; bool operator!=(const SquareBox &) const; + bool operator|(const SquareBox &) const; private: Position _position; diff --git a/source/engine/physic/front/engine/Engine.cpp b/source/engine/physic/front/engine/Engine.cpp index 2e39c9fae3c4d2b04c92e38979512901bb9cb7f5..7458412d90fe19eeb095f9d20a9a69e039dbfeb5 100644 --- a/source/engine/physic/front/engine/Engine.cpp +++ b/source/engine/physic/front/engine/Engine.cpp @@ -48,24 +48,24 @@ namespace megu { void PhysicEngine::step(double delta, Priority priority) { for(auto & source : this->_dynamic[priority]) { - source.get().update_physic(delta); + source.get().updatePhysic(delta); for(auto & target : this->_statics[priority]) { - if(source.get().isColliding(target)) { + if(source.get() | target) { this->_collisions.insert(Collision(source, target)); this->_collisions.insert(Collision(target, source)); } } for(auto & target : this->_dynamic[priority]) { - if(source.get().isColliding(target)) { + if(source.get() | target) { this->_collisions.insert(Collision(source, target)); } } } } - std::optional<SquareBox> PhysicEngine::makeCollision(const SquareBox & box, Priority priority) const { + std::optional<SquareBox> PhysicEngine::checkCollision(const SquareBox & box, Priority priority) const { for(const auto & source : this->_statics.at(priority)) { auto obox = source.get().isColliding(box); if(obox.has_value()) { diff --git a/source/engine/physic/front/engine/Engine.hpp b/source/engine/physic/front/engine/Engine.hpp index 7c8304d12fb3357a1812c798cc64227e1a7f5952..51d152f5e9ec907dbd839fbf4ec826b3d781bea8 100644 --- a/source/engine/physic/front/engine/Engine.hpp +++ b/source/engine/physic/front/engine/Engine.hpp @@ -28,7 +28,7 @@ namespace megu { void step(double); void step(double, Priority); - std::optional<SquareBox> makeCollision(const SquareBox &, Priority) const; + std::optional<SquareBox> checkCollision(const SquareBox &, Priority) const; std::optional<std::reference_wrapper<const Tangible>> get(const Identifiable &) const; diff --git a/source/engine/physic/front/object/Tangible.cpp b/source/engine/physic/front/object/Tangible.cpp index 58708a0e6f2b6bc34977fedfbc9ad17ef991e8c9..bb258d78dca354ef6304af049f0ac71e1ceddf4c 100644 --- a/source/engine/physic/front/object/Tangible.cpp +++ b/source/engine/physic/front/object/Tangible.cpp @@ -4,6 +4,9 @@ #include <iostream> namespace megu { + Tangible::Tangible() + : _box({0, 0, 0}, {1, 1, 1}) {} + Tangible::Tangible(const Position & position, const Dimension & dimension) : _box(position, dimension) {} @@ -25,7 +28,11 @@ namespace megu { return this->_box == entity._box; } - /*bool Tangible::operator!=(const Tangible & entity) const { - return !(*this == entity); - }*/ + std::optional<SquareBox> Tangible::operator|(const Tangible & tangible) const { + return this->isColliding(tangible); + } + + std::optional<SquareBox> Tangible::operator|(const SquareBox & box) const { + return this->isColliding(box); + } } \ No newline at end of file diff --git a/source/engine/physic/front/object/Tangible.hpp b/source/engine/physic/front/object/Tangible.hpp index 9b98a61ddf136d62c7c597b2a3b407d3776388d8..a85b5fff3175e5bc1fbf63b65e7969552272c6f3 100644 --- a/source/engine/physic/front/object/Tangible.hpp +++ b/source/engine/physic/front/object/Tangible.hpp @@ -10,18 +10,20 @@ namespace megu { class Tangible : virtual public Identifiable { public: - Tangible() = delete; + Tangible(); Tangible(const Position &, const Dimension &); virtual ~Tangible() = default; - inline const Position & getPosition() const {return this->_box.position();} + inline const Position & getPosition() const {return this->_box.getPosition();} inline const SquareBox & getBox() const {return this->_box;} - inline float x() const {return this->_box.position().x();} - inline float y() const {return this->_box.position().y();} - inline float z() const {return this->_box.position().z();} + inline float x() const {return this->_box.getPosition().x();} + inline float y() const {return this->_box.getPosition().y();} + inline float z() const {return this->_box.getPosition().z();} + + inline void setPosition(float x, float y, float z = 0.f) {this->_box.setPosition(x, y, z);} + inline void setDimension(float x, float y, float z = 0.f) {this->_box.setDimension(x, y, z);} - inline void setPosition(const Position & position) {this->_box.setPosition(position);} inline void move(const Direction & direction) {this->_box.move(direction);} inline void move(float x, float y, float z = 0.f) {return this->move(Direction(x, y, z));} @@ -29,6 +31,8 @@ namespace megu { virtual std::optional<SquareBox> isColliding(const SquareBox &) const; bool operator==(const Tangible &) const; + std::optional<SquareBox> operator|(const Tangible &) const; + std::optional<SquareBox> operator|(const SquareBox &) const; using UpdateLambda = std::function<void(double)>; diff --git a/source/engine/physic/front/object/TangibleMovable.cpp b/source/engine/physic/front/object/TangibleMovable.cpp index e79172924120856b7e95459f712aeda96523f07b..186a68433a0d15e1f313ed70ba2587ad8b7d49bf 100644 --- a/source/engine/physic/front/object/TangibleMovable.cpp +++ b/source/engine/physic/front/object/TangibleMovable.cpp @@ -5,6 +5,6 @@ namespace megu { : Tangible(position, dimension) {} void TangibleMovable::update(double delta) { - this->update_physic(delta); + this->updatePhysic(delta); } } \ No newline at end of file diff --git a/source/engine/physic/front/object/TangibleMovable.hpp b/source/engine/physic/front/object/TangibleMovable.hpp index 2d44fad23d36bcce3e7243872273dce222d40249..6bf1655de878564c4759d4d212b9a76ee9ec0dc1 100644 --- a/source/engine/physic/front/object/TangibleMovable.hpp +++ b/source/engine/physic/front/object/TangibleMovable.hpp @@ -9,7 +9,7 @@ namespace megu { TangibleMovable(const Position &, const Dimension &); virtual ~TangibleMovable() = default; - virtual void update_physic(double) = 0; + virtual void updatePhysic(double) = 0; protected: void update(double) override; diff --git a/source/engine/physic/front/object/TangibleStatic.cpp b/source/engine/physic/front/object/TangibleStatic.cpp index 244d16c52fa03e79d5d0c9f6092cf75c10639e24..3c4de7ed0740e16c24a3e018d8e7431d67f34a71 100644 --- a/source/engine/physic/front/object/TangibleStatic.cpp +++ b/source/engine/physic/front/object/TangibleStatic.cpp @@ -5,6 +5,6 @@ namespace megu { : Tangible(position, dimension) {} void TangibleStatic::update(double delta) { - this->update_physic(delta); + this->updatePhysic(delta); } } \ No newline at end of file diff --git a/source/engine/physic/front/object/TangibleStatic.hpp b/source/engine/physic/front/object/TangibleStatic.hpp index 2d4d335351c1d70fab9512fd45433fa71752937a..711dec2286bc39d129088a7051d024189be8f05e 100644 --- a/source/engine/physic/front/object/TangibleStatic.hpp +++ b/source/engine/physic/front/object/TangibleStatic.hpp @@ -9,7 +9,7 @@ namespace megu { TangibleStatic(const Position &, const Dimension &); virtual ~TangibleStatic() = default; - virtual void update_physic(double) const = 0; + virtual void updatePhysic(double) const = 0; protected: void update(double) override; diff --git a/source/game/Game.cpp b/source/game/Game.cpp index e0022680178b27197094d113b6a18a4b64666017..5231a27d01d8110cbca4794c96750ea320fd60bd 100644 --- a/source/game/Game.cpp +++ b/source/game/Game.cpp @@ -8,12 +8,9 @@ #include <game/back/object/Level.hpp> #include <game/back/object/Terrain.hpp> #include <game/back/object/tile/TileSolide.hpp> -#include <game/object/Test.hpp> #include <game/front/Layer.hpp> - #include <game/front/object/Klinck.hpp> - #include <game/utility/FrameCouter.hpp> namespace megu::game { @@ -54,8 +51,8 @@ namespace megu::game { terrain.setTileEvent(2, new TileSolide(32.f, physic::TERRAIN)); for(size_t i = 0; i < 11; ++i) { - terrain.graphic().addAnimation(i, 9, {18, 19, 20, 21}); - terrain.graphic().addAnimation(i, 10, {24, 25, 26, 27}); + terrain.graphic().pushAnimation(i, 9, {18, 19, 20, 21}); + terrain.graphic().pushAnimation(i, 10, {24, 25, 26, 27}); } for(size_t i = 0; i < 11; ++i) { @@ -63,7 +60,7 @@ namespace megu::game { terrain.setValue(j, i, layer0.at(i*11 + j)); } } - + terrain.getGraphicComponent()->setLayerPriority(graphic::TERRAIN); terrain.getPhysicComponent()->setLayer(physic::TERRAIN); diff --git a/source/game/back/GameObject.cpp b/source/game/back/GameObject.cpp new file mode 100644 index 0000000000000000000000000000000000000000..beea43fb3a426680f7334977ba12550bffedb897 --- /dev/null +++ b/source/game/back/GameObject.cpp @@ -0,0 +1,6 @@ +#include "GameObject.hpp" + +namespace megu::game { + GameProps::GameProps(kernel::Prop * props) + : _parent(props) {} +} \ No newline at end of file diff --git a/source/game/back/GameObject.hpp b/source/game/back/GameObject.hpp index 72aa6e966cdb0043ac9042c646e58bfd7d4126c4..dfa5954bb8fbb6d48eb8f3f80ab13a1e5a2c1610 100644 --- a/source/game/back/GameObject.hpp +++ b/source/game/back/GameObject.hpp @@ -21,13 +21,14 @@ namespace megu::game { class GameProps : public GameObject, public GameEvent { public: - GameProps(kernel::Prop * prop) - : _props(prop) {} + GameProps() = delete; + GameProps(kernel::Prop *); + virtual ~GameProps() = default; - inline kernel::Prop * get() {return this->_props;} + inline kernel::Prop * parent() const {return this->_parent;} private: - kernel::Prop * _props; + kernel::Prop * _parent; }; } \ No newline at end of file diff --git a/source/game/back/object/Damagable.cpp b/source/game/back/object/Damagable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cea8177419213c13937a85190884fd43e8f2ed06 --- /dev/null +++ b/source/game/back/object/Damagable.cpp @@ -0,0 +1,18 @@ +#include "Damagable.hpp" + +namespace megu::game { + Damagable::Damagable(uint32_t life, bool dead) + : _life(life), _dead(dead) {} + + void Damagable::damage(uint32_t damage) { + this->_life -= damage; + if(this->_life <= 0) { + this->_life = 0; + this->_dead = true; + } + } + + void Damagable::heal(uint32_t heal) { + this->_life += heal; + } +} \ No newline at end of file diff --git a/source/game/back/object/Damagable.hpp b/source/game/back/object/Damagable.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3f0bead00e940b33edba82bc6d3108890a0ed75d --- /dev/null +++ b/source/game/back/object/Damagable.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include <stdint.h> + +namespace megu::game { + class Damagable { + public: + Damagable(uint32_t = 0, bool = false); + virtual ~Damagable() = default; + + inline uint32_t getLife() const {return this->_life;} + inline bool isAlive() const {return !this->_dead;} + inline bool isDead() const {return this->_dead;} + + inline void setLife(uint32_t l) {this->_life = l;} + inline void setDead(bool s) {this->_dead = s;} + + inline void kill() {this->_dead = true;} + + void damage(uint32_t); + void heal(uint32_t); + + private: + uint32_t _life; + bool _dead; + }; +} \ No newline at end of file diff --git a/source/game/back/object/Enemy.cpp b/source/game/back/object/Enemy.cpp index 5e93f2bf1365aeeb69d157ba7fc6af8b3bd275bb..b684689c73a16ba29621e8191873a7ecf1a07061 100644 --- a/source/game/back/object/Enemy.cpp +++ b/source/game/back/object/Enemy.cpp @@ -1,33 +1,35 @@ #include "Enemy.hpp" #include <kernel/front/Kernel.hpp> +#include <game/back/object/Level.hpp> + +#include <game/front/Stats.hpp> namespace megu::game { Enemy::Enemy(float x, float y, float w, float h, std::filesystem::path & path) : kernel::PropsDynamic(this->_sprite, this->_movable), GameProps(this), _sprite(path), _movable(x, y, w, h) { - this->_sprite.setPosition({x, y}); - } - - void Enemy::move(float x, float y) { - this->_movable.move(x, y); - this->_movable.move(x, y); + this->_sprite.setPosition(x, y); } void Enemy::setup(kernel::Kernel & kernel, Level & level) { - this->_sprite.setFrame({0.f, 0.f, 51.f, 98.f}); - this->_sprite.setSize({51.f, 98.f}); + this->_sprite.setFrame(0.f, 0.f, 51.f, 98.f); + this->_sprite.setSize(51.f, 98.f); this->_movable.setCollideLambda([this, &level](kernel::Kernel &, kernel::PhysicEngine &, Identifiable & id, kernel::Physical<kernel::PhysicEngine> & comp, double) { auto object = level.get(id); if(object.has_value()) { auto event = object->get().on(); if(event.has_value()) { - this->on(*object->get().get(), event.value()); + this->on(*object->get().parent(), event.value()); } } }); } + void Enemy::destroy(kernel::Kernel & kernel, Level & level) { + + } + void Enemy::on(const kernel::Prop &, const Event & event) { if(event & Event::Type::SOLID) { this->onSolide(event); @@ -40,17 +42,13 @@ namespace megu::game { std::optional<Event> Enemy::on() const { Event b(Event::DAMAGE); - b.set(0, 10); + b.set(Stats::ATK, 10); return b; } - void Enemy::destroy(kernel::Kernel & kernel, Level & level) { - - } - void Enemy::apply(kernel::Kernel & kernel) { - kernel.add(this); + kernel.push(*this); } void Enemy::onDamage(const Event &) { diff --git a/source/game/back/object/Enemy.hpp b/source/game/back/object/Enemy.hpp index 89bacf93a7c541db9d8941550d3edbdb839eb1c2..9dc862c2a95a4941786e5a4ec5b74ae3d6964315 100644 --- a/source/game/back/object/Enemy.hpp +++ b/source/game/back/object/Enemy.hpp @@ -2,23 +2,22 @@ #include <kernel/front/props/PropsDynamic.hpp> #include <game/back/GameObject.hpp> -#include <game/back/object/Level.hpp> namespace megu::game { class Enemy : public kernel::PropsDynamic, public GameProps { public: Enemy(float, float, float, float, std::filesystem::path &); - void move(float, float); - void setup(kernel::Kernel &, Level &) override; void destroy(kernel::Kernel &, Level &) override; - void apply(kernel::Kernel &) override; + void on(const kernel::Prop &, const Event &) override; std::optional<Event> on() const override; + void apply(kernel::Kernel &) override; + void onDamage(const Event &); void onSolide(const Event &); diff --git a/source/game/back/object/Level.cpp b/source/game/back/object/Level.cpp index 5fbbcfdd34eaa8874a794b385bfd95acc06008c3..a36db161dd4d12ad487375b9adad913978c5d326 100644 --- a/source/game/back/object/Level.cpp +++ b/source/game/back/object/Level.cpp @@ -14,12 +14,12 @@ namespace megu::game { } void Level::add(GameProps * prop) { - this->_objecs.insert({prop->get()->id(), prop}); + this->_objecs.insert({prop->parent()->id(), prop}); } void Level::apply(kernel::Kernel & kernel) { for(auto & [id, prop] : this->_objecs) { - kernel.add(prop->get()); + kernel.push(*prop->parent()); } } @@ -29,7 +29,7 @@ namespace megu::game { void Level::destroy(kernel::Kernel & kernel, Level & level) { for(auto & [id, prop] : this->_objecs) { - kernel.remove(prop->get()); + kernel.remove(*prop->parent()); } } } \ No newline at end of file diff --git a/source/game/back/object/Player.cpp b/source/game/back/object/Player.cpp index f78ddf3b1871d7f4d94709831ffc494e6dc19954..464b93167d350cd767a0afc1eb7bc79dabb49b45 100644 --- a/source/game/back/object/Player.cpp +++ b/source/game/back/object/Player.cpp @@ -6,13 +6,13 @@ namespace megu::game { : kernel::PropsPlayable(this->_sprite, this->_movable), GameProps(this), _sprite(path), _movable(x, y, w, h) {} void Player::move(float x, float y) { - this->_sprite.move({x, y}); + this->_sprite.move(x, y); this->_movable.move(x, y); } void Player::setPosition(float x, float y) { - this->_sprite.setPosition({x, y}); - this->_movable.setPosition({x, y}); + this->_sprite.setPosition(x, y); + this->_movable.setPosition(x, y); } const Position & Player::getPosition() const { @@ -26,7 +26,7 @@ namespace megu::game { if(object.has_value()) { auto event = object.value().get().on(); if(event.has_value()) { - this->on(*object.value().get().get(), event.value()); + this->on(*object.value().get().parent(), event.value()); } } }); @@ -53,6 +53,6 @@ namespace megu::game { } void Player::apply(kernel::Kernel & kernel) { - kernel.add(this); + kernel.push(*this); } } \ No newline at end of file diff --git a/source/game/back/object/Player.hpp b/source/game/back/object/Player.hpp index 9859acff8db2fc60d1fec773aba4a5b4bdd9032d..68232404be2b46300f4bb49f2ae89cc8e917b8fc 100644 --- a/source/game/back/object/Player.hpp +++ b/source/game/back/object/Player.hpp @@ -9,17 +9,16 @@ namespace megu::game { public: Player(float x, float y, float w, float h, std::filesystem::path); - void move(float, float); - void setPosition(float, float); - - const Position & getPosition() const; - void setup(kernel::Kernel &, Level &) override final; void destroy(kernel::Kernel &, Level &) override final; + + void setPosition(float, float); + void move(float, float); - void apply(kernel::Kernel &) override final; - + const Position & getPosition() const; + void on(const kernel::Prop &, const Event &) override final; + void apply(kernel::Kernel &) override final; std::optional<Event> on() const = 0; diff --git a/source/game/back/object/Terrain.cpp b/source/game/back/object/Terrain.cpp index eea0a8613cd0b31e7b982e6fafeea631495eab72..d0ea840dc37cb4d71236c5cee6954ee576849325 100644 --- a/source/game/back/object/Terrain.cpp +++ b/source/game/back/object/Terrain.cpp @@ -7,7 +7,7 @@ namespace megu::game { Terrain::Terrain(float x, float y, float w, float h, const std::filesystem::path & path, size_t r, size_t c , float size, size_t tileSize) : PropsTileMap(this->_graphic, this->_physic), GameProps(this), _graphic(path, r, c, size, tileSize), _physic(x, y, r * w, c * h) { //! Taille Pour 1 tile ! - this->_graphic.setSize({w, h}); + this->_graphic.setSize(w, h); } void Terrain::setValue(size_t x, size_t y, size_t value) { @@ -16,7 +16,7 @@ namespace megu::game { this->_physic.push( { static_cast<float>(x) * this->_graphic.getSize().x, - (this->_graphic.getSize().y * (this->_graphic.height()- 1)) - static_cast<float>(y) * this->_graphic.getSize().y + (this->_graphic.getSize().y * (this->_graphic.collumn()- 1)) - static_cast<float>(y) * this->_graphic.getSize().y }, *this->_event[value] ); @@ -52,7 +52,7 @@ namespace megu::game { } void Terrain::apply(kernel::Kernel & kernel) { - kernel.add(this); + kernel.push(*this); } void Terrain::on(const kernel::Prop &, const Event & event) { diff --git a/source/game/back/object/Terrain.hpp b/source/game/back/object/Terrain.hpp index 44e91279949165ea7040670c9b27e8625af8691a..eedfe496bbc44afd28ef07c4b8e32dc48cd2eadf 100644 --- a/source/game/back/object/Terrain.hpp +++ b/source/game/back/object/Terrain.hpp @@ -1,9 +1,6 @@ #pragma once #include <kernel/front/props/PropsTileMap.hpp> -#include <kernel/front/component/physic/TileArray.hpp> -#include <kernel/front/component/graphic/TileMap.hpp> - #include <game/back/GameObject.hpp> #include <game/back/object/tile/Tile.hpp> @@ -12,14 +9,16 @@ namespace megu::game { public: Terrain() = delete; Terrain(float, float, float, float, const std::filesystem::path &, size_t, size_t, float, size_t); - - void setValue(size_t, size_t, size_t); - void setTileEvent(size_t, Tile *); + virtual ~Terrain() = default; void setup(kernel::Kernel &, Level &) override; void destroy(kernel::Kernel &, Level &) override; - void apply(kernel::Kernel &) override; + void setValue(size_t, size_t, size_t); + void setTileEvent(size_t, Tile *); + + + void apply(kernel::Kernel &) override; void on(const kernel::Prop &, const Event &) override; std::optional<Event> on() const override; diff --git a/source/game/front/object/Klinck.cpp b/source/game/front/object/Klinck.cpp index b668e0b5383d09d20081ef19ddfcb0931eb7f497..5619d09cc75afde88521639945bc5cd0bc1aee84 100644 --- a/source/game/front/object/Klinck.cpp +++ b/source/game/front/object/Klinck.cpp @@ -6,7 +6,7 @@ namespace megu::game { Klinck::Klinck(kernel::Kernel & k, float x, float y) - : Player(0.f, 0.f, 32.f, 32.f, "assets/game/objects/klinck.png"), _kernel(k), _life(100), _atk(10), _def(25), _vx(0.f), _vy(0.f) { + : Player(0.f, 0.f, 32.f, 32.f, "assets/game/objects/klinck.png"), Damagable(100), _kernel(k), _atk(10), _def(25), _vx(0.f), _vy(0.f) { this->getGraphic().setLayerObject(graphic::Layer::ENTITY); this->getPhysic().setLayer(physic::Layer::ENTITY); this->move(x, y); @@ -15,18 +15,18 @@ namespace megu::game { void Klinck::onSetup(kernel::Kernel & kernel, Level &) { auto & sprite = this->getGraphic(); - sprite.push(Animation::IDL_BACK, 0, 32, 16, 16); - sprite.push(Animation::IDL_FRONT, 16, 32, 16, 16); - sprite.push(Animation::IDL_LEFT, 32, 32, 16, 16); - sprite.push(Animation::IDL_RIGHT, 48, 32, 16, 16); + sprite.pushAnimation(Animation::IDL_BACK, 0, 32, 16, 16); + sprite.pushAnimation(Animation::IDL_FRONT, 16, 32, 16, 16); + sprite.pushAnimation(Animation::IDL_LEFT, 32, 32, 16, 16); + sprite.pushAnimation(Animation::IDL_RIGHT, 48, 32, 16, 16); - sprite.push(Animation::WALK_BACK, {{0, 16, 16, 16}, { 16, 16, 16, 16}}); - sprite.push(Animation::WALK_FRONT, {{32, 16, 16, 16}, { 48, 16, 16, 16}}); - sprite.push(Animation::WALK_LEFT, {{0, 0, 16, 16}, { 16, 0, 16, 16}}); - sprite.push(Animation::WALK_RIGHT, {{32, 0, 16, 16}, { 48, 0, 16, 16}}); + sprite.pushAnimation(Animation::WALK_BACK, {{0, 16, 16, 16}, { 16, 16, 16, 16}}); + sprite.pushAnimation(Animation::WALK_FRONT, {{32, 16, 16, 16}, { 48, 16, 16, 16}}); + sprite.pushAnimation(Animation::WALK_LEFT, {{0, 0, 16, 16}, { 16, 0, 16, 16}}); + sprite.pushAnimation(Animation::WALK_RIGHT, {{32, 0, 16, 16}, { 48, 0, 16, 16}}); - sprite.setAnimation(Animation::IDL_BACK); - sprite.setSize({32.f, 32.f}); + sprite.setCurrentAnimation(Animation::IDL_BACK); + sprite.setSize(32.f, 32.f); this->setControl(kernel.window(), new KlinckKeyProfile(*this, kernel)); @@ -34,15 +34,14 @@ namespace megu::game { this->_moving[DOWN] = false; this->_moving[LEFT] = false; this->_moving[RIGHT] = false; - } void Klinck::onDestroy(kernel::Kernel &, Level &) { } - void Klinck::onDamage(const Event &) { - + void Klinck::onDamage(const Event & event) { + this->damage(event.get(Stats::ATK).value_or(0)); } void Klinck::onSolide(const kernel::Prop &) { @@ -82,9 +81,9 @@ namespace megu::game { SquareBox box = this->getPhysic().getBox(); box.move({0.f, this->_vy, 0.f}); - std::optional<SquareBox> obox = this->_kernel.getPhysicEngine().get().makeCollision(box, physic::TERRAIN); + std::optional<SquareBox> obox = this->_kernel.getPhysicEngine().get().checkCollision(box, physic::TERRAIN); if(obox.has_value()) { - float pos_y = this->_vy > 0 ? obox.value().position().y() - obox.value().height() : obox.value().position().y() + obox.value().height(); + float pos_y = this->_vy > 0 ? obox.value().y() - obox.value().height() : obox.value().y() + obox.value().height(); this->setPosition(this->getPosition().x(), pos_y); this->_vy = 0.f; } @@ -97,9 +96,9 @@ namespace megu::game { SquareBox box = this->getPhysic().getBox(); box.move({this->_vx, 0.f, 0.f}); - std::optional<SquareBox> obox = this->_kernel.getPhysicEngine().get().makeCollision(box, physic::TERRAIN); + std::optional<SquareBox> obox = this->_kernel.getPhysicEngine().get().checkCollision(box, physic::TERRAIN); if(obox.has_value()) { - float pos_x = this->_vx > 0 ? obox.value().position().x() - obox.value().width() : obox.value().position().x() + obox.value().width(); + float pos_x = this->_vx > 0 ? obox.value().x() - obox.value().width() : obox.value().x() + obox.value().width(); this->setPosition(pos_x, this->getPosition().y()); this->_vx = 0.f; } diff --git a/source/game/front/object/Klinck.hpp b/source/game/front/object/Klinck.hpp index 178046966f70a4804c008d0f98093eade1f792ed..51ca28024a52c2ce547e420a9bff290761ec5ba1 100644 --- a/source/game/front/object/Klinck.hpp +++ b/source/game/front/object/Klinck.hpp @@ -1,9 +1,10 @@ #pragma once #include <game/back/object/Player.hpp> +#include <game/back/object/Damagable.hpp> namespace megu::game { - class Klinck : public Player { + class Klinck : public Player, public Damagable { public: enum Animation { IDL_FRONT = 1, @@ -42,7 +43,6 @@ namespace megu::game { private: kernel::Kernel & _kernel; - unsigned int _life; unsigned int _atk; unsigned int _def; float _vx, _vy; diff --git a/source/game/front/profile/KlinckKeys.cpp b/source/game/front/profile/KlinckKeys.cpp index 2da47f3d96240ddb2989f7786506262203cfd3fb..25760f30322344f1956a751bf2279c5f80ddade8 100644 --- a/source/game/front/profile/KlinckKeys.cpp +++ b/source/game/front/profile/KlinckKeys.cpp @@ -11,25 +11,25 @@ namespace megu::game { if(key == Keyboard::Key::ARROW_LEFT) { this->_player.setMovingDirection(Klinck::Direction::LEFT, action != Action::RELEASE); //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_LEFT : Klinck::Animation::WALK_LEFT); - this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_LEFT); + this->_player.getGraphic().setCurrentAnimation(Klinck::Animation::IDL_LEFT); } if(key == Keyboard::Key::ARROW_RIGHT) { this->_player.setMovingDirection(Klinck::Direction::RIGHT, action != Action::RELEASE); //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_RIGHT : Klinck::Animation::WALK_RIGHT); - this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_RIGHT); + this->_player.getGraphic().setCurrentAnimation(Klinck::Animation::IDL_RIGHT); } if(key == Keyboard::Key::ARROW_UP) { this->_player.setMovingDirection(Klinck::Direction::UP, action != Action::RELEASE); //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_FRONT : Klinck::Animation::WALK_FRONT); - this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_FRONT); + this->_player.getGraphic().setCurrentAnimation(Klinck::Animation::IDL_FRONT); } if(key == Keyboard::Key::ARROW_DOWN) { this->_player.setMovingDirection(Klinck::Direction::DOWN, action != Action::RELEASE); //this->_player.getGraphic().setAnimation(action == Action::RELEASE ? Klinck::Animation::IDL_BACK : Klinck::Animation::WALK_BACK); - this->_player.getGraphic().setAnimation(Klinck::Animation::IDL_BACK); + this->_player.getGraphic().setCurrentAnimation(Klinck::Animation::IDL_BACK); } } } \ No newline at end of file diff --git a/source/game/object/Test.cpp b/source/game/object/Test.cpp deleted file mode 100644 index 8433087c2e2b919b4a0b4d45ca97aa2a6e267aa4..0000000000000000000000000000000000000000 --- a/source/game/object/Test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "Test.hpp" - -namespace megu::game { - Object::Object(std::filesystem::path & path) - : _physic(0, 0, 64, 64), _graphic(path), _map("assets/tilemap.png", 8, 8, 8.f, 16, 0.125) { - this->_graphic.setFrame({0.f, 0.f, 51.f, 98.f}); - this->_graphic.setSize({51.f, 98.f}); - - size_t tab[8][8] = { - {44, 45, 44, 47, 2, 1, 1, 1}, - {45, 45, 44, 47, 1, 1, 1, 1}, - {45, 44, 44, 47, 1, 1, 1, 1}, - {22, 22, 22, 23, 1, 1, 2, 1}, - {28, 28, 28, 29, 1, 1, 1, 1}, - { 1, 2, 1, 1, 1, 1, 1, 1}, - { 1, 2, 1, 1, 1, 1, 1, 1}, - { 1, 1, 1, 2, 1, 1, 1, 1} - }; - - for(size_t i = 0; i < 8; ++i) { - for(size_t j = 0; j < 8; ++j) { - this->_map.setValue(j, i, tab[i][j]); - } - } - - this->_map.addAnimation(0, 6, {18, 18, 20, 21}); - this->_map.addAnimation(1, 6, {18, 18, 20, 21}); - this->_map.addAnimation(2, 6, {18, 18, 20, 21}); - this->_map.addAnimation(3, 6, {18, 18, 20, 21}); - this->_map.addAnimation(4, 6, {18, 18, 20, 21}); - this->_map.addAnimation(5, 6, {18, 18, 20, 21}); - this->_map.addAnimation(6, 6, {18, 18, 20, 21}); - this->_map.addAnimation(7, 6, {18, 18, 20, 21}); - - this->_map.addAnimation(0, 7, {24, 25, 26, 27}); - this->_map.addAnimation(1, 7, {24, 25, 26, 27}); - this->_map.addAnimation(2, 7, {24, 25, 26, 27}); - this->_map.addAnimation(3, 7, {24, 25, 26, 27}); - this->_map.addAnimation(4, 7, {24, 25, 26, 27}); - this->_map.addAnimation(5, 7, {24, 25, 26, 27}); - this->_map.addAnimation(6, 7, {24, 25, 26, 27}); - this->_map.addAnimation(7, 7, {24, 25, 26, 27}); - - this->_map.setSize({360 / 8, 360 / 8}); - } -} \ No newline at end of file diff --git a/source/game/object/Test.hpp b/source/game/object/Test.hpp deleted file mode 100644 index a7b123f7d5dbbdfd8e4d920c9ccd74622246ff83..0000000000000000000000000000000000000000 --- a/source/game/object/Test.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include <kernel/front/props/Props.hpp> -#include <kernel/front/component/physic/Fixed.hpp> -#include <kernel/front/component/graphic/Sprite.hpp> -#include <kernel/front/component/graphic/TileMap.hpp> - -namespace megu::game { - class Object : public kernel::Prop { - public: - Object(std::filesystem::path &); - - inline kernel::Prop::Physical_Component * getPhysicComponent() override {return &this->_physic;} - inline kernel::Prop::Graphical_Component * getGraphicComponent() override {return &this->_map;} - - private: - kernel::Fixed _physic; - kernel::Sprite _graphic; - kernel::Tilemap _map; - }; -} \ No newline at end of file diff --git a/source/kernel/back/component/Component.hpp b/source/kernel/back/component/Component.hpp index b95d28028461cea183ce507563e4837cf50f5819..c36d0cf9dc454de172ed8439b88061b9f8cfd965 100644 --- a/source/kernel/back/component/Component.hpp +++ b/source/kernel/back/component/Component.hpp @@ -9,7 +9,7 @@ namespace megu::kernel { template <class E> class Component : public virtual Identifiable { public: - virtual void apply(Kernel & k, E &) = 0; - virtual void unapply(Kernel & k, E &) = 0; + virtual void apply(E &) = 0; + virtual void unapply(E &) = 0; }; } \ No newline at end of file diff --git a/source/kernel/back/component/Graphical.hpp b/source/kernel/back/component/Graphical.hpp index 0354e05f9e2b6ed89651a0b5bf15adbcd4ec45d5..9f50729764ed9e87b5a7b161e86e105c63208132 100644 --- a/source/kernel/back/component/Graphical.hpp +++ b/source/kernel/back/component/Graphical.hpp @@ -4,11 +4,10 @@ #include <engine/utility/Priority.hpp> namespace megu::kernel { - template <class Ge> - class Graphical : public Component<Ge> { + template <class E> + class Graphical : public Component<E> { public: - inline Graphical(Priority l = 0, Priority o = 0) - : _layer(l), _object(o) {} + inline Graphical(Priority = 0, Priority = 0); inline Priority getLayerPriority() const {return this->_layer;} inline Priority getObjectPriority() const {return this->_object;} @@ -23,4 +22,6 @@ namespace megu::kernel { Priority _object; }; -} \ No newline at end of file +} + +#include "Graphical.tpp" \ No newline at end of file diff --git a/source/kernel/back/component/Graphical.tpp b/source/kernel/back/component/Graphical.tpp new file mode 100644 index 0000000000000000000000000000000000000000..4f9b6ac45469f76ebd9dd94ec5a5904144585b7d --- /dev/null +++ b/source/kernel/back/component/Graphical.tpp @@ -0,0 +1,7 @@ +#include "Graphical.hpp" + +namespace megu::kernel { + template <class E> + Graphical<E>::Graphical(Priority layer, Priority object) + : _layer(layer), _object(object) {} +} \ No newline at end of file diff --git a/source/kernel/back/component/Physical.hpp b/source/kernel/back/component/Physical.hpp index 7701eb4e19a963ba21ca08cdc76a8bcc4787aab5..e427e6f3faf6179409921ec9dcf1cc0906e99e78 100644 --- a/source/kernel/back/component/Physical.hpp +++ b/source/kernel/back/component/Physical.hpp @@ -7,19 +7,22 @@ #include <engine/utility/Priority.hpp> namespace megu::kernel { - template <class Pe> - class Physical : public Component<Pe> { + template <class E> + class Physical : public Component<E> { public: - inline Physical(Priority p = 0) - : _layer(p) {} + Physical(Priority p = 0); + virtual ~Physical() = default; - virtual void on_collide(Kernel &, Pe &, Identifiable &, Physical &, double) = 0; - - using CollideLambda = std::function<void(Kernel &, Pe &, Identifiable &, Physical &, double)>; inline void setLayer(Priority p) {this->_layer = p;} inline Priority getLayer() const {return this->_layer;} + virtual void onCollide(Kernel &, E &, Identifiable &, Physical &, double) = 0; + + using CollideLambda = std::function<void(Kernel &, E &, Identifiable &, Physical &, double)>; + private: Priority _layer; }; -} \ No newline at end of file +} + +#include "Physical.tpp" \ No newline at end of file diff --git a/source/kernel/back/component/Physical.tpp b/source/kernel/back/component/Physical.tpp new file mode 100644 index 0000000000000000000000000000000000000000..c04e5c07bc8e4799dd38353731ba7c13187aea60 --- /dev/null +++ b/source/kernel/back/component/Physical.tpp @@ -0,0 +1,7 @@ +#include "Physical.hpp" + +namespace megu::kernel { + template <class E> + Physical<E>::Physical(Priority layer) + : _layer(layer) {} +} \ No newline at end of file diff --git a/source/kernel/back/engine/Engine.hpp b/source/kernel/back/engine/Engine.hpp index 8842381e573323690742b546eff4e1693399f3c5..33f2bdf0172140e6d5ce940cc3c902693eb97a7e 100644 --- a/source/kernel/back/engine/Engine.hpp +++ b/source/kernel/back/engine/Engine.hpp @@ -7,14 +7,14 @@ namespace megu::kernel { template <class T, class C, class O> class Engine { public: - virtual void boot(Kernel &) = 0; - virtual void stop(Kernel &) = 0; - virtual void step(Kernel &, double) = 0; + virtual void boot() = 0; + virtual void stop() = 0; + virtual void step(double) = 0; virtual T & get() = 0; virtual const O & get(const C &) const = 0; - virtual void add(Kernel &, C &) = 0; - virtual void remove(Kernel &, C &) = 0; + virtual void push(C &) = 0; + virtual void remove(C &) = 0; }; } \ No newline at end of file diff --git a/source/kernel/back/engine/GraphicEngine.cpp b/source/kernel/back/engine/GraphicEngine.cpp index 1aa1931a565523b5d408b065b6e5d2ffb066efc8..81beaa14caec0f64d528300fa6c457eb1ee82a20 100644 --- a/source/kernel/back/engine/GraphicEngine.cpp +++ b/source/kernel/back/engine/GraphicEngine.cpp @@ -6,26 +6,26 @@ namespace megu::kernel { GraphicEngine::GraphicEngine(Window & window) : _engine(window), _renderer(360, 360) {} - void GraphicEngine::boot(Kernel &) { + void GraphicEngine::boot() { this->_engine.push(0, this->_renderer); this->_engine.push(1, this->_renderer); this->_engine.push(2, this->_renderer); } - void GraphicEngine::stop(Kernel &) { + void GraphicEngine::stop() { } - void GraphicEngine::step(Kernel & kernel, double time) { + void GraphicEngine::step(double time) { this->_engine.step(); } - void GraphicEngine::add(Kernel & kernel, Graphical<GraphicEngine> & graphical) { - graphical.apply(kernel, *this); + void GraphicEngine::push(Graphical<GraphicEngine> & graphical) { + graphical.apply(*this); } - void GraphicEngine::remove(Kernel & kernel, Graphical<GraphicEngine> & graphical) { - graphical.unapply(kernel, *this); + void GraphicEngine::remove(Graphical<GraphicEngine> & graphical) { + graphical.unapply(*this); } const Renderable & GraphicEngine::get(const Graphical<GraphicEngine> & graphical) const { diff --git a/source/kernel/back/engine/GraphicEngine.hpp b/source/kernel/back/engine/GraphicEngine.hpp index 77ce58f4d206378f1fd31ec4a7c513572b5e149a..0ad5196c9a75ea87f2fb24b3aea3eae387080069 100644 --- a/source/kernel/back/engine/GraphicEngine.hpp +++ b/source/kernel/back/engine/GraphicEngine.hpp @@ -19,12 +19,12 @@ namespace megu::kernel { inline megu::GraphicEngine & get() {return this->_engine;} - void boot(Kernel &) override; - void stop(Kernel &) override; - void step(Kernel &, double) override; + void boot() override; + void stop() override; + void step(double) override; - void add(Kernel &, Graphical<GraphicEngine> &) override; - void remove(Kernel &, Graphical<GraphicEngine> &) override; + void push(Graphical<GraphicEngine> &) override; + void remove(Graphical<GraphicEngine> &) override; const megu::Renderable & get(const Graphical<GraphicEngine> &) const override; diff --git a/source/kernel/back/engine/PhysicEngine.cpp b/source/kernel/back/engine/PhysicEngine.cpp index 26476f5ccf355024dd1bb79900438d2ad6c03459..781977e43cbfb160a7073cd98e87a9f51323c86d 100644 --- a/source/kernel/back/engine/PhysicEngine.cpp +++ b/source/kernel/back/engine/PhysicEngine.cpp @@ -6,24 +6,24 @@ namespace megu::kernel { PhysicEngine::PhysicEngine() : _engine() {} - void PhysicEngine::boot(Kernel &) { + void PhysicEngine::boot() { } - void PhysicEngine::stop(Kernel &) { + void PhysicEngine::stop() { } - void PhysicEngine::step(Kernel &, double time) { + void PhysicEngine::step(double time) { this->_engine.step(time); } - void PhysicEngine::add(Kernel & kernel, Physical<PhysicEngine> & props) { - props.apply(kernel, *this); + void PhysicEngine::push(Physical<PhysicEngine> & props) { + props.apply(*this); } - void PhysicEngine::remove(Kernel & kernel, Physical<PhysicEngine> & props) { - props.unapply(kernel, *this); + void PhysicEngine::remove(Physical<PhysicEngine> & props) { + props.unapply(*this); } const megu::Tangible & PhysicEngine::get(const Physical<PhysicEngine> & props) const { diff --git a/source/kernel/back/engine/PhysicEngine.hpp b/source/kernel/back/engine/PhysicEngine.hpp index 59921974c80ad27714b4c106300466a7cd382d6b..c4379ca7b6d1e9a884696f1f57fa8e61b44b2a06 100644 --- a/source/kernel/back/engine/PhysicEngine.hpp +++ b/source/kernel/back/engine/PhysicEngine.hpp @@ -12,12 +12,14 @@ namespace megu::kernel { inline megu::PhysicEngine & get() override {return this->_engine;} - void boot(Kernel &) override; - void stop(Kernel &) override; - void step(Kernel &, double) override; + void boot() override; + void stop() override; + void step(double) override; - void add(Kernel &, Physical<PhysicEngine> &) override; - void remove(Kernel &, Physical<PhysicEngine> &) override; + void push(Physical<PhysicEngine> &) override; + void remove(Physical<PhysicEngine> &) override; + + inline std::optional<SquareBox> check(SquareBox box, Priority prio) const {return this->_engine.checkCollision(box, prio);} const megu::Tangible & get(const Physical<PhysicEngine> &) const override; diff --git a/source/kernel/front/Kernel.cpp b/source/kernel/front/Kernel.cpp index b69022ea59d1d298f4d29346425347666c4e4598..f6cd84b05dc280ee4dfb9bcb73bb7276a233c8e5 100644 --- a/source/kernel/front/Kernel.cpp +++ b/source/kernel/front/Kernel.cpp @@ -3,57 +3,57 @@ namespace megu::kernel { Kernel::Kernel(Window & window) : _window(window), _pEngine(), _gEngine(window) { - this->_pEngine.boot(*this); - this->_gEngine.boot(*this); + this->_pEngine.boot(); + this->_gEngine.boot(); } Kernel::~Kernel() { - this->_pEngine.stop(*this); - this->_pEngine.stop(*this); + this->_pEngine.stop(); + this->_pEngine.stop(); } void Kernel::step() { double time = Window::Time(); if(this->_window.isOpen()) { - this->_gEngine.step(*this, time); + this->_gEngine.step(time); this->_gResolver.resolve(*this, this->_gEngine, time); } - this->_pEngine.step(*this, time); + this->_pEngine.step(time); this->_pResolver.resolve(*this, this->_pEngine, time); } - void Kernel::add(Prop * props) { - this->_props[props->id()] = props; - auto * pComponent = props->getPhysicComponent(); + void Kernel::push(Prop & props) { + this->_props[props.id()] = &props; + auto * pComponent = props.getPhysicComponent(); if(pComponent != nullptr) { - this->_pEngine.add(*this, *pComponent); - this->_pResolver.add(*pComponent); + this->_pEngine.push(*pComponent); + this->_pResolver.push(*pComponent); } - auto * gComponent = props->getGraphicComponent(); + auto * gComponent = props.getGraphicComponent(); if(gComponent != nullptr) { - this->_gEngine.add(*this, *gComponent); - this->_gResolver.add(*gComponent); + this->_gEngine.push(*gComponent); + this->_gResolver.push(*gComponent); } } - void Kernel::remove(Prop * props) { - auto * pComponent = props->getPhysicComponent(); + void Kernel::remove(Prop & props) { + auto * pComponent = props.getPhysicComponent(); if(pComponent != nullptr) { - this->_pEngine.remove(*this, *pComponent); + this->_pEngine.remove(*pComponent); this->_pResolver.remove(*pComponent); } - auto * gComponent = props->getGraphicComponent(); + auto * gComponent = props.getGraphicComponent(); if(gComponent != nullptr) { - this->_gEngine.remove(*this, *gComponent); + this->_gEngine.remove(*gComponent); this->_gResolver.remove(*gComponent); } - this->_props.erase(props->id()); + this->_props.erase(props.id()); } Prop * Kernel::get(const Prop::Physical_Component & pc) { diff --git a/source/kernel/front/Kernel.hpp b/source/kernel/front/Kernel.hpp index 0593c91ebe451cde6e81eabfbc8f2222ca21f0ca..541b459b158bf0ebee242d7b815267417af3ac86 100644 --- a/source/kernel/front/Kernel.hpp +++ b/source/kernel/front/Kernel.hpp @@ -15,14 +15,13 @@ namespace megu::kernel { class Kernel { public: + Kernel() = delete; Kernel(Window &); ~Kernel(); void step(); - void add(Prop *); - void remove(Prop *); - - inline Identifiable_Map<Prop> & props() {return this->_props;} + void push(Prop &); + void remove(Prop &); inline PhysicEngine & getPhysicEngine() {return this->_pEngine;} inline GraphicEngine & getGraphicEngine() {return this->_gEngine;} diff --git a/source/kernel/front/component/graphic/Sprite.cpp b/source/kernel/front/component/graphic/Sprite.cpp index 4545186dfc24023da15107321bf0e4d7d10ace94..ae6824b89ad81115f90a0ee591859456df2db658 100644 --- a/source/kernel/front/component/graphic/Sprite.cpp +++ b/source/kernel/front/component/graphic/Sprite.cpp @@ -1,13 +1,10 @@ #include "Sprite.hpp" -//this->_sprite.setFrame({0.f, 0.f, 51.f, 98.f}); -//this->_sprite.setSize({50, 100}); - namespace megu::kernel { GraphicLinker<megu::Sprite> Sprite::_Linker = GraphicLinker<megu::Sprite>(); - Sprite::Sprite(const std::filesystem::path & path) - : Sprite(path, {0, 0, 0, 0}) {} + Sprite::Sprite() + : megu::Sprite() {} Sprite::Sprite(const std::filesystem::path & path, const Frame & frame) : megu::Sprite(path, frame), _animation(0), _index(0) { @@ -16,52 +13,52 @@ namespace megu::kernel { } } - const Frame_List & Sprite::getAnimations(size_t name) const { + const Frame_List & Sprite::getCurrentAnimations(size_t name) const { if(this->_frames.contains(name)) { return this->_frames.at(name); } - throw std::runtime_error("Cannot get inexisting animation"); + throw std::runtime_error("Missing animation : " + name); } - const Frame & Sprite::getFrame(size_t name, size_t index) const { - auto & frames = this->getAnimations(name); + const Frame & Sprite::getCurrentFrame(size_t name, size_t index) const { + auto & frames = this->getCurrentAnimations(name); if(frames.size() > index) { return frames.at(index); } - throw std::runtime_error("Cannot get inexisting frame"); + throw std::runtime_error("Missing frame for animation : " + name); } - void Sprite::setAnimation(size_t name) { + void Sprite::setCurrentAnimation(size_t name) { if(this->_frames.contains(name)) { this->_animation = name; this->_previous = 0.0; } else { - throw std::runtime_error("Cannot set inexisting animation"); + throw std::runtime_error("Cannot set inexisting animation : " + name); } } - void Sprite::push(size_t name, const Frame_List & frames) { + void Sprite::pushAnimation(size_t name, const Frame_List & frames) { for(auto & frame : frames) { - this->push(name, frame); + this->pushAnimation(name, frame); } } - void Sprite::push(size_t name, const Frame & frame) { + void Sprite::pushAnimation(size_t name, const Frame & frame) { this->_frames[name].push_back(frame); } - void Sprite::push(size_t name, float x, float y, float w, float h) { + void Sprite::pushAnimation(size_t name, float x, float y, float w, float h) { this->_frames[name].push_back({x, y, w, h}); } - void Sprite::remove(size_t name) { + void Sprite::removeAnimation(size_t name) { if(this->_frames.contains(name)) { this->_frames.erase(name); } } - void Sprite::remove(size_t name, size_t index) { + void Sprite::removeAnimation(size_t name, size_t index) { if(this->_frames.contains(name) && this->_frames[name].size() > index) { this->_frames[name].erase(this->_frames[name].begin() + index); } @@ -83,12 +80,12 @@ namespace megu::kernel { } } - void Sprite::apply(Kernel & kernel, GraphicEngine & engine) { + void Sprite::apply(GraphicEngine & engine) { Sprite::_Linker.link(*this, this->getLayerPriority(), this->getObjectPriority()); Sprite::_Linker.link(engine); } - void Sprite::unapply(Kernel & kernel, GraphicEngine & engine) { + void Sprite::unapply(GraphicEngine & engine) { Sprite::_Linker.unlink(*this); Sprite::_Linker.link(engine); } diff --git a/source/kernel/front/component/graphic/Sprite.hpp b/source/kernel/front/component/graphic/Sprite.hpp index f3e5e57c1ca157b6015c7a3981c6cd53943f707e..6c0c14823cc29ddcbd003bbfeb1f80baed976253 100644 --- a/source/kernel/front/component/graphic/Sprite.hpp +++ b/source/kernel/front/component/graphic/Sprite.hpp @@ -18,27 +18,28 @@ namespace megu::kernel { class Sprite : public Graphical<GraphicEngine>, public megu::Sprite { public: - Sprite(const std::filesystem::path &); - Sprite(const std::filesystem::path &, const Frame &); + Sprite(); + Sprite(const std::filesystem::path &, const Frame & = {0, 0, 0, 0}); + virtual ~Sprite() = default; - inline size_t getCurrentFrameIndex() const {return this->_index;} inline double getDuration() const {return this->_duration;} - inline void setDuration(double d) {this->_duration = d;} + inline size_t getCurrentFrameIndex() const {return this->_index;} + const Frame & getCurrentFrame(size_t, size_t) const; + const Frame_List & getCurrentAnimations(size_t) const; - const Frame_List & getAnimations(size_t) const; - const Frame & getFrame(size_t, size_t) const; + inline void setDuration(double d) {this->_duration = d;} + void setCurrentAnimation(size_t); - void setAnimation(size_t); - void push(size_t, const Frame_List & = {}); - void push(size_t, const Frame &); - void push(size_t, float, float, float, float); + void pushAnimation(size_t, const Frame_List & = {}); + void pushAnimation(size_t, const Frame &); + void pushAnimation(size_t, float, float, float, float); - void remove(size_t); - void remove(size_t, size_t); + void removeAnimation(size_t); + void removeAnimation(size_t, size_t); + void apply(GraphicEngine &) override; + void unapply(GraphicEngine &) override; void update(double) override; - void apply(Kernel &, GraphicEngine &) override; - void unapply(Kernel &, GraphicEngine &) override; static const GraphicLinker<megu::Sprite> & linker() {return Sprite::_Linker;} diff --git a/source/kernel/front/component/graphic/TileMap.cpp b/source/kernel/front/component/graphic/TileMap.cpp index 4e4acd33524d465bbe2e9c68f366306ead4b7803..2f79759e0422fee45ff6c4507253b4eb453133e5 100644 --- a/source/kernel/front/component/graphic/TileMap.cpp +++ b/source/kernel/front/component/graphic/TileMap.cpp @@ -8,34 +8,32 @@ namespace megu::kernel { /*if(lenght % width != 0 && lenght % height != 0) { throw std::runtime_error("Tilemap dimension not matching tiles size."); }*/ - - size_t tileWidth = this->texture().width() / this->_tileSize; - size_t tileHeight = this->texture().height() / this->_tileSize; + size_t tileWidth = this->getTextureWidth() / lenght; + size_t tileHeight = this->getTextureHeight() / lenght; + for(size_t y = 0; y < tileHeight; ++y) { for(size_t x = 0; x < tileWidth; ++x) { - this->_tilesPosition.push_back({x * this->_tileSize, y * this->_tileSize}); + this->_tilesPosition.push_back({x * lenght, y * lenght}); } } size_t i = 0; - for(size_t x = 0; x < width * this->_tileSize; x += this->_tileSize) { + for(size_t x = 0; x < width * lenght; x += lenght) { this->_tilesValue.push_back({}); - for(size_t y = 0; y < height * this->_tileSize; y += this->_tileSize) { + for(size_t y = 0; y < height * lenght; y += lenght) { this->_tilesValue[i].push_back(0); } ++i; } if(!Tilemap::_Linker.haveModule()) { - Tilemap::_Linker.setModule(new TileArray_Module{}); + Tilemap::_Linker.setModule(new TileArray_Module{}); } - - //this->setSize({width * size, height * size}); } void Tilemap::setValue(size_t x, size_t y, size_t value) { - if(this->width() <= x || this->height() <= y) { + if(this->row() <= x || this->collumn() <= y) { throw std::runtime_error("Set Tilemap coords out of range."); } @@ -46,11 +44,11 @@ namespace megu::kernel { TilePosition position = this->_tilesPosition[value]; glm::vec4 uv = {position.x, - this->texture().height() - position.y - this->_tileSize, + this->texture().height() - position.y - this->_tileSize, this->_tileSize, this->_tileSize}; - this->setUv(this->height() - 1 - y, x, uv); + this->setUv(this->collumn() - 1 - y, x, uv); this->_tilesValue[x][y] = value; } @@ -66,8 +64,8 @@ namespace megu::kernel { throw std::runtime_error("Tilemap coords out of bound"); } - void Tilemap::addAnimation(size_t x, size_t y, const std::vector<size_t> & ids) { - if(x < this->width() && y < this->height()) { + void Tilemap::pushAnimation(size_t x, size_t y, const std::vector<size_t> & ids) { + if(x < this->row() && y < this->collumn()) { this->_animations[{x, y}] = std::pair<std::vector<size_t>, size_t>(ids, 0); } } @@ -91,12 +89,12 @@ namespace megu::kernel { } } - void Tilemap::apply(Kernel & kernel, GraphicEngine & engine) { + void Tilemap::apply(GraphicEngine & engine) { Tilemap::_Linker.link(*this, this->getLayerPriority(), this->getObjectPriority()); Tilemap::_Linker.link(engine); } - void Tilemap::unapply(Kernel & kernel, GraphicEngine & engine) { + void Tilemap::unapply(GraphicEngine & engine) { Tilemap::_Linker.unlink(*this); Tilemap::_Linker.link(engine); } diff --git a/source/kernel/front/component/graphic/TileMap.hpp b/source/kernel/front/component/graphic/TileMap.hpp index 648beddcef7e9dda26389c05220a7b0a4a7b5035..d4f72a62ab475896e84af04c4f638fcbd2c39147 100644 --- a/source/kernel/front/component/graphic/TileMap.hpp +++ b/source/kernel/front/component/graphic/TileMap.hpp @@ -16,28 +16,24 @@ namespace megu::kernel { struct TilePosition { size_t x = 0; size_t y = 0; - - bool operator<(const TilePosition & p) const { - if(this->x == p.x) { - return this->y < p.y; - } - return this->y < p.y; - } }; + Tilemap() = delete; Tilemap(const std::filesystem::path &, size_t, size_t, float, size_t, double = 0.1); + virtual ~Tilemap() = default; + inline void setDuration(double duration) {this->_duration = duration;} void setValue(size_t, size_t, size_t); + + inline double getDuration() const {return this->_duration;} size_t getValue(size_t, size_t) const; - void addAnimation(size_t, size_t, const std::vector<size_t> &); + void pushAnimation(size_t, size_t, const std::vector<size_t> &); void removeAnimation(size_t, size_t); - - const std::map<TilePosition, std::pair<std::vector<size_t>, size_t>, reference_sorter<TilePosition>> & animation() const {return this->_animations;} - + + void apply(GraphicEngine &) override; + void unapply(GraphicEngine &) override; void update(double) override; - void apply(Kernel &, GraphicEngine &) override; - void unapply(Kernel &, GraphicEngine &) override; private: std::vector<TilePosition> _tilesPosition; diff --git a/source/kernel/front/component/physic/Fixed.cpp b/source/kernel/front/component/physic/Fixed.cpp index fcaa667a3b39ef888a972800897e79e54edbde1e..df2bfe0c22303cb7693eddfb328c0706a21c5115 100644 --- a/source/kernel/front/component/physic/Fixed.cpp +++ b/source/kernel/front/component/physic/Fixed.cpp @@ -6,23 +6,23 @@ namespace megu::kernel { Fixed::Fixed(float x, float y, float w, float h, CollideLambda cl, UpdateLambda ul) : TangibleStatic(Position(x, y), Dimension(w, h, 0.f)), _collide(cl), _update(ul) {} - void Fixed::update_physic(double time) const { + void Fixed::updatePhysic(double time) const { if(this->_update != nullptr) { this->_update(time); } } - void Fixed::on_collide(Kernel & kernel, PhysicEngine & engine, Identifiable & id, Physical & physical, double time) { + void Fixed::onCollide(Kernel & kernel, PhysicEngine & engine, Identifiable & id, Physical & physical, double time) { if(this->_collide != nullptr) { this->_collide(kernel, engine, id, physical, time); } } - void Fixed::apply(Kernel & kernel, PhysicEngine & engine) { + void Fixed::apply(PhysicEngine & engine) { engine.get().push(this->getLayer(), *this); } - void Fixed::unapply(Kernel & kernel, PhysicEngine & engine) { + void Fixed::unapply(PhysicEngine & engine) { engine.get().remove(*this); } diff --git a/source/kernel/front/component/physic/Fixed.hpp b/source/kernel/front/component/physic/Fixed.hpp index 22fe2dd7c827a3861ecf8ea5148b2543651c5ae9..8edb22e938bf24b55a065eff35ea152a1d2ed1d2 100644 --- a/source/kernel/front/component/physic/Fixed.hpp +++ b/source/kernel/front/component/physic/Fixed.hpp @@ -10,12 +10,14 @@ namespace megu::kernel { class Fixed : public TangibleStatic, public Physical<PhysicEngine> { public: + Fixed() = delete; Fixed(float x, float y, float w, float h, CollideLambda = nullptr, UpdateLambda = nullptr); + virtual ~Fixed() = default; - void update_physic(double) const override; - void on_collide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; - void apply(Kernel & k, PhysicEngine &) override; - void unapply(Kernel & k, PhysicEngine &) override; + void updatePhysic(double) const override; + void onCollide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; + void apply(PhysicEngine &) override; + void unapply(PhysicEngine &) override; void setCollideLambda(CollideLambda); void setUpdateLambda(UpdateLambda); diff --git a/source/kernel/front/component/physic/Movable.cpp b/source/kernel/front/component/physic/Movable.cpp index c9aeaf29dfc3518a0bb51a9f74a82853d0125b55..49e05eb8f1c87bb0a18a1287d723fdc7a9b72ea9 100644 --- a/source/kernel/front/component/physic/Movable.cpp +++ b/source/kernel/front/component/physic/Movable.cpp @@ -4,23 +4,23 @@ namespace megu::kernel { Movable::Movable(float x, float y, float w, float h, CollideLambda cl, UpdateLambda ul) : TangibleMovable(Position(x, y), Dimension(w, h, 0.f)), _collide(cl), _update(ul) {} - void Movable::update_physic(double time) { + void Movable::updatePhysic(double time) { if(this->_update != nullptr) { this->_update(time); } } - void Movable::on_collide(Kernel & kernel, PhysicEngine & engine, Identifiable & id, Physical & physical, double time) { + void Movable::onCollide(Kernel & kernel, PhysicEngine & engine, Identifiable & id, Physical & physical, double time) { if(this->_collide != nullptr) { this->_collide(kernel, engine, id, physical, time); } } - void Movable::apply(Kernel & kernel, PhysicEngine & engine) { + void Movable::apply(PhysicEngine & engine) { engine.get().push(this->getLayer(), *this); } - void Movable::unapply(Kernel & kernel, PhysicEngine & engine) { + void Movable::unapply(PhysicEngine & engine) { engine.get().remove(*this); } diff --git a/source/kernel/front/component/physic/Movable.hpp b/source/kernel/front/component/physic/Movable.hpp index 45cd76036e0e8b49f33322e898cde4c51e0b5061..4ae79c0367c8503d1631a03e4acfdba265ceb328 100644 --- a/source/kernel/front/component/physic/Movable.hpp +++ b/source/kernel/front/component/physic/Movable.hpp @@ -10,12 +10,14 @@ namespace megu::kernel { class Movable : public TangibleMovable, public Physical<PhysicEngine> { public: + Movable() = delete; Movable(float x, float y, float w, float h, CollideLambda = nullptr, UpdateLambda = nullptr); + virtual ~Movable() = default; - void update_physic(double) override; - void on_collide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; - void apply(Kernel & k, PhysicEngine &) override; - void unapply(Kernel & k, PhysicEngine &) override; + void updatePhysic(double) override; + void onCollide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; + void apply(PhysicEngine &) override; + void unapply(PhysicEngine &) override; void setCollideLambda(CollideLambda); void setUpdateLambda(UpdateLambda); diff --git a/source/kernel/front/component/physic/Tile.cpp b/source/kernel/front/component/physic/Tile.cpp index 47e0e34045dcb27c8444ae6e015d58760100e42b..1ef1b88f9cff5acbfa413a8e3efcf23732b7066d 100644 --- a/source/kernel/front/component/physic/Tile.cpp +++ b/source/kernel/front/component/physic/Tile.cpp @@ -1,6 +1,9 @@ #include "Tile.hpp" namespace megu::kernel { + Tile::Tile() + : Fixed(0, 0, 1, 1) {} + Tile::Tile(float x, float y, float d, Priority p) : Fixed(x, y, d, d) { this->setLayer(p); diff --git a/source/kernel/front/component/physic/Tile.hpp b/source/kernel/front/component/physic/Tile.hpp index 3b914c426b5da3ab3a0ef735bdfd2cff6ad19f48..ac13aeaa2d14e718535eac7fd0b3630dbe7804f7 100644 --- a/source/kernel/front/component/physic/Tile.hpp +++ b/source/kernel/front/component/physic/Tile.hpp @@ -5,7 +5,9 @@ namespace megu::kernel { class Tile : public Fixed { public: + Tile(); Tile(float x, float y, float d, Priority p); + virtual ~Tile() = default; bool operator==(const Tile &) const; bool operator>=(const Tile &) const; diff --git a/source/kernel/front/component/physic/TileArray.cpp b/source/kernel/front/component/physic/TileArray.cpp index 7a2e45584642ae2a6b01ba3f13e957a4592b180a..fddf358ccce0387b7a7be856aec1b1341630b30f 100644 --- a/source/kernel/front/component/physic/TileArray.cpp +++ b/source/kernel/front/component/physic/TileArray.cpp @@ -20,7 +20,7 @@ namespace megu::kernel { this->_tiles.insert({position, tile}); } - void TileArray::erase(const Tile & tile) { + void TileArray::remove(const Tile & tile) { for(auto it = this->_tiles.begin(); it != this->_tiles.end();) { if(it->second.get().id() == tile.id()) { it = this->_tiles.erase(it); @@ -31,14 +31,14 @@ namespace megu::kernel { } } - void TileArray::on_collide(Kernel & kernel, PhysicEngine & engine, Identifiable & id, Physical & physical, double time) { + void TileArray::onCollide(Kernel & kernel, PhysicEngine & engine, Identifiable & id, Physical & physical, double time) { if(this->_collide == nullptr) { return; } auto & tangible = engine.get(physical); for(auto & [positon, tile] : this->_tiles) { - SquareBox box = SquareBox(positon, tile.get().getBox().dimension()); + SquareBox box = SquareBox(positon, tile.get().getBox().getDimension()); if(tangible.isColliding(box)) { this->_collide(kernel, engine, id, tile, time); } @@ -47,7 +47,7 @@ namespace megu::kernel { std::optional<SquareBox> TileArray::isColliding(const SquareBox & box) const { for(auto & [positon, tile] : this->_tiles) { - SquareBox tbox = SquareBox(positon, tile.get().getBox().dimension()); + SquareBox tbox = SquareBox(positon, tile.get().getBox().getDimension()); if(box.intersect(tbox)) { return tbox; } @@ -55,17 +55,17 @@ namespace megu::kernel { return {}; } - void TileArray::update_physic(double time) const { + void TileArray::updatePhysic(double time) const { if(this->_update != nullptr) { this->_update(time); } } - void TileArray::apply(Kernel & kernel, PhysicEngine & engine) { + void TileArray::apply(PhysicEngine & engine) { engine.get().push(this->getLayer(), *this); } - void TileArray::unapply(Kernel & kernel, PhysicEngine & engine) { + void TileArray::unapply(PhysicEngine & engine) { engine.get().remove(*this); } diff --git a/source/kernel/front/component/physic/TileArray.hpp b/source/kernel/front/component/physic/TileArray.hpp index 3bd463130ac1b14eac78c4bc000646d11f29accb..2578bd6b1515b01cdacb0e60ceff2fc6b4df89ee 100644 --- a/source/kernel/front/component/physic/TileArray.hpp +++ b/source/kernel/front/component/physic/TileArray.hpp @@ -10,22 +10,24 @@ namespace megu::kernel { class TileArray : public Physical<PhysicEngine>, public TangibleStatic { public: + TileArray() = delete; TileArray(float, float, float, float, CollideLambda = nullptr, UpdateLambda = nullptr); + virtual ~TileArray() = default; std::optional<std::reference_wrapper<const Tile>> at(const Position &) const; void push(const Position &, Tile &); - void erase(const Tile &); + void remove(const Tile &); using TileCollideLambda = std::function<void(Kernel &, PhysicEngine &, Identifiable &, Tile &, double)>; void setCollideLambda(TileCollideLambda); void setUpdateLambda(UpdateLambda); - void update_physic(double) const override; - void apply(Kernel & k, PhysicEngine &) override; - void unapply(Kernel & k, PhysicEngine &) override; - void on_collide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; + void updatePhysic(double) const override; + void apply(PhysicEngine &) override; + void unapply(PhysicEngine &) override; + void onCollide(Kernel &, PhysicEngine &, Identifiable &, Physical &, double) override; virtual std::optional<SquareBox> isColliding(const SquareBox &) const override; diff --git a/source/kernel/front/props/Props.hpp b/source/kernel/front/props/Props.hpp index d86d795c2f1bd9e8649fa8b44b77e87ba7624486..8ab0804e00aaccef081fc66c0103e9f4031c0f3b 100644 --- a/source/kernel/front/props/Props.hpp +++ b/source/kernel/front/props/Props.hpp @@ -9,11 +9,11 @@ #include <kernel/back/engine/GraphicEngine.hpp> namespace megu::kernel { - template <class Pe, class Ge> + template <class P, class G> class BaseProps : virtual public Identifiable { public: - using Graphical_Component = Graphical<Ge>; - using Physical_Component = Physical<Pe>; + using Graphical_Component = Graphical<G>; + using Physical_Component = Physical<P>; virtual Graphical_Component * getGraphicComponent() = 0; virtual Physical_Component * getPhysicComponent() = 0; diff --git a/source/kernel/front/props/PropsDynamic.hpp b/source/kernel/front/props/PropsDynamic.hpp index b86d8155d8b4c8c869104028adccc02712f2c481..8eb06992acc0aa38a384f4212528a3f9a09b4fc2 100644 --- a/source/kernel/front/props/PropsDynamic.hpp +++ b/source/kernel/front/props/PropsDynamic.hpp @@ -7,7 +7,9 @@ namespace megu::kernel { class PropsDynamic : public Prop { public: + PropsDynamic() = delete; PropsDynamic(Sprite &, Movable &); + virtual ~PropsDynamic() = default; inline Prop::Graphical_Component * getGraphicComponent() {return &this->_graphic;} inline Prop::Physical_Component * getPhysicComponent() {return &this->_physic;} diff --git a/source/kernel/front/props/PropsPlayable.hpp b/source/kernel/front/props/PropsPlayable.hpp index 8857cd2f816ddea19f7c21128900e105bdce4a85..e0a811be1f2c949c94063ec65ee2ffabed385ba2 100644 --- a/source/kernel/front/props/PropsPlayable.hpp +++ b/source/kernel/front/props/PropsPlayable.hpp @@ -13,13 +13,15 @@ namespace megu { namespace megu::kernel { class PropsPlayable : public Prop { public: + PropsPlayable() = delete; PropsPlayable(Sprite &, Movable &); + virtual ~PropsPlayable() = default; void setControl(Window &, Keyboard *); void setControl(Window &, Mouse *); - virtual Graphical_Component * getGraphicComponent() {return &this->_graphic;} - virtual Physical_Component * getPhysicComponent() {return &this->_physic;} + virtual Prop::Graphical_Component * getGraphicComponent() {return &this->_graphic;} + virtual Prop::Physical_Component * getPhysicComponent() {return &this->_physic;} private: Sprite & _graphic; diff --git a/source/kernel/front/props/PropsStatic.hpp b/source/kernel/front/props/PropsStatic.hpp index 3210fcdfbe1b7f60b055768fc91eddaa5c0ac5d5..b65b8e819a19f7b741afa770ac843dff596242d6 100644 --- a/source/kernel/front/props/PropsStatic.hpp +++ b/source/kernel/front/props/PropsStatic.hpp @@ -7,7 +7,9 @@ namespace megu::kernel { class PropsStatic : public Prop { public: + PropsStatic() = delete; PropsStatic(Sprite &, Fixed &); + virtual ~PropsStatic() = default; inline Prop::Graphical_Component * getGraphicComponent() override {return &this->_graphic;} inline Prop::Physical_Component * getPhysicComponent() override {return &this->_physic;} diff --git a/source/kernel/front/props/PropsTileMap.hpp b/source/kernel/front/props/PropsTileMap.hpp index 993e9b52d90dcba507bae111ea76f52044c8c2f0..bc8408b4bb71edd4f90211d142bd6663dc7c6eba 100644 --- a/source/kernel/front/props/PropsTileMap.hpp +++ b/source/kernel/front/props/PropsTileMap.hpp @@ -7,7 +7,9 @@ namespace megu::kernel { class PropsTileMap : public Prop { public: + PropsTileMap() = delete; PropsTileMap(Tilemap &, TileArray &); + virtual ~PropsTileMap() = default; inline Prop::Graphical_Component * getGraphicComponent() override {return &this->_graphic;} inline Prop::Physical_Component * getPhysicComponent() override {return &this->_physic;} diff --git a/source/kernel/front/resolver/PhysicResolver.cpp b/source/kernel/front/resolver/PhysicResolver.cpp index 593ab0a4a79b07dfa8325531ea3a79875d604d4b..0eeb855c02144e12ab36a6d529c40beef1868e28 100644 --- a/source/kernel/front/resolver/PhysicResolver.cpp +++ b/source/kernel/front/resolver/PhysicResolver.cpp @@ -11,7 +11,7 @@ namespace megu::kernel { auto target_comp = this->get(collision.target()); if(source_comp.has_value() && target_comp.has_value()) { - source_comp.value().get().on_collide(kernel, engine, *kernel.get(target_comp.value()), target_comp.value(), time); + source_comp.value().get().onCollide(kernel, engine, *kernel.get(target_comp.value()), target_comp.value(), time); } } diff --git a/source/kernel/front/resolver/Resolver.hpp b/source/kernel/front/resolver/Resolver.hpp index 40ac2935c7e3a5b0e56ab9690e281babf9edcb0e..8b73424271e6366f325cd2433735eb71d68a40da 100644 --- a/source/kernel/front/resolver/Resolver.hpp +++ b/source/kernel/front/resolver/Resolver.hpp @@ -11,7 +11,7 @@ namespace megu::kernel { public: inline ref_set<O> & components() {return this->_components;} - void add(O &); + void push(O &); void remove(const Identifiable &); std::optional<std::reference_wrapper<O>> get(const Identifiable &); diff --git a/source/kernel/front/resolver/Resolver.tpp b/source/kernel/front/resolver/Resolver.tpp index 89f265d4c5c7e144d4df10ca53e45dd2cc1a0e18..36e80dad72ddcfdca2c1de7d43ba84fe1e572969 100644 --- a/source/kernel/front/resolver/Resolver.tpp +++ b/source/kernel/front/resolver/Resolver.tpp @@ -2,7 +2,7 @@ namespace megu::kernel { template <class E, class O> - void Resolver<E, O>::add(O & c) { + void Resolver<E, O>::push(O & c) { this->_components.insert(c); }