1 // Construo - A wire-frame construction game 2 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de> 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 #ifndef HEADER_CONSTRUO_CONTROLLER_HPP 18 #define HEADER_CONSTRUO_CONTROLLER_HPP 19 20 #include "world.hpp" 21 #include "delta_manager.hpp" 22 23 /** Holds all the different World states, handles undo and things like that */ 24 class Controller 25 { 26 private: 27 std::vector<World*> undo_world_stack; 28 std::vector<World*> redo_world_stack; 29 30 bool running; 31 bool slow_down; 32 bool action_cam; 33 bool hide_dots; 34 35 /** The current active world, don't delete this, delet is handled in 36 the undo stacks */ 37 World* world; 38 39 DeltaManager delta_manager; 40 41 static Controller* instance_; 42 public: 43 /** Create an empty world workspace */ 44 Controller (); 45 Controller (const std::string& filename); 46 ~Controller (); 47 instance()48 static inline Controller* instance() { return instance_; } 49 has_been_run()50 bool has_been_run () { return world && world->get_has_been_run (); } 51 is_running()52 bool is_running () { return running; } slow_down_active()53 bool slow_down_active () { return slow_down; } set_slow_down(bool s)54 void set_slow_down (bool s) { slow_down = s; } 55 56 void set_action_cam(bool); 57 bool get_action_cam(); 58 59 void set_hide_dots (bool); 60 bool get_hide_dots (); 61 get_world()62 World* get_world () { assert(world); return world; } 63 64 /** Load a world by name, name is relative to the construo user directory */ 65 void load_world (const std::string& name); 66 67 /** Save a world by name, name is relative to the construo user directory */ 68 void save_world (const std::string& name); 69 70 std::string get_slot_filename(int n); 71 void save_to_slot (int n); 72 void load_from_slot (int n); 73 74 /** Updates the state of the controller and also the world */ 75 void update (); 76 77 void clear_world (); 78 79 void undo (); 80 void redo (); 81 82 /** Push the current world to the undo stack */ 83 void push_undo(); 84 85 /** start or stops the simulation */ 86 void start_simulation (); 87 }; 88 89 #endif 90 91 /* EOF */ 92