79 lines
3.0 KiB
C++
79 lines
3.0 KiB
C++
#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"
|
|
#include "sdlpp_visitor.hpp"
|
|
|
|
namespace SDLPP {
|
|
class SDLPPSCOPE Scene {
|
|
public:
|
|
Scene( std::shared_ptr< Renderer > &r );
|
|
void addObject( const std::shared_ptr< RenderObject > &obj );
|
|
void setZIndex( const std::shared_ptr< RenderObject > &obj, uint64_t 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 );
|
|
void moveZTop( const std::shared_ptr< RenderObject > &obj );
|
|
void moveZBottom( const std::shared_ptr< RenderObject > &obj );
|
|
void moveZJustAboveBackground( const std::shared_ptr< RenderObject > &obj );
|
|
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 updateScene();
|
|
void pauseScene();
|
|
void unpauseScene();
|
|
std::vector< std::pair< uint64_t, std::shared_ptr< RenderObject > > >
|
|
getCollisions( RenderObject &r );
|
|
void visitCollisions( RenderObject &r, Visitor &v );
|
|
std::vector< std::pair< uint64_t, 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();
|
|
Vec2D< int > getDimensions() const;
|
|
int getWidth() const;
|
|
int getHeight() const;
|
|
Renderer &getRenderer();
|
|
std::shared_ptr< Renderer > getRendererShared();
|
|
void setPrevTicks( int ticks );
|
|
void saveScene();
|
|
void resetScene();
|
|
void setBackgroundObjectIDs(const std::unordered_set<uint64_t> &ids);
|
|
void updateBackgroundObjectZIndex();
|
|
|
|
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;
|
|
int diff_ticks = 0;
|
|
std::shared_ptr< RenderObject > leftmost_obj;
|
|
std::shared_ptr< RenderObject > rightmost_obj;
|
|
uint64_t max_object_id = 0;
|
|
std::mutex render_mutex;
|
|
std::unordered_set<uint64_t> background_ids;
|
|
uint64_t first_non_background_index = 1;
|
|
bool paused = false;
|
|
};
|
|
} // end of namespace SDLPP
|
|
#endif
|