SDLPP: Add scene pause function
This commit is contained in:
parent
aa5043a811
commit
9e4cc97f79
@ -90,6 +90,9 @@ Scene::getObjects( const std::unordered_set< int > &objectIDs ) {
|
||||
return ret;
|
||||
}
|
||||
void Scene::updateScene() {
|
||||
if(paused) {
|
||||
return;
|
||||
}
|
||||
// check for objects that should be removed
|
||||
checkKilled();
|
||||
std::lock_guard< std::mutex > lock( render_mutex );
|
||||
@ -102,6 +105,14 @@ void Scene::updateScene() {
|
||||
}
|
||||
prev_ticks = now_ticks;
|
||||
}
|
||||
void Scene::pauseScene() {
|
||||
paused = true;
|
||||
diff_ticks = SDL_GetTicks() - prev_ticks;
|
||||
}
|
||||
void Scene::unpauseScene() {
|
||||
paused = false;
|
||||
prev_ticks = SDL_GetTicks() - diff_ticks;
|
||||
}
|
||||
std::vector< std::pair< uint64_t, std::shared_ptr< RenderObject > > >
|
||||
Scene::getCollisions( RenderObject &r ) {
|
||||
if ( r.getHidden() )
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
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 );
|
||||
@ -63,12 +65,14 @@ private:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user