mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 22:12:59 +00:00 
			
		
		
		
	tour:: a system for easier restoration of slide-changed values
This commit is contained in:
		
							
								
								
									
										33
									
								
								tour.cpp
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								tour.cpp
									
									
									
									
									
								
							| @@ -63,23 +63,40 @@ static const flagtype SIDESCREEN = 64; | |||||||
| static const flagtype USE_SLIDE_NAME = 128; | static const flagtype USE_SLIDE_NAME = 128; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | EX vector<reaction_t> restorers; | ||||||
|  |  | ||||||
|  | #if HDR | ||||||
|  | template<class T> void slide_backup(T& what, T value) { | ||||||
|  |   T backup = what; | ||||||
|  |   restorers.push_back([&what, backup] { what = backup; }); | ||||||
|  |   what = value; | ||||||
|  |   } | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | EX void on_restore(const reaction_t& t) { | ||||||
|  |   restorers.push_back(t); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | EX void slide_restore_all() { | ||||||
|  |   while(!restorers.empty()) { | ||||||
|  |     restorers.back()(); | ||||||
|  |     restorers.pop_back(); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
| /** \brief an auxiliary function to enable a visualization in the Canvas land */ | /** \brief an auxiliary function to enable a visualization in the Canvas land */ | ||||||
| EX void setCanvas(presmode mode, char canv) { | EX void setCanvas(presmode mode, char canv) { | ||||||
|   static char wc; |  | ||||||
|   static eLand ld; |  | ||||||
|   if(mode == pmStart) { |   if(mode == pmStart) { | ||||||
|     gamestack::push(); |     gamestack::push(); | ||||||
|     wc = patterns::whichCanvas; |     slide_backup(patterns::whichCanvas, canv); | ||||||
|     patterns::whichCanvas = canv; |     slide_backup(firstland, laCanvas); | ||||||
|     ld = firstland; |     slide_backup(specialland, laCanvas); | ||||||
|     firstland = laCanvas; |  | ||||||
|     start_game(); |     start_game(); | ||||||
|     resetview(); |     resetview(); | ||||||
|     } |     } | ||||||
|   if(mode == pmStop) { |   if(mode == pmStop) { | ||||||
|     gamestack::pop(); |     gamestack::pop(); | ||||||
|     patterns::whichCanvas = wc; |     slide_restore_all(); | ||||||
|     firstland = ld; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue