1 // $Id: controller.cxx,v 1.12 2003/07/27 18:46:11 grumbel Exp $
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "worldview_component.hxx"
21 #include "construo_error.hxx"
22 #include "controller.hxx"
24 Controller
* Controller::instance_
= 0;
26 Controller::Controller ()
36 Controller::Controller (const std::string
& filename
)
43 world
= new World (filename
);
46 Controller::~Controller ()
52 Controller::load_world (const std::string
& filename
)
55 undo_world_stack
.push_back(world
);
57 std::cout
<< "Loading World..." << std::endl
;
58 world
= new World (filename
);
60 WorldViewComponent::instance()->on_world_change();
63 std::cout
<< "Loading World... DONE" << std::endl
;
67 Controller::save_world (const std::string
& filename
)
69 std::cout
<< "Saving World..." << std::endl
;
70 world
->write_lisp (filename
);
71 std::cout
<< "Saving World... DONE" << std::endl
;
76 Controller::get_slot_filename(int n
)
78 return "/user/" + std::string("quicksave") + char('0' + n
) + ".construo";
82 Controller::save_to_slot (int n
)
85 save_world (get_slot_filename (n
));
86 } catch (ConstruoError
& err
) {
87 std::cout
<< "Controller: Error: " << err
.msg
<< std::endl
;
92 Controller::load_from_slot (int n
)
95 load_world (get_slot_filename (n
));
96 } catch (ConstruoError
& err
) {
97 std::cout
<< "Controller: Error: " << err
.msg
<< std::endl
;
102 Controller::update ()
104 float delta
= delta_manager
.getset ();
112 delta
/= 50.0f
/20.0f
;
118 min_skip
= 0.02; // 0.02
124 world
->update (min_skip
);
131 Controller::start_simulation ()
134 undo_world_stack
.push_back(world
->duplicate());
136 if (undo_world_stack
.size() > 100)
138 // FIXME: shrink stack here
139 //delete *undo_world_stack.front();
147 Controller::push_undo()
149 undo_world_stack
.push_back(world
->duplicate());
153 Controller::clear_world ()
155 std::cout
<< "Controller: Clear" << std::endl
;
156 undo_world_stack
.push_back(world
);
157 world
= new World ();
165 std::cout
<< "Controller::undo (): undostack: " << undo_world_stack
.size()
166 << " redostack: " << redo_world_stack
.size() << std::endl
;
169 if (!undo_world_stack
.empty())
171 //delete world; // fixme: memory hole
172 redo_world_stack
.push_back (world
);
173 world
= undo_world_stack
.back();
174 undo_world_stack
.pop_back();
179 std::cout
<< "Undo stack empty" << std::endl
;
186 if (!redo_world_stack
.empty())
188 undo_world_stack
.push_back (world
);
189 world
= redo_world_stack
.back();
190 redo_world_stack
.pop_back();
195 std::cout
<< "Redo stack empty" << std::endl
;
200 Controller::set_action_cam(bool a
)
206 Controller::get_action_cam()
212 Controller::set_hide_dots (bool d
)
218 Controller::get_hide_dots ()