~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/client.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-02-28 19:44:25 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080228194425-e8ilohlijv02kgcf
Tags: 0.7.2-2
* Fix FTBFS with gcc-4.3 by adding the missing include in
  src/input/evdev_device.cpp (Closes: #462238):
   + debian/patches/20_fix_FTBFS_with_gcc-4.3.
* Rename former patch so that the filename reflects the order in which
  the patches are applied:
   - debian/patches/data_dir.patch
   + debian/patches/10_fix_data_directory.
* Bump Standards-Version from 3.7.2 to 3.7.3, no changes needed.
* Add a dh_desktop call in the arch-dep part of debian/rules.
* Adjust the “missing-dep-for-interpreter guile” override since lintian
  now lists an alternative for that dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  $Id: client.cxx,v 1.43 2003/03/25 00:37:44 grumbel Exp $
2
 
// 
3
 
//  Pingus - A free Lemmings clone
4
 
//  Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>
5
 
//
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.
10
 
//
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.
15
 
//
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.
19
 
 
20
 
#include <iostream>
21
 
#include <ClanLib/Display/Display/display.h>
22
 
#include <ClanLib/Display/Display/mousecursor_provider.h>
23
 
#include "globals.hxx"
24
 
#include "playfield.hxx"
25
 
#include "timer.hxx"
26
 
#include "pingus_resource.hxx"
27
 
#include "sound/sound.hxx"
28
 
#include "time_display.hxx"
29
 
#include "pingus_counter.hxx"
30
 
#include "smallmap.hxx"
31
 
#include "plf.hxx"
32
 
#include "hurry_up.hxx"
33
 
#include "path_manager.hxx"
34
 
#include "gui/cursor.hxx"
35
 
#include "true_server.hxx"
36
 
#include "button_panel.hxx"
37
 
#include "gui/gui_manager.hxx"
38
 
 
39
 
Client::Client (TrueServer * s)
40
 
  : server       (s),
41
 
    skip_frame   (0),
42
 
    do_replay    (false),
43
 
    is_finished  (false),
44
 
    unplayable   ("misc/unplayable2", "core"),
45
 
    button_panel (0),
46
 
    pcounter     (0),
47
 
    playfield    (0),
48
 
    time_display (0),
49
 
    small_map    (0),
50
 
    hurry_up     (0)
51
 
  //cursor       (new Cursor ("cursors/animcross", "core", controller))
52
 
{
53
 
  //Display::add_flip_screen_hook(cursor);
54
 
 
55
 
  unplayable.set_align_center();
56
 
  
57
 
  Timer timer("Client UI generation");
58
 
 
59
 
  Display::set_cursor(CL_MouseCursorProvider::load("Cursors/cursor", 
60
 
                                                   PingusResource::get("game")));
61
 
 
62
 
  // These object will get deleted by the gui_manager
63
 
  button_panel = new ButtonPanel(this, 2, CL_Display::get_height()/2);
64
 
  playfield    = new Playfield(this);
65
 
  hurry_up     = new HurryUp(this);
66
 
  pcounter     = new PingusCounter(get_server());  
67
 
  small_map    = new SmallMap(this);
68
 
  time_display = new TimeDisplay(this);
69
 
 
70
 
  gui_manager->add (playfield, true);
71
 
  gui_manager->add (button_panel, true);
72
 
  gui_manager->add (hurry_up, true);
73
 
  gui_manager->add (pcounter, true);
74
 
  gui_manager->add (small_map, true);
75
 
  gui_manager->add (time_display, true);
76
 
 
77
 
  gui_manager->add (new ArmageddonButton(server, CL_Display::get_width() - 40,     CL_Display::get_height() - 62), true);
78
 
  gui_manager->add (new ForwardButton   (server, CL_Display::get_width() - 40 * 2, CL_Display::get_height() - 62), true);
79
 
  gui_manager->add (new PauseButton     (server, CL_Display::get_width() - 40 * 3, CL_Display::get_height() - 62), true);
80
 
  // Connect the button_panel with the playfield
81
 
  playfield->set_buttons(button_panel);
82
 
  playfield->set_server(server);
83
 
 
84
 
  timer.stop();
85
 
}
86
 
 
87
 
Client::~Client()
88
 
{
89
 
}
90
 
 
91
 
void
92
 
Client::update (const GameDelta& delta)
93
 
{
94
 
  GUIScreen::update (delta);
95
 
  process_events(delta);
96
 
}
97
 
 
98
 
void
99
 
Client::process_events (const GameDelta& delta)
100
 
{
101
 
  const Input::EventLst& events = delta.get_events ();
102
 
 
103
 
  for (Input::EventLst::const_iterator i = events.begin (); 
104
 
       i != events.end (); 
105
 
       ++i)
106
 
    {
107
 
      //std::cout << "Events: " << (*i)->get_type () << std::endl;
108
 
    
109
 
      switch (i->type)
110
 
        {
111
 
        case Input::ButtonEventType:
112
 
          {
113
 
            const Input::ButtonEvent& ev = i->button;
114
 
            
115
 
            if (ev.state == Input::pressed)
116
 
              {
117
 
                if (ev.name >= Input::action_1 && ev.name <= Input::action_10)
118
 
                  {
119
 
                    button_panel->set_button(ev.name - Input::action_1);
120
 
                  }
121
 
                else if (ev.name == Input::action_down)
122
 
                  {
123
 
                    button_panel->next_action();
124
 
                  }
125
 
                else if (ev.name == Input::action_up)
126
 
                  {
127
 
                    button_panel->previous_action();
128
 
                  }
129
 
              }
130
 
          }
131
 
          break;
132
 
 
133
 
        case Input::PointerEventType:
134
 
          // Ignore, is handled in GUIScreen
135
 
          //process_pointer_event (dynamic_cast<class Input::PointerEvent* const>(*i));
136
 
          break;
137
 
 
138
 
        case Input::AxisEventType:
139
 
          // ???
140
 
          process_axis_event (i->axis);
141
 
          break;
142
 
          
143
 
        case Input::ScrollEventType:
144
 
          process_scroll_event(i->scroll);
145
 
          break;
146
 
 
147
 
        default:
148
 
          // unhandled event
149
 
          std::cout << "Client::process_events (): unhandled event: " << i->type << std::endl;
150
 
          break;
151
 
        }
152
 
    }
153
 
}
154
 
 
155
 
void
156
 
Client::process_scroll_event (const Input::ScrollEvent& ev)
157
 
{
158
 
  std::cout << "Client::process_scroll_event ()" << std::endl;    
159
 
  playfield->scroll(static_cast<int>(ev.x_delta),
160
 
                    static_cast<int>(ev.y_delta));
161
 
}
162
 
 
163
 
void
164
 
Client::process_axis_event (const Input::AxisEvent& event)
165
 
{
166
 
  std::cout << "Client::process_axis_event ()" << std::endl;
167
 
  UNUSED_ARG(event);
168
 
}
169
 
 
170
 
bool
171
 
Client::replay()
172
 
{
173
 
  return do_replay;
174
 
}
175
 
 
176
 
void
177
 
Client::do_restart()
178
 
{
179
 
  do_replay = true;
180
 
  server->set_finished();
181
 
}
182
 
 
183
 
bool
184
 
Client::finished()
185
 
{
186
 
  return is_finished;
187
 
}
188
 
 
189
 
void
190
 
Client::set_finished()
191
 
{
192
 
  is_finished = true;
193
 
  server->set_finished();  
194
 
}
195
 
 
196
 
#if 0
197
 
void
198
 
Client::on_keyboard_button_press(const CL_Key& /*key*/)
199
 
{
200
 
  if (CL_Keyboard::get_keycode(CL_KEY_LSHIFT)
201
 
      || CL_Keyboard::get_keycode(CL_KEY_RSHIFT))
202
 
    {
203
 
      playfield->scroll_speed = 50;
204
 
    }
205
 
  else
206
 
    {
207
 
      playfield->scroll_speed = 15;
208
 
    }
209
 
}
210
 
 
211
 
void
212
 
Client::on_keyboard_button_release(const CL_Key& key)
213
 
{
214
 
  std::cout << "Keyboard pressed: " << key.id << std::endl;
215
 
  switch (key.id)
216
 
    {
217
 
    case CL_KEY_O:
218
 
      enabled = false;
219
 
      Display::hide_cursor();
220
 
      option_menu.display ();
221
 
      Display::show_cursor();
222
 
      enabled = true;
223
 
      break;
224
 
 
225
 
      // Playfield scrolling    
226
 
    case CL_KEY_LEFT:
227
 
      playfield->view[playfield->current_view]->set_x_offset(playfield->view[playfield->current_view]->get_x_offset() + playfield->scroll_speed);
228
 
      break;
229
 
          
230
 
    case CL_KEY_RIGHT:
231
 
      playfield->view[playfield->current_view]->set_x_offset(playfield->view[playfield->current_view]->get_x_offset() - playfield->scroll_speed);
232
 
      break;
233
 
          
234
 
    case CL_KEY_UP:
235
 
      playfield->view[playfield->current_view]->set_y_offset(playfield->view[playfield->current_view]->get_y_offset() + playfield->scroll_speed);
236
 
      break;
237
 
      
238
 
    case CL_KEY_DOWN:
239
 
      playfield->view[playfield->current_view]->set_y_offset(playfield->view[playfield->current_view]->get_y_offset() - playfield->scroll_speed);
240
 
      break;
241
 
 
242
 
      // Playfield zooming
243
 
    case CL_KEY_PAGEDOWN:
244
 
      playfield->view[playfield->current_view]->set_zoom(playfield->view[playfield->current_view]->get_zoom() / 1.05);
245
 
      break;
246
 
      
247
 
    case CL_KEY_PAGEUP:
248
 
      playfield->view[playfield->current_view]->set_zoom(playfield->view[playfield->current_view]->get_zoom() / 0.95);
249
 
      break;
250
 
      
251
 
    case CL_KEY_END:
252
 
      playfield->view[playfield->current_view]->set_zoom(1.0);
253
 
      break;
254
 
 
255
 
      // Misc
256
 
    case CL_KEY_P:
257
 
      pause = !pause;
258
 
      server->set_pause(pause);
259
 
      break;
260
 
 
261
 
    case CL_KEY_A:
262
 
      server->send_armageddon_event();
263
 
      break;
264
 
          
265
 
    case CL_KEY_R:
266
 
      do_restart();
267
 
      break;
268
 
          
269
 
    case CL_KEY_SPACE:
270
 
      set_fast_forward(!get_fast_forward());
271
 
      break;
272
 
 
273
 
    case CL_KEY_ESCAPE:
274
 
      server->set_finished();
275
 
      break;
276
 
 
277
 
    case CL_KEY_F1:
278
 
      button_panel->set_button(0);
279
 
      break;
280
 
    case CL_KEY_F2:
281
 
      button_panel->set_button(1);
282
 
      break;
283
 
    case CL_KEY_F3:
284
 
      button_panel->set_button(2);
285
 
      break;      
286
 
    case CL_KEY_F4:
287
 
      button_panel->set_button(3);
288
 
      break;      
289
 
    case CL_KEY_F5:
290
 
      button_panel->set_button(4);
291
 
      break;      
292
 
    case CL_KEY_F6:
293
 
      button_panel->set_button(5);
294
 
      break;      
295
 
    case CL_KEY_F7:
296
 
      button_panel->set_button(6);
297
 
      break;      
298
 
    case CL_KEY_F8:
299
 
      button_panel->set_button(7);
300
 
      break;      
301
 
    default:
302
 
      if (verbose > 1) std::cout << "Client: Got unknown button: ID=" << key.id << " ASCII=" << char(key.ascii) << std::endl;
303
 
    }
304
 
}
305
 
#endif
306
 
 
307
 
void
308
 
Client:: on_escape_press ()
309
 
{
310
 
  server->set_finished();
311
 
}
312
 
 
313
 
void
314
 
Client:: on_pause_press ()
315
 
{
316
 
  server->set_pause (!server->get_pause ());
317
 
}
318
 
 
319
 
void 
320
 
Client::on_fast_forward_press ()
321
 
{
322
 
  server->set_fast_forward(!server->get_fast_forward());
323
 
}
324
 
 
325
 
void 
326
 
Client::on_armageddon_press ()
327
 
{
328
 
  server->send_armageddon_event();
329
 
}
330
 
 
331
 
void
332
 
Client::on_action_axis_move (float move)
333
 
{
334
 
  if (move > 0)
335
 
    button_panel->next_action ();
336
 
  else if (move < 0)
337
 
    button_panel->previous_action ();
338
 
}
339
 
 
340
 
bool
341
 
Client::draw (GraphicContext& gc)
342
 
{
343
 
  GUIScreen::draw (gc);
344
 
  if (!server->get_plf()->get_playable())
345
 
    gc.draw(unplayable, Vector(400, 50));
346
 
  return true;
347
 
}
348
 
 
349
 
void
350
 
Client::on_startup ()
351
 
{
352
 
  /** Hide the system cursor and show the software one */
353
 
  Display::show_cursor();
354
 
  // FIXME: using this twice will crash with an X Error
355
 
  //CL_MouseCursor::hide ();
356
 
 
357
 
  do_replay = false;
358
 
  is_finished = false;
359
 
  skip_frame = 0;
360
 
 
361
 
  if (maintainer_mode)
362
 
    std::cout << "Starting Music: " << server->get_plf()->get_music() << std::endl;
363
 
 
364
 
  if (server->get_plf()->get_music() == "none")
365
 
    {
366
 
      PingusSound::stop_music();
367
 
    }
368
 
  else
369
 
    {
370
 
      PingusSound::play_music(server->get_plf ()->get_music());
371
 
    }
372
 
 
373
 
  if (verbose)
374
 
    std::cout << "Client: Entering main_loop. Startup time: " 
375
 
              << CL_System::get_time() << " msec." << std::endl;
376
 
}
377
 
 
378
 
void
379
 
Client::on_shutdown ()
380
 
{
381
 
  Display::hide_cursor();
382
 
}
383
 
 
384
 
/* EOF */