Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Nov 16, 2024
1 parent 8228e6b commit ca5959a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
3 changes: 0 additions & 3 deletions src/debugger.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions src/debugger.hpp

This file was deleted.

11 changes: 11 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "resourcemanager.hpp"
#include "statemanager.hpp"
#include "window.hpp"
#include "world.hpp"

using namespace framework;

Expand Down Expand Up @@ -49,6 +50,14 @@ std::shared_ptr<input::eventmanager> engine::eventmanager() const {
return _eventmanager;
}

void engine::set_world(std::shared_ptr<framework::world> world) {
_world = std::move(world);
}

std::shared_ptr<framework::world> engine::world() const {

Check warning on line 57 in src/engine.cpp

View workflow job for this annotation

GitHub Actions / lint

src/engine.cpp:57:43 [modernize-use-trailing-return-type]

use a trailing return type for this function
return _world;
}

void engine::set_entitymanager(std::shared_ptr<framework::entitymanager> entitymanager) {
_entitymanager = std::move(entitymanager);
}
Expand Down Expand Up @@ -152,6 +161,7 @@ void engine::_loop() {
_resourcemanager->update(delta);
_scenemanager->update(delta);
_eventmanager->update(delta);
_world->update(delta);
_entitymanager->update(delta);

for (auto &loopable : _loopables) {
Expand All @@ -161,6 +171,7 @@ void engine::_loop() {
_renderer->begin();
_scenemanager->draw();
_entitymanager->draw();
_world->draw();
_renderer->end();
}

Expand Down
4 changes: 4 additions & 0 deletions src/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class engine : public input::eventreceiver {
void set_audiodevice(std::shared_ptr<audio::audiodevice> audiodevice);
std::shared_ptr<audio::audiodevice> audiodevice() const;

void set_world(std::shared_ptr<framework::world> world);
std::shared_ptr<framework::world> world() const;

void set_entitymanager(std::shared_ptr<framework::entitymanager> entitymanager);
std::shared_ptr<framework::entitymanager> entitymanager() const;

Expand Down Expand Up @@ -67,6 +70,7 @@ class engine : public input::eventreceiver {
std::shared_ptr<graphics::renderer> _renderer;
std::shared_ptr<audio::audiodevice> _audiodevice;
std::shared_ptr<input::eventmanager> _eventmanager;
std::shared_ptr<framework::world> _world;
std::shared_ptr<framework::entitymanager> _entitymanager;
std::shared_ptr<framework::resourcemanager> _resourcemanager;
std::shared_ptr<framework::statemanager> _statemanager;
Expand Down
1 change: 1 addition & 0 deletions src/enginefactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ std::shared_ptr<engine> enginefactory::create() {
engine->set_renderer(std::move(renderer));
engine->set_audiodevice(std::move(audiodevice));
engine->set_eventmanager(std::move(eventmanager));
engine->set_world(std::move(world));
engine->set_entitymanager(std::move(entitymanager));
engine->set_statemanager(std::move(statemanager));
engine->set_resourcemanager(std::move(resourcemanager));
Expand Down
4 changes: 0 additions & 4 deletions src/entitymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ std::shared_ptr<entity> entitymanager::find(uint64_t id) const noexcept {
void entitymanager::update(float_t delta) {
UNUSED(delta);

cpSpaceStep(_world->space().get(), 1.0 / 60.0);

for (const auto &entity : _entities) {
entity->update();
}
Expand All @@ -133,8 +131,6 @@ void entitymanager::draw() noexcept {
for (const auto &entity : _entities) {
entity->draw();
}

_world->draw();
}

void entitymanager::on_mail(const input::mailevent &event) noexcept {
Expand Down
7 changes: 6 additions & 1 deletion src/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ space_ptr world::space() const noexcept {
return _space;
}

void world::update(float_t delta) const noexcept {
UNUSED(delta);

cpSpaceStep(_space.get(), 1.0 / 60.0);
}

void world::draw() noexcept {
auto drawShape = [&](cpShape *shape) {
const cpBody *body = cpShapeGetBody(shape);
const cpVect position = cpBodyGetPosition(body);

int count = cpPolyShapeGetCount(shape);
std::vector<cpVect> vertices(count);

std::generate(vertices.begin(), vertices.end(), [&, i = 0]() mutable {
return cpPolyShapeGetVert(shape, i++);
});
Expand Down
2 changes: 2 additions & 0 deletions src/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class world {

space_ptr space() const noexcept;

void update(float_t delta) const noexcept;

void draw() noexcept;

private:
Expand Down

0 comments on commit ca5959a

Please sign in to comment.