1
// $Id: game_session.cxx,v 1.39 2003/04/09 16:20:19 torangan Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 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.
21
#include "gui/screen_manager.hxx"
23
#include "true_server.hxx"
24
#include "game_session.hxx"
25
#include "game_session_result.hxx"
27
#include "pingus_resource.hxx"
29
#include "pingu_holder.hxx"
31
#include "result_screen.hxx"
32
#include "savegame_manager.hxx"
33
#include "globals.hxx"
35
PingusGameSession::PingusGameSession (PLFHandle arg_plf, bool arg_show_result_screen)
37
show_result_screen(arg_show_result_screen)
39
Timer plf_timer("GameSession plf creation");
43
Timer server_timer("GameSession server creation");
44
server = new TrueServer(*plf);
47
Timer client_timer("GameSession client creation");
48
client = new Client(server);
51
number_of_redraws = 0;
52
number_of_updates = 0;
57
PingusGameSession::~PingusGameSession ()
60
std::cout << "XXXXXXXX"
61
<< " Redraws: " << number_of_redraws
62
<< " Updates: " << number_of_updates
63
<< " FrameSkip: " << number_of_updates - number_of_redraws
71
PingusGameSession::on_startup()
77
PingusGameSession::on_shutdown()
79
client->on_shutdown();
82
PingusGameSessionResult
83
PingusGameSession::get_result ()
85
return PingusGameSessionResult ();
89
PingusGameSession::draw(GraphicContext& gc)
97
PingusGameSession::update (const GameDelta& delta)
99
// FIXME: Timing code could need another rewrite...
100
if (server->is_finished())
102
//ScreenManager::instance()->pop_screen();
103
PinguHolder* pingu_holder = server->get_world()->get_pingus();
106
result.plf = server->get_plf();
108
result.saved = pingu_holder->get_number_of_exited();
109
result.killed = pingu_holder->get_number_of_killed();
110
result.total = server->get_plf()->get_pingus();
112
result.needed = server->get_plf()->get_number_to_save();
114
result.max_time = server->get_plf()->get_time();
115
result.used_time = server->get_time();
117
{ // Write the savegame
119
savegame.levelname = result.plf->get_resname();
120
savegame.time = result.used_time;
121
savegame.saved_pingus = result.saved;
123
if (result.saved >= result.needed)
124
savegame.status = Savegame::FINISHED;
126
savegame.status = Savegame::ACCESSIBLE;
128
SavegameManager::instance()->store(savegame);
131
if (show_result_screen)
132
ScreenManager::instance()->replace_screen(new ResultScreen(result));
134
ScreenManager::instance()->pop_screen();
138
int time_passed = int(delta.get_time() * 1000) + left_over_time;
139
int update_time = game_speed;
146
((i * update_time < time_passed)
147
|| i < min_frame_skip)
148
&& !(i > max_frame_skip);
151
// This updates the world and all objects
156
// Time that got not used for updates
157
left_over_time = time_passed - (i * update_time);
160
if (left_over_time < 0)
162
// FIXME: This doesn't really belong here
163
CL_System::sleep(-left_over_time);
166
// Client is independend of the update limit, well, not completly...
167
client->update (delta);
170
// Move the game one loop further
172
client->update (delta);
177
PingusGameSession::on_pause_press ()
179
client->on_pause_press ();
183
PingusGameSession::on_fast_forward_press ()
185
client->on_fast_forward_press ();
189
PingusGameSession::on_armageddon_press ()
191
client->on_armageddon_press ();
195
PingusGameSession::on_escape_press ()
197
client->on_escape_press ();