pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3851 - in trunk/pingus: . src src/components src/input


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3851 - in trunk/pingus: . src src/components src/input
Date: Thu, 17 Jul 2008 12:52:47 +0200

Author: grumbel
Date: 2008-07-17 12:52:41 +0200 (Thu, 17 Jul 2008)
New Revision: 3851

Removed:
   trunk/pingus/src/config.cpp
   trunk/pingus/src/config.hpp
Modified:
   trunk/pingus/SConstruct
   trunk/pingus/src/components/playfield.cpp
   trunk/pingus/src/config_manager.cpp
   trunk/pingus/src/globals.cpp
   trunk/pingus/src/globals.hpp
   trunk/pingus/src/input/core_driver.cpp
   trunk/pingus/src/input/usbmouse_driver.cpp
   trunk/pingus/src/pingus_main.cpp
Log:
Removed screen_width/height variables
Removed Config file class, will be replaced with something sexpr based

Modified: trunk/pingus/SConstruct
===================================================================
--- trunk/pingus/SConstruct     2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/SConstruct     2008-07-17 10:52:41 UTC (rev 3851)
@@ -63,7 +63,6 @@
 'src/components/playfield.cpp', 
 'src/components/smallmap.cpp', 
 'src/components/time_display.cpp', 
-'src/config.cpp', 
 'src/credits.cpp', 
 'src/debug.cpp', 
 'src/debug_stream.cpp', 

Modified: trunk/pingus/src/components/playfield.cpp
===================================================================
--- trunk/pingus/src/components/playfield.cpp   2008-07-17 10:02:16 UTC (rev 
3850)
+++ trunk/pingus/src/components/playfield.cpp   2008-07-17 10:52:41 UTC (rev 
3851)
@@ -138,9 +138,7 @@
 
   if (auto_scrolling && (fullscreen_enabled || 
SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON))
     {
-      // FIXME: May need to modify this function if it's not gradient enough.
-      scroll_speed = static_cast<int>(default_screen_width * delta);
-      //std::cout << "scroll_speed: " << scroll_speed << std::endl;
+      scroll_speed = static_cast<int>(800 * delta);
     
       if (mouse_pos.x < 10)
        {

Deleted: trunk/pingus/src/config.cpp
===================================================================
--- trunk/pingus/src/config.cpp 2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/src/config.cpp 2008-07-17 10:52:41 UTC (rev 3851)
@@ -1,396 +0,0 @@
-//  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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include <stdio.h>
-#include <iostream>
-
-#include "globals.hpp"
-#include "pingus_error.hpp"
-#include "config.hpp"
-#include "system.hpp"
-#include "gettext.h"
-
-
-struct ConfigParserEOF {};
-
-// Create a PLF object and start parsing the given file
-ConfigParser::ConfigParser()
-{
-}
-
-// Destroy all data
-ConfigParser::~ConfigParser()
-{
-}
-
-void
-ConfigParser::init(std::string filename)
-{
-  // Init local vars
-  last_atom = ' ';
-  lineno = 1;
-
-  try {
-    // Start parsing
-    if (System::exist(filename))
-      {
-        open(filename);
-        parse();
-      }
-  }
-
-  catch (PingusError& err) {
-    std::cout << err.get_message () << std::endl;
-  }
-}
-
-// Open the file and do some error checking.
-void
-ConfigParser::open(std::string filename)
-{
-  in.open(filename.c_str());
-  eof = false;
-
-  if (!in)
-    PingusError::raise(_("Couldn't open: ") + filename);
-
-  if (verbose > 1)
-    std::cout << "Successfully opened plf file." << std::endl;
-}
-
-// Return the next char from file and check for eof.
-char
-ConfigParser::get_char(void)
-{
-  int c;
-
-  if (eof) {
-    if (verbose > 1) std::cout << "ConfigParser: Result of get_char() will be 
undefined" << std::endl;
-    PingusError::raise("");
-  }
-
-  c = in.get();
-
-  if (c == EOF) {
-    if (verbose > 1) std::cout << "PLF::get_char(): Found EOF!" << std::endl;
-    eof = true;
-    throw ConfigParserEOF();
-  }
-
-  if (c == '\n')
-    ++lineno;
-
-  return c;
-}
-
-// Return the next char from file, remove all comments and spaces before.
-char
-ConfigParser::get_raw_atom(void)
-{
-  char c;
-  char temp_c;
-  c = get_char();
-
-  if (c == '#')
-    {
-      while(get_char() != '\n'); // Ignoring until EOL
-
-      if (eof)
-       return ' ';
-
-      return get_atom();
-    }
-
-  if (isspace(c))
-    {
-      temp_c = c;
-      while (isspace(c = get_char()));
-      in.putback(c);
-      if (isspace(last_atom))
-       return get_atom();
-      return temp_c;
-    }
-
-  return c;
-}
-
-// Return the next atom and keep it.
-char
-ConfigParser::get_atom(void)
-{
-  last_atom = get_raw_atom();
-
-  return last_atom;
-}
-
-// Return the name of the value identiver.
-std::string
-ConfigParser::get_valueid(void)
-{
-  std::string ret_val;
-  char   atom;
-
-  jump();
-
-  while(true)
-    {
-      atom = get_atom();
-
-      if (isgraph(atom) && atom != '=')
-       {
-         ret_val += atom;
-       }
-      else if (isspace(atom))
-       {
-         return ret_val;
-       }
-      else if (atom == '=')
-       {
-         in.putback(atom);
-         return ret_val;
-       }
-      else
-       {
-         syntax_error(std::string(_("Unexpected char: '")) + atom + "'");
-       }
-    }
-
-  return ret_val;
-}
-
-std::string
-ConfigParser::get_value(void)
-{
-  std::string ret_val;
-  char   atom;
-
-  jump();
-
-  while(true) {
-    atom = get_atom();
-
-    if (atom == '"' && ret_val == "") {
-      while((atom = get_char()) != '"') {
-       ret_val += atom;
-      }
-      return ret_val;
-    }
-
-    if (atom == ';') {
-      in.putback(atom);
-      return ret_val;
-    }
-
-    if (!isalnum(atom) && atom != '-' && atom != '_') {
-      if (isspace(atom)){
-       return ret_val;
-      } else {
-        syntax_error(std::string(_("Unexpected char: '")) + atom + "'");
-      }
-    }
-
-    ret_val += atom;
-  }
-
-  return ret_val;
-}
-
-// Jumps to the position of the next token after 'a', no other char's
-// then spaces are allowed before 'a'.
-void
-ConfigParser::jump_after(char c)
-{
-  char atom;
-
-  jump();
-
-  atom = get_atom();
-  if (isspace(atom) || atom == c)
-    {
-      if (atom == c) {
-       return;
-      } else {
-       atom = get_atom();
-       if (atom == c)
-         return;
-      }
-    }
-  syntax_error(std::string("jump_after(): Expected '") + c + "', got '" + atom 
+ "'" );
-}
-
-void
-ConfigParser::jump(void)
-{
-  char atom;
-  atom = get_atom();
-
-  if (isspace(atom)) {
-    return;
-  } else {
-    in.putback(atom);
-  }
-}
-
-// Print a error message with lineno and filename.
-void
-ConfigParser::syntax_error(std::string error = "")
-{
-  std::string error_str;
-  char tmp[16];
-
-  snprintf(tmp, 16, "%d\n", lineno);
-
-  error_str = std::string("PLF: Syntax Error at line ") + tmp;
-
-  if (error != "")
-    error_str += "PLF:" + error + "\n";
-
-  PingusError::raise(error_str);
-}
-
-// Parse the file and fill all structs with the values.
-void
-ConfigParser::parse(void)
-{
-  std::string valueid;
-  std::string value;
-
-  try
-    {
-      while(!eof)
-       {
-         valueid = get_valueid();
-         jump_after('=');
-         value   = get_value();
-         jump_after(';');
-         set_value(valueid, value);
-       }
-    }
-  catch (ConfigParserEOF)
-       {
-       }
-}
-
-Config::Config()
-{
-
-}
-
-Config::Config(std::string f)
-{
-  filename = f;
-  init(filename);
-}
-
-void
-Config::set_value(const std::string& valueid, const std::string& value)
-{
-  if (valueid == "fullscreen")
-    {
-      fullscreen_enabled = str_to_bool(value);
-    }
-  else if (valueid == "tile-size")
-    {
-      tile_size = str_to_int(value);
-    }
-  else if (valueid == "game-speed")
-    {
-      game_speed = str_to_int(value);
-    }
-  else if (valueid == "print-fps")
-    {
-      print_fps = str_to_bool(value);
-    }
-  else if (valueid == "maintainer-mode")
-    {
-      maintainer_mode = str_to_bool(value);
-    }
-  else if (valueid == "auto-scrolling")
-    {
-      auto_scrolling = str_to_bool(value);
-    }
-  else if (valueid == "verbose")
-    {
-      verbose = str_to_int(value);
-    }
-  else if (valueid == "width")
-    {
-      screen_width = str_to_int(value);
-    }
-  else if (valueid == "height")
-    {
-      screen_height = str_to_int(value);
-    }
-  else if (valueid == "sound")
-    {
-      sound_enabled = str_to_bool(value);
-    }
-  else if (valueid == "music")
-    {
-      music_enabled = str_to_bool(value);
-    }
-  else if (valueid == "swcursor-enabled")
-    {
-      swcursor_enabled = str_to_bool(value);
-    }
-  else if (valueid == "username")
-    {
-      global_username = valueid;
-    }
-  else if (valueid == "email")
-    {
-      global_email = valueid;
-    }
-  else
-    {
-      PingusError::raise("Config: Unknown valueid: " + valueid);
-    }
-}
-
-bool
-Config::str_to_bool(const std::string& str)
-{
-  if (str == "true" || str == "1")
-    {
-      return true;
-    }
-  else if (str == "false" || str == "0")
-    {
-      return false;
-    }
-  else
-    {
-      PingusError::raise("Config: value: " + str + " is not of type bool.");
-    }
-
-  return false; // never reached
-}
-
-int
-Config::str_to_int(const std::string& str)
-{
-  int ret_val;
-
-  if (sscanf(str.c_str(), "%d", &ret_val) != 1)
-    {
-      PingusError::raise("Config: Couldn't convert std::string to integer: " + 
str);
-    }
-
-  return ret_val;
-}
-
-/* EOF */
-

Deleted: trunk/pingus/src/config.hpp
===================================================================
--- trunk/pingus/src/config.hpp 2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/src/config.hpp 2008-07-17 10:52:41 UTC (rev 3851)
@@ -1,90 +0,0 @@
-//  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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_CONFIG_HPP
-#define HEADER_PINGUS_CONFIG_HPP
-
-#include "pingus.hpp"
-#include <string>
-#include <fstream>
-
-
-/** FIXME: Rewrite or replace me */
-class ConfigParser
-{
-private:
-
-  ///
-  std::ifstream in;            /// The file to parse
-
-  char   last_atom;            /// The last returned atom
-  int    lineno;               /// Current line number
-  bool   eof;
-  //  std::string filename;             // The name of the current file
-
-  /// private functions
-  char   get_char(void);       /// Return the next char and to a eof check
-  char   get_atom(void);       /// Return the next atom and keep the old one
-  char   get_raw_atom(void);   /// Return the next atom (removes all comments)
-  std::string get_valueid(void);    /// Return the value identifer
-  std::string get_value(void);      /// Return the value
-  void   jump_after(char);     /// Jump to the next token, after char
-  void   jump(void);           /// Jump over spaces to the next token
-  void   syntax_error(std::string); /// Do a clean shutdown on a syntax error
-  void   parse(void);          /// Parse the opened file
-  void   open(std::string);          // Open the file
-
-  // Some virtual functions
-  /// Put the retrieved value in the correct struct
-  virtual void set_value(const std::string& valueid, const std::string& value) 
= 0;
-
-public:
-  ///
-  ConfigParser();
-  ///
-  ConfigParser(std::string);         /// Open the file and parse it
-  virtual ~ConfigParser();      /// Close the file
-
-  void init(std::string);
-
-private:
-  ConfigParser (const ConfigParser&);
-  ConfigParser& operator= (const ConfigParser&);
-};
-
-class Config : public ConfigParser
-{
-private:
-  std::string filename;
-
-  bool str_to_bool(const std::string&);
-  int  str_to_int(const std::string&);
-
-public:
-  Config ();
-  Config (std::string);
-
-  void set_value(const std::string& valueid, const std::string& value);
-
-private:
-  Config (const Config&);
-  Config& operator= (const Config&);
-};
-
-
-#endif
-
-/* EOF */

Modified: trunk/pingus/src/config_manager.cpp
===================================================================
--- trunk/pingus/src/config_manager.cpp 2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/src/config_manager.cpp 2008-07-17 10:52:41 UTC (rev 3851)
@@ -79,9 +79,7 @@
 
   if (size != get_resolution())
     {
-      screen_width  = size.width;
-      screen_height = size.height;
-      Display::set_video_mode(Size(screen_width, screen_height), 
fullscreen_enabled);
+      Display::set_video_mode(size, fullscreen_enabled);
       on_resolution_change(size);
     }
 }

Modified: trunk/pingus/src/globals.cpp
===================================================================
--- trunk/pingus/src/globals.cpp        2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/src/globals.cpp        2008-07-17 10:52:41 UTC (rev 3851)
@@ -31,8 +31,6 @@
 
 int         default_screen_width            = 800;
 int         default_screen_height           = 600;
-int         screen_width                    = default_screen_width;
-int         screen_height                   = default_screen_height;
 bool        draw_collision_map              = false;
 bool        swcursor_enabled                = false;
 

Modified: trunk/pingus/src/globals.hpp
===================================================================
--- trunk/pingus/src/globals.hpp        2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/src/globals.hpp        2008-07-17 10:52:41 UTC (rev 3851)
@@ -42,8 +42,6 @@
 extern bool        delta_drawing;                   ///< --delta-drawing
 extern int         default_screen_width;            ///< default screen width
 extern int         default_screen_height;           ///< default screen height
-extern int         screen_width;                    ///< user configured 
screen width
-extern int         screen_height;                   ///< user configured 
screen height
 extern bool        draw_collision_map;              ///<
 extern bool        swcursor_enabled;                ///< --enable-swcursor
 

Modified: trunk/pingus/src/input/core_driver.cpp
===================================================================
--- trunk/pingus/src/input/core_driver.cpp      2008-07-17 10:02:16 UTC (rev 
3850)
+++ trunk/pingus/src/input/core_driver.cpp      2008-07-17 10:52:41 UTC (rev 
3851)
@@ -17,6 +17,7 @@
 #include "math.hpp"
 #include "manager.hpp"
 #include "core_driver.hpp"
+#include "../display/display.hpp"
 #include "globals.hpp"
 
 namespace Input {
@@ -71,8 +72,8 @@
     new_pos.y += y_axis->get_pos() * c_speed * delta;
 
     // FIXME: shouldn't depend on Display
-    new_pos.x = Math::clamp(0.0f, new_pos.x, 
static_cast<float>(default_screen_width));
-    new_pos.y = Math::clamp(0.0f, new_pos.y, 
static_cast<float>(default_screen_height));
+    new_pos.x = Math::clamp(0.0f, new_pos.x, 
static_cast<float>(Display::get_width()));
+    new_pos.y = Math::clamp(0.0f, new_pos.y, 
static_cast<float>(Display::get_height()));
 
     if (new_pos != pos)
       {

Modified: trunk/pingus/src/input/usbmouse_driver.cpp
===================================================================
--- trunk/pingus/src/input/usbmouse_driver.cpp  2008-07-17 10:02:16 UTC (rev 
3850)
+++ trunk/pingus/src/input/usbmouse_driver.cpp  2008-07-17 10:52:41 UTC (rev 
3851)
@@ -26,6 +26,7 @@
 #include "globals.hpp"
 #include "math/vector2i.hpp"
 #include "usbmouse_driver.hpp"
+#include "../display/display.hpp"
 
 namespace Input {
 
@@ -110,13 +111,13 @@
 
             if (mouse_pos.x < 0) 
               mouse_pos.x = 0;
-            else if (mouse_pos.x > default_screen_width)
-              mouse_pos.x = default_screen_width - 1;
+            else if (mouse_pos.x >= Display::get_width())
+              mouse_pos.x = Display::get_width() - 1;
 
             if (mouse_pos.y < 0) 
               mouse_pos.y = 0;
-            else if (mouse_pos.y > default_screen_height)
-              mouse_pos.y = default_screen_height - 1;
+            else if (mouse_pos.y >= Display::get_height())
+              mouse_pos.y = Display::get_height() - 1;
 
             for(std::vector<Pointer*>::iterator i = pointer_bindings.begin(); 
i != pointer_bindings.end(); ++i)
               (*i)->set_pos(mouse_pos);

Modified: trunk/pingus/src/pingus_main.cpp
===================================================================
--- trunk/pingus/src/pingus_main.cpp    2008-07-17 10:02:16 UTC (rev 3850)
+++ trunk/pingus/src/pingus_main.cpp    2008-07-17 10:52:41 UTC (rev 3851)
@@ -27,6 +27,7 @@
 #include "demo_session.hpp"
 #include "sexpr_file_reader.hpp"
 #include "fonts.hpp"
+#include "config_manager.hpp"
 #include "display/display.hpp"
 #include "pingus_menu.hpp"
 
@@ -61,7 +62,6 @@
 #include "globals.hpp"
 #include "system.hpp"
 #include "pingus_error.hpp"
-#include "config.hpp"
 #include "fps_counter.hpp"
 #include "plf_res_mgr.hpp"
 #include "game_session.hpp"
@@ -154,7 +154,7 @@
        rcfile = cmd_options.config_file.get();
 
       //constructor of config must be run
-      Config config(rcfile);
+      //FIXME: Config config(rcfile);
     }
 }
 
@@ -187,10 +187,7 @@
     swcursor_enabled = options.swcursor.get();
 
   if (options.geometry.is_set())
-    {
-      screen_width  = options.geometry.get().width;
-      screen_height = options.geometry.get().height;
-    }
+    config_manager.set_resolution(options.geometry.get());
 
   // Sound
   if (options.disable_music.is_set())
@@ -594,7 +591,9 @@
   else
     std::cout << "music support:          disabled" << std::endl;
 
-  std::cout << "resolution:              " << screen_width << "x" << 
screen_height << std::endl;
+  std::cout << "resolution:              " 
+            << config_manager.get_resolution().width << "x"
+            << config_manager.get_resolution().height << std::endl;
   std::cout << "fullscreen:              "
             << (fullscreen_enabled ? " enabled" : "disabled")
             << std::endl;
@@ -731,7 +730,7 @@
     exit(1);
   }
   atexit(SDL_Quit); 
-  Display::set_video_mode(Size(screen_width, screen_height), 
fullscreen_enabled);
+  Display::set_video_mode(config_manager.get_resolution(), fullscreen_enabled);
 
   SDL_WM_SetCaption("Pingus " VERSION " - SDL Edition", 0 /* icon */);
 





reply via email to

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