pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src Debug.cc,NONE,1.1 Debug.hh,NONE,1.1 P


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src Debug.cc,NONE,1.1 Debug.hh,NONE,1.1 PingusStream.cc,NONE,1.1 PingusStream.hh,NONE,1.1 Console.cc,1.19,1.20 Makefile.am,1.73,1.74 PingusMain.cc,1.59,1.60 PingusMenu.cc,1.54,1.55
Date: 5 Jun 2002 17:51:10 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv17391

Modified Files:
        Console.cc Makefile.am PingusMain.cc PingusMenu.cc 
Added Files:
        Debug.cc Debug.hh PingusStream.cc PingusStream.hh 
Log Message:
added some multiplexing custom streams with prefix

--- NEW FILE: Debug.cc ---
//  $Id: Debug.cc,v 1.1 2002/06/05 17:51:08 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  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 "Debug.hh"

/* Stream for error messages */
MultiplexStream perr("[Error] ");

/* Stream for warnings */
MultiplexStream pwarn("[Warning] ");

/* For everything else (temporary stuff only) */
MultiplexStream pout ("[Output] ");

/* EOF */

--- NEW FILE: Debug.hh ---
//  $Id: Debug.hh,v 1.1 2002/06/05 17:51:08 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  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 DEBUG_HH
#define DEBUG_HH

#include "PingusStream.hh"

/* Stream for error messages */
extern MultiplexStream perr;

/* Stream for warnings */
extern MultiplexStream pwarn;

/* Stream for warnings */
extern MultiplexStream pout;

#endif

/* EOF */

--- NEW FILE: PingusStream.cc ---
//  $Id: PingusStream.cc,v 1.1 2002/06/05 17:51:08 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  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 "PingusStream.hh"

const int MultiplexStreamBuffer::buffersize = 200;

MultiplexStreamBuffer::MultiplexStreamBuffer (const std::string& p)
  : prefix (p)
{
  // Set the output buffer
  setp (char_buffer, char_buffer + buffersize - 1);

  // Switch of input buffer
  setg(0, 0, 0);
}

MultiplexStreamBuffer::~MultiplexStreamBuffer ()
{
  sync ();
}

int
MultiplexStreamBuffer::overflow (int c)
{
  std::string str;
    
  for (char* ptr = pbase (); ptr != pptr (); ++ptr)
    {
      str += *ptr;
      
      if (*ptr == '\n') 
        {
          put_line (prefix + str);
          str = "";
        }
    }
  str += c;
  put_line (str);
    
  setp (char_buffer, char_buffer + buffersize - 1);
  return 0;
}

void
MultiplexStreamBuffer::put_line (const std::string& line)
{
  if (!out_streams.empty ())
    {
      for (std::vector<std::ostream*>::iterator i = out_streams.begin ();
           i != out_streams.end (); ++i)
        {
          *(*i) << line;
        }
    }
  else
    {
      std::cout << "[MultiplexStreamBuffer fallback stream] " << line;
    }
}

int
MultiplexStreamBuffer::sync ()
{
  std::string str;
    
  // Walk through the buffer 
  for (char* c = pbase (); c != pptr (); ++c)
    {
        str += *c;

      if (*c == '\n') 
        {
          put_line (prefix + str);
          str = "";
        }
    }
    
  if (!str.empty ()) // Why to we check this?
    {
      put_line (str);
    }

  setp (char_buffer, char_buffer + buffersize - 1);
  return 0;
}

void
MultiplexStreamBuffer::add (std::ostream& s)
{
  out_streams.push_back (&s);
}

MultiplexStream::MultiplexStream (const std::string& prefix)
  : std::ostream (&buffer),
    buffer (prefix)
{
}

MultiplexStream::~MultiplexStream ()
{
}

void
MultiplexStream::add (std::ostream& s)
{
  buffer.add (s);
}

/* EOF */

--- NEW FILE: PingusStream.hh ---
//  $Id: PingusStream.hh,v 1.1 2002/06/05 17:51:08 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  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 PINGUSSTREAM_HH
#define PINGUSSTREAM_HH

#include <string>
#include <vector>
#include <iostream>

class MultiplexStreamBuffer
  : public std::streambuf
{
private:
  static const int buffersize;

  std::vector<std::ostream*> out_streams;

  std::string current_line;
  bool continue_last;
  std::vector<std::string> buffer;
  char char_buffer[200];
  
  std::string prefix;

  void put_line (const std::string& line);
public:
  MultiplexStreamBuffer (const std::string& prefix);
  virtual ~MultiplexStreamBuffer ();

  int overflow (int c);  
  int sync ();

  void add (std::ostream& s);
};

class MultiplexStream
  : public std::ostream
{
private:
  MultiplexStreamBuffer buffer;
  
public:
  MultiplexStream (const std::string& prefix);
  virtual ~MultiplexStream ();

  void add (std::ostream& s);
};

#endif

/* EOF */

Index: Console.cc
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Console.cc,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- Console.cc  4 Jun 2002 08:35:30 -0000       1.19
+++ Console.cc  5 Jun 2002 17:51:08 -0000       1.20
@@ -35,7 +35,7 @@
   // Set the output buffer
   setp (char_buffer, char_buffer + CONSOLE_BUFFER_SIZE - 1);
   
-    // Switch of input buffer
+  // Switch of input buffer
   setg(0, 0, 0);
 }
   

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- Makefile.am 2 Jun 2002 21:09:11 -0000       1.73
+++ Makefile.am 5 Jun 2002 17:51:08 -0000       1.74
@@ -200,6 +200,8 @@
                  WorldObjDataFactory.cc  WorldObjDataFactory.hh \
                  EditorHotspot.hh \
                  PinguActionFactory.cc PinguActionFactory.hh \
-                 USBMouseController.hh USBMouseController.cc
+                 USBMouseController.hh USBMouseController.cc \
+                 PingusStream.hh     PingusStream.cc \
+                 Debug.cc            Debug.hh
 
 ## EOF ##

Index: PingusMain.cc
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/PingusMain.cc,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- PingusMain.cc       4 Jun 2002 08:35:30 -0000       1.59
+++ PingusMain.cc       5 Jun 2002 17:51:08 -0000       1.60
@@ -71,6 +71,7 @@
 #include "PingusMessageBox.hh"
 #include "audio.hh"
 #include "PingusGameSession.hh"
+#include "Debug.hh"
 #include "editor/Editor.hh"
 
 #include "PingusMenuManager.hh"
@@ -614,6 +615,13 @@
 
   fps_counter.init();
   console.init();
+
+  pout.add (std::cerr);
+  pout.add (console);
+  pwarn.add (std::cerr);
+  pout.add (console);
+  perr.add (std::cerr);
+  perr.add (console);
 }
 
 // Get all filenames and directories
@@ -790,7 +798,7 @@
 PingusMain::start_game(void)
 {
   if (verbose) {
-    std::cout << _("PingusMain: Starting Main: ") << CL_System::get_time() << 
std::endl;
+    pout << _("PingusMain: Starting Main: ") << CL_System::get_time() << 
std::endl;
   }
 
   if (print_fps)
@@ -814,7 +822,7 @@
            levelfile = "levels/" + levelfile + ".xml";
          else
            {
-             std::cout << _("PingusMain: Levelfile not found, ignoring: ") << 
levelfile << std::endl;
+             pout << _("PingusMain: Levelfile not found, ignoring: ") << 
levelfile << std::endl;
              successfull = false;
            }
        }
@@ -857,8 +865,8 @@
   signal(SIGINT,  signal_handler);
 
 #ifdef WIN32
-  CL_ConsoleWindow console(PACKAGE VERSION);
-  console.redirect_stdio();
+  CL_ConsoleWindow cl_console(PACKAGE VERSION);
+  cl_console.redirect_stdio();
 #endif
 
   executable_name = argv[0];

Index: PingusMenu.cc
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/PingusMenu.cc,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- PingusMenu.cc       1 Jun 2002 18:05:35 -0000       1.54
+++ PingusMenu.cc       5 Jun 2002 17:51:08 -0000       1.55
@@ -30,6 +30,7 @@
 #include "Loading.hh"
 #include "Display.hh"
 #include "PingusSound.hh"
+#include "Debug.hh"
 #include "blitter.hh"
 
 PingusMenu::PingusMenu(PingusMenuManager* m)
@@ -43,7 +44,7 @@
 {
   if (!is_init)
     {
-      std::cout << "PingusMenu::init ()" << std::endl;
+      pout << "PingusMenu::init ()" << std::endl;
       event_enabled = true;
       is_init = true;
       boost::shared_ptr<SurfaceButton> editor_button (new EditorButton (this));
@@ -91,7 +92,7 @@
 PingusMenu::on_button_press(CL_InputDevice *device, const CL_Key &key)
 {
   if (!event_enabled) return;
-  std::cout << "Buttonpress: " << event_enabled << std::endl;
+  pout << "Buttonpress: " << event_enabled << std::endl;
 
   draw();
   
@@ -109,7 +110,7 @@
          }
          break;
        default:
-         std::cout << "PingusMenu: Unknown key pressed:" << key.ascii << 
std::endl;
+         pout << "PingusMenu: Unknown key pressed:" << key.ascii << std::endl;
        }
     }
 }
@@ -118,7 +119,7 @@
 PingusMenu::on_button_release(CL_InputDevice *device, const CL_Key &key)
 {
   if (!event_enabled) return;
-  std::cout << "Buttonrel: " << event_enabled << std::endl;
+  pout << "Buttonrel: " << event_enabled << std::endl;
   
   draw();
 
@@ -131,13 +132,13 @@
        case CL_KEY_F:
          break;
        default:
-         if (verbose) std::cout << "PingusMenu::Event: Unknown key pressed: " 
<< key.id << std::endl;
+         if (verbose) pout << "PingusMenu::Event: Unknown key pressed: " << 
key.id << std::endl;
          break;
        }
     }
   else if (device == CL_Input::pointers[0])
     {
-      if (verbose) std::cout << "PingusMenu::Event: on_button_press" << 
std::endl;
+      if (verbose) pout << "PingusMenu::Event: on_button_press" << std::endl;
 
       for(std::list<boost::shared_ptr<SurfaceButton> >::iterator i = 
buttons.begin(); 
          i != buttons.end(); 
@@ -159,7 +160,7 @@
 void
 PingusMenu::on_resize(int w, int h)
 {
-  std::cout << "Width: " << w << " Height: " << h << std::endl;
+  pout << "Width: " << w << " Height: " << h << std::endl;
 }
 
 /* EOF */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]