Skip to content
Snippets Groups Projects
Commit 6e6dd041 authored by BATON Theau's avatar BATON Theau
Browse files

Remake Linkers

parent 2a0fa130
Branches
No related tags found
No related merge requests found
Showing
with 258 additions and 60 deletions
...@@ -59,21 +59,17 @@ set_property(TARGET ${CURRENT_TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY $<1:${CM ...@@ -59,21 +59,17 @@ set_property(TARGET ${CURRENT_TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY $<1:${CM
target_include_directories(${CURRENT_TARGET} PRIVATE ${INCLUDE}) target_include_directories(${CURRENT_TARGET} PRIVATE ${INCLUDE})
#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glew_x64-linux") list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glew_x64-linux")
#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glm_x64-linux") list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/glm_x64-linux")
#list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/imgui_x64-linux") list(APPEND CMAKE_PREFIX_PATH "/amuhome/b20017738/Bureau/vcpkg/packages/imgui_x64-linux")
list(APPEND CMAKE_PREFIX_PATH "C:/vcpkg/packages/freetype_x64-windows")
find_package(glfw3 REQUIRED) find_package(glfw3 REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
find_package(glm CONFIG REQUIRED) find_package(glm CONFIG REQUIRED)
find_package(imgui REQUIRED) find_package(imgui REQUIRED)
find_package(Freetype REQUIRED)
target_link_libraries(${CURRENT_TARGET} PRIVATE glfw) target_link_libraries(${CURRENT_TARGET} PRIVATE glfw)
target_link_libraries(${CURRENT_TARGET} PRIVATE GLEW::GLEW) target_link_libraries(${CURRENT_TARGET} PRIVATE GLEW::GLEW)
target_link_libraries(${CURRENT_TARGET} PRIVATE glm::glm-header-only) target_link_libraries(${CURRENT_TARGET} PRIVATE glm::glm-header-only)
target_link_libraries(${CURRENT_TARGET} PRIVATE imgui::imgui) target_link_libraries(${CURRENT_TARGET} PRIVATE imgui::imgui)
target_link_libraries(${CURRENT_TARGET} PRIVATE Freetype::Freetype)
...@@ -24,6 +24,15 @@ namespace megu { ...@@ -24,6 +24,15 @@ namespace megu {
} }
} }
void GraphicEngine::remove(const Identifiable & identifiable) {
for(auto & [priority, layer] : this->_layers) {
auto r = layer.get()->get(identifiable);
if(r.has_value()) {
layer.get()->remove(identifiable);
}
}
}
std::optional<std::reference_wrapper<const Layer>> GraphicEngine::get(Priority priority) const { std::optional<std::reference_wrapper<const Layer>> GraphicEngine::get(Priority priority) const {
const auto it = this->_layers.find(priority); const auto it = this->_layers.find(priority);
if(it != this->_layers.end()) { if(it != this->_layers.end()) {
......
...@@ -19,8 +19,8 @@ namespace megu { ...@@ -19,8 +19,8 @@ namespace megu {
void push(Priority, Renderer &); void push(Priority, Renderer &);
template <class T> template <class T>
void push(Priority layer_priority, Priority object_priority, T & object, Module<T> * modul) { size_t push(Priority layer_priority, Priority object_priority, T & object, Module<T> * modul) {
this->_layers[layer_priority].get()->push<T>(object_priority, object, modul); return this->_layers[layer_priority].get()->push<T>(object_priority, object, modul);
} }
/*void push(Priority layer_priority, Priority object_priority, Renderable & renderable) { /*void push(Priority layer_priority, Priority object_priority, Renderable & renderable) {
...@@ -28,6 +28,7 @@ namespace megu { ...@@ -28,6 +28,7 @@ namespace megu {
}*/ }*/
void remove(Priority); void remove(Priority);
void remove(const Identifiable &);
std::optional<std::reference_wrapper<const Layer>> get(Priority) const; std::optional<std::reference_wrapper<const Layer>> get(Priority) const;
std::optional<std::reference_wrapper<const Renderable>> get(const Identifiable &) const; std::optional<std::reference_wrapper<const Renderable>> get(const Identifiable &) const;
......
...@@ -26,16 +26,23 @@ namespace megu { ...@@ -26,16 +26,23 @@ namespace megu {
inline const Renderer & renderer() const {return this->_renderer;} inline const Renderer & renderer() const {return this->_renderer;}
template <class T> template <class T>
void push(Priority priority, T & object, Module<T> * modul) { size_t push(Priority priority, T & object, Module<T> * modul) {
if(this->_objects.contains(priority)) {
if(!this->_objects.contains(priority)) {
this->_objects.erase(priority); this->_objects.erase(priority);
} }
this->_objects.insert({priority, Renderable{ object, modul }}); this->_objects.insert({priority, Renderable{ object, modul }});
return this->_objects.at(priority).id();
} }
/*void push(Priority priority, Renderable & renderable) { void remove(const Identifiable & identifiable) {
this->_objects[priority] = renderable; for(auto & [priority, renderable] : this->_objects) {
}*/ if(renderable.id() == identifiable.id()) {
this->_objects.erase(priority);
break;
}
}
}
std::optional<std::reference_wrapper<const Renderable>> get(const Identifiable & id) const { std::optional<std::reference_wrapper<const Renderable>> get(const Identifiable & id) const {
for(const auto & [priority, object] : this->_objects) { for(const auto & [priority, object] : this->_objects) {
...@@ -43,6 +50,7 @@ namespace megu { ...@@ -43,6 +50,7 @@ namespace megu {
return object; return object;
} }
} }
return {};
} }
const Texture & draw(const Window & w, const TextureArray & a) { const Texture & draw(const Window & w, const TextureArray & a) {
......
#include "Text.hpp" #include "Text.hpp"
#include <exception> #include <exception>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <iostream> #include <iostream>
namespace megu { namespace megu {
......
...@@ -19,6 +19,26 @@ namespace megu { ...@@ -19,6 +19,26 @@ namespace megu {
} }
} }
void PhysicEngine::remove(TangibleStatic & t) {
for(auto & [p, objs] : this->_statics) {
auto it = std::find(objs.begin(), objs.end(), t);
if(it != objs.end()) {
objs.erase(it);
break;
}
}
}
void PhysicEngine::remove(TangibleMovable & t) {
for(auto & [p, objs] : this->_dynamic) {
auto it = std::find(objs.begin(), objs.end(), t);
if(it != objs.end()) {
objs.erase(it);
break;
}
}
}
void PhysicEngine::step(double time) { void PhysicEngine::step(double time) {
this->_collisions.clear(); this->_collisions.clear();
for(const auto & [priority, layer] : this->_dynamic) { for(const auto & [priority, layer] : this->_dynamic) {
......
...@@ -22,6 +22,9 @@ namespace megu { ...@@ -22,6 +22,9 @@ namespace megu {
void push(Priority, TangibleStatic &); void push(Priority, TangibleStatic &);
void push(Priority, TangibleMovable &); void push(Priority, TangibleMovable &);
void remove(TangibleStatic &);
void remove(TangibleMovable &);
void step(double); void step(double);
void step(double, Priority); void step(double, Priority);
......
...@@ -15,7 +15,7 @@ namespace megu { ...@@ -15,7 +15,7 @@ namespace megu {
return this->_box == entity._box; return this->_box == entity._box;
} }
bool Tangible::operator!=(const Tangible & entity) const { /*bool Tangible::operator!=(const Tangible & entity) const {
return !(*this == entity); return !(*this == entity);
} }*/
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ namespace megu { ...@@ -27,7 +27,7 @@ namespace megu {
bool isColliding(const Tangible &) const; bool isColliding(const Tangible &) const;
bool operator==(const Tangible &) const; bool operator==(const Tangible &) const;
bool operator!=(const Tangible &) const; //bool operator!=(const Tangible &) const;
using UpdateLambda = std::function<void(double)>; using UpdateLambda = std::function<void(double)>;
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
#include <kernel/front/Kernel.hpp> #include <kernel/front/Kernel.hpp>
#include <engine/io/Window.hpp>
#include <game/utility/FrameCouter.hpp>
#include <game/back/object/Player.hpp>
#include <game/back/object/Enemy.hpp>
#include <game/object/Test.hpp> #include <game/object/Test.hpp>
#include <game/utility/FrameCouter.hpp>
namespace megu::game { namespace megu::game {
Game::Game(const std::string & title) Game::Game(const std::string & title)
: _title(title) { : _title(title) {
...@@ -22,13 +24,29 @@ namespace megu::game { ...@@ -22,13 +24,29 @@ namespace megu::game {
kernel::Kernel kernel(window); kernel::Kernel kernel(window);
auto path = std::filesystem::path("assets/textures/Neera.png"); auto path = std::filesystem::path("assets/textures/Neera.png");
megu::game::Object object(path); megu::game::Object object(path);
kernel.add(&object); //kernel.add(&object);
Player player(16, 16, 16, 16, path);
Enemy enemy(64, 64, 16, 16, path);
player.setup(kernel);
enemy.setup(kernel);
std::cout << "..." << std::endl;
player.apply(kernel);
enemy.apply(kernel);
//kernel.remove(&object);
while(window.isOpen()) { while(window.isOpen()) {
counter.count(Window::Time()); counter.count(Window::Time());
window.pollEvents(); window.pollEvents();
kernel.step(); kernel.step();
} }
player.destroy(kernel);
enemy.destroy(kernel);
} }
catch(std::exception & error) { catch(std::exception & error) {
std::cerr << "[Error] : " << error.what() << std::endl; std::cerr << "[Error] : " << error.what() << std::endl;
......
#pragma once #pragma once
#include <kernel/front/Kernel.hpp>
namespace megu::game { namespace megu::game {
class GameObject { class GameObject {
public: public:
virtual void setup() = 0; virtual void setup(kernel::Kernel &) = 0;
virtual void destroy() = 0; virtual void destroy(kernel::Kernel &) = 0;
virtual void apply(kernel::Kernel &) = 0;
}; };
} }
\ No newline at end of file
#pragma once
#include <game/back/GameObject.hpp>
namespace megu::game {
class Message;
class Collider : public GameObject {
public:
Collider<>
virtual void setup();
virtual void on(Message &);
virtual Message make()
};
}
\ No newline at end of file
#include "Enemy.hpp"
#include <kernel/front/Kernel.hpp>
namespace megu::game {
Enemy::Enemy(float x, float y, float w, float h, std::filesystem::path & path)
: kernel::PropsDynamic(this->_sprite, this->_movable), _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);
}
void Enemy::setup(kernel::Kernel &) {
this->_sprite.setFrame({0.f, 0.f, 51.f, 98.f});
this->_sprite.setSize({51.f, 98.f});
this->_movable.setCollideLambda([this](kernel::Kernel & kernel, const kernel::PhysicEngine &, const megu::kernel::Physical<kernel::PhysicEngine> &, double) {
std::cout << "Enemy Collide !" << std::endl;
kernel.remove(this);
});
}
void Enemy::destroy(kernel::Kernel &) {
}
void Enemy::apply(kernel::Kernel & kernel) {
kernel.add(this);
}
}
\ No newline at end of file
#pragma once
#include <game/back/GameObject.hpp>
#include <kernel/front/props/PropsDynamic.hpp>
namespace megu::game {
class Enemy : public kernel::PropsDynamic, public GameObject {
public:
Enemy(float, float, float, float, std::filesystem::path &);
void move(float, float);
void setup(kernel::Kernel &) override;
void destroy(kernel::Kernel &) override;
void apply(kernel::Kernel &) override;
private:
kernel::Sprite _sprite;
kernel::Movable _movable;
};
}
\ No newline at end of file
#include "Level.hpp"
namespace megu::game {
Level::Level(const std::string & name)
: _name(name) {}
void Level::apply(kernel::Kernel & kernel) {
for(auto & [id, prop] : this->_objecs) {
kernel.add(prop);
}
}
void Level::destroy(kernel::Kernel & kernel) {
for(auto & [id, prop] : this->_objecs) {
kernel.remove(prop);
}
}
}
\ No newline at end of file
#pragma once
#include <game/back/GameObject.hpp>
#include <kernel/front/props/Props.hpp>
namespace megu::game {
class Level : public GameObject {
private:
Level(const std::string &);
inline const std::string & name() const {return this->_name;}
virtual void apply(kernel::Kernel &) override final;
virtual void destroy(kernel::Kernel &) override final;
public:
std::string _name;
std::map<size_t, kernel::Prop *> _objecs;
};
}
\ No newline at end of file
#include "Player.hpp"
#include <game/front/profile/PlayerKeys.hpp>
namespace megu::game {
Player::Player(float x, float y, float w, float h, std::filesystem::path & path)
: kernel::PropsPlayable(this->_sprite, this->_movable), _sprite(path), _movable(x, y, w, h) {
this->_sprite.setPosition({x, y});
}
void Player::move(float x, float y) {
this->_sprite.move({x, y});
this->_movable.move(x, y);
}
void Player::setup(kernel::Kernel & kernel) {
this->setControl(kernel.window(), new PlayerKeyProfile(*this));
this->_sprite.setFrame({0.f, 0.f, 51.f, 98.f});
this->_sprite.setSize({51.f, 98.f});
this->_movable.setCollideLambda([](kernel::Kernel &, const kernel::PhysicEngine &, const megu::kernel::Physical<kernel::PhysicEngine> &, double) {
std::cout << "Player Collide !" << std::endl;
});
}
void Player::destroy(kernel::Kernel &) {
}
void Player::apply(kernel::Kernel & kernel) {
kernel.add(this);
}
}
\ No newline at end of file
#pragma once
#include <kernel/front/props/PropsPlayable.hpp>
#include <game/back/GameObject.hpp>
namespace megu::game {
class Player : public kernel::PropsPlayable, public GameObject {
public:
Player(float x, float y, float w, float h, std::filesystem::path &);
void move(float, float);
void setup(kernel::Kernel &) override;
void destroy(kernel::Kernel &) override;
void apply(kernel::Kernel &) override;
private:
kernel::Sprite _sprite;
kernel::Movable _movable;
};
}
\ No newline at end of file
#pragma once
#include <kernel/front/props/PropsTileMap.hpp>
namespace megu::game {
class Terrain : public kernel::PropsTileMap {
public:
Terrain(float, float);
private:
kernel::Tilemap _graphicMap;
kernel::FixedArray _solidMap;
};
}
\ No newline at end of file
#include "PlayerKeys.hpp"
namespace megu::game {
PlayerKeyProfile::PlayerKeyProfile(Player & player)
: _player(player) {}
void PlayerKeyProfile::on(Key key, int code, Action action, Mod mode) {
if(key == Keyboard::Key::ARROW_UP) {
this->_player.move(0.f, 1.f);
}
if(key == Keyboard::Key::ARROW_DOWN) {
this->_player.move(0.f, -1.f);
}
if(key == Keyboard::Key::ARROW_LEFT) {
this->_player.move(-1.f, 0.f);
}
if(key == Keyboard::Key::ARROW_RIGHT) {
this->_player.move(1.f, 0.f);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment