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

Remake Linkers

parent 2a0fa130
No related branches found
No related tags found
No related merge requests found
......@@ -13,17 +13,15 @@ namespace megu::kernel {
Fixed(float x, float y, float w, float h);
void update_physic(double) const override;
void on_collide(const Kernel &, const PhysicEngine &, Physical &, double) override;
void on_collide(Kernel &, const PhysicEngine &, Physical &, double) override;
void apply(Kernel & k, PhysicEngine &) override;
void unapply(Kernel & k, PhysicEngine &) override;
void setCollideLambda(const CollideLambda &);
void setUpdateLambda(const UpdateLambda &);
void setCollideLambda(CollideLambda);
void setUpdateLambda(UpdateLambda);
private:
CollideLambda _collide;
UpdateLambda _update;
};
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ namespace megu::kernel {
this->_tangibles.erase(position);
}
void FixedArray::on_collide(const Kernel & kernel, const PhysicEngine & engine, Physical & physical, double time) {
void FixedArray::on_collide(Kernel & kernel, const PhysicEngine & engine, Physical & physical, double time) {
auto & tangible = engine.get(physical);
for(auto & [position, fixed] : this->_tangibles) {
if(fixed.isColliding(tangible)) {
......@@ -40,4 +40,16 @@ namespace megu::kernel {
void FixedArray::apply(Kernel & kernel, PhysicEngine & engine) {
engine.get().push(0, *this);
}
void FixedArray::unapply(Kernel & kernel, PhysicEngine & engine) {
engine.get().remove(*this);
}
void FixedArray::setCollideLambda(CollideLambda lambda) {
this->_collide = lambda;
}
void FixedArray::setUpdateLambda(UpdateLambda lambda) {
this->_update = lambda;
}
}
\ No newline at end of file
......@@ -16,12 +16,13 @@ namespace megu::kernel {
void erase(const Fixed &);
void erase(const Position &);
void setCollideLambda(CollideLambda &);
void setUpdateLambda(UpdateLambda &);
void setCollideLambda(CollideLambda);
void setUpdateLambda(UpdateLambda);
void update_physic(double) const override;
void on_collide(const Kernel &, const PhysicEngine &, Physical &, double) override;
void on_collide(Kernel &, const PhysicEngine &, Physical &, double) override;
void apply(Kernel & k, PhysicEngine &) override;
void unapply(Kernel & k, PhysicEngine &) override;
private:
std::map<Position, Fixed> _tangibles;
......
......@@ -10,21 +10,25 @@ namespace megu::kernel {
}
}
void Movable::on_collide(const Kernel & kernel, const PhysicEngine & engine, Physical & physical, double time) {
void Movable::on_collide(Kernel & kernel, const PhysicEngine & engine, Physical & physical, double time) {
if(this->_collide != nullptr) {
this->_collide(kernel, engine, physical, time);
}
}
void Movable::apply(Kernel & kernel, PhysicEngine & engine) {
engine.add(kernel, *this);
engine.get().push(0, *this);
}
void Movable::setCollideLambda(CollideLambda & lambda) {
void Movable::unapply(Kernel & kernel, PhysicEngine & engine) {
engine.get().remove(*this);
}
void Movable::setCollideLambda(CollideLambda lambda) {
this->_collide = lambda;
}
void Movable::setUpdateLambda(UpdateLambda & lambda) {
void Movable::setUpdateLambda(UpdateLambda lambda) {
this->_update = lambda;
}
}
\ No newline at end of file
......@@ -13,11 +13,12 @@ namespace megu::kernel {
Movable(float x, float y, float w, float h);
void update_physic(double) override;
void on_collide(const Kernel &, const PhysicEngine &, Physical &, double) override;
void on_collide(Kernel &, const PhysicEngine &, Physical &, double) override;
void apply(Kernel & k, PhysicEngine &) override;
void unapply(Kernel & k, PhysicEngine &) override;
void setCollideLambda(CollideLambda &);
void setUpdateLambda(UpdateLambda &);
void setCollideLambda(CollideLambda);
void setUpdateLambda(UpdateLambda);
private:
CollideLambda _collide;
......
#include "PropsPlayable.hpp"
#include <engine/io/Window.hpp>
namespace megu::kernel {
PropsPlayable::PropsPlayable(Sprite & graphic, Movable & physic)
: _graphic(graphic), _physic(physic) {}
void PropsPlayable::setControl(Window & window, Keyboard * keyboard) {
this->_profiler.set(keyboard);
this->_profiler.link(window);
}
void PropsPlayable::setControl(Window & window, Mouse * mouse) {
this->_profiler.set(mouse);
this->_profiler.link(window);
}
}
\ No newline at end of file
#pragma once
#include <kernel/front/props/Props.hpp>
#include <kernel/front/component/graphic/Sprite.hpp>
#include <kernel/front/component/physic/Movable.hpp>
#include <engine/io/Profiler.hpp>
namespace megu {
class Window;
}
namespace megu::kernel {
class PropsPlayable : public Prop {
public:
PropsPlayable(Sprite &, Movable &);
void setControl(Window &, Keyboard *);
void setControl(Window &, Mouse *);
virtual Graphical_Component * getGraphicComponent() {return &this->_graphic;}
virtual Physical_Component * getPhysicComponent() {return &this->_physic;}
private:
Sprite & _graphic;
Movable & _physic;
Profiler _profiler;
};
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ namespace megu::kernel {
inline ref_set<O> & components() {return this->_components;}
void add(O &);
void erase(const Identifiable &);
void remove(const Identifiable &);
std::optional<std::reference_wrapper<O>> get(const Identifiable &);
virtual void resolve(Kernel &, E &, double) = 0;
......
......@@ -7,8 +7,9 @@ namespace megu::kernel {
}
template <class E, class O>
void Resolver<E, O>::erase(const Identifiable & c) {
this->_components.erase(c);
void Resolver<E, O>::remove(const Identifiable & c) {
auto it = std::find(this->_components.begin(), this->_components.end(), c);
this->_components.erase(it);
}
template <class E, class O>
......
......@@ -10,51 +10,3 @@ int main(int argc, const char * argv[]) {
std::cout << "Running..." << std::endl;
return game.run();
}
\ No newline at end of file
/*int main(int argc, const char * argv[]) {
std::cout << "Program Init" << std::endl;
try {
megu::Window window;
window.open("Kernel Test", WINDOW_WIDTH, WINDOW_HEIGHT);
std::cout << "Window Init" << std::endl;
megu::kernel::Kernel kernel(window);
std::cout << "Kernel Init" << std::endl;
auto path = std::filesystem::path("assets/textures/Neera.png");
megu::game::Object object(path);
megu::game::Object object2(path);
object2.tmp_setPos(100, 0);
std::cout << "Object Init" << std::endl;
kernel.add(&object2);
kernel.add(&object);
double previousTime = megu::Window::Time();
int frameCount = 0;
std::cout << "Render Loop Init" << std::endl;
while(window.isOpen()) {
double currentTime = megu::Window::Time();
frameCount++;
if(currentTime - previousTime >= 1.0) {
window.setTitle(std::to_string(frameCount));
frameCount = 0;
previousTime = currentTime;
}
window.pollEvents();
kernel.step();
}
std::cout << "Render Loop End" << std::endl;
}
catch(std::exception & error) {
std::cerr << error.what() << std::endl;
}
std::cout << "Program End" << std::endl;
return EXIT_SUCCESS;
}*/
\ No newline at end of file
......@@ -20,9 +20,9 @@ namespace megu {
return this->_id == identifiable._id;
}
bool Identifiable::operator!=(const Identifiable & identifiable) const {
/*bool Identifiable::operator!=(const Identifiable & identifiable) const {
return !(*this == identifiable);
}
}*/
bool Identifiable::operator<=(const Identifiable & identifiable) const {
return this->_id <= identifiable._id;
......
......@@ -15,7 +15,7 @@ namespace megu {
inline void setId(size_t id) {this->_id = id;}
bool operator==(const Identifiable &) const;
bool operator!=(const Identifiable &) const;
//bool operator!=(const Identifiable &) const;
bool operator>=(const Identifiable &) const;
bool operator<=(const Identifiable &) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment