Compare commits
1 commit
master
...
feature-de
Author | SHA1 | Date | |
---|---|---|---|
075cb5977e |
2 changed files with 38 additions and 0 deletions
14
src/game/depth_renderer.cpp
Normal file
14
src/game/depth_renderer.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "depth_renderer.hpp"
|
||||||
|
|
||||||
|
void DepthRenderer::addGameObject(const std::shared_ptr<GameObject>& gameObject)
|
||||||
|
{
|
||||||
|
// TODO: Subscribe to depth changes!
|
||||||
|
gameObjects.insert(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DepthRenderer::render(const std::shared_ptr<sf::RenderWindow> &window) const
|
||||||
|
{
|
||||||
|
for (const auto& gameObject : gameObjects) {
|
||||||
|
gameObject->draw(window.get());
|
||||||
|
}
|
||||||
|
}
|
24
src/game/depth_renderer.hpp
Normal file
24
src/game/depth_renderer.hpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef HOLESOME_DEPTH_RENDERER_HPP
|
||||||
|
#define HOLESOME_DEPTH_RENDERER_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include "game_object.h"
|
||||||
|
|
||||||
|
auto compareGameObjectDepth = [](const std::shared_ptr<GameObject>& a, const std::shared_ptr<GameObject>& b) { return a->coordinates->isometric().depth < b->coordinates->isometric().depth; };
|
||||||
|
|
||||||
|
class DepthRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DepthRenderer() = default;
|
||||||
|
|
||||||
|
void addGameObject(const std::shared_ptr<GameObject>& gameObject);
|
||||||
|
|
||||||
|
void render(const std::shared_ptr<sf::RenderWindow>& window) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::multiset<std::shared_ptr<GameObject>, decltype(compareGameObjectDepth)> gameObjects;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //HOLESOME_DEPTH_RENDERER_HPP
|
Loading…
Reference in a new issue