refactored some supertux mainloops
[supertux.git] / src / game_session.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 #include <config.h>
22
23 #include <fstream>
24 #include <sstream>
25 #include <cassert>
26 #include <cstdio>
27 #include <cstdlib>
28 #include <cmath>
29 #include <cstring>
30 #include <cerrno>
31 #include <unistd.h>
32 #include <ctime>
33 #include <stdexcept>
34
35 #include <SDL.h>
36
37 #include "game_session.hpp"
38 #include "msg.hpp"
39 #include "worldmap.hpp"
40 #include "mainloop.hpp"
41 #include "video/screen.hpp"
42 #include "audio/sound_manager.hpp"
43 #include "gui/menu.hpp"
44 #include "sector.hpp"
45 #include "level.hpp"
46 #include "tile.hpp"
47 #include "player_status.hpp"
48 #include "object/particlesystem.hpp"
49 #include "object/background.hpp"
50 #include "object/gradient.hpp"
51 #include "object/tilemap.hpp"
52 #include "object/camera.hpp"
53 #include "object/player.hpp"
54 #include "object/level_time.hpp"
55 #include "lisp/lisp.hpp"
56 #include "lisp/parser.hpp"
57 #include "resources.hpp"
58 #include "worldmap.hpp"
59 #include "misc.hpp"
60 #include "statistics.hpp"
61 #include "timer.hpp"
62 #include "object/fireworks.hpp"
63 #include "textscroller.hpp"
64 #include "control/codecontroller.hpp"
65 #include "control/joystickkeyboardcontroller.hpp"
66 #include "main.hpp"
67 #include "file_system.hpp"
68 #include "gameconfig.hpp"
69 #include "gettext.hpp"
70 #include "exceptions.hpp"
71 #include "flip_level_transformer.hpp"
72
73 // the engine will be run with a logical framerate of 64fps.
74 // We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
75 // binary fraction...
76 static const float LOGICAL_FPS = 64.0;
77
78 using namespace WorldMapNS;
79
80 GameSession* GameSession::current_ = 0;
81
82 GameSession::GameSession(const std::string& levelfile_, GameSessionMode mode,
83     Statistics* statistics)
84   : level(0), currentsector(0), mode(mode),
85     end_sequence(NO_ENDSEQUENCE), end_sequence_controller(0),
86     levelfile(levelfile_), best_level_statistics(statistics),
87     capture_demo_stream(0), playback_demo_stream(0), demo_controller(0)
88 {
89   current_ = this;
90   currentsector = 0;
91   
92   game_pause = false;
93   fps_fps = 0;
94
95   Console::registerCommandReceiver(this);
96
97   restart_level(true);
98 }
99
100 void
101 GameSession::restart_level(bool fromBeginning)
102 {
103   game_pause   = false;
104   end_sequence = NO_ENDSEQUENCE;
105
106   main_controller->reset();
107
108   delete level;
109   currentsector = 0;
110
111   level = new Level;
112   level->load(levelfile);
113
114   global_stats.reset();
115   global_stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins());
116   global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys());
117   
118   // get time
119   int time = 0;
120   for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
121   {
122     Sector* sec = *i;
123
124     for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
125         j != sec->gameobjects.end(); ++j)
126     {
127       GameObject* obj = *j;
128       
129       LevelTime* lt = dynamic_cast<LevelTime*> (obj);
130       if(lt)
131         time += int(lt->get_level_time());
132     }
133   }
134   global_stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
135
136   if (fromBeginning) reset_sector="";
137   if(reset_sector != "") {
138     currentsector = level->get_sector(reset_sector);
139     if(!currentsector) {
140       std::stringstream msg;
141       msg << "Couldn't find sector '" << reset_sector << "' for resetting tux.";
142       throw std::runtime_error(msg.str());
143     }
144     currentsector->activate(reset_pos);
145   } else {
146     currentsector = level->get_sector("main");
147     if(!currentsector)
148       throw std::runtime_error("Couldn't find main sector");
149     currentsector->activate("main");
150   }
151   
152   if(mode == ST_GL_PLAY || mode == ST_GL_LOAD_LEVEL_FILE)
153     levelintro();
154
155   currentsector->play_music(LEVEL_MUSIC);
156
157   if(capture_file != "")
158     record_demo(capture_file);
159 }
160
161 GameSession::~GameSession()
162 {
163   delete capture_demo_stream;
164   delete playback_demo_stream;
165   delete demo_controller;
166
167   delete end_sequence_controller;
168   delete level;
169   Console::unregisterCommandReceiver(this);
170
171   current_ = NULL;
172 }
173
174 void
175 GameSession::record_demo(const std::string& filename)
176 {
177   delete capture_demo_stream;
178   
179   capture_demo_stream = new std::ofstream(filename.c_str()); 
180   if(!capture_demo_stream->good()) {
181     std::stringstream msg;
182     msg << "Couldn't open demo file '" << filename << "' for writing.";
183     throw std::runtime_error(msg.str());
184   }
185   capture_file = filename;
186 }
187
188 void
189 GameSession::play_demo(const std::string& filename)
190 {
191   delete playback_demo_stream;
192   delete demo_controller;
193   
194   playback_demo_stream = new std::ifstream(filename.c_str());
195   if(!playback_demo_stream->good()) {
196     std::stringstream msg;
197     msg << "Couldn't open demo file '" << filename << "' for reading.";
198     throw std::runtime_error(msg.str());
199   }
200
201   Player& tux = *currentsector->player;
202   demo_controller = new CodeController();
203   tux.set_controller(demo_controller);
204 }
205
206 void
207 GameSession::levelintro()
208 {
209   char str[60];
210
211   sound_manager->stop_music();
212
213   DrawingContext context;
214   for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin();
215       i != currentsector->gameobjects.end(); ++i) {
216     Background* background = dynamic_cast<Background*> (*i);
217     if(background) {
218       background->draw(context);
219     }
220     Gradient* gradient = dynamic_cast<Gradient*> (*i);
221     if(gradient) {
222       gradient->draw(context);
223     }
224   }
225
226 //  context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160),
227 //      CENTER_ALLIGN, LAYER_FOREGROUND1);
228   context.draw_center_text(gold_text, level->get_name(), Vector(0, 160),
229       LAYER_FOREGROUND1);
230
231   sprintf(str, "Coins: %d", player_status->coins);
232   context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210),
233       CENTER_ALLIGN, LAYER_FOREGROUND1);
234
235   if((level->get_author().size()) && (level->get_author() != "SuperTux Team"))
236     //TODO make author check case/blank-insensitive
237     context.draw_text(white_small_text,
238       std::string(_("contributed by ")) + level->get_author(), 
239       Vector(SCREEN_WIDTH/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1);
240
241
242   if(best_level_statistics != NULL)
243     best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
244
245   wait_for_event(1.0, 3.0);
246 }
247
248 void
249 GameSession::on_escape_press()
250 {
251   if(currentsector->player->is_dying() || end_sequence != NO_ENDSEQUENCE)
252     return;   // don't let the player open the menu, when he is dying
253   
254   if(mode == ST_GL_TEST) {
255     main_loop->exit_screen();
256   } else if (!Menu::current()) {
257     Menu::set_current(game_menu);
258     game_menu->set_active_item(MNID_CONTINUE);
259     game_pause = true;
260   } else {
261     game_pause = false;
262   }
263 }
264
265 void
266 GameSession::process_events()
267 {
268   Player& tux = *currentsector->player;
269
270   // end of pause mode?
271   if(!Menu::current() && game_pause) {
272     game_pause = false;
273   }
274
275   if (end_sequence != NO_ENDSEQUENCE) {
276     if(end_sequence_controller == 0) {
277       end_sequence_controller = new CodeController();
278       tux.set_controller(end_sequence_controller);
279     }
280
281     end_sequence_controller->press(Controller::RIGHT);
282     
283     if (int(last_x_pos) == int(tux.get_pos().x))
284       end_sequence_controller->press(Controller::JUMP);    
285     last_x_pos = tux.get_pos().x;
286   }
287
288   // playback a demo?
289   if(playback_demo_stream != 0) {
290     demo_controller->update();
291     char left = false;
292     char right = false;
293     char up = false;
294     char down = false;
295     char jump = false;
296     char action = false;
297     playback_demo_stream->get(left);
298     playback_demo_stream->get(right);
299     playback_demo_stream->get(up);
300     playback_demo_stream->get(down);
301     playback_demo_stream->get(jump);
302     playback_demo_stream->get(action);
303     demo_controller->press(Controller::LEFT, left);
304     demo_controller->press(Controller::RIGHT, right);
305     demo_controller->press(Controller::UP, up);
306     demo_controller->press(Controller::DOWN, down);
307     demo_controller->press(Controller::JUMP, jump);
308     demo_controller->press(Controller::ACTION, action);
309   }
310
311   // save input for demo?
312   if(capture_demo_stream != 0) {
313     capture_demo_stream ->put(main_controller->hold(Controller::LEFT));
314     capture_demo_stream ->put(main_controller->hold(Controller::RIGHT));
315     capture_demo_stream ->put(main_controller->hold(Controller::UP));
316     capture_demo_stream ->put(main_controller->hold(Controller::DOWN));
317     capture_demo_stream ->put(main_controller->hold(Controller::JUMP));   
318     capture_demo_stream ->put(main_controller->hold(Controller::ACTION));
319   }
320 }
321
322 bool
323 GameSession::consoleCommand(std::string command)
324 {
325   if (command == "foo") {
326     msg_info("bar");
327     return true;
328   }
329
330   //TODO: Build command list automatically
331   if (command == "cmdlist") {
332     msg_info("foo, cmdlist, cheats, whereami, camera");
333     return true;
334   }
335   //TODO: remove (or at least hide) this before release
336   if (command == "cheats") {
337     msg_info("grow, fire, ice, lifeup, numberofthebeast, lifedown, grease, invincible, mortal, shrink, kill, gotoend, flip, finish");
338     return true;
339   }
340
341   if (currentsector == 0) return false;
342   Player& tux = *currentsector->player;
343   
344   // Cheating words (the goal of this is really for debugging,
345   // but could be used for some cheating, nothing wrong with that)
346   if (command == "grow") {
347     tux.set_bonus(GROWUP_BONUS, false);
348     return true;
349   }
350   if (command == "fire") {
351     tux.set_bonus(FIRE_BONUS, false);
352     return true;
353   }
354   if (command == "ice") {
355     tux.set_bonus(ICE_BONUS, false);
356     return true;
357   }
358   if (command == "lifeup") {
359     player_status->incLives();
360     return true;
361   }
362   if (command == "numberofthebeast") {
363     player_status->coins += 55;
364     return true;
365   }
366   if (command == "lifedown") {
367     player_status->coins = std::max(player_status->coins-25, 0);
368     return true;
369   }
370   if (command == "grease") {
371     tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3);
372     return true;
373   }
374   if (command == "invincible") {
375     // be invincle for the rest of the level
376     tux.invincible_timer.start(10000);
377     return true;
378   }
379   if (command == "mortal") {
380     // give up invincibility
381     tux.invincible_timer.stop();
382     return true;
383   }
384   if (command == "shrink") {
385     // remove powerups
386     tux.kill(tux.SHRINK);
387     return true;
388   }
389   if (command == "kill") {
390     tux.kill(tux.KILL);
391     return true;
392   }
393   if (command == "whereami") {
394     msg_info("You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y);
395     return true;
396   }
397 #if 0
398   if(command == "grid")) {
399     // toggle debug grid
400     debug_grid = !debug_grid;
401     return true;
402   }
403 #endif
404   if (command == "gotoend") {
405     // goes to the end of the level
406     tux.move(Vector(
407           (currentsector->solids->get_width()*32) - (SCREEN_WIDTH*2), 0));
408     currentsector->camera->reset(
409         Vector(tux.get_pos().x, tux.get_pos().y));
410     return true;
411   }
412   if (command == "flip") {
413         FlipLevelTransformer flip_transformer;
414     flip_transformer.transform(GameSession::current()->get_current_level());
415     return true;
416   }
417   if (command == "finish") {
418     if(WorldMap::current() != NULL) {
419       WorldMap::current()->finished_level(levelfile);
420     }
421
422     return true;
423   }
424   if (command == "camera") {
425     msg_info("Camera is at " 
426               << Sector::current()->camera->get_translation().x << "," 
427               << Sector::current()->camera->get_translation().y);
428     return true;
429   }
430
431   return false;
432 }
433
434 void
435 GameSession::check_end_conditions()
436 {
437   Player* tux = currentsector->player;
438
439   /* End of level? */
440   if(end_sequence && endsequence_timer.check()) {
441     finish(true);
442     
443     // add time spent to statistics
444     int tottime = 0, remtime = 0;
445     for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
446     {
447       Sector* sec = *i;
448
449       for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
450           j != sec->gameobjects.end(); ++j)
451       {
452         GameObject* obj = *j;
453
454         LevelTime* lt = dynamic_cast<LevelTime*> (obj);
455         if(lt)
456         {
457           tottime += int(lt->get_level_time());
458           remtime += int(lt->get_remaining_time());
459         }
460       }
461     }
462     global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
463
464     return;
465   } else if (!end_sequence && tux->is_dead()) {
466     if (player_status->coins < 0) { 
467       // No more coins: restart level from beginning
468       player_status->coins = 0;
469       restart_level(true);
470     } else { 
471       // Still has coins: restart level from last reset point
472       restart_level(false);
473     }
474     
475     return;
476   }
477 }
478
479 void 
480 GameSession::draw(DrawingContext& context)
481 {
482   currentsector->draw(context);
483   drawstatus(context);
484
485   if(game_pause)
486     draw_pause(context);
487 }
488
489 void
490 GameSession::draw_pause(DrawingContext& context)
491 {
492   context.draw_filled_rect(
493       Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
494       Color(.2, .2, .2, .5), LAYER_FOREGROUND1);
495 }
496   
497 void
498 GameSession::process_menu()
499 {
500   Menu* menu = Menu::current();
501   if(menu) {
502     menu->update();
503
504     if(menu == game_menu) {
505       switch (game_menu->check()) {
506         case MNID_CONTINUE:
507           Menu::set_current(0);
508           break;
509         case MNID_ABORTLEVEL:
510           Menu::set_current(0);
511           main_loop->exit_screen();
512           break;
513       }
514     } else if(menu == options_menu) {
515       process_options_menu();
516     }
517   }
518 }
519
520 void
521 GameSession::setup()
522 {
523   Menu::set_current(NULL);
524   current_ = this;
525
526   // Eat unneeded events
527   SDL_Event event;
528   while(SDL_PollEvent(&event))
529   {}
530 }
531
532 void
533 GameSession::update(float elapsed_time)
534 {
535   process_events();
536   process_menu();
537
538   check_end_conditions();
539
540   // handle controller
541   if(main_controller->pressed(Controller::PAUSE_MENU))
542     on_escape_press();
543   
544   // respawning in new sector?
545   if(newsector != "" && newspawnpoint != "") {
546     Sector* sector = level->get_sector(newsector);
547     if(sector == 0) {
548       msg_warning("Sector '" << newsector << "' not found");
549     }
550     sector->activate(newspawnpoint);
551     sector->play_music(LEVEL_MUSIC);
552     currentsector = sector;
553     newsector = "";
554     newspawnpoint = "";
555   }
556
557   // Update the world state and all objects in the world
558   if(!game_pause) {
559     // Update the world
560     if (end_sequence == ENDSEQUENCE_RUNNING) {
561       currentsector->update(elapsed_time/2);
562     } else if(end_sequence == NO_ENDSEQUENCE) {
563       if(!currentsector->player->growing_timer.started())
564         currentsector->update(elapsed_time);
565     } 
566   }
567
568   // update sounds
569   sound_manager->set_listener_position(currentsector->player->get_pos());
570
571   /* Handle music: */
572   if (currentsector->player->invincible_timer.started() && 
573       currentsector->player->invincible_timer.get_timeleft() 
574       > TUX_INVINCIBLE_TIME_WARNING && !end_sequence) {
575     currentsector->play_music(HERRING_MUSIC);
576   } else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence) {
577     currentsector->play_music(LEVEL_MUSIC);
578   }
579 }
580
581 #if 0
582 GameSession::ExitStatus
583 GameSession::run()
584 {
585   Menu::set_current(0);
586   current_ = this;
587   
588   int fps_cnt = 0;
589
590   // Eat unneeded events
591   SDL_Event event;
592   while(SDL_PollEvent(&event))
593   {}
594
595   draw();
596
597   Uint32 fps_ticks = SDL_GetTicks();
598   Uint32 fps_nextframe_ticks = SDL_GetTicks();
599   Uint32 ticks;
600   bool skipdraw = false;
601
602   while (exit_status == ES_NONE) {
603     // we run in a logical framerate so elapsed time is a constant
604     // This will make the game run determistic and not different on different
605     // machines
606     static const float elapsed_time = 1.0 / LOGICAL_FPS;
607     // old code... float elapsed_time = float(ticks - lastticks) / 1000.;
608     if(!game_pause)
609       game_time += elapsed_time;
610
611     // regulate fps
612     ticks = SDL_GetTicks();
613     if(ticks > fps_nextframe_ticks) {
614       if(skipdraw == true) {
615         // already skipped last frame? we have to slow down the game then...
616         skipdraw = false;
617         fps_nextframe_ticks -= (Uint32) (1000.0 / LOGICAL_FPS);
618       } else {
619         // don't draw all frames when we're getting too slow
620         skipdraw = true;
621       }
622     } else {
623       skipdraw = false;
624       while(fps_nextframe_ticks > ticks) {
625         /* just wait */
626         // If we really have to wait long, then do an imprecise SDL_Delay()
627         Uint32 diff = fps_nextframe_ticks - ticks;
628         if(diff > 15) {
629           SDL_Delay(diff - 10);
630         } 
631         ticks = SDL_GetTicks();
632       }
633     }
634     fps_nextframe_ticks = ticks + (Uint32) (1000.0 / LOGICAL_FPS);
635
636     process_events();
637     process_menu();
638
639     // Update the world state and all objects in the world
640     if(!game_pause)
641     {
642       // Update the world
643       check_end_conditions();
644       if (end_sequence == ENDSEQUENCE_RUNNING)
645         update(elapsed_time/2);
646       else if(end_sequence == NO_ENDSEQUENCE)
647         update(elapsed_time);
648     }
649
650     if(!skipdraw)
651       draw();
652
653     // update sounds
654     sound_manager->update();
655
656     /* Time stops in pause mode */
657     if(game_pause || Menu::current())
658     {
659       continue;
660     }
661
662     /* Handle music: */
663     if (currentsector->player->invincible_timer.started() && 
664             currentsector->player->invincible_timer.get_timeleft() 
665             > TUX_INVINCIBLE_TIME_WARNING && !end_sequence)
666     {
667       currentsector->play_music(HERRING_MUSIC);
668     }
669     /* or just normal music? */
670     else if(currentsector->get_music_type() != LEVEL_MUSIC && !end_sequence)
671     {
672       currentsector->play_music(LEVEL_MUSIC);
673     }
674
675     /* Calculate frames per second */
676     if(config->show_fps)
677     {
678       ++fps_cnt;
679       
680       if(SDL_GetTicks() - fps_ticks >= 500)
681       {
682         fps_fps = (float) fps_cnt / .5;
683         fps_cnt = 0;
684         fps_ticks = SDL_GetTicks();
685       }
686     }
687   }
688  
689   // just in case
690   currentsector = 0;
691   main_controller->reset();
692   return exit_status;
693 }
694 #endif
695
696 void
697 GameSession::finish(bool win)
698 {
699   if(win) {
700     if(WorldMap::current())
701       WorldMap::current()->finished_level(levelfile);
702   }
703   
704   main_loop->exit_screen();
705 }
706
707 void
708 GameSession::respawn(const std::string& sector, const std::string& spawnpoint)
709 {
710   newsector = sector;
711   newspawnpoint = spawnpoint;
712 }
713
714 void
715 GameSession::set_reset_point(const std::string& sector, const Vector& pos)
716 {
717   reset_sector = sector;
718   reset_pos = pos;
719 }
720
721 std::string
722 GameSession::get_working_directory()
723 {
724   return FileSystem::dirname(levelfile);
725 }
726
727 void
728 GameSession::display_info_box(const std::string& text)
729 {
730   InfoBox* box = new InfoBox(text);
731
732   bool running = true;
733   DrawingContext context;
734   
735   while(running)  {
736
737     main_controller->update();
738     SDL_Event event;
739     while (SDL_PollEvent(&event)) {
740       main_controller->process_event(event);
741       if(event.type == SDL_QUIT)
742         throw graceful_shutdown();
743     }
744
745     if(main_controller->pressed(Controller::JUMP)
746         || main_controller->pressed(Controller::ACTION)
747         || main_controller->pressed(Controller::PAUSE_MENU)
748         || main_controller->pressed(Controller::MENU_SELECT))
749       running = false;
750     else if(main_controller->pressed(Controller::DOWN))
751       box->scrolldown();
752     else if(main_controller->pressed(Controller::UP))
753       box->scrollup();
754     box->draw(context);
755     draw(context);
756     context.do_drawing();
757     sound_manager->update();
758   }
759
760   delete box;
761 }
762
763 void
764 GameSession::start_sequence(const std::string& sequencename)
765 {
766   if(sequencename == "endsequence" || sequencename == "fireworks") {
767     if(end_sequence)
768       return;
769
770     end_sequence = ENDSEQUENCE_RUNNING;
771     endsequence_timer.start(7.3);
772     last_x_pos = -1;
773     sound_manager->play_music("music/leveldone.ogg", false);
774     currentsector->player->invincible_timer.start(7.3);
775
776     // Stop all clocks.
777     for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
778         i != currentsector->gameobjects.end(); ++i)
779     {
780       GameObject* obj = *i;
781
782       LevelTime* lt = dynamic_cast<LevelTime*> (obj);
783       if(lt)
784         lt->stop();
785     }
786
787     if(sequencename == "fireworks") {
788       currentsector->add_object(new Fireworks());
789     }
790   } else if(sequencename == "stoptux") {
791     if(!end_sequence) {
792       msg_warning("Final target reached without "
793         << "an active end sequence");
794       this->start_sequence("endsequence");
795     }
796     end_sequence =  ENDSEQUENCE_WAITING;
797   } else {
798     msg_warning("Unknown sequence '" << sequencename << "'");
799   }
800 }
801
802 /* (Status): */
803 void
804 GameSession::drawstatus(DrawingContext& context)
805 {
806   player_status->draw(context);
807
808   if(config->show_fps) {
809     char str[60];
810     snprintf(str, sizeof(str), "%3.1f", fps_fps);
811     const char* fpstext = "FPS";
812     context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
813     context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1);
814   }
815 }
816