2020-11-21 20:57:40 +01:00
|
|
|
#ifndef SDLPP_HPP_SCENE
|
|
|
|
|
#define SDLPP_HPP_SCENE
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
|
|
#include "sdlpp_common.hpp"
|
|
|
|
|
#include "sdlpp_renderer.hpp"
|
|
|
|
|
#include "sdlpp_renderobject.hpp"
|
|
|
|
|
|
|
|
|
|
namespace SDLPP {
|
2020-11-22 23:37:55 +01:00
|
|
|
class SDLPPSCOPE Scene {
|
2020-11-21 20:57:40 +01:00
|
|
|
public:
|
|
|
|
|
Scene( std::shared_ptr< Renderer > &r );
|
|
|
|
|
void addObject( const std::shared_ptr< RenderObject > &obj );
|
|
|
|
|
void setZIndex( const std::shared_ptr< RenderObject > &obj, int index );
|
|
|
|
|
void moveDownZ( const std::shared_ptr< RenderObject > &obj );
|
|
|
|
|
void moveUpZ( const std::shared_ptr< RenderObject > &obj );
|
|
|
|
|
void moveZ( const std::shared_ptr< RenderObject > &obj, int addition );
|
|
|
|
|
// TODO addCollision
|
|
|
|
|
std::shared_ptr< RenderObject > getObject( int index );
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > > getObjects();
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > >
|
|
|
|
|
getObjects( const std::unordered_set< int > &objectIDs );
|
|
|
|
|
void movement();
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > >
|
|
|
|
|
getCollisions( RenderObject &r );
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > >
|
|
|
|
|
getCollisions( RenderObject &r,
|
|
|
|
|
const std::unordered_set< int > &objectIDs );
|
|
|
|
|
void renderScene( bool clear_renderer = true );
|
|
|
|
|
void presentScene();
|
|
|
|
|
void setBackground( std::shared_ptr< Texture > bg );
|
|
|
|
|
void setBackground( const std::string &img_path );
|
|
|
|
|
void updateSizeAndPosition();
|
|
|
|
|
void moveEverything( double x, double y );
|
|
|
|
|
const std::shared_ptr< RenderObject > &leftmost();
|
|
|
|
|
const std::shared_ptr< RenderObject > &rightmost();
|
|
|
|
|
std::pair< int, int > getDimensions() const;
|
|
|
|
|
int getWidth() const;
|
|
|
|
|
int getHeight() const;
|
|
|
|
|
Renderer &getRenderer();
|
|
|
|
|
std::shared_ptr< Renderer > getRendererShared();
|
|
|
|
|
void setPrevTicks( int ticks );
|
|
|
|
|
void saveScene();
|
|
|
|
|
void resetScene();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void checkKilled();
|
|
|
|
|
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > > render_objects;
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > > collision_objects;
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > > saved_render_objects;
|
|
|
|
|
std::vector< std::shared_ptr< RenderObject > > saved_collision_objects;
|
|
|
|
|
std::shared_ptr< Renderer > renderer;
|
|
|
|
|
std::shared_ptr< Texture > background;
|
|
|
|
|
int prev_ticks = 0;
|
|
|
|
|
std::shared_ptr< RenderObject > leftmost_obj;
|
|
|
|
|
std::shared_ptr< RenderObject > rightmost_obj;
|
|
|
|
|
uint64_t max_object_id = 0;
|
|
|
|
|
std::mutex render_mutex;
|
|
|
|
|
};
|
|
|
|
|
} // end of namespace SDLPP
|
|
|
|
|
#endif
|