--- /dev/null
+// $Id: worldmap.cpp 3209 2006-04-02 22:19:22Z sommer $
+//
+// SuperTux - Console
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include <config.h>
+#include <iostream>
+#include "console.hpp"
+#include "video/drawing_context.hpp"
+#include "video/surface.hpp"
+#include "player_status.hpp"
+#include "main.hpp"
+#include "resources.hpp"
+
+namespace {
+ int ticks; // TODO: use a clock?
+}
+
+Console::Console(DrawingContext* context) : context(context)
+{
+ background = new Surface("images/engine/console.jpg");
+}
+
+Console::~Console()
+{
+ delete background;
+}
+
+void
+Console::flush()
+{
+ lines.push_front(outputBuffer.str());
+ if (lines.size() >= 256) lines.pop_back();
+ if (height < 64) {
+ if (height < 4) height=4;
+ height+=9;
+ }
+ ticks=120;
+ std::cerr << outputBuffer.str() << std::flush;
+ outputBuffer.str(std::string());
+}
+
+void
+Console::draw()
+{
+ if (height == 0) return;
+ if (ticks-- < 0) {
+ height-=1;
+ ticks=0;
+ if (height < 0) height=0;
+ }
+ if (height == 0) return;
+
+ context->draw_surface(background, Vector(SCREEN_WIDTH/2 - background->get_width()/2, height - background->get_height()), LAYER_FOREGROUND1+1);
+
+ int lineNo = 0;
+ for (std::list<std::string>::iterator i = lines.begin(); i != lines.end(); i++) {
+ lineNo++;
+ float py = height-4-lineNo*9;
+ if (py < -9) break;
+ context->draw_text(white_small_text, *i, Vector(BORDER_X, py), LEFT_ALLIGN, LAYER_FOREGROUND1+1);
+ }
+}
+
+int Console::height = 0;
+std::list<std::string> Console::lines;
+ConsoleStreamBuffer Console::outputBuffer;
+std::ostream Console::output(&Console::outputBuffer);
+
--- /dev/null
+// $Id: worldmap.hpp 3209 2006-04-02 22:19:22Z sommer $
+//
+// SuperTux - Console
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef SUPERTUX_CONSOLE_H
+#define SUPERTUX_CONSOLE_H
+
+#include <list>
+#include <string>
+#include <sstream>
+#include <iostream>
+
+class Console;
+class ConsoleStreamBuffer;
+class DrawingContext;
+class Surface;
+
+class Console
+{
+ public:
+ Console(DrawingContext* context);
+ ~Console();
+
+ static std::ostream output;
+
+ static void flush();
+
+ void draw();
+
+ protected:
+ static std::list<std::string> lines;
+ DrawingContext* context;
+ Surface* background;
+ static int height;
+
+ static ConsoleStreamBuffer outputBuffer;
+};
+
+class ConsoleStreamBuffer : public std::stringbuf
+{
+ public:
+ int sync()
+ {
+ Console::flush();
+ return std::stringbuf::sync();
+ }
+};
+
+#endif
+
+
fps_fps = 0;
context = new DrawingContext();
+ console = new Console(context);
restart_level();
}
delete end_sequence_controller;
delete level;
delete context;
+ delete console;
current_ = NULL;
}
if(best_level_statistics != NULL)
best_level_statistics->draw_message_info(context, _("Best Level Statistics"));
+ console->draw();
context.do_drawing();
wait_for_event(1.0, 3.0);
Menu::current()->draw(*context);
}
+ console->draw();
context->do_drawing();
}
sprintf(str, _("COINS: %d"), player_status->coins);
context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2, 224), CENTER_ALLIGN, LAYER_FOREGROUND1);
+ console->draw();
context.do_drawing();
wait_for_event(2.0, 5.0);
#include "timer.hpp"
#include "statistics.hpp"
#include "math/vector.hpp"
+#include "console.hpp"
/* GameLoop modes */
enum GameSessionMode {
std::string capture_file;
std::istream* playback_demo_stream;
CodeController* demo_controller;
+ Console* console;
};
std::string slotinfo(int slot);
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-#ifndef __SUPERTUX_DEBUG_H__
-#define __SUPERTUX_DEBUG_H__
+#ifndef __SUPERTUX_MSG_H__
+#define __SUPERTUX_MSG_H__
#include <iostream>
#include <stdio.h>
+#include "console.hpp"
+
+// TODO: make macros more C++ish?
+
#ifdef DEBUG
-#define msg_debug(message) std::cerr << "[DEBUG] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl
-#define msg_info(message) std::cout << "[INFO] " << message << std::endl
-#define msg_warning(message) std::cerr << "[WARNING] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl
-#define msg_fatal(message) std::cerr << "[FATAL] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl
+#define msg_debug(message) Console::output << "[DEBUG] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl
+#define msg_info(message) Console::output << "[INFO] " << message << std::endl
+#define msg_warning(message) Console::output << "[WARNING] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl
+#define msg_fatal(message) Console::output << "[FATAL] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl
#else
#define msg_debug(message)
-#define msg_info(message) std::cout << message << std::endl
-#define msg_warning(message) std::cerr << "Warning: " << message << std::endl
-#define msg_fatal(message) std::cerr << "Fatal: " << message << std::endl
+#define msg_info(message) Console::output << message << std::endl
+#define msg_warning(message) Console::output << "Warning: " << message << std::endl
+#define msg_fatal(message) Console::output << "Fatal: " << message << std::endl
#endif
#include "main.hpp"
#include "exceptions.hpp"
#include "msg.hpp"
+#include "console.hpp"
static Surface* bkg_title;
static Surface* logo;
static LevelSubset* current_contrib_subset = 0;
static int current_subset = -1;
+static Console* console;
+
/* If the demo was stopped - because game started, level
editor was excuted, etc - call this when you get back
to the title code.
Menu::set_current(main_menu);
DrawingContext& context = *titlesession->context;
+
+ console = new Console(&context);
+
bool running = true;
while (running)
{
Menu::set_current(main_menu);
}
+ console->draw();
+
context.do_drawing();
sound_manager->update();
delete titlesession;
delete bkg_title;
delete logo;
+ delete console;
//delete img_choose_subset;
}
Uint32 lastticks = SDL_GetTicks();
DrawingContext context;
+ Console* console = new Console(&context);
while(!quit) {
Uint32 ticks = SDL_GetTicks();
float elapsed_time = float(ticks - lastticks) / 1000;
Menu::current()->draw(context);
}
+ console->draw();
context.do_drawing();
}
+
+ delete console;
}
void
#include "timer.hpp"
#include "tile_manager.hpp"
#include "game_object.hpp"
+#include "console.hpp"
class Sprite;
class Menu;
TileMap* solids;
TileManager* tile_manager;
+
+ Console* console;
public:
struct SpecialTile