SDLPP: add option to specify background objects in scene and move Z index of objects just above those background objects

This commit is contained in:
zvon 2021-08-07 21:58:53 +02:00
parent f35aa095f3
commit 0608202483
2 changed files with 21 additions and 0 deletions

View File

@ -69,6 +69,9 @@ void Scene::moveZTop( const std::shared_ptr< RenderObject > &obj ) {
void Scene::moveZBottom( const std::shared_ptr< RenderObject > &obj ) {
setZIndex( obj, 0 );
}
void Scene::moveZJustAboveBackground( const std::shared_ptr< RenderObject > &obj ) {
setZIndex( obj, first_non_background_index );
}
std::shared_ptr< RenderObject > Scene::getObject( int index ) {
return render_objects[index];
}
@ -231,6 +234,19 @@ void Scene::resetScene() {
}
}
void Scene::setBackgroundObjectIDs(const std::unordered_set<uint64_t> &ids) {
background_ids = ids;
}
void Scene::updateBackgroundObjectZIndex() {
first_non_background_index = 1;
for(uint64_t i = 1; i < render_objects.size(); i++) {
if(background_ids.find(render_objects[i]->getId()) != background_ids.end()) {
setZIndex(render_objects[i], 1);
first_non_background_index++;
}
}
}
void Scene::checkKilled() {
std::lock_guard< std::mutex > lock( render_mutex );
std::vector< int > killed;

View File

@ -22,6 +22,7 @@ public:
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 > >
@ -49,6 +50,8 @@ public:
void setPrevTicks( int ticks );
void saveScene();
void resetScene();
void setBackgroundObjectIDs(const std::unordered_set<uint64_t> &ids);
void updateBackgroundObjectZIndex();
private:
void checkKilled();
@ -64,6 +67,8 @@ private:
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;
};
} // end of namespace SDLPP
#endif